Results 1 to 19 of 19

Thread: Disable "close window option"

Hybrid View

  1. #1
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Disable "close window option"

    VB Code:
    1. 'In a module
    2.     'Call from any form, passing the Form object
    3.     Option Explicit On
    4.  
    5.     Private Const MF_DISABLED = &H2&
    6.     Private Const MF_BYPOSITION = &H400&
    7.  
    8.     Private Declare Function GetSystemMenu Lib "user32.dll" (ByVal hwnd As Int32, ByVal bRevert As Int32) As Int32
    9.     Private Declare Function GetMenuItemCount Lib "user32" (ByVal hMenu As Integer) As Integer
    10.     Private Declare Function RemoveMenu Lib "user32" (ByVal hMenu As Integer, ByVal nPosition As Integer, ByVal wFlags As Integer) As Integer
    11.     Private Declare Function DrawMenuBar Lib "user32" (ByVal hwnd As Integer) As Integer
    12.  
    13.     Public Function DisableX(ByRef oForm As System.Windows.Forms.Form)
    14.         '<VB/OUTLOOK GURU 11/09/2004 - REMOVES FORM SYSTEM MENU ITEMS BY POSITIONS>
    15.         Dim hMenu As Int32
    16.         Dim nCount As Integer
    17.         hMenu = GetSystemMenu(oForm.Handle.ToInt32, 0)
    18.         nCount = GetMenuItemCount(hMenu)
    19.         Call RemoveMenu(hMenu, nCount - 1, MF_DISABLED Or MF_BYPOSITION)
    20.         nCount = GetMenuItemCount(hMenu)
    21.         Call RemoveMenu(hMenu, nCount - 1, MF_DISABLED Or MF_BYPOSITION)
    22.         Call DrawMenuBar(oForm.Handle.ToInt32)
    23.     End Function
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  2. #2
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949

    Re: Disable "close window option"

    Hi,

    You could put
    If bCheck = False then e.Cancel = True


    in the closing event of the form. Then when you come to the point in your code wher you want the form to close, set bCheck to true. (bCheck must have form scope of course)
    Taxes
    The more I learn about VB.NET the more I like dBaseIII Plus

    The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.

  3. #3
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Disable "close window option"

    True, but I like the greyed out disabled look and feel of removing the close option from the system menu.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  4. #4
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949

    Re: Disable "close window option"

    By the time I'd written all that code it would be ME that had the "Greyed out look"
    Taxes
    The more I learn about VB.NET the more I like dBaseIII Plus

    The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.

  5. #5
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Disable "close window option"

    Grey huh,
    VB Code:
    1. 'In Form1
    2. DisableX(Me)
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  6. #6
    Still learning kebo's Avatar
    Join Date
    Apr 2004
    Location
    Gardnerville,nv
    Posts
    3,762

    Re: Disable "close window option"

    damn...posted in the wrong thread....good beer tho
    kevin
    Process control doesn't give you good quality, it gives you consistent quality.
    Good quality comes from consistently doing the right things.

    Vague general questions have vague general answers.
    A $100 donation is required for me to help you if you PM me asking for help. Instructions for donating to one of our local charities will be provided.

    ______________________________
    Last edited by kebo : Now. Reason: superfluous typo's

  7. #7

    Thread Starter
    Member
    Join Date
    Nov 2004
    Posts
    35

    Re: Disable "close window option"

    Hello RobDog888,

    I used the code that you provided in my module where I have some more codes for different forms. So my module looks like as foloows now:

    VB Code:
    1. Module mdlMain
    2.     Public optionInterface As New frmOptions
    3.     Public insertNewmember As New frmInsertmember
    4.  
    5.     Option Explicit On
    6.  
    7.     Private Const MF_DISABLED = &H2&
    8.     Private Const MF_BYPOSITION = &H400&
    9.  
    10.     Private Declare Function GetSystemMenu Lib "user32.dll" (ByVal hwnd As Int32, ByVal bRevert As Int32) As Int32
    11.     Private Declare Function GetMenuItemCount Lib "user32" (ByVal hMenu As Integer) As Integer
    12.     Private Declare Function RemoveMenu Lib "user32" (ByVal hMenu As Integer, ByVal nPosition As Integer, ByVal wFlags As Integer) As Integer
    13.     Private Declare Function DrawMenuBar Lib "user32" (ByVal hwnd As Integer) As Integer
    14.  
    15.     Public Function DisableX(ByRef oForm As System.Windows.Forms.Form)
    16.         '<VB/OUTLOOK GURU 11/09/2004 - REMOVES FORM SYSTEM MENU ITEMS BY POSITIONS>
    17.         Dim hMenu As Int32
    18.         Dim nCount As Integer
    19.         hMenu = GetSystemMenu(oForm.Handle.ToInt32, 0)
    20.         nCount = GetMenuItemCount(hMenu)
    21.         Call RemoveMenu(hMenu, nCount - 1, MF_DISABLED Or MF_BYPOSITION)
    22.         nCount = GetMenuItemCount(hMenu)
    23.         Call RemoveMenu(hMenu, nCount - 1, MF_DISABLED Or MF_BYPOSITION)
    24.         Call DrawMenuBar(oForm.Handle.ToInt32)
    25.     End Function
    26. End Module



    VB.NET does not like "Option Explicit On" so I commented it out and run the code. I could not achive the goal.

    I am new in VB.NET so please bear with me and let me know how to handle this situation. Thank you.

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