AutoHotkey Community

It is currently May 26th, 2012, 9:10 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 139 posts ]  Go to page Previous  1, 2, 3, 4, 5, 6, 7 ... 10  Next
Author Message
 Post subject:
PostPosted: July 15th, 2008, 2:48 am 
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.


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: July 15th, 2008, 4:10 am 
Offline

Joined: February 12th, 2007, 7:54 am
Posts: 2462
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()


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 15th, 2008, 5:37 am 
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 :?


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: July 15th, 2008, 6:45 am 
Offline

Joined: February 12th, 2007, 7:54 am
Posts: 2462
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)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 15th, 2008, 9:29 am 
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


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: July 15th, 2008, 12:13 pm 
Offline

Joined: February 12th, 2007, 7:54 am
Posts: 2462
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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 15th, 2008, 11:52 pm 
Bravo! :) It works Sean. I don't have x32 bit testing platform.... would this mod only work on x64 bit+ machines?


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: July 16th, 2008, 1:46 am 
Offline

Joined: February 12th, 2007, 7:54 am
Posts: 2462
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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 16th, 2008, 2:10 am 
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? :)


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: July 16th, 2008, 2:12 am 
Offline

Joined: June 26th, 2006, 6:14 pm
Posts: 1379
Location: USA
A_OSType

_________________
Image
ʞɔпɟ əɥʇ ʇɐɥʍ


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 16th, 2008, 2:59 am 
Offline

Joined: February 12th, 2007, 7:54 am
Posts: 2462
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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 16th, 2008, 3:12 am 
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


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: July 16th, 2008, 3:24 am 
Offline

Joined: July 21st, 2006, 12:26 am
Posts: 223
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 ]


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 16th, 2008, 3:24 am 
Offline

Joined: June 26th, 2006, 6:14 pm
Posts: 1379
Location: USA
here is a link to (apparently) a solution
http://www.autohotkey.com/forum/viewtopic.php?t=28369

_________________
Image
ʞɔпɟ əɥʇ ʇɐɥʍ


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 16th, 2008, 3:27 am 
Offline

Joined: February 12th, 2007, 7:54 am
Posts: 2462
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:
Code:
NumGet(btn,12)
If it's zero, then can assume the OS is 64bit, otherwise 32bit.


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 139 posts ]  Go to page Previous  1, 2, 3, 4, 5, 6, 7 ... 10  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: Bing [Bot], Klark92, Stigg and 20 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group