DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 3 of 3
  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

Bookmarks

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


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links