Results 1 to 4 of 4

Thread: Removing the X

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Mar 2001
    Posts
    82

    Exclamation



    I got this code from a reply. I couldn't find my thread so I couldn't follow it up there. It's suppose to disable the X at the upper right corner of the Window which exits the form.

    Private Declare Function RemoveMenu Lib "user32" (ByVal hMenu As Long, ByVal nPosition As Long, ByVal wFlags As Long) As Long
    Private Declare Function GetSystemMenu Lib "user32" (ByVal hWnd As Long, ByVal bRevert As Long) As Long
    Private Const MF_BYPOSITION = &H400&

    Private Sub Form_Load()
    RemoveMenu GetSystemMenu(Me.hWnd, 0), 6, MF_BYPOSITION 'removes the "X" box and the System Menu
    End Sub

    Well, if you'll try this code, it would look as if it would work the way it does. The X would become gray in color, but when I accidentally clicked the button, my form still exits!!!

    Please help!!!

  2. #2
    Matthew Gates
    Guest
    It's disabled for me.
    But to keep your form from closing when the X button is clicked, add this to the Form_Unload() or Form_QueryUnload() event(s).

    Code:
    Cancel = True

  3. #3
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Cool

    The API call worked just fine for me.
    Here is my working example - just download the project I attacheed for you. I clicked on the 'X' and it doesn't cancel. If it doesn't work then and the queryunload event event with cancel = true like Matthew said.

    btw - what version VB and Windows are you running?

    Attached Files Attached Files
    Last edited by RobDog888; Apr 23rd, 2001 at 03:50 PM.

  4. #4
    Megatron
    Guest
    Matthew Gates: That code will prevent the Form from closing, but it will prevent it in all cases. What you need to do in this case is to make use of the UnloadMode argument of the QueryUnload() event.
    Code:
    If UnloadMode = 0 Then Cancel = True

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width