Archive: System Plugin and SHAppBarMessage help


System Plugin and SHAppBarMessage help
I need some help with SHAppBarMessage call, the code below:

!define stRECT '(i,i,i,i) i'
!define APPBARDATA '(i,i,i,i,i,i) i'

!include "WinMessages.nsh"

System::Call '*${stRECT} .r2'
System::Call '*${APPBARDATA} .r3'
System::Call 'shell32::SHAppBarMessage(i ${ABM_GETTASKBARPOS}, i r3) i.r0'
System::Call "*$3${APPBARDATA} (.R9, .R8, .R7, .R6, .r2, .R5)"
System::Call "*$2${stRECT}(.r5, .r6, .r7, .r8)" ; screen application rect
System::Free $3
System::Free $2
messagebox mb_ok "$R9, $R8, $R7, $R6, $2, $R5$\r$\nleft=$5 - top=$6 - right=$7 - bottom=$8"


$R6 contains the relative taskbar position (top, bottom, left, right), but stRECT is empty. But if I use the code below I can get the values, but not the relative position:

System::Call '*${stRECT} .r2'
FindWindow $TASKBAR 'Shell_TrayWnd' '' ''
System::Call 'user32::GetWindowRect(i $TASKBAR , i r2)'
System::Call "*$2${stRECT}(.r5, .r6, .r7, .r8)"
System::Free $2
messagebox mb_ok "left=$5 - top=$6 - right=$7 - bottom=$8"


Any ideas? Thanks :)

Do you define the size of the APPBARDATA structure somewhere? It appears to me that you need to allocate memory first before passing anything to APPBARDATA as its first member is its size in bytes. Is this a 'working' example of your code or are there bits (relating to the call you make) missing?
CF


Yes, it is a working example but could be smaller.

I don't know if I have defined APPBARDATA correctly:

!define APPBARDATA '(i,i,i,i,i,i) i'


The first code works partially, with SHAppBarMessage I got only relative taskbar location, but this function gives the taskbar coordinates too, in stRECT structure, and here is my problem because stRECT is empty. If I use it with the second code, stRECT comes with the values I need, but I wanna know why the first stRECT is empty.

Well, the first value must be &l and not i, but the installer crashes. Maybe there is a value to put there too.

!define APPBARDATA '(&l,i,i,i,i,i) i'


if I move taskbar to the right, using (i,i,i,i,i,i), the installer crashes too :(

Almost, it's not crashing but no stRECT.

!define stRECT                '(i,i,i,i) i'
!define APPBARDATA '(&l4,i,i,i,i,i) i'

!include "WinMessages.nsh"

System::Call '*${stRECT} .r2'
System::Call '*${APPBARDATA} .r3'
System::Call 'shell32::SHAppBarMessage(i ${ABM_GETTASKBARPOS}, i r3) i.r0'
System::Call "*$3${APPBARDATA} (,,, .R6, r2,)"
System::Call "*$2${stRECT}(.r5, .r6, .r7, .r8)"
System::Free $3
System::Free $2
messagebox mb_ok "relative pos=$R6$\r$\nleft=$5$\r$\ntop=$6$\r$\nright=$7$\r$\nbottom=$8"

Now I am really confused :(
I think I am using the wrong message and getting the wrong results. I think now ABM_QUERYPOS is the correct way to get what I want (taskbar relative position and coordinates), but it returns nothing. Below are the MSDN reference links:

SHAppBarMessage Function

ABM_GETTASKBARPOS Message

ABM_QUERYPOS Message

APPBARDATA Structure


!define APPBARDATA '(&l4,i,i,i,i,i) i', where is the rect struct, you only have a INT there, add 3 more i's?


The APPBARDATA Structure is:

typedef struct _AppBarData {
DWORD cbSize;
HWND hWnd;
UINT uCallbackMessage;
UINT uEdge;
RECT rc;
LPARAM lParam;
} APPBARDATA, *PAPPBARDATA;


How can I define it correctly with rect struct?

I give up from using ABM_GETTASKBARPOS Message. The code below does what I need, it gets taskbar coordinates and its relative position, for those interested:

!define stRECT '(i,i,i,i) i'
!include "LogicLib.nsh"

System::Call '*${stRECT} .r0'
FindWindow $1 'Shell_TrayWnd' '' ''
System::Call 'user32::GetWindowRect(i r1 , i r0)'
System::Call "*$0${stRECT}(.r2, .r3, .r4, .r5)" ;left-top-right-bottom
System::Free $0

${If} $3 == $2
${AndIf} $5 > $4
MessageBox MB_OK "Left"
${ElseIf} $3 == $2
${AndIf} $5 < $4
MessageBox MB_OK "Top"
${ElseIf} $3 > $2
MessageBox MB_OK "Bottom"
${Else}
MessageBox MB_OK "Right"
${EndIf}