|
-
Apr 7th, 2005, 11:59 AM
#1
Re: Disable "close window option"
VB Code:
'In a module
'Call from any form, passing the Form object
Option Explicit On
Private Const MF_DISABLED = &H2&
Private Const MF_BYPOSITION = &H400&
Private Declare Function GetSystemMenu Lib "user32.dll" (ByVal hwnd As Int32, ByVal bRevert As Int32) As Int32
Private Declare Function GetMenuItemCount Lib "user32" (ByVal hMenu As Integer) As Integer
Private Declare Function RemoveMenu Lib "user32" (ByVal hMenu As Integer, ByVal nPosition As Integer, ByVal wFlags As Integer) As Integer
Private Declare Function DrawMenuBar Lib "user32" (ByVal hwnd As Integer) As Integer
Public Function DisableX(ByRef oForm As System.Windows.Forms.Form)
'<VB/OUTLOOK GURU 11/09/2004 - REMOVES FORM SYSTEM MENU ITEMS BY POSITIONS>
Dim hMenu As Int32
Dim nCount As Integer
hMenu = GetSystemMenu(oForm.Handle.ToInt32, 0)
nCount = GetMenuItemCount(hMenu)
Call RemoveMenu(hMenu, nCount - 1, MF_DISABLED Or MF_BYPOSITION)
nCount = GetMenuItemCount(hMenu)
Call RemoveMenu(hMenu, nCount - 1, MF_DISABLED Or MF_BYPOSITION)
Call DrawMenuBar(oForm.Handle.ToInt32)
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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 
-
Apr 7th, 2005, 12:15 PM
#2
PowerPoster
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.
-
Apr 7th, 2005, 12:20 PM
#3
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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 
-
Apr 7th, 2005, 06:43 PM
#4
PowerPoster
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.
-
Apr 7th, 2005, 07:35 PM
#5
Re: Disable "close window option"
Grey huh, 
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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 
-
Apr 7th, 2005, 09:17 PM
#6
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
-
Apr 11th, 2005, 09:44 AM
#7
Thread Starter
Member
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:
Module mdlMain
Public optionInterface As New frmOptions
Public insertNewmember As New frmInsertmember
Option Explicit On
Private Const MF_DISABLED = &H2&
Private Const MF_BYPOSITION = &H400&
Private Declare Function GetSystemMenu Lib "user32.dll" (ByVal hwnd As Int32, ByVal bRevert As Int32) As Int32
Private Declare Function GetMenuItemCount Lib "user32" (ByVal hMenu As Integer) As Integer
Private Declare Function RemoveMenu Lib "user32" (ByVal hMenu As Integer, ByVal nPosition As Integer, ByVal wFlags As Integer) As Integer
Private Declare Function DrawMenuBar Lib "user32" (ByVal hwnd As Integer) As Integer
Public Function DisableX(ByRef oForm As System.Windows.Forms.Form)
'<VB/OUTLOOK GURU 11/09/2004 - REMOVES FORM SYSTEM MENU ITEMS BY POSITIONS>
Dim hMenu As Int32
Dim nCount As Integer
hMenu = GetSystemMenu(oForm.Handle.ToInt32, 0)
nCount = GetMenuItemCount(hMenu)
Call RemoveMenu(hMenu, nCount - 1, MF_DISABLED Or MF_BYPOSITION)
nCount = GetMenuItemCount(hMenu)
Call RemoveMenu(hMenu, nCount - 1, MF_DISABLED Or MF_BYPOSITION)
Call DrawMenuBar(oForm.Handle.ToInt32)
End Function
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|