make the 'X' button go away


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: make the 'X' button go away

  1. #1
    Join Date
    Aug 2004
    Posts
    43,023

    make the 'X' button go away

    [Originally posted by j]

    Hi,

    I am able to make the MinButton and MaxButton disappear from the title bar on a form, but how do I make the "X" button disappear. I do not want the user to close the window this way.

    Thanks in advance.

    j

  2. #2
    Join Date
    Aug 2004
    Posts
    43,023

    Re:make the 'X' button go away

    [Originally posted by vtd]


    Try this one
    http://www.freevbcode.com/ShowCode.ASP?ID=342

    I just copy from a link above:

    Private Declare Function GetSystemMenu Lib "user32" (ByVal hwnd _
    As Long, ByVal bRevert As Boolean) As Long

    Private Declare Function GetMenuItemCount Lib "user32" (ByVal _
    hMenu As Long) As Long

    Private Declare Function RemoveMenu Lib "user32" (ByVal _
    hMenu As Long, ByVal nPosition As Long, ByVal wFlags As Long) _
    As Long

    Private Declare Function DrawMenuBar Lib "user32" _
    (ByVal hwnd As Long) As Long

    Private Const MF_BYPOSITION = &H400&
    Private Const MF_REMOVE = &H1000&
    Public Sub DisableClose(frm As Form, Optional _
    Disable As Boolean = True)
    'Setting Disable to False disables the 'X',
    'otherwise, it's reset

    Dim hMenu As Long
    Dim nCount As Long

    If Disable Then
    hMenu = GetSystemMenu(frm.hwnd, False)
    nCount = GetMenuItemCount(hMenu)

    Call RemoveMenu(hMenu, nCount - 1, MF_REMOVE Or _
    MF_BYPOSITION)
    Call RemoveMenu(hMenu, nCount - 2, MF_REMOVE Or _
    MF_BYPOSITION)

    DrawMenuBar frm.hwnd
    Else
    GetSystemMenu frm.hwnd, True

    DrawMenuBar frm.hwnd
    End If

    End Sub

    Private Sub Form_Load()
    DisableClose Me
    End Sub

  3. #3
    Join Date
    Aug 2004
    Posts
    43,023

    Re:make the 'X' button go away

    [Originally posted by Faisal Ali]

    in forms properties set
    control box = false

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center