Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.
Keywords: disable close menu
I want to disable the Minimize, Zoom, etc icons on the title bar, and also the control icon in the top left corner.
It's time you bought the API book for VB or something so you can look up all these API calls...
#define SC_SIZE 0xF000 ; 61440 #define SC_MOVE 0xF010 ; 61456 #define SC_MINIMIZE 0xF020 ; 61472 #define SC_MAXIMIZE 0xF030 ; 61488 #define SC_NEXTWINDOW 0xF040 ; 61504 #define SC_PREVWINDOW 0xF050 ; 61520 #define SC_CLOSE 0xF060 ; 61536 #define SC_VSCROLL 0xF070 ; 61552 #define SC_HSCROLL 0xF080 ; 61568 #define SC_MOUSEMENU 0xF090 ; 61584 #define SC_KEYMENU 0xF100 ; 61696 #define SC_ARRANGE 0xF110 ; 61712 #define SC_RESTORE 0xF120 ; 61728 #define SC_TASKLIST 0xF130 ; 61744 #define SC_SCREENSAVE 0xF140 ; 61760 #define SC_HOTKEY 0xF150 ; 61776 #define SC_DEFAULT 0xF160 ; 61792 #define SC_MONITORPOWER 0xF170 ; 61808 #define SC_CONTEXTHELP 0xF180 ; 61824 #define SC_PROPERTIES 0xE005 ; 57349 ; for DOS windows #define SC_TOOLBAR 0xE00E ; 57358 ; for DOS windows
This code written for 32 bit Windows 95 will remove the Close Menu item from the system menu, thus preventing the application from being closed. It also shows you how to re-enable the close menu item.
When porting to Windows NT, you might have to poke around at the USER32.DLL to find the correct file. Maybe USER32.EXE or similiar file.
As an example, this code affects a 'WinBatch Studio' window.
hwnd=DllHwnd("WinBatch Studio") ;Window Title of desired window goes here sysmenu=DllCall(strcat(DirWindows(1),"USER32.DLL"),long:"GetSystemMenu",long:hwnd,long:0) DllCall(strcat(DirWindows(1),"USER32.DLL"),long:"RemoveMenu",long:sysmenu,long:61536,long:0) ;Sc_Close MF_ByCommand Message("Check Close line now","Should be gone") ;and to turn Close back on DllCall(strcat(DirWindows(1),"USER32.DLL"),long:"GetSystemMenu",long:hwnd,long:1) Message("Check Close line now","Should be back")The 61536 was the SC_CLOSE. Replace that number with the decimal number of the item you want. Hint: Windows Calculator in "Scientific" mode can do hex to decimal conversions.
You ought to be able to get the example posted running. It removes the close button, then puts it back.
Intcontrol(12,10,"",0,0) Boxopen("Title","") hwnd=DllHwnd("Title") ;Window Title of desired window goes here sysmenu=DllCall(strcat(DirWindows(1),"USER32.DLL"),long:"GetSystemMenu",long:hwnd,long:0) DllCall(strcat(DirWindows(1),"USER32.DLL"),long:"RemoveMenu",long:sysmenu,long:61536,long:0);close DllCall(strcat(DirWindows(1),"USER32.DLL"),long:"RemoveMenu",long:sysmenu,long:61472,long:0);minimize DllCall(strcat(DirWindows(1),"USER32.DLL"),long:"RemoveMenu",long:sysmenu,long:61728,long:0);restore DllCall(strcat(DirWindows(1),"USER32.DLL"),long:"RemoveMenu",long:sysmenu,long:61488,long:0);max ;Sc_Close MF_ByCommand Message("Check Close/Min/Max/Restore","Shouldn't work now") timedelay(10) ;and to turn back on ;DllCall(strcat(DirWindows(1),"USER32.DLL"),long:"GetSystemMenu",long:hwnd,long:1) exit
It seems that under Win XP, the menu items disappear, but the icons remain (and remain functional to boot). However if using the XP theme type windows the minimize and restore remove options are ignored...
Any further insight would be greatly appreciated.
BTW, I also tried EnableMenuItem(...) but that didn't work either... :(
;constants user32=StrCat(DirWindows(1),"user32.dll") WS_MAXIMIZEBOX=65536 GWL_STYLE=-16 ;remove maximize style oldstyle=DllCall(user32,long:"GetWindowLongA",long:handle,long:GWL_STYLE) newstyle=oldstyle & ~WS_MAXIMIZEBOX DllCall(User32,long:"SetWindowLongA",long:handle,long:GWL_STYLE,long:newstyle)Assuming that handle is your dialog handle. I don't know if it's safe to use it anyway.
You can also add in minimize removal (WS_MINIMIZE = 131072), which effectively removes them from the dialog entirely.
Here is s UDF to Remove all but the terminate menu item:
#DefineFunction BoxRemoveSystemMenu(hwnd) sc_minimize= 61472 sc_maximize= 61488 sc_size = 61440 sc_move = 61456 sc_close = 61536 sc_restore = 61728 sysmenu=DllCall(StrCat(DirWindows(1),"USER32.DLL"),long:"GetSystemMenu",long:hwnd,long:0) DllCall(StrCat(DirWindows(1),"USER32.DLL"),long:"RemoveMenu",long:sysmenu,long:sc_minimize,long:0) DllCall(StrCat(DirWindows(1),"USER32.DLL"),long:"RemoveMenu",long:sysmenu,long:sc_maximize,long:0) DllCall(StrCat(DirWindows(1),"USER32.DLL"),long:"RemoveMenu",long:sysmenu,long:sc_size,long:0) DllCall(StrCat(DirWindows(1),"USER32.DLL"),long:"RemoveMenu",long:sysmenu,long:sc_move,long:0) DllCall(StrCat(DirWindows(1),"USER32.DLL"),long:"RemoveMenu",long:sysmenu,long:sc_close,long:0) DllCall(StrCat(DirWindows(1),"USER32.DLL"),long:"RemoveMenu",long:sysmenu,long:sc_restore,long:0) Return 1 #EndFunction hwnd=DllHwnd("") ; "" is shortcut for the WinBatch BoxOpen window BoxOpen("BoxRemoveSystemMenu","See that system menu itmes have been removed") BoxRemoveSystemMenu(hwnd) TimeDelay(5) BoxShut()
Article ID: W13252
Filename: Disable an Apps Close Menu Item.txt
File Created: 2012:04:04:07:56:58
Last Updated: 2012:04:04:07:56:58