
OutFile "Untitlebarred.exe"
RequestExecutionLevel User

!define WS_MINIMIZEBOX 0x00020000
!define WS_SYSMENU     0x00080000
!define WS_DLGFRAME    0x00400000
!define WS_CAPTION     0x00C00000

!define SWP_NOSIZE       0x0001
!define SWP_NOMOVE       0x0002
!define SWP_NOZORDER     0x0004
!define SWP_FRAMECHANGED 0x0020

!define RECT '(i, i, i, i) i' ; RECT struct

!include "MUI2.nsh"
!define MUI_WELCOMEPAGE_TITLE "$\r$\nAchtung!"
!define MUI_WELCOMEPAGE_TEXT "$\r$\nThis window can easily detonate when shaken.$\r$\nFor your protection, we removed the title bar."
!define MUI_CUSTOMFUNCTION_GUIINIT onGUIInit
!insertmacro MUI_PAGE_WELCOME
!insertmacro MUI_LANGUAGE "English"


             Function onGUIInit

; After we remove the titlebar, the client area will expand (because the window dimensions are unchanged).
; This results in an ugly-looking extra margin at the bottom. Most of the code below serves just to fix that.

System::Call '*${RECT} .R5' ; create RECT
System::Call 'user32::GetClientRect(i $HWNDPARENT, i R5)' ; get the initial client area dimensions
System::Call '*$R5 ${RECT} (., ., ., .R1)' ; GetClientRect returns 0, 0, width, height

System::Call "user32::GetWindowLong(i $HWNDPARENT, i ${GWL_STYLE})i. R0" ; get window styles
IntOp $R0 $R0 ^ ${WS_SYSMENU}
IntOp $R0 $R0 ^ ${WS_MINIMIZEBOX}
IntOp $R0 $R0 ^ ${WS_CAPTION}
IntOp $R0 $R0 | ${WS_DLGFRAME}
System::Call "user32::SetWindowLong(i $HWNDPARENT, i ${GWL_STYLE}, i R0) i." ; apply new styles
; needed for changes to take effect:
System::Call "User32::SetWindowPos(i $HWNDPARENT, i 0, i 0, i 0, i 0, i 0, i '${SWP_FRAMECHANGED}|${SWP_NOMOVE}|${SWP_NOSIZE}|${SWP_NOZORDER}') i."

System::Call 'user32::GetClientRect(i $HWNDPARENT, i R5)' ; get the new client area dimensions
System::Call '*$R5 ${RECT} (., ., ., .R2)'
IntOp $R0 $R2 - $R1 ; client area height has grown this much

System::Call 'user32::GetWindowRect(i $HWNDPARENT, i R5)' ; get window dimensions
System::Call '*$R5 ${RECT} (.R1, .R2, .R3, .R4)' ; left, top, right, bottom
System::Free $R5 ; won't be needing RECT anymore
IntOp $R3 $R3 - $R1 ; width
IntOp $R4 $R4 - $R2 ; height
IntOp $R4 $R4 - $R0 ; corrected height (counteract the client area growth)
; apply new window dimensions:
System::Call "User32::SetWindowPos(i $HWNDPARENT, i 0, i 0, i 0, i R3, i R4, i '${SWP_NOMOVE}|${SWP_NOZORDER}') i."

FunctionEnd


Section Blank
SectionEnd
