[Tutorial] Disable X Button

Posts 1–14 of 14 · Page 1 of 1
[Tutorial] Disable X Button
Disable [X] button on form
More of a Snippet of code with a example project
Easy to follow.


Code:
     
' Description:This code will disable the [x] button on any form you know the HWND for
' By: NextGen1 of Mpgh.net
' This code is copyrighted and comes  with no warranties.
' This code is intended for demonstration and all rights are granted soley to mpgh.net and it's members
' If you require any further information please contact me at mpgh.net via PM (Get an account if you don't have one) 
' Tutorials and apps create by me for mpgh.net will contain the following agreement 
' By adding this code in whole or part to any existing or new application you agree to the following terms 
' You agree to keep these notes connected with this code.
' You agree to grant credit to it's source (Mpgh.net)   
' You agree to keep this note in whole without edit inside of your code

  Private Const MF_BYPOSITION = &H400
    Private Const MF_REMOVE = &H1000
    Private Const MF_ DISABLED = &H2

  Private Declare Function RemoveMenu Lib "user32" (ByVal hMenu As IntPtr, ByVal nPosition As Integer, ByVal wFlags As Long) As IntPtr
    Private Declare Function GetSystemMenu Lib "user32" (ByVal hWnd As IntPtr, ByVal bRevert As Boolean) As IntPtr
    Private Declare Function GetMenuItemCount Lib "user32" (ByVal hMenu As IntPtr) As Integer
    Private Declare Function DrawMenuBar Lib "user32" (ByVal hwnd As IntPtr) As Boolean

Public Sub DisableCloseButton(ByVal hwnd As IntPtr)
        Dim hMenu As IntPtr
        Dim menuItemCount As Integer

        hMenu = GetSystemMenu(hwnd, False)
        menuItemCount = GetMenuItemCount(hMenu)
        Call RemoveMenu(hMenu, menuItemCount - 1, MF_DISABLED Or MF_BYPOSITION)
        Call RemoveMenu(hMenu, menuItemCount - 2, MF_DISABLED Or MF_BYPOSITION)
        Call DrawMenuBar(hwnd)
    End Sub
This part disables the [x] Button

Code:
  ' Call disable , Examples: on button click , on load, wherever you want it.
DisableCloseButton(Me.Handle)
Screen Shots





Virus Scans

Source Code Scan

Sample Program Scan

Links

Source

Example

Note: Yes I just realized the linklabel says mpght.net it should be mpgh.net, however, it's a clickable link that takes you to mpgh.net

Note: You may need to make some minor changes to the code to match your controls and it's names
Thanks again ^^
Quote Originally Posted by Zoom View Post
Thanks again ^^
No Problem
problem with source, and i have this error:
MF_ DISABLED is not declared
Code:
Private Const MF_BYPOSITION = &H400
    Private Const MF_REMOVE = &H1000
    Private Const MF_ DISABLED = &H2


When you copy and paste (leecher )

It adds a space , remove it

Thats what you get for not typing it out...

Remove the space after MF_ before disabled
well i was going to give credit, but ok.
IMALEECHER
well, problem solved
XD another days work...
@NextGen1

Can You Give Me A Code For Visual Basic 8??

I'm using Visual Basic 2008
This is for visual basic 2008...

Vb.net = vb07-10, correct?
Oh I Get It...

EDIT:
But How Can Enable It???
what the...

there's a tut in the first post lol -.-
Sorry..

My Bad...

"How To Enable It Again??"
Enabletaskbar()

and for the text

startmenutext(textbox1.text)

the errors in bold are the typos in the tut.
Posts 1–14 of 14 · Page 1 of 1
This thread is closed for replies.

Similar Threads

Tags for this Thread

None

Talk with us