From: Karl E. Peterson on 6 May 2010 20:00 Claire wrote : > Almost done but I need to disable (grayed) X > How to do that? Not sure it's exactly what you're looking for, but what about that ControlBox property in the CFormBorder class I directed you to?
From: Claire on 6 May 2010 20:04 I have found the way. using GWL_EXSTYLE with WS_EX_TOOLWINDOW does disable X but also it removes the icon. I can live without the icon. I wonder if in my case should I use first GWL_STYLE and then GWL_EXSTYLE like below: =================== oldStyle = GetWindowLong(Me.hWnd, GWL_STYLE) SetWindowLong Me.hWnd, GWL_STYLE, oldStyle Or WS_CAPTION Or WS_SYSMENU oldStyle = GetWindowLong(Me.hWnd, GWL_EXSTYLE) SetWindowLong Me.hWnd, GWL_EXSTYLE, oldStyle Or WS_EX_TOOLWINDOW =================== Is that correct? Thanks, Claire "Claire" <replyto(a)fra> wrote in message news:%23c8tkSX7KHA.3924(a)TK2MSFTNGP04.phx.gbl... > Thank you Karl and Mike. > It does work perfectly. > Claire > > "Claire" <replyto(a)fra> wrote in message > news:%23i%236t$V7KHA.3504(a)TK2MSFTNGP05.phx.gbl... >> Hello, >> Is there any workaround to change the form's BorderStyle >> property before the form is loaded? >> I need to change it from None to Fixed Single depending on user's >> preferences. >> That form is not the main form of the project. >> Your thoughts appreciated, >> Claire >> > >
From: David Youngblood on 6 May 2010 20:47 "Claire" <replyto(a)fra> wrote in message news:uAcqRbX7KHA.356(a)TK2MSFTNGP05.phx.gbl... > Almost done but I need to disable (grayed) X That one's not so easy, but is doable. Using the below code To disable, m_fCloseEnabled = EnableCloseButton(hwnd, False) To toggle, m_fCloseEnabled = EnableCloseButton(hwnd, Not m_fCloseEnabled) David Watch for word wrap, Private Const SC_CLOSE As Long = &HF060& Private Const MIIM_STATE As Long = &H1& Private Const MIIM_ID As Long = &H2& Private Const MF_ENABLED As Long = &H0& Private Const MF_GRAYED As Long = &H3& Private Type MENUITEMINFO cbSize As Long fMask As Long fType As Long fState As Long wID As Long hSubMenu As Long hbmpChecked As Long hbmpUnchecked As Long dwItemData As Long dwTypeData As Long 'String cch As Long End Type '* Retreives the handle to the system menu for the specified window Private Declare Function GetSystemMenu Lib "user32" ( _ ByVal hwnd As Long, _ ByVal bRevert As Long) As Long '* Retreives inforamtion about a menu entry Private Declare Function GetMenuItemInfo Lib "user32" _ Alias "GetMenuItemInfoA" ( _ ByVal hMenu As Long, _ ByVal un As Long, _ ByVal b As Boolean, _ lpMenuItemInfo As MENUITEMINFO) As Long '* Set the specified information for a menu entry Private Declare Function SetMenuItemInfo Lib "user32" _ Alias "SetMenuItemInfoA" ( _ ByVal hMenu As Long, _ ByVal un As Long, _ ByVal bool As Boolean, _ lpcMenuItemInfo As MENUITEMINFO) As Long '* Enables/disables the specified menu item Private Declare Function EnableMenuItem Lib "user32" ( _ ByVal hMenu As Long, _ ByVal wIDEnableItem As Long, _ ByVal wEnable As Long) As Long '* Redraws the menu for the specified window Private Declare Function DrawMenuBar Lib "user32" ( _ ByVal hwnd As Long) As Long '* Form close button state Private m_fCloseEnabled As Boolean Public Function EnableCloseButton(ByVal hwnd As Long, ByVal Enable As Boolean) As Boolean '* Purpose : Enables/disables Close system menu item '* Accepts : hWnd - handle of the window ' Enable - True to enable, False to disable '* Returns : Boolean - enabled state '* Modified : 8/14/2006 dwy '* Note : Alt+F4 must be handled in the Query_Unload event '* : Errors are handled by the calling procedure Dim hMenu As Long Dim mii As MENUITEMINFO '* Default value EnableCloseButton = Enable '* Get a handle to the system menu hMenu = GetSystemMenu(hwnd, 0) If hMenu Then '* Fill in size parameter mii.cbSize = Len(mii) If Enable Then '* Get the menu item information for the close menu item '* Exit if it fails, item is most likely already enabled If GetMenuItemInfo(hMenu, -SC_CLOSE, False, mii) = 0 Then GoTo PROC_EXIT End If '* Switch the ID of the menu item so that VB can't reset it mii.wID = SC_CLOSE mii.fMask = MIIM_ID If SetMenuItemInfo(hMenu, -SC_CLOSE, False, mii) = 0 Then GoTo PROC_EXIT End If '* Set enabled state of the menu item EnableCloseButton = EnableMenuItem(hMenu, SC_CLOSE, MF_ENABLED) Else '* Get the menu item information for the close menu item '* Exit if it fails, item is most likely already disabled(grayed) If GetMenuItemInfo(hMenu, SC_CLOSE, False, mii) = 0 Then GoTo PROC_EXIT End If '* Switch the ID of the menu item so that VB can't reset it mii.wID = -SC_CLOSE mii.fMask = MIIM_ID If SetMenuItemInfo(hMenu, SC_CLOSE, False, mii) = 0 Then GoTo PROC_EXIT End If '* Set disabled state of the menu item EnableCloseButton = EnableMenuItem(hMenu, -SC_CLOSE, MF_GRAYED) End If '* Force a redraw of the menu Call DrawMenuBar(hwnd) End If PROC_EXIT: Exit Function End Function Private Sub Form_Load() m_fCloseEnabled = True End Sub Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer) If UnloadMode = vbFormControlMenu Then Cancel = Not m_fCloseEnabled End If End Sub
First
|
Prev
|
Pages: 1 2 Prev: monitor if computer is in idle Next: Microsoft Responds to the Evolution of Online Communities |