[SOLVED] Help calling Shell_NotifyIconGetRect(), build NOTIFYICONIDENTIFIER structure

Get help with using AutoHotkey and its commands and hotkeys
gwarble
Posts: 469
Joined: 30 Sep 2013, 15:01

[SOLVED] Help calling Shell_NotifyIconGetRect(), build NOTIFYICONIDENTIFIER structure

25 Jun 2015, 23:08

Hey all,

I'm was messing around trying to get Shell_NotifyIconGetRect to work but can't figure out the structure... hoping one of you experts can point me in the right direction:

see last post for fixed function

Reference:
NOTIFYICONIDENTIFIER: https://msdn.microsoft.com/en-us/librar ... 85%29.aspx
Shell_NotifyIconGetRect: https://msdn.microsoft.com/en-us/librar ... 85%29.aspx
typedef struct _NOTIFYICONIDENTIFIER {
DWORD cbSize;
HWND hWnd;
UINT uID;
GUID guidItem;
} NOTIFYICONIDENTIFIER, *PNOTIFYICONIDENTIFIER;
Any help appreciated, thanks
- gwarble
Last edited by gwarble on 08 Jul 2015, 14:07, edited 1 time in total.
EitherMouse - Multiple mice, individual settings . . . . www.EitherMouse.com . . . . forum . . . .
User avatar
LinearSpoon
Posts: 156
Joined: 29 Sep 2013, 22:55

Re: Help calling Shell_NotifyIconGetRect(), build NOTIFYICONIDENTIFIER structure

26 Jun 2015, 08:52

For reference, here is the layout of the structure on all AHK builds:
ANSI/Unicode 32

Code: Select all

Struct: NOTIFYICONIDENTIFIER    total size: 28
Member                   Pos     C++ Type                AHK Type
cbSize                   @ 0     unsigned long           uint
hWnd                     @ 4     struct HWND__ *         ptr
uID                      @ 8     unsigned int            uint
guidItem                 @ 12    struct _GUID
Unicode 64 bit

Code: Select all

Struct: NOTIFYICONIDENTIFIER    total size: 40
Member                   Pos     C++ Type                AHK Type
cbSize                   @ 0     unsigned long           uint
hWnd                     @ 8     struct HWND__ * __ptr64 ptr
uID                      @ 16    unsigned int            uint
guidItem                 @ 20    struct _GUID
I see a few problems with this.
1. None of your code is likely to work on 64 bit AHK (I guess you use 32 bit, but you didn't say, so I mention this)
2. You set the wrong value for cbSize. Many Win API functions fail if this is set incorrectly.
3. guidItem is a 16 byte structure which cannot be set with a single Numput.
gwarble
Posts: 469
Joined: 30 Sep 2013, 15:01

Re: Help calling Shell_NotifyIconGetRect(), build NOTIFYICONIDENTIFIER structure

26 Jun 2015, 10:54

Thanks LinearSpoon,

1. Yeah I'm testing in 32-bit... once I got it working I figured I'd try to make the changes to support 64-bit, but as you can tell I'm an amateur so just trying to get it working is first priority
2. is see, I was assuming guidItem was a pointer to the structure, which made my size assumption wrong... oops
3. since I'm using hWnd and uID, guidItem isn't supposed to be needed, so should I just assign 0 to it?

- gwarble

Edit: exactly the direction I needed, thanks (edit: no need to set guidItem with VarSetCapacity setting all 0's):

Code: Select all

Shell_NotifyIconGetRect(Left, Top, Right, Bottom)
MsgBox % "Left " . Left . " Top " . Top . " Right " . Right . " Bottom " . Bottom

Shell_NotifyIconGetRect(ByRef Left, ByRef Top, ByRef Right, ByRef Bottom)
{
 cbSize := A_PtrSize*3 + 16
 VarSetCapacity( NII,cbSize,0 )
 NumPut( cbSize,       NII,  0,           "uint" )
 NumPut( A_ScriptHwnd, NII,  A_PtrSize,   "ptr" )
 NumPut( 1028,         NII,  A_PtrSize*2, "uint" )
 VarSetCapacity(Rect,16)

 If DllCall( "shell32\Shell_NotifyIconGetRect", UInt,&NII, UInt,&Rect )
  Return 0

 Left   := NumGet(Rect, 0, "Int")
 Top    := NumGet(Rect, 4, "Int")
 Right  := NumGet(Rect, 8, "Int")
 Bottom := NumGet(Rect, 12,"Int")

Return 1
}
EitherMouse - Multiple mice, individual settings . . . . www.EitherMouse.com . . . . forum . . . .
gwarble
Posts: 469
Joined: 30 Sep 2013, 15:01

Re: Help calling Shell_NotifyIconGetRect(), build NOTIFYICONIDENTIFIER structure

08 Jul 2015, 14:05

Unfortunately we lost some posts in this thread from LinearSpoon, Lexikos, HotkeyIt explaining the structure build up and padding and stuff I can't speak to personally, but here are the two versions cleaned up with their help:

Code: Select all

NotifyIconGetRect(Left, Top, Right, Bottom)
SplitPath, A_AhkPath, , ,, A_AhkPath_
MsgBox,,%A_AhkPath_%, % "Left " . Left . " Top " . Top
    . " Right " . Right . " Bottom " . Bottom

NotifyIconGetRect(ByRef Left, ByRef Top, ByRef Right, ByRef Bottom)
{
 cbSize := A_PtrSize*3 + 16
 VarSetCapacity( NII,cbSize,0 )
 NumPut( cbSize,       NII,  0,           "uint" )
 NumPut( A_ScriptHwnd, NII,  A_PtrSize,   "ptr" )
 NumPut( 1028,         NII,  A_PtrSize*2, "uint" )
 VarSetCapacity(Rect,16)

 If DllCall( "shell32\Shell_NotifyIconGetRect", UInt,&NII, UInt,&Rect )
  Return 0

 Left   := NumGet(Rect, 0, "Int")
 Top    := NumGet(Rect, 4, "Int")
 Right  := NumGet(Rect, 8, "Int")
 Bottom := NumGet(Rect, 12,"Int")

Return 1
}
and the _Struct dependent version:

Code: Select all

#Include <_Struct>
_GUID:="ulong Data1;ushort Data2;ushort Data3;uchar Data4[8]"
_NOTIFYICONIDENTIFIER:="DWORD cbSize,HWND  hWnd,UINT  uID,_GUID guid"
NII := new _Struct(_NOTIFYICONIDENTIFIER, {cbSize:sizeof(_NOTIFYICONIDENTIFIER), hWnd:A_ScriptHwnd,uID:1028})
rc := new _Struct("UInt left,UInt top,UInt right,UInt bottom")
DllCall("shell32\Shell_NotifyIconGetRect", "Ptr", NII[], "PTR", rc[])
MsgBox % "Left " . rc.left . " Top " . rc.top
    . " Right " . rc.right . " Bottom " . rc.bottom
Thanks for all the help...
-gwarble
EitherMouse - Multiple mice, individual settings . . . . www.EitherMouse.com . . . . forum . . . .

Return to “Ask For Help”

Who is online

Users browsing this forum: Bing [Bot], genericindividual69, MatthewMirage, mikeyww, Nixcalo, roysubs, XMCQCX and 57 guests