Changing Form's BorderStyle property at run time but before form is loaded 
Author Message
 Changing Form's BorderStyle property at run time but before form is loaded

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


Tue, 23 Oct 2012 05:05:57 GMT  
 Changing Form's BorderStyle property at run time but before form is loaded

Quote:

>           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.

Technically, not before it's loaded, but you can change it during the
Form_Load event using the techniques demonstrated here:

  http://vb.mvps.org/samples/FormBdr

--
.NET: It's About Trust!
http://vfred.mvps.org



Tue, 23 Oct 2012 05:40:43 GMT  
 Changing Form's BorderStyle property at run time but before form is loaded

Quote:
> 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.

Don't know if you actually do mean "before the form is loaded". You can
change its BorderStyle after it loads, or as it loads:

  Dim oldStyle As Long
  oldStyle = GetWindowLong(Form2.hwnd, GWL_STYLE)
  SetWindowLong Form2.hwnd, GWL_STYLE, oldStyle _
        And Not WS_THICKFRAME
  SetWindowPos Form2.hwnd, 0, 0, 0, 0, 0, _
        SWP_FRAMECHANGED Or SWP_NOMOVE Or _
        SWP_NOZORDER Or SWP_NOSIZE
  Form2.Show

Mike



Tue, 23 Oct 2012 05:51:14 GMT  
 Changing Form's BorderStyle property at run time but before form is loaded
Thank you Karl and Mike.
It does work perfectly.
Claire


Quote:
> 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



Tue, 23 Oct 2012 07:34:14 GMT  
 Changing Form's BorderStyle property at run time but before form is loaded

Almost done but I need to disable (grayed) X
How to do that?
Thanks,
Claire


Quote:
> Thank you Karl and Mike.
> It does work perfectly.
> Claire



>> 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



Tue, 23 Oct 2012 07:49:48 GMT  
 Changing Form's BorderStyle property at run time but before form is loaded
Claire wrote :

Quote:
> 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?


Tue, 23 Oct 2012 08:00:16 GMT  
 Changing Form's BorderStyle property at run time but before form is loaded
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


Quote:
> Thank you Karl and Mike.
> It does work perfectly.
> Claire



>> 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



Tue, 23 Oct 2012 08:04:57 GMT  
 Changing Form's BorderStyle property at run time but before form is loaded

Quote:
> 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



Tue, 23 Oct 2012 08:47:02 GMT  
 
 [ 8 post ] 

 Relevant Pages 

1. Changing form-properties while running before loading the form

2. Run-time error '31037': Error load form file

3. Changing a control's borderstyle and appearance at run-time

4. Run-Time form loading - form name retrieved from database

5. Changing form's icon during run-time

6. Help: Change a MDI child's parent MDI form at run-time

7. TextBox .BorderStyle property at run-time

8. changing BorderStyle at run-time

9. MDI parent forms and 'fixed borderstyle'

10. Loading a form at run-time

11. Loading a form at run-time

12. Help: Loading forms at run-time.

 

 
Powered by phpBB® Forum Software