Skip to content
⌘ NSIS Forum Archive

Disable or remove Windows close button?

14 posts

Comperio#

Disable or remove Windows close button?

Odd question:
Is there a way that I can disable the Close button (little 'x' in the upper right-hand corner) of an installer window?

Or, perhaps a way to remove the title bar altogether?

First, I thought perhpas a SendMessage or EnableWindow command might do it, but couldn't find a handle to this control or a command to use to do it.

Next, I thought maybe I could use Resource Hacker to do it, but couldn't find a way to get to that part of the Window.

Can anyone give me a push in the right direction?
Afrow UK#
Edit the dialog in Resource Hacker and remove the WS_SYSMENU style from IDD 105 (or to remove the whole caption, remove WS_CAPTION).

-Stu
Comperio#
Perhaps I'm doing something wrong as I cannot make this work. Using Resource Hacker, I changed the file ${NSISDIR}\Contrib\UIs\default.exe to remove WS_SYSMENU. I saved the EXE and confirmed the save by viewing the modified date of default.exe. I then just recompile my NSIS script, but nothing changes. Have I missed a step?

2nd qustion:
I found this article about how to disable the close box that I thought I'd try using the system plugin. I found the function on MSDN, so I decided to GetSystemMenu setup an experiment with Windows Notepad using this function:

FindWindow $5 '' 'Untitled - Notepad'
MessageBox MB_OK "handle of Notepad: $5"
System::Call "user32::GetSystemMenu (i r5,i 0) i.r6"
;MessageBox MB_OK "Return value #1: $R1"
MessageBox MB_OK "Result: $6"
But each time I run, my result returns 'error'. Can anyone tell me what I might be doing wrong?
Afrow UK#
Are you using Modern UI? If so you need to modify modern.exe. Also, when removing the styles, make sure you click the Compile button in Resource Hacker and then File>Save.

-Stu
Comperio#
No, I'm not using MUI. (I wanted to start with baby steps). and yes, I did both compile and save.
Anders#edited
disable close:
function .onGuiInit
push $1
System::Call "user32::GetSystemMenu(i $HWNDPARENT,i 0) i.s"
pop $1
System::Call "user32::EnableMenuItem(i $1,i 0xF060,i 1)"
pop $1
functionEnd 
nasty hack to remove titlebar: (windows size is a bit off, and you really should do the proper bit-twiddling to remove the required bits and call Redraw window instead of all those ShowWindow calls)
function .onGuiInit
System::Call 'user32::SetWindowLong(i $HWNDPARENT,i -16,i 339871820)'
ShowWindow $HWNDPARENT 0
ShowWindow $HWNDPARENT 2
ShowWindow $HWNDPARENT 0
ShowWindow $HWNDPARENT 1
functionEnd 
Comperio#
Thanks, Anders!

For some reason, I wasn't getting the handle returned from my GetSystemMenu function, but since your function seems to work, so I'll just go with that. 😉
r2du-soft#
Originally Posted by Anders View Post
disable close:
function .onGuiInit
push $1
System::Call "user32::GetSystemMenu(i $HWNDPARENT,i 0) i.s"
pop $1
System::Call "user32::EnableMenuItem(i $1,i 0xF060,i 1)"
pop $1
functionEnd 
nasty hack to remove titlebar: (windows size is a bit off, and you really should do the proper bit-twiddling to remove the required bits and call Redraw window instead of all those ShowWindow calls)
function .onGuiInit
System::Call 'user32::SetWindowLong(i $HWNDPARENT,i -16,i 339871820)'
ShowWindow $HWNDPARENT 0
ShowWindow $HWNDPARENT 2
ShowWindow $HWNDPARENT 0
ShowWindow $HWNDPARENT 1
functionEnd 

Mr Anders

When i use from:
function .onGuiInit
System::Call 'user32::SetWindowLong(i $HWNDPARENT,i -16,i 339871820)'
ShowWindow $HWNDPARENT 0
ShowWindow $HWNDPARENT 2
ShowWindow $HWNDPARENT 0
ShowWindow $HWNDPARENT 1
functionEnd
Then i cant move installer position in screen with mouse,i want hide title bar but i want change installer position in screen with mouse...

This method possible?
Anders#
Originally Posted by r2du-soft View Post
Mr Anders

When i use from:
function .onGuiInit
System::Call 'user32::SetWindowLong(i $HWNDPARENT,i -16,i 339871820)'
ShowWindow $HWNDPARENT 0
ShowWindow $HWNDPARENT 2
ShowWindow $HWNDPARENT 0
ShowWindow $HWNDPARENT 1
functionEnd
Then i cant move installer position in screen with mouse,i want hide title bar but i want change installer position in screen with mouse...

This method possible?
Are you using the MoveAnywhere plugin?
Anders#
Originally Posted by r2du-soft View Post
No i usent that plugin,i search but not found that...
Why do you think it would be possible without a plug-in? This is non-standard Windows behavior.

Search this forum for MoveAnywhere and I'm sure you'll find it...
r2du-soft#
i use from

function .onGuiInit
System::Call 'user32::SetWindowLong(i $HWNDPARENT,i -16,i 339871820)'
ShowWindow $HWNDPARENT 0
ShowWindow $HWNDPARENT 2
ShowWindow $HWNDPARENT 0
ShowWindow $HWNDPARENT 1
functionEnd 
to remove installer titlebar in custome pages
now i want restore and show deafult (minimize,close,maximize,titlebar) in Section
how can do it?

i use ShowWindow $HWNDPARENT ${SW_SHOW} but not restore!!
Anders#
Save the style first
var originalstyle
function .onGuiInit
System::Call 'user32::GetWindowLong(i $HWNDPARENT,i -16)i.s
pop $originalstyle
and then you can probably use that to restore instead of using a magic number.