Sign in to follow this  
Followers 0
Divane

Re-enable Closure [X]

3 posts in this topic

is there any way to revert? to enable close button previously disabled

Share this post


Link to post
Share on other sites



Divane,

Welcome to the AutoIt forums. :)

Did you notice that the original thread in which you posted dated from nearly 7 years ago? :huh:

Please do not necro-post like this again - just open a new thread and link to the old one if it is absolutely necessary for understanding the problem. We ask you to do this for two main reasons:

 

- 1. The language advances and the functionality might well be included in core or UDF code by now

- 2. The changes in language syntax mean that it is likely that code from more than a couple of years ago may well not run under the current release interpreter without significant modification.

All clear? :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

I looked into MSDN and wrapped the functions needed for more ease of use:

 

#include <GUIConstants.au3>
Global Const $SC_CLOSE = 0xF060
Global Const $MF_BYCOMMAND = 0x00000000
Global Const $MF_BYPOSITION = 0x00000400
Global Const $MF_DISABLED = 0x00000002
Global Const $MF_ENABLED = 0x00000000
Global Const $MF_GRAYED = 0x00000001

;disable automatic min/maximize and restore functionality
Opt("GUIEventOptions", 1)

$hGUI = GUICreate("Example", 200, 22, -1, -1, BitOR($WS_CAPTION, $WS_MINIMIZEBOX, $WS_MAXIMIZEBOX, $WS_SYSMENU))
$hSystemMenu = _WinAPI_GetSystemMenu($hGUI)
_WinAPI_EnableMenuItem($hSystemMenu, $SC_CLOSE, $MF_GRAYED)
GUICtrlCreateLabel("Push the minimize and maximize buttons.", 5, 5)
GUISetState()

#cs - doesn't really work (only close/maximize buttons stop sending notifications, but are not greyed out)
_WinAPI_EnableMenuItem($hSystemMenu, $SC_CLOSE, $MF_ENABLED)
$aItems = DllCall("user32.dll", "uint", "GetMenuItemCount", "hwnd", $hSystemMenu)
;~ MsgBox(0, "", $aItems[0])

For $i = 0 To $aItems[0] - 1
    $iPrev = _WinAPI_EnableMenuItem($hSystemMenu, $i, BitOR($MF_GRAYED, $MF_BYPOSITION))
    MsgBox(0, "Index: " & $i, "Previous state: 0x" & Hex($iPrev))
Next
#ce

While 1
    $idMsg = GUIGetMsg()
    Switch $idMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $GUI_EVENT_MAXIMIZE, $GUI_EVENT_RESTORE
            _WinAPI_EnableMenuItem($hSystemMenu, $SC_CLOSE, $MF_GRAYED)
        Case $GUI_EVENT_MINIMIZE
            _WinAPI_EnableMenuItem($hSystemMenu, $SC_CLOSE, $MF_ENABLED)
    EndSwitch
WEnd

Func _WinAPI_EnableMenuItem($hMenu, $iItem, $iEnable)
    #cs
    Parameters
        $hMenu
            A handle to the menu.

        $iItem
            The menu item to be enabled, disabled, or grayed, as determined by the uEnable parameter. This parameter specifies an item in a menu bar, menu, or submenu.

        $iEnable
            Controls the interpretation of the $iItem parameter and indicate whether the menu item is enabled, disabled, or grayed. This parameter must be a combination of the following values.

            Values:
                MF_BYCOMMAND
                0x00000000L
                Indicates that $iItem gives the identifier of the menu item. If neither the MF_BYCOMMAND nor MF_BYPOSITION flag is specified, the MF_BYCOMMAND flag is the default flag.

                MF_BYPOSITION
                0x00000400L
                Indicates that $iItem gives the zero-based relative position of the menu item.

                MF_DISABLED
                0x00000002L
                Indicates that the menu item is disabled, but not grayed, so it cannot be selected.

                MF_ENABLED
                0x00000000L
                Indicates that the menu item is enabled and restored from a grayed state so that it can be selected.

                MF_GRAYED
                0x00000001L
                Indicates that the menu item is disabled and grayed so that it cannot be selected.

    Return value
        The return value specifies the previous state of the menu item (it is either MF_DISABLED, MF_ENABLED, or MF_GRAYED).
        If the menu item does not exist, the return value is -1.
    #ce
    $aResult = DllCall("user32.dll", "bool", "EnableMenuItem", "hwnd", $hMenu, "uint", $iItem, "uint", $iEnable)
    If @error Then Return SetError(@error, @extended, 0)

    Return $aResult[0]
EndFunc

Func _WinAPI_GetSystemMenu($hWnd, $bRevert = False)
    #cs
    Parameters
        $hWnd
            A handle to the window that will own a copy of the window menu.

        $bRevert
            The action to be taken.
            If this parameter is FALSE, GetSystemMenu returns a handle to the copy of the window menu currently in use. The copy is initially identical to the window menu, but it can be modified.
            If this parameter is TRUE, GetSystemMenu resets the window menu back to the default state. The previous window menu, if any, is destroyed.

    Return value
        If the $bRevert parameter is FALSE, the return value is a handle to a copy of the window menu.
        If the $bRevert parameter is TRUE, the return value is NULL.
    #ce

    $aResult = DllCall("user32.dll", "hwnd", "GetSystemMenu", "hwnd", $hWnd, "bool", $bRevert)
    If @error Then Return SetError(@error, @extended, 0)

    ;uncomment the following line to replicate the winapi return if $bRevert is true (otherwise $aResult[0] will be 0x00000000)
;~     If $bRevert = True Then $aResult[0] = Null

    Return $aResult[0]
EndFunc
All the neccessary info is commented inside the functions. For further functionality with menus you can take a look at all the available menu functions http://msdn.microsoft.com/en-us/library/windows/desktop/ff468865(v=vs.85).aspx.
1 person likes this

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0