DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 3 of 3
  1. #1
    Join Date
    Sep 2004
    Posts
    37

    add function to exit (X) control button

    Is there a way to have the (X) button (in the upper right hand corner of a form) call a function? Right now in the program I am writing I have a saveChanges() function and I want it to be called when the user tries to exit (if they haven't saved). The saveChanges() function I wrote works great with everything else, but when I have it called on formClosing and I cancel (from the save changes dialog) it continues to close the application. What I'd like to do is...

    onClick "X"
    saveChanges()

    This way I could either tell the form to close or to do nothing. Anyway to access that buttons controls?

    merci

    vs

  2. #2
    Join Date
    Nov 2003
    Location
    Portland, OR
    Posts
    8,387
    See if this helps:
    http://www.ftponline.com/archives/pr...111/qa0111.asp

    (Look at the second Q&A in the article)
    Phil Weber
    http://www.philweber.com

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

  3. #3
    Join Date
    Aug 2004
    Location
    Iowa
    Posts
    28
    Another option you have is to disable the "X" completely and make the user click another button somewhere on the form to exit. There should be a post on here somewhere about it (because these gentlemen helped me with it a couple months ago). Here is the code from my program:


    Private Declare Function GetSystemMenu Lib "user32.dll" (ByVal hWnd As IntPtr, ByVal bRevert As Int32) As IntPtr

    Private Declare Function GetMenuItemCount Lib "user32.dll" (ByVal hMenu As IntPtr) As Int32

    Private Declare Function DrawMenuBar Lib "user32.dll" (ByVal hWnd As IntPtr) As Int32

    Private Declare Function RemoveMenu Lib "user32.dll" (ByVal hMenu As IntPtr, ByVal nPosition As Int32, ByVal wFlags As Int32) As Int32

    Private Const MF_BYPOSITION As Int32 = &H400
    Private Const MF_REMOVE As Int32 = &H1000

    Private Sub RemoveCloseButton(ByVal frmForm As Form)
    Dim hMenu As IntPtr, n As Int32
    hMenu = GetSystemMenu(frmForm.Handle, 0)
    If Not hMenu.Equals(IntPtr.Zero) Then
    n = GetMenuItemCount(hMenu)
    If n > 0 Then
    RemoveMenu(hMenu, n - 1, MF_BYPOSITION Or MF_REMOVE)
    RemoveMenu(hMenu, n - 2, MF_BYPOSITION Or MF_REMOVE)
    DrawMenuBar(frmForm.Handle)
    End If
    End If
    End Sub

    I then have another button somewhere else on the form that, when clicked, does whatever I tell it to.

    Hope this helps!

    Shaun
    One, two, FIVE!
    Three, sir.
    THREE!

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