Results 1 to 9 of 9

Thread: Problem in Subclassing

  1. #1

    Thread Starter
    Frenzied Member moinkhan's Avatar
    Join Date
    Jun 2000
    Location
    Karachi, Pakistan
    Posts
    2,011

    Problem in Subclassing

    i m having the problem in subclassing.. I want to capture WM_CLOSE message and want to do something other than just closing.. then i want to close the form as well. ... everything goes right..other than when i try to close the form.. i don't want it's default proc to handle this message so i skip calling it.. but when i use SendMessage to close my form.. it's closing my whole application... and if i use DestroyWindow then it's not returning resources to the system... so form is out but resources are still there...
    Do u have any idea?

  2. #2
    Frenzied Member Shawn N's Avatar
    Join Date
    Dec 2001
    Location
    Houston
    Posts
    1,631
    Why not "unsubclass" right before sending out the WM_CLOSE message?
    Please rate my post.

  3. #3

    Thread Starter
    Frenzied Member moinkhan's Avatar
    Join Date
    Jun 2000
    Location
    Karachi, Pakistan
    Posts
    2,011
    This way wouldn't its default proc run?

  4. #4
    Frenzied Member Shawn N's Avatar
    Join Date
    Dec 2001
    Location
    Houston
    Posts
    1,631
    I'm not sure what your last reply meant.

    Anyways, 2nd option: Try sending additional data in your wParam or lParam. Test for it in your subclassing procedure and skip the message processing if necessary.

    Example:

    VB Code:
    1. SendMessage frmMain.hwnd, WM_CLOSE, 12345, 0

    VB Code:
    1. Case WM_CLOSE
    2.      If wParam = 12345 Then 'No need to process
    3.           'call default proc
    4.           Exit Sub
    5.      End If
    Please rate my post.

  5. #5

    Thread Starter
    Frenzied Member moinkhan's Avatar
    Join Date
    Jun 2000
    Location
    Karachi, Pakistan
    Posts
    2,011
    But it's also not working..

  6. #6
    Frenzied Member wpearsall's Avatar
    Join Date
    Feb 2002
    Location
    England / UK
    Posts
    1,065
    is this what u mean....

    [make sure if u are closing the app, u unsubclass first, AND DONT USE END! it will screw the app.]
    Attached Files Attached Files
    Wayne

  7. #7

    Thread Starter
    Frenzied Member moinkhan's Avatar
    Join Date
    Jun 2000
    Location
    Karachi, Pakistan
    Posts
    2,011
    I am doing exactly whatever u said....

    Let me tell u the actual situation....
    I have a control which shows a dialog box when i close the form containing that control... (it does so only in exe) i want to override this behavior my hooking the default window procedure...and process WM_CLOSE message myself..
    the problem is that.. whenever i used any method to close the form that messes up the things..
    If I use sendmessage to send WM_CLOSE Event. that closes the whole application with an illegal operation message, when i use DestroyWindow it doesn't unload the form..and another thing that form doesn't get loaded again..once i've used DestroyWindow to close the form...
    I think now the things are clear

  8. #8
    Frenzied Member wpearsall's Avatar
    Join Date
    Feb 2002
    Location
    England / UK
    Posts
    1,065
    how bout shelling a seperate app,
    instead of loading a form....

    depending on what you need to do on the "exit form", it should work...

    VB Code:
    1. private sub form_unload(cancel as integer)
    2. on error resume next
    3.     call shell(app.path & "\ExitApp.exe")
    4.     if err then err.clear
    5. end sub
    Wayne

  9. #9
    Addicted Member Abilio's Avatar
    Join Date
    May 2003
    Location
    Aveiro - Portugal
    Posts
    222
    Post the code. I must see it before.

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