DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 4 of 4

Thread: How to capture Control Box events

  1. #1
    Join Date
    Feb 2007

    How to capture Control Box events

    Darn - I've done this years ago but forgot how. I want to take control when a user clicks on the little red X in the upper right corner of a form. You know, the one that closes a program. I need to control how the program terminates. I have a special icon for the user to click on to end the program but I need to keep a control box so that the program can be minimized. If I could only show the Minimize option in the upper right corner, that would be good but it looks like I can only enable/disable the MaxButton or the whole ControlBox.

  2. #2
    Join Date
    Apr 2007
    Sterling Heights, Michigan
    Do whatever you need to do for any or all of the possibilities
    Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
    'there are 5 unloadmode levels
            Select Case UnloadMode
                Case vbFormControlMenu 'UnloadMode 0
                     'form is being unloaded via the Close
                     'or by hitting the X in the upper right hand corner
                     'command from the System menu
                Case vbFormCode        'UnloadMode 1
                     'Unload Me has been issued from code
                Case vbAppWindows      'UnloadMode 2
                     'Windows itself is closing
                Case vbAppTaskManager  'UnloadMode 3
                     'the Task Manager is closing the app
                Case vbFormMDIForm     'UnloadMod 4
                     'an MDI child form is closing because
                     'its parent form is closing
            End Select
    End Sub
    vbFormControlMenu, or UnloadMode 0, is probably the one you want to focus on.

  3. #3
    Join Date
    Nov 2003
    Portland, OR
    You can also disable the Close option in the control menu:, but I don't recommend changing Windows' standard behavior.
    Phil Weber

    Please post questions to the forums, where others may benefit.
    I do not offer free assistance by e-mail. Thank you!

  4. #4
    Join Date
    Feb 2007
    Thanks all. Hack, your code worked perfectly. The more I do in VB, the more I realize I don't know much. Now that I know about QueryUnload, I can use it. The trick is finding out about QueryUnload in the first place. Seems like things were a lot easier in my old Fortran/Algol/Cobol/C/Assembler days. I need to get that book that promises to make VB simple in only 2,000 pages

Similar Threads

  1. CEdit Control Event Capture
    By Complete in forum C++
    Replies: 2
    Last Post: 08-02-2007, 09:03 PM
  2. Declaring control events in XML file
    By mhadamji in forum .NET
    Replies: 0
    Last Post: 09-01-2006, 04:34 AM
  3. Replies: 0
    Last Post: 08-28-2003, 11:15 PM
  4. Drag capture screen of Webbrowser control
    By Phil N. in forum VB Classic
    Replies: 3
    Last Post: 10-30-2001, 10:57 AM
  5. Move Windows ( control box )
    By Marcelo Duarte in forum VB Classic
    Replies: 4
    Last Post: 06-27-2001, 08:14 AM

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
Latest Articles
Questions? Contact us.
Web Development
Latest Tips
Open Source

   Development Centers

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