Flashz Posted February 13, 2006 Share Posted February 13, 2006 From the previous posts I got the 2 lines below to disable the X button from a cmd window. $SC_CLOSE = 0xF060 DllCall("User32.dll", "int", "RemoveMenu", "hwnd", $hSysMenu, "int", $SC_CLOSE, "int", 0) DllCall("User32.dll", "int", "DrawMenuBar", "hwnd", $handle) Is there a way to enable the X button again after executing the codes above? Link to comment Share on other sites More sharing options...
GaryFrost Posted February 13, 2006 Share Posted February 13, 2006 From the previous posts I got the 2 lines below to disable the X button from a cmd window. $SC_CLOSE = 0xF060 DllCall("User32.dll", "int", "RemoveMenu", "hwnd", $hSysMenu, "int", $SC_CLOSE, "int", 0) DllCall("User32.dll", "int", "DrawMenuBar", "hwnd", $handle) Is there a way to enable the X button again after executing the codes above? You'll need to save the handle to the menu before removing it, for example Func _GUICtrlMenuGetSub($GSM_hWnd, $GSM_pos) If $GSM_hWnd <= 0 Or $GSM_pos < 0 Then Return 0 $GSM_r = DLLCall("user32.dll","hwnd","GetSubMenu", _ "hwnd",$GSM_hWnd, _ "int",$GSM_pos) If Not @error Then Return $GSM_r[0] Return 0 EndFunc Not sure if an appendmenu would be the way to get it back. instead of remove, you might want to look into EnableMenuItem at MSDN The EnableMenuItem function enables, disables, or grays the specified menu item. SciTE for AutoItDirections for Submitting Standard UDFs Don't argue with an idiot; people watching may not be able to tell the difference. Link to comment Share on other sites More sharing options...
GaryFrost Posted February 13, 2006 Share Posted February 13, 2006 (edited) expandcollapse popupGlobal $MF_CHECKED = 0x00000008;..... A check mark is placed next ; to the item (for drop-down menus, ; submenus, and shortcut menus only). Global $MF_ENABLED = 0x00000000;..... Indicates that the menu item is enabled ; and restored from a grayed state so that ; it can be selected. Global $MF_DISABLED = 0x00000002;.... The item is disabled. Global $MF_GRAYED = 0x00000001;...... The item is disabled and grayed. Global $MF_HILITE = 0x00000080;...... The item is highlighted. Global $MF_MENUBARBREAK = 0x00000020; This is the same as the ; MF_MENUBREAK flag, except for ; drop-down menus, submenus, and ; shortcut menus, where the new column ; is separated from the old column ; by a vertical line. Global $MF_MENUBREAK = 0x00000040;... The item is placed on a new line ; (for menu bars) or in a new column ; (for drop-down menus, submenus, and ; shortcut menus) without separating columns. Global $MF_OWNERDRAW = 0x00000100;... The item is owner-drawn. Global $MF_POPUP = 0x00000010 ;... Menu item is a submenu. Global $MF_SEPARATOR = 0x00000800;... There is a horizontal dividing line ; (for drop-down menus, submenus, and ; shortcut menus only). Run("calc") WinWait("Calculator") $hWnd = WinGetHandle("Calculator") $hMenu = GetSystemMenu($hWnd) EnableMenuItem($hMenu,6,1,BitOR($MF_DISABLED,$MF_GRAYED)) HotKeySet("{F5}","_ReEnable") While 1 Sleep ( 200 ) WEnd Func _ReEnable() EnableMenuItem($hMenu,6,1,$MF_ENABLED) Exit EndFunc Func EnableMenuItem($DMI_hWnd, $DMI_id, $DMI_Opt, $DMI_State) If $DMI_hWnd <= 0 Or $DMI_id < 0 Then Return -1 $MF_BYCOMMAND = 0x00000000 $MF_BYPOSITION = 0x00000400 If $DMI_Opt = 0 Then $DMI_Opt = BitOR($MF_BYCOMMAND,$DMI_State) Else $DMI_Opt = BitOR($MF_BYPOSITION,$DMI_State) EndIf $DMI_r = DllCall("user32.dll","hwnd","EnableMenuItem", _ "hwnd",$DMI_hWnd, _ "int",$DMI_id, _ "int",$DMI_opt ) If @error Then Return 0 Return $DMI_r[0] EndFunc Func GetSystemMenu($GSM_hWnd, $GSM_bRevert=0) If $GSM_hWnd <= 0 Then Return -1 If $GSM_bRevert <> 0 Then $GSM_bRevert = 1 $GSM_r = DllCall("user32.dll","hwnd","GetSystemMenu", _ "hwnd",$GSM_hWnd, _ "int",$GSM_bRevert) If @error Then Return -1 Return $GSM_r[0] EndFunc Edited February 13, 2006 by gafrost SciTE for AutoItDirections for Submitting Standard UDFs Don't argue with an idiot; people watching may not be able to tell the difference. Link to comment Share on other sites More sharing options...
Flashz Posted February 14, 2006 Author Share Posted February 14, 2006 Your codes work great. Thanks a lot. I've added DllCall("User32.dll", "int", "DrawMenuBar", "hwnd", $hWnd) to refresh the menubar right after the changes. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now