Important alert: (current site time 7/16/2013 2:02:17 AM EDT)
 

VB icon

[ A trick for forms ] Variation

Email
Submitted on: 3/29/2005 11:19:05 PM
By: Daniel M  
Level: Beginner
User Rating: By 1 Users
Compatibility: VB 6.0
Views: 12700
(About the author)
 
     After reading "Power of Anubis'" submission and reading LaVolpe's suggestion I decided to write a variation of his code and add on to it. Enjoy! Description: "This code kills the X of the control box. And kills the Close of the menu when click on the icon of the program!!!! WORKS!!!!!"
 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
 
Terms of Agreement:   
By using this code, you agree to the following terms...   
  1. You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
  2. You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
  3. You may link to this code from another website, but ONLY if it is not wrapped in a frame. 
  4. You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.
				
'**************************************
' Name: [ A trick for forms ] Variation
' Description:After reading "Power of Anubis'" submission and reading LaVolpe's suggestion I decided to write a variation of his code and add on to it. Enjoy!
Description: "This code kills the X of the control box. And kills the Close of the menu when click on the icon of the program!!!! WORKS!!!!!"
' By: Daniel M
'
'This code is copyrighted and has' limited warranties.Please see http://www.Planet-Source-Code.com/vb/scripts/ShowCode.asp?txtCodeId=59715&lngWId=1'for details.'**************************************

Option Explicit
'API Declarations
Private Declare Function GetMenuItemID Lib "user32" _
 (ByVal hMenu As Long, ByVal nPos As Long) As Long
Private Declare Function DrawMenuBar Lib "user32" _
 (ByVal hwnd As Long) As Long
 
Private Declare Function GetMenuItemCount Lib "user32" _
 (ByVal hMenu As Long) As Long
 
Private Declare Function GetSystemMenu Lib "user32" _
 (ByVal hwnd As Long, _
 ByVal bRevert As Long) As Long
Private Declare Function RemoveMenu Lib "user32" _
 (ByVal hMenu As Long, _
 ByVal nPosition As Long, _
 ByVal wFlags As Long) As Long
'Constants
Private Const MF_BYPOSITION = &H400
Private Const MF_REMOVE = &H1000
Private Const SC_CLOSE = &HF060&
Private Sub Form_Load()
 Dim hMenu As Long 'Menu Handle
 Dim menuItemCount As Long 'Menu Count
 Dim theItem As Long 'Item to remove
 Dim iAs Long
 
 hMenu = GetSystemMenu(Me.hwnd, 0) 'Get system menu from form
 theItem = -1 'Set initial variable for "not found"
 
 If hMenu Then 'If found then
menuItemCount = GetMenuItemCount(hMenu) 'Retrieve menu count
For i = 0 To menuItemCount 'Look for the "close" ID
 If GetMenuItemID(hMenu, i) = SC_CLOSE Then
theItem = i 'If found, quit loop
Exit For
 End If
Next i
If theItem <> -1 Then 'If found then remove item
 Call RemoveMenu(hMenu, theItem, _
 MF_REMOVE Or MF_BYPOSITION)
End If
If GetMenuItemID(hMenu, theItem - 1) = 0 Then 'If previous item is a menu sep
 Call RemoveMenu(hMenu, theItem - 1, _
 MF_REMOVE Or MF_BYPOSITION) 'then remove it for consistency.
End If
Call DrawMenuBar(Me.hwnd) 'Draw it!
 End If
End Sub


Other 27 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Beginner category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments

9/14/2007 10:56:44 AMarvind_ahd

nice one
(If this comment was disrespectful, please report it.)

 
8/25/2009 10:02:41 AMNguyen Van Thanh

I want become a good programmer
(If this comment was disrespectful, please report it.)

 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.