GetWindowInfo: Difference between revisions

From NSIS Wiki
Jump to navigationJump to search
(WINDOWINFO is 60 bytes, not 56)
 
Line 2: Line 2:
== Description ==
== Description ==
Quick and dirty example of how to use System plug-in to call GetWindowInfo.
Quick and dirty example of how to use System plug-in to call GetWindowInfo.
'''Warning: before September 2019, this example contained a buffer overrun error that could cause crashes. <code>sizeof(WINDOWINFO)</code> is 60, not 56.'''
== GetWindowInfo Example.nsi ==
== GetWindowInfo Example.nsi ==
<highlight-nsis>
<highlight-nsis>
Line 9: Line 11:


Section Main1
Section Main1
     System::Alloc 56
     System::Alloc 60
     Pop $0
     Pop $0
     System::Call "*$0(i 56)"
     System::Call "*$0(i 60)"
     System::Call "User32::GetWindowInfo(i $HWNDPARENT,i r0) i .r1"
     System::Call "User32::GetWindowInfo(i $HWNDPARENT,i r0) i .r1"
      
      

Latest revision as of 22:14, 19 September 2019

Author: Zinthose (talk, contrib)


Description

Quick and dirty example of how to use System plug-in to call GetWindowInfo.

Warning: before September 2019, this example contained a buffer overrun error that could cause crashes. sizeof(WINDOWINFO) is 60, not 56.

GetWindowInfo Example.nsi

OutFile "GetWindowInfo Example.exe"
ShowInstDetails show 
!include WinMessages.nsh
 
Section Main1
    System::Alloc 60
    Pop $0
    System::Call "*$0(i 60)"
    System::Call "User32::GetWindowInfo(i $HWNDPARENT,i r0) i .r1"
 
    DetailPrint "RC=$1"
 
    ## rcWindow
        IntOp $R0 $0 + 4
        System::Call "*$R0(i .r1,i .r2,i .r3,i .r4)"
 
        DetailPrint "rcWindow.left=$1"
        DetailPrint "rcWindow.top=$2"
        DetailPrint "rcWindow.right=$3"
        DetailPrint "rcWindow.bottom=$4"
 
    ## rcClient
        IntOp $R0 $0 + 20
        System::Call "*$R0(i .r1,i .r2,i .r3,i .r4)"
 
        DetailPrint "rcClient.left=$1"
        DetailPrint "rcClient.top=$2"
        DetailPrint "rcClient.right=$3"
        DetailPrint "rcClient.bottom=$4"
 
    ## dwStyle
        IntOp $R0 $0 + 36
        System::Call "*$R0(i .r1)"
        intfmt $1 "0x%08X" $1
 
        DetailPrint "dwStyle=$1"
 
    ## dwExStyle
        IntOp $R0 $0 + 40
        System::Call "*$R0(i .r1)"
        intfmt $1 "0x%08X" $1
 
        DetailPrint "dwExStyle=$1"
 
    ## dwWindowStatus
        IntOp $R0 $0 + 44
        System::Call "*$R0(i .r1)"
        intfmt $1 "0x%08X" $1
 
        DetailPrint "dwWindowStatus=$1"
 
    ## cxWindowBorders
        IntOp $R0 $0 + 48
        System::Call "*$R0(i .r1)"
        intfmt $1 "%u" $1
 
        DetailPrint "cxWindowBorders=$1"         
 
    ## cyWindowBorders
        IntOp $R0 $0 + 52
        System::Call "*$R0(i .r1)"
        intfmt $1 "%u" $1
 
        DetailPrint "cyWindowBorders=$1"   
 
        System::Free $0
 
SectionEnd