|
Hello,
First, excuse my bad english (it's not my native language, I'm French).
Then, I'm a studient and I have to create a programm which could hide/unhide any icons in the systray (even extern processes' icons) in VB or in C/C++. Do you know a way to do it?
|
|
|
|
|
:(How to enumerate the icons in the Systray???And How to Get the programe who founds the button in systray? for instance,sound Icon and its button,who founds them??? how to get?
|
|
|
|
|
I can suggest one more approach (not perfect, but worth considering, I think).
Having found the tray window you can send WM_MOUSEMOVE to it with different coordinates trying to guess the icon location. As soon the message is forwarded to your application (wrapped in the message specified when calling Shell_NotifyIcon) you have found it.
Regards,
Sergei.
|
|
|
|
|
|
Oops! Sorry, somehow I have missed that part.
|
|
|
|
|
Thanks to the article,I acquired some knowledges from this.but I have a problem:how to get the tip of the icon in the system tray, and how to get the index of the certain icon in the system tray?
|
|
|
|
|
if the taskbar is hided the arrow of the balloontip appears outside screen, and it should call the taskbar up, like any normal infotips displayed in the taskbar (eg. see how the XP SP2 security warning does). This ballon instead points to the outside of the screen and it's not painted entirely.
otherwise it's a great control.
|
|
|
|
|
I would like to force my tray icon to be always the first in tray.
How can I achieve that ?
|
|
|
|
|
you can modify a direct traking metchod to check if your icon is the first in the toolbar and when it's not - just remove it and then add again - It will land at the first position.
Check out my software at: http://www.ireksoftware.com
|
|
|
|
|
Sounds like a race condition if 2 apps starts doing this
- thomasa88
|
|
|
|
|
Does anyone know if there is an official mechanism (or have unofficial ideas;)) to keep a tray icon active so that Windows XP does not "hide" the inactive icon? I assume that by updating the icon periodically, I can keep it "active", but that seems inefficient.
Thanks,
Dave
|
|
|
|
|
If you use a custom dpi in your display settings, say 120 then the code will always fail because windows will scale the icon in the tray area.
|
|
|
|
|
Hmmm... my display settings are actually "big fonts" (120 dpi) and it seems to work perfect.
Scaling the icon is not a problem for this code since plain black icon scaled to be larger will also be a black icon.
Check out my software at: http://www.ireksoftware.com
|
|
|
|
|
That was the only reason i could come up with for it not working on my Win XP system. the only other variable is that I have the task bar at the top of the screen. Anyway I've worked out a way to do the same, without any image processing, See below.
The codes is in vb6 but you should be able to easily convert it. The call to GethWndTray (which gets the tray's toolbar control has been ommited for compactness.
Private Type TrayData
hWnd As Long
ID As Long
End Type
Public Function GetSystemTrayItemRect(ByVal hWnd As Long, ByVal ID As Long) As RECT
Dim hWndTray As Long
Dim hProc As Long
Dim pid As Long
Dim vaPtr As Long
Dim ret As Long
Dim tbut As TBBUTTON
Dim cButtons As Long
Dim td As TrayData
Dim i As Long
Dim rc As RECT
hWndTray = GethWndTray
If hWndTray = 0 Then Exit Function
Call GetWindowThreadProcessId(hWndTray, pid)
If pid = 0 Then Exit Function
hProc = OpenProcess(PROCESS_VM, 0, pid)
If hProc = 0 Then Exit Function
vaPtr = VirtualAllocEx(hProc, ByVal 0&, Len(tbut), MEM_COMMIT, PAGE_READWRITE)
If vaPtr = 0 Then GoTo cleanup
cButtons = SendMessage(hWndTray, TB_BUTTONCOUNT, ByVal 0&, ByVal 0&)
On Error GoTo cleanup
For i = 0 To cButtons - 1
Call SendMessage(hWndTray, TB_GETBUTTON, i, ByVal vaPtr)
Call ReadProcessMemory(hProc, ByVal vaPtr, tbut, Len(tbut), ret)
If Not tbut.dwData = 0 Then
Call ReadProcessMemory(hProc, ByVal tbut.dwData, td, Len(td), ret)
If hWnd = td.hWnd Then
If ID = td.ID Then
Call SendMessage(hWndTray, TB_GETITEMRECT, i, ByVal vaPtr)
Call ReadProcessMemory(hProc, ByVal vaPtr, rc, Len(rc), ret)
Exit For
End If
End If
End If
Next
Call MapWindowPoints(hWndTray, 0&, rc, 2)
GetSystemTrayItemRect = rc
cleanup:
If hProc Then
If vaPtr Then
Call VirtualFreeEx(hProc, ByVal vaPtr, 0&, MEM_RELEASE)
End If
End If
If hProc Then CloseHandle (hProc)
End Function
|
|
|
|
|
Hi
I have ported VB example you provided to C++ and it looks promising. The problem is that all you can retrive with this example it's rectangle of each button in a tray (cool!) and TBBUTTON structure. But TBBUTTON seems to be not enought to determinate witch one of the buttons belongs to our application. Especialy there is no HWND member and button ID member seems to have different values that this ID we specify while adding icon to the tray.
in VB code there is a piece of code:
If hWnd = td.hWnd Then<br />
If ID = td.ID Then
but in C++ definition of TBBUTTON of this structure there are no such members.
Anyone hve any idea how to solve it?
Best regars,
Irek
Check out my software at: http://www.ireksoftware.com
|
|
|
|
|
Copy the first 8 bytes of the dwData member of the TBBUTTON, using the ReadProcessMemory API as you did to get the TBBUTTON struct. The first 4 bytes is the hWnd the button belongs to. The second 4 bytes is the NOTIFYICONDATA.iUD.
Then using the index of the button you can then get the it's rect by calling TB_GETITEMRECT, again ReadProcessMemory is required. As seen in my earlier post.
There appear's to be alot more info in dwData but I just use the first 8.
Hope that helps.
Regards
Neal
|
|
|
|
|
|
VirtuaWin uses an icon with a lot of black,
this is sometimes seen as the icon we're looking for!
|
|
|
|
|
I recommend to change a bit code that detects an icon. Now code serches only few lines and test if it's black or near black. Adding more lines to search should help in this case.
Check out my software at: http://www.ireksoftware.com
|
|
|
|
|
CheckIfColorIsBlackOrNearBlack could be implemented like this:
BOOL CTrayIconPosition::CheckIfColorIsBlackOrNearBlack(COLORREF crColor)
{
return !(((DWORD)crColor)&0xFCFCFC);
}
and make it inline. code will become mutch faster (well not really a problem here)
or fastest would be to use it as define
#define CheckIfColorIsBlackOrNearBlack(crColor) (!(((DWORD)crColor)&0xFCFCFC))
Or a bit slower
BOOL CTrayIconPosition::CheckIfColorIsBlackOrNearBlack(COLORREF crColor)
{
return (GetRValue(crColor)<4) && (GetGValue(crColor)<4) && (GetBValue(crColor)<4);
}
BTW: nice idea to solve the problem!
What do you think of using an icon with a white border (2pix for 32*32 icon) and calculate the exact rectangle of the icon?
Harald
|
|
|
|
|
Hi
Thanks for the feed-back.
I have just submited an update to souce code with:
BOOL CTrayIconPosition::CheckIfColorIsBlackOrNearBlack(COLORREF crColor)
{
return !(((DWORD)crColor)&0xFCFCFC);
}
>What do you think of using an icon with a white border (2pix for 32*32 icon) and calculate the exact rectangle of the icon?
I think that this could fail since there is no proof that border will not be disrupted by Windows. But I was thinking on a different approach. First you put a plain black icon into the tray and detect all black points, then put a bit lighter icon (dark gray) and check previously black pixels if now those are dark gray - is should stil take a blink of eye and be able to detect an rectangle of icon with a great precision.... I don't plan to implement this feature but (since simple point detection is enought in my applicatins) but I would gladly update souce code if someone would do this
Best regards!
Irek
Check out my software at: http://www.ireksoftware.com
|
|
|
|
|
Add this:
TrayIconPosition.h
CRect m_rcLastTrayPos
TrayIconPosition.cpp
GetTrayIconPosition(CPoint &point, Precision prPrec)
{
...
if(m_rcLastTrayPos!=m_rtRectangleOfTheTray)
bUpdateRequired=1;
if(bUpdateRequired)
{
... m_rcLastTrayPos = m_rtRectangleOfTheTray;
|
|
|
|
|
This isn't good because the icon rect could move inside the tray rect
Instead we could track the mouse position from where the function gets called and see if fits the old icon rect. If not..scan for the new rect icon; at least this will lower the scan operations...especially on vista or later which requires visual scan only...that black icon.
|
|
|
|
|
re hello,
I have some mistake with my application. In the OnInitDialog function i do that( i have include CBalloonHelp):
NOTIFYICONDATA nid; <br />
nid.cbSize = sizeof(nid); <br />
nid.hWnd = m_hWnd; <br />
nid.uID = 1; <br />
nid.uFlags = NIF_ICON|NIF_TIP; <br />
Shell_NotifyIcon(NIM_ADD, &nid);<br />
<br />
m_tipPosition.InitializePositionTracking(m_hWnd,1);<br />
<br />
TraySetIcon(IDR_ICON2);<br />
sprintf(status,"Applicom = %d .Twincat = %d",Appli.GetStatusUnitel(),Appli.GetStatusTwin());<br />
TraySetToolTip(status);<br />
<br />
TraySetMenu(IDR_MENU1);<br />
TrayShow();
ShowWindow(SW_HIDE);
But when i call GetTrayIconPosition in CTrayIconPosition, it load a black icon. After what i refresh my icone in the OnTimer() like that:
sprintf(status,"Applicom = %s Twincat = %s",mot,mot2);<br />
TraySetToolTip(status);<br />
TrayUpdate();
Finaly, my problem is the menu is not attach to my icon and i have to restart my PC because Windows can't killed the thread.
Have you some ideas.
Thanks by advance.
|
|
|
|
|
re
it is like that:
sprintf(status,"Applicom = %s Twincat = %s",mot,mot2);<br />
TraySetToolTip(status);<br />
TraySetMenu(IDR_MENU1);<br />
TrayUpdate();
|
|
|
|