 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
ACoder Guest
|
Posted: Tue Jul 15, 2008 2:48 am Post subject: |
|
|
| Sean wrote: | | ACoder wrote: | how do i find out the UID for the program i have in mind?  | You can obtain uID of your application's trayicon using the following. Probably you need to run it only once as uID is pretty constant with many apps.
| Code: | | MsgBox % TrayIcons("myprogram.exe") |
|
Hmm... that didn't work for me. So we are talking about two different UNIQUE ID'S?
When I run this
| Code: |
DetectHiddenWindows, On
WinGet, hWnd,, myprogram
MsgBox, %hWnd%
|
I am getting back a UID for the process.... correct? But this isn't quite the same as the UID for the trayicon I am supposing?
When I run,
MsgBox % TrayIcons ("myprogram.exe")
I get back a blank var. Even though I am sure that is correct.
I am not sure if this is right. Basically, what I am attempting to do, is to not have an orphaned trayicon after using Process, close. I thought I could run RemoveTrayIcon before issuing Process, close... but not getting too far.
Do you have any clue what I may be missing, or this is the best way to achieve my goal? Have a great day & thanks Sean for your time here. I think I almost see light flickering at the end of the tunnel. |
|
| Back to top |
|
 |
Sean
Joined: 12 Feb 2007 Posts: 1359
|
Posted: Tue Jul 15, 2008 4:10 am Post subject: |
|
|
| ACoder wrote: | Hmm... that didn't work for me. So we are talking about two different UNIQUE ID'S?  | uID, unsigned (integer) ID literally, is not unique ID, i.e., different from hWnd.
| Quote: | | I get back a blank var. Even though I am sure that is correct | What does the following produce?
| Code: | | MsgBox % TrayIcons() |
|
|
| Back to top |
|
 |
ACoder Guest
|
Posted: Tue Jul 15, 2008 5:37 am Post subject: |
|
|
Ah, uID is something else, ok.
Yes, when I run that, I get a bunch of results. However, with the 12 or so trayicons I have.... I am getting I think approximately 12 results back in the MsgBox return with MsgBox % TrayIcons()
... but it is strange, they look like
idx: 0 | idn: 10 | Pid: | uID: 0 | MessageID: 0 | hWnd: 0 | Class: | Process: | Tooltip: ?X
idx: 1 | idn: 6 | Pid: | uID: 0 | MessageID: 0 | hWnd: 0 | Class: | Process: | Tooltip: ?X
idx: 2 | idn: 2 | Pid: | uID: 0 | MessageID: 0 | hWnd: 0 | Class: | Process: | Tooltip: ?X
idx: 3 | idn: 23 | Pid: | uID: 0 | MessageID: 0 | hWnd: 0 | Class: | Process: | Tooltip: ?X
idx: 4 | idn: 14 | Pid: | uID: 0 | MessageID: 0 | hWnd: 0 | Class: | Process: | Tooltip: ?X
idx: 5 | idn: 9 | Pid: | uID: 0 | MessageID: 0 | hWnd: 0 | Class: | Process: | Tooltip: ?X
idx: 6 | idn: 7 | Pid: | uID: 0 | MessageID: 0 | hWnd: 0 | Class: | Process: | Tooltip: ?X
idx: 7 | idn: 5 | Pid: | uID: 0 | MessageID: 0 | hWnd: 0 | Class: | Process: | Tooltip: ?X
idx: 8 | idn: 4 | Pid: | uID: 0 | MessageID: 0 | hWnd: 0 | Class: | Process: | Tooltip: ?X
idx: 9 | idn: 3 | Pid: | uID: 0 | MessageID: 0 | hWnd: 0 | Class: | Process: | Tooltip: ?X
idx: 10 | idn: 2 | Pid: | uID: 0 | MessageID: 0 | hWnd: 0 | Class: | Process: | Tooltip: ?X
idx: 11 | idn: 1 | Pid: | uID: 0 | MessageID: 0 | hWnd: 0 | Class: | Process: | Tooltip: ?X
idx: 12 | idn: 0 | Pid: | uID: 0 | MessageID: 0 | hWnd: 0 | Class: | Process: | Tooltip: ?X
I note the uID is 0 in every case! Not sure why. BTW, I am running this on Windows XP 64 bit.... but not sure if that would make any difference at all. Like I said, I can get a hWND for the app running in the tooltray.... but haven't progressed to understand past this point what I have  |
|
| Back to top |
|
 |
Sean
Joined: 12 Feb 2007 Posts: 1359
|
Posted: Tue Jul 15, 2008 6:45 am Post subject: |
|
|
| ACoder wrote: | | I note the uID is 0 in every case! Not sure why. BTW, I am running this on Windows XP 64 bit.... | AHK is a 32bit app. Do you really expect 32bit app can read 64bit app's memory? However, it seems to have worked... surprise surprise... Very interesting. I usually don't go further into the cases like this (:I haven't accessed 64bit Windows), but I'm tempted.
You may try again after search-and-replace the corresponding ones in the script with the followings:
| Code: | | pRB := DllCall("VirtualAllocEx","Uint",hProc,"Uint",0,"Uint",32,"Uint",0x1000,"Uint",0x4) |
| Code: | | VarSetCapacity(btn,32,0) |
| Code: | | DllCall("ReadProcessMemory","Uint",hProc,"Uint",pRB,"Uint",&btn,"Uint",32,"Uint",0) |
| Code: | dwData := NumGet(btn,16,"int64")
iString := NumGet(btn,24,"int64") |
| Code: | hWnd := NumGet(nfo, 0,"int64")
uID := NumGet(nfo, 8)
nMsg := NumGet(nfo,12) |
|
|
| Back to top |
|
 |
ACoder Guest
|
Posted: Tue Jul 15, 2008 9:29 am Post subject: |
|
|
Ah very interesting, I am building this for 64 bit and 32 bit systems..... but maybe I am going over my head , when instead -- maybe my question should be simpler.
I want to eliminate the orphaned desktray icons after issuing Process, Close. But I don't like the Zig-Zag mouse hover routines demonstrated here.... seems like too much interfearance.
This is the only thing I found (works on 64bit XP), that eliminates the desktray icons.... however, it seems to work too well, and removes all of them on my machine. From reading the author who posted this, it is your code (modified by Author)
| Code: |
SetTimer, TrayIcons, 500
^!a::msgbox % TrayIcons()
TrayIcons:
TrayIcons()
Return
TrayIcons(sExeName = "")
{
DetectHiddenWindows, On
idxTB := GetTrayBar()
WinGet, pidTaskbar, PID, ahk_class Shell_TrayWnd
hProc := DllCall("OpenProcess", "Uint", 0x38, "int", 0, "Uint", pidTaskbar)
pRB := DllCall("VirtualAllocEx", "Uint", hProc, "Uint", 0, "Uint", 20, "Uint", 0x1000, "Uint", 0x4)
VarSetCapacity(btn, 20)
VarSetCapacity(nfo, 24)
SendMessage, 0x418, 0, 0, ToolbarWindow32%idxTB%, ahk_class Shell_TrayWnd ; TB_BUTTONCOUNT
max = %errorlevel%
Loop, %max%
{
i := max - A_index
SendMessage, 0x417, i, pRB, ToolbarWindow32%idxTB%, ahk_class Shell_TrayWnd ; TB_GETBUTTON
DllCall("ReadProcessMemory", "Uint", hProc, "Uint", pRB, "Uint", &btn, "Uint", 20, "Uint", 0)
dwData := NumGet(btn,12)
DllCall("ReadProcessMemory", "Uint", hProc, "Uint", dwData, "Uint", &nfo, "Uint", 24, "Uint", 0)
hWnd := NumGet(nfo, 0)
WinGet, pid, PID, ahk_id %hWnd%
ifwinnotexist, ahk_id %hWnd%
{
idx := i+1
;MsgBox, 4, , Delete tray icon %idx%?
;IfMsgBox Yes
deletetrayicon(idx)
}
tmp = index=%a_index%, i=%i%, pid=%pid%`n
strayicons .= tmp
}
DllCall("VirtualFreeEx", "Uint", hProc, "Uint", pRB, "Uint", 0, "Uint", 0x8000)
DllCall("CloseHandle", "Uint", hProc)
Return sTrayIcons
}
DeleteTrayIcon(idx)
{
idxTB := GetTrayBar()
SendMessage, 0x416, idx - 1, 0, ToolbarWindow32%idxTB%, ahk_class Shell_TrayWnd ; TB_DELETEBUTTON
SendMessage, 0x1A, 0, 0, , ahk_class Shell_TrayWnd
}
GetTrayBar()
{
WinGet, ControlList, ControlList, ahk_class Shell_TrayWnd
RegExMatch(ControlList, "(?<=ToolbarWindow32)\d+(?!.*ToolbarWindow32)", nTB)
Loop, %nTB%
{
ControlGet, hWnd, hWnd,, ToolbarWindow32%A_Index%, ahk_class Shell_TrayWnd
hParent := DllCall("GetParent", "Uint", hWnd)
WinGetClass, sClass, ahk_id %hParent%
If (sClass <> "SysPager")
Continue
idxTB := A_Index
Break
}
Return idxTB
}
|
Anyway... I am just looking for a straightforward way to do this for just one application I specify in the desktray
If you have any clues that would be really great Sean.
best-ACODER |
|
| Back to top |
|
 |
Sean
Joined: 12 Feb 2007 Posts: 1359
|
Posted: Tue Jul 15, 2008 12:13 pm Post subject: |
|
|
| ACoder wrote: | | This is the only thing I found (works on 64bit XP), that eliminates the desktray icons.... however, it seems to work too well, and removes all of them on my machine. | It's because TrayIcons() didn't work in 64bit Windows, and it used DeleteTrayIcon() instead of RemoveTrayIcon(). DeleteTrayIcon() needs only (0-based) index, so the loop blindly removed all trayicons.
| Quote: | I am just looking for a straightforward way to do this for just one application I specify in the desktray  | Have you thought about why hovering the mouse over the orphaned trayicon could remove it correctly? Because then the shell tries to send WM_MOUSEMOVE message to the window and finally check whether the hWnd is valid or not. That means the simplest way is to make TrayIcons() working in 64bit Windows too, so, I urge to try my suggestion in the previous message and post back the result. There exists an inherent limitation for 32bit app in 64bit Windows, but I reckon this limitation might not be faced in normal system. If really so, it may be possible to modify TrayIcons() actually working in 64bit Windows too. |
|
| Back to top |
|
 |
ACoder Guest
|
Posted: Tue Jul 15, 2008 11:52 pm Post subject: |
|
|
Bravo! It works Sean. I don't have x32 bit testing platform.... would this mod only work on x64 bit+ machines? |
|
| Back to top |
|
 |
Sean
Joined: 12 Feb 2007 Posts: 1359
|
Posted: Wed Jul 16, 2008 1:46 am Post subject: |
|
|
| ACoder wrote: | Bravo! It works Sean. I don't have x32 bit testing platform.... would this mod only work on x64 bit+ machines? |
Really? Unbelievable! Thanks for the feedback of the result. Yes, this one will work only in 64bit Windows. Although it's easy to combine them, IMO they better be kept separately like TrayIcons() and TrayIcons64(). OTOH, TrayIcons64() could stop working intermittently whenever the limitation is reached, so better be prepared for it. |
|
| Back to top |
|
 |
ACoder Guest
|
Posted: Wed Jul 16, 2008 2:10 am Post subject: |
|
|
When you say limitation, that kinda scares me :/ ... do you mean something accumulating within the code, whereas if this is run over and over, it may bonk out?
Separately, I am wondering Sean, is there any sure-fire way to ping windows to get some return result, which identifies if it's 32bit or 64 bit?  |
|
| Back to top |
|
 |
ahklerner
Joined: 26 Jun 2006 Posts: 1219 Location: USA
|
Posted: Wed Jul 16, 2008 2:12 am Post subject: |
|
|
A_OSType _________________
 |
|
| Back to top |
|
 |
Sean
Joined: 12 Feb 2007 Posts: 1359
|
Posted: Wed Jul 16, 2008 2:59 am Post subject: |
|
|
| ACoder wrote: | | When you say limitation, that kinda scares me :/ | No need to be scared, just the script would stop working, or would crash at most. No harm at all to the machine. BTW, I suppose it would happen rarely if it ever happen.
| Quote: | is there any sure-fire way to ping windows to get some return result, which identifies if it's 32bit or 64 bit?  | I believe that the 64bit Windows tries to conceal its 64bit nature from 32bit apps, but I can't tell for sure as I've never used 64bit Windows. There may be a workaround. Have you tried A_OSType as ahklerner suggested? As matter of a fact, I think I saw a few posts about this issue in the forum. You may search the forum. |
|
| Back to top |
|
 |
ACoder Guest
|
Posted: Wed Jul 16, 2008 3:12 am Post subject: |
|
|
I gave that a try... I thought maybe there could be some var attribute which would identify a 32/bit, 64/bit native structure just by its format. For instance, on Windows Vista-64 Bit Ultimate Edition ... A_OsType merely returns WIN32_NT.... so no gold knowing there.....
I thought you might know some not thought of way to ascertain bitworthyness haha |
|
| Back to top |
|
 |
ahklerner
Joined: 26 Jun 2006 Posts: 1219 Location: USA
|
|
| Back to top |
|
 |
k3ph
Joined: 21 Jul 2006 Posts: 129
|
Posted: Wed Jul 16, 2008 3:24 am Post subject: |
|
|
| ACoder wrote: | I gave that a try... I thought maybe there could be some var attribute which would identify a 32/bit, 64/bit native structure just by its format. For instance, on Windows Vista-64 Bit Ultimate Edition ... A_OsType merely returns WIN32_NT.... so no gold knowing there.....
I thought you might know some not thought of way to ascertain bitworthyness haha |
| Code: | | HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion |
_________________ [ profile | ahk.net | ahk.talk ] |
|
| Back to top |
|
 |
Sean
Joined: 12 Feb 2007 Posts: 1359
|
Posted: Wed Jul 16, 2008 3:27 am Post subject: |
|
|
| ACoder wrote: | | I thought you might know some not thought of way to ascertain bitworthyness haha |
Actually there is a possible way in TrayIcons()/TrayIcons64(), under the assumption that the SendMessage succeeded.
Just check what the following returns:
If it's zero, then can assume the OS is 64bit, otherwise 32bit. |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|