Results 1 to 2 of 2

Thread: Enable and Disable EXIT window button

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Oct 2001
    Location
    Philippines
    Posts
    136

    Unhappy Enable and Disable EXIT window button

    Hello there.

    Is there an API that i can use to Enable or Disable the EXIT (X) window button. I want to Enable or Disable it during run time of my application. pls help.


    Thanks in advance.
    elbimbo

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333
    VB Code:
    1. Private Const SC_CLOSE As Long = &HF060&
    2. Private Const MIIM_STATE As Long = &H1&
    3. Private Const MIIM_ID As Long = &H2&
    4. Private Const MFS_GRAYED As Long = &H3&
    5. Private Const WM_NCACTIVATE As Long = &H86
    6.  
    7. Private Type MENUITEMINFO
    8.     cbSize As Long
    9.     fMask As Long
    10.     fType As Long
    11.     fState As Long
    12.     wID As Long
    13.     hSubMenu As Long
    14.     hbmpChecked As Long
    15.     hbmpUnchecked As Long
    16.     dwItemData As Long
    17.     dwTypeData As String
    18.     cch As Long
    19. End Type
    20.  
    21. Private Declare Function GetSystemMenu Lib "user32" ( _
    22.     ByVal hWnd As Long, ByVal bRevert As Long) As Long
    23.  
    24. Private Declare Function GetMenuItemInfo Lib "user32" Alias _
    25.     "GetMenuItemInfoA" (ByVal hMenu As Long, ByVal un As Long, _
    26.     ByVal b As Boolean, lpMenuItemInfo As MENUITEMINFO) As Long
    27.  
    28. Private Declare Function SetMenuItemInfo Lib "user32" Alias _
    29.     "SetMenuItemInfoA" (ByVal hMenu As Long, ByVal un As Long, _
    30.     ByVal bool As Boolean, lpcMenuItemInfo As MENUITEMINFO) As Long
    31.  
    32. Private Declare Function SendMessage Lib "user32" Alias _
    33.     "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, _
    34.     ByVal wParam As Long, lParam As Any) As Long
    35.  
    36. Private Declare Function IsWindow Lib "user32" _
    37.     (ByVal hWnd As Long) As Long
    38.  
    39. Private m_blnCloseEnabled As Boolean
    40.  
    41. Public Function EnableCloseButton(ByVal hWnd As Long, Enable As Boolean) _
    42.                                                                 As Integer
    43.     Const xSC_CLOSE As Long = -10
    44.  
    45.     ' Check that the window handle passed is valid
    46.    
    47.     EnableCloseButton = -1
    48.     If IsWindow(hWnd) = 0 Then Exit Function
    49.    
    50.     ' Retrieve a handle to the window's system menu
    51.    
    52.     Dim hMenu As Long
    53.     hMenu = GetSystemMenu(hWnd, 0)
    54.    
    55.     ' Retrieve the menu item information for the close menu item/button
    56.    
    57.     Dim MII As MENUITEMINFO
    58.     MII.cbSize = Len(MII)
    59.     MII.dwTypeData = String(80, 0)
    60.     MII.cch = Len(MII.dwTypeData)
    61.     MII.fMask = MIIM_STATE
    62.    
    63.     If Enable Then
    64.         MII.wID = xSC_CLOSE
    65.     Else
    66.         MII.wID = SC_CLOSE
    67.     End If
    68.    
    69.     EnableCloseButton = -0
    70.     If GetMenuItemInfo(hMenu, MII.wID, False, MII) = 0 Then Exit Function
    71.    
    72.     ' Switch the ID of the menu item so that VB can not undo the action itself
    73.    
    74.     Dim lngMenuID As Long
    75.     lngMenuID = MII.wID
    76.    
    77.     If Enable Then
    78.         MII.wID = SC_CLOSE
    79.     Else
    80.         MII.wID = xSC_CLOSE
    81.     End If
    82.    
    83.     MII.fMask = MIIM_ID
    84.     EnableCloseButton = -2
    85.     If SetMenuItemInfo(hMenu, lngMenuID, False, MII) = 0 Then Exit Function
    86.    
    87.     ' Set the enabled / disabled state of the menu item
    88.    
    89.     If Enable Then
    90.         MII.fState = (MII.fState Or MFS_GRAYED)
    91.         MII.fState = MII.fState - MFS_GRAYED
    92.     Else
    93.         MII.fState = (MII.fState Or MFS_GRAYED)
    94.     End If
    95.    
    96.     MII.fMask = MIIM_STATE
    97.     EnableCloseButton = -3
    98.     If SetMenuItemInfo(hMenu, MII.wID, False, MII) = 0 Then Exit Function
    99.    
    100.     ' Activate the non-client area of the window to update the titlebar, and
    101.     ' draw the close button in its new state.
    102.    
    103.     SendMessage hWnd, WM_NCACTIVATE, True, 0
    104.    
    105.     EnableCloseButton = 0
    106.    
    107. End Function
    108.  
    109. 'Example
    110. Private Sub Command1_Click()
    111.         m_blnCloseEnabled = Not m_blnCloseEnabled
    112.         EnableCloseButton Me.hwnd, m_blnCloseEnabled
    113. End Sub

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width