AutoHotkey Community

It is currently May 27th, 2012, 11:01 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 139 posts ]  Go to page Previous  1 ... 6, 7, 8, 9, 10  Next
Author Message
 Post subject:
PostPosted: February 11th, 2011, 1:35 am 
Offline

Joined: February 12th, 2007, 7:54 am
Posts: 2462
You can combine the two like:
Code:
RegExMatch(TrayIcons("app.exe"), "uID: (\d+).+?hWnd: (\d+)", id)
RemoveTrayIcon(id2, id1)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 22nd, 2011, 1:50 am 
Offline

Joined: November 8th, 2009, 2:46 am
Posts: 234
Location: Canberra Oz
Being without a cleaner for my notification tray eventually got me annoyed enough...

For Windows 7 64 bit & AutoHotkey_L UNICODE 64 Bit ONLY!!

EDIT Designed for 'Always show all icons and notifications' mode.

TrayIcon_Cleanup()

Verry lightly tested!!! Works for me!

Possible Bug Alert!!
This morning (after working for 3 days) I had many blank/empty tray icons, probably due to this script.
But it doesn't get called that often?
They went away once mouse-overed.
UPDATE:
Was the script, when I ran it I got one blank icon for each existing one.
However on reboot, it went away.
I had not rebooted since debugging this script, I'm putting this one down to Windows twisted nickers.
If nothing happens in a while I'll remove the above.

Code:
;#NoTrayIcon      ;  to test standalone, uncomment these four lines
;#SingleInstance, force
;TrayIcon_CleanUp()
;Return

TrayIcon_CleanUp()
{   ; Remove abandoned icons in notification tray, such as left behine by "Process Close"
   ; Windows 7 64 bit & AutoHotkey_L UNICODE 64Bit ONLY version!!!!!!!
   ; v0-5 - extensive change for Win7/64
   ; Originally based on TrayIcon by Sean @ http://www.autohotkey.com/forum/topic17314.html
   ;
   DetectHiddenWindows, On
   TBW:=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", 32
                  , "Uint", 0x1000
                  , "Uint", 0x4)
   VarSetCapacity(btn, 32, 0)
   VarSetCapacity(nfo, 32, 0)
   SendMessage, 0x418, 0, 0, ToolbarWindow32%TBW%
                     , ahk_class Shell_TrayWnd   ; TB_BUTTONCOUNT
   Counter := ErrorLevel
   Loop, %Counter%
   {
      Counter-- ; Must count DOWN as the zero-based indexes change if you remove a lower one
;
      SendMessage, 0x417, Counter, pRB, ToolbarWindow32%TBW%
                              , ahk_class Shell_TrayWnd ; TB_GETBUTTON
      VarSetCapacity(bread,8,32)
      VarSetCapacity(bread2,8,32)
      DllCall("ReadProcessMemory", "int64", hProc
                           ,"int64", pRB
                           ,"int64", &btn
                           ,"int64", 32
                           ,"int64", &bread)
      dwData := Numget(btn,0x10,"int64") ; see struct way below
      DllCall("ReadProcessMemory"   , "int64", hProc
                           , "int64", dwData
                           , "int64", &nfo
                           , "int64", 32
                           , "int64", &bread2)
      hWnd   := NumGet(nfo, 0, "int64")
      if !WinExist("ahk_id " . hWnd) {
         SendMessage, 1046, Counter , 0, ToolbarWindow32%TBW%      ; zero-based index of button
                                 , ahk_class Shell_TrayWnd ; TB_DELETEBUTTON
      }
   } ; /Loop
   DllCall("VirtualFreeEx"
            , "Uint", hProc
            , "Uint", pRB
            , "Uint", 0
            , "Uint", 0x8000)
   DllCall("CloseHandle", "Uint", hProc)
   Return   sTrayIcon_CleanUp
}

GetTrayBar()   ; Get the notification area traybar number. For Windows 7 ONLY!!!!!!!
{              ; Sorry, forgot who I got this approach from. Note it works, I confirmed hWnd
   ControlGet, hParent, hWnd,, TrayNotifyWnd1  , ahk_class Shell_TrayWnd
   ControlGet, hChild , hWnd,, ToolbarWindow321, ahk_id %hParent%
   Loop
   {
      ControlGet, hWnd, hWnd,, ToolbarWindow32%A_Index%, ahk_class Shell_TrayWnd
      If  Not   hWnd
         Break
      Else If   hWnd = %hChild%
      {
         idxTB := A_Index
         Break
      }
   }
   Return   idxTB
}

; Structs for W7/64
/*typedef struct {
  int       iBitmap;      x00
  int       idCommand;       x04
  BYTE      fsState;      x08
  BYTE      fsStyle;      x09
#ifdef _WIN64
  BYTE      bReserved[6];   x0A
#else
#if defined(_WIN32)
  BYTE      bReserved[2];   x0A
#endif
#endif                   WIN32/WIN64
  DWORD_PTR dwData;         x0C/x10      d12/d16
  INT_PTR   iString;      x10/x18      d16/d24
                     x14/x20      d20/d32
} TBBUTTON, *PTBBUTTON, *LPTBBUTTON;
*/
/*
BOOL WINAPI ReadProcessMemory(
  __in   HANDLE hProcess, 64
  __in   LPCVOID lpBaseAddress, 64
  __out  LPVOID lpBuffer,64
  __in   SIZE_T nSize, 64
  __out  SIZE_T *lpNumberOfBytesRead 64
);
*/


Someone can use it to update the other TrayIcon stuff if they wish.

EDIT
Works on Ahk 1.0.92.02 :)

I just saw the change log:

"1.0.97.01 - April 2, 2011
Fixed the 64-bit build to not truncate HWNDs or SendMessage/PostMessage params to 32 bits."

I suspect my code will not work. :( I'll get around to it.... eventually... EDIT Had a quick look, you could be lucky.


Last edited by Michael@Oz on May 27th, 2011, 7:48 am, edited 1 time in total.

Report this post
Top
 Profile  
Reply with quote  
PostPosted: May 27th, 2011, 4:34 am 
i use it but failed ,can't get normal tip text.


Report this post
Top
  
Reply with quote  
PostPosted: May 27th, 2011, 5:35 am 
is there any way to use it with AutoHotKey_L

i use it but failed ,can't get normal tip text.


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: May 27th, 2011, 6:34 am 
Offline

Joined: November 8th, 2009, 2:46 am
Posts: 234
Location: Canberra Oz
This (the above) is only for 64bit Windows 7 and 64bit AutoHotkey_L, is that what you're on?

Also what do you mean by "can't get normal tip text"?

EDIT

Are you talking about TrayIcon_Cleanup or TrayIcon.ahk? If the latter it doesn't work on unicode ahk or 64bit.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 27th, 2011, 8:23 am 
Offline

Joined: November 8th, 2009, 2:46 am
Posts: 234
Location: Canberra Oz
By the way, if anyone's going to try 64bit versions of the other TrayIcon functions, here is my 64bit unicode struc. May come in handy. I think it's correct.
Code:
   /*typedef struct _NOTIFYICONDATA {
  DWORD cbSize;            x00
  HWND  hWnd;              x04
  UINT  uID;               x0c/d12
  UINT  uFlags;            x10/d16
  UINT  uCallbackMessage;  x14/d20
  HICON hIcon;             x18/d24
  TCHAR szTip[64];         x20 (UNICODE)
  DWORD dwState;           xa0
  DWORD dwStateMask;       xa4
  TCHAR szInfo[256];       xa8 (UNICODE)
  union {
    UINT uTimeout;         x01a8
    UINT uVersion;         x01a8
  };
  TCHAR szInfoTitle[64];   x01ac (UNICODE)
  DWORD dwInfoFlags;       x022c
  GUID  guidItem; (128bits) x0230
  HICON hBalloonIcon;      x023c
            ;end           x0244
} NOTIFYICONDATA, *PNOTIFYICONDATA;
*/

Note that W7 apps can use GUID guiditem, and if icon added using guiditem rather than uid, it then needs to be manipulated via guiditem. Hence if guiditem is not zero can't use uid.

ps don't call Shell_NotifyIconA, A=ANSI, try W.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 1st, 2011, 6:00 am 
Offline

Joined: December 19th, 2010, 5:32 am
Posts: 235
Edit: Never mind, it works fine for what I needed.


Last edited by zzzooo10 on June 2nd, 2011, 12:04 am, edited 2 times in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 1st, 2011, 10:33 am 
If you rewrite it! Can't you read!


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: June 26th, 2011, 11:47 pm 
Offline

Joined: December 2nd, 2010, 11:14 pm
Posts: 214
Location: Poland
Hi Sean,

thank you for this handsome piece of code. I have a question: in your script you read some data into 'nfo' buffer. This data is retrieved through dwData pointer address. Can you tell me, what is the interpretation of this data? I mean, there is a handle inside (hWnd variable in the code) and I don't know, to what window / control / other object is this handle actually pointing to? And how do you know this, since MSDN documentation states only that dwData is:
Quote:
dwData

Type: DWORD_PTR

Application-defined value.


Regards.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 27th, 2011, 12:02 am 
Offline

Joined: December 2nd, 2010, 11:14 pm
Posts: 214
Location: Poland
I'm going to reply to myself. The hWnd in 'nfo' structure is a handle to a window. When the application minimizes itself to the tray icon, the window of the application is actually not destroyed, but hidden (or at least the window handle is preserved). That preserved window handle is inside dwData field. Also, here is an extract from the article I've found:

Source: http://www.codeproject.com/KB/shell/taskbarsorter.aspx
Quote:
Getting the window handle

This was the really lucky part. I thought to myself: "Where would I keep the window handle?". They must keep it somewhere, to enable the activation of the correct window when a button is selected. The obvious place to keep it would be in a structure for each button, and the obvious place to keep the pointer to this structure would be in the dwData field of each TBBUTTON.

So I had a look at the dwData fields, and they appeared to be pointers. OK so far. Then I had a look at the memory they pointed to, and there they were: the first field stores the window handle :))) Microsoft developers aren't so different, after all :)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 4th, 2011, 1:36 pm 
Offline

Joined: November 4th, 2011, 1:34 pm
Posts: 4
Any chance of the taskbar script getting updated to work on win 7? I'm trying to make a script that monitors the windows listed in the taskbar for the purpose of making a dock-like launcher.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 5th, 2011, 4:59 pm 
@figpetus,
It already works fine on 7, just browse the last couple of pages on this thread.
However, it doesn't work to hide tray icons if you have the option "always show all icons and notifications on the taskbar" unchecked and the icon you are trying to hide is among those hidden in that group.


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: November 8th, 2011, 7:23 am 
Offline

Joined: November 4th, 2011, 1:34 pm
Posts: 4
anigav wrote:
@figpetus,
It already works fine on 7, just browse the last couple of pages on this thread.
However, it doesn't work to hide tray icons if you have the option "always show all icons and notifications on the taskbar" unchecked and the icon you are trying to hide is among those hidden in that group.


The systray function works fine, but the taskbar listing does not work. I have read the whole thread, the last few pages are all about the systray.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 10th, 2011, 3:17 am 
any updates to this?


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: December 30th, 2011, 9:43 pm 
Offline

Joined: October 11th, 2010, 12:30 pm
Posts: 406
Is there any way to get coordinates of a tray icon?
EDIT: TrayIcon_...() by HotkeyIt is what I was looking for


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 ... 6, 7, 8, 9, 10  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: Google [Bot], iDrug and 59 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