Results 1 to 12 of 12

Thread: DestroyWindow Problems

  1. #1
    Megatron
    Guest
    Try WM_QUIT.

  2. #2
    PowerPoster
    Join Date
    Aug 2000
    Location
    India
    Posts
    2,288
    Yes, tried but of no use. Or maybe I ma not using the right sequence. What's the right sequence? I will the post the code in a few minutes.

  3. #3
    PowerPoster
    Join Date
    Aug 2000
    Location
    India
    Posts
    2,288
    I will post the code a little later(hour or two) as i have to go for
    some urgent work right now.

  4. #4
    Megatron
    Guest
    The correct order should be:

    WM_CLOSE
    WM_DESTROY
    WM_NCDESTROY
    WM_QUIT

  5. #5
    PowerPoster
    Join Date
    Aug 2000
    Location
    India
    Posts
    2,288
    Still doesn't work in some cases. I have explained in the comments
    Code:
    Option Explicit
    Private Declare Function DestroyWindow Lib "user32" _
    (ByVal hwnd As Long) As Long
    
    Private Declare Function SendMessage Lib "user32" _
    Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, _
    ByVal wParam As Long, lParam As Any) As Long
    
    Private Declare Function FindWindowEx Lib "user32" _
    Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, _
    ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
    
    Dim lngHwndMsgBox As Long
    Dim lngRV As Long
    
    Private Const WM_CLOSE = &H10
    
    Private Const WM_DESTROY = &H2
    
    Private Const WM_NCDESTROY = &H82
    
    Private Const WM_QUIT = &H12
    
    Private Sub Command1_Click()
        lngHwndMsgBox = FindWindowEx(0&, 0&, vbNullString, "Test MsgBox")
        
    'Send Message with WM_CLOSE
    'works on vbOkOnly,vbOkCancel,vbYesNoCancel & vbRetryCancel buttons MsgBox
    'All the above working MsgBox conditions have "Esc" key enabled
    'doesnot work on vbAbortRetryIgnore and vbYesNo
        'lngRV = SendMessage(lngHwndMsgBox, WM_CLOSE, 0&, 0&)
        
    
    
    'Kills all MsgBoxes, but the application stops responding
        lngRV = SendMessage(lngHwndMsgBox, WM_CLOSE, 0&, 0&)
        lngRV = SendMessage(lngHwndMsgBox, WM_DESTROY, 0&, 0&)
        lngRV = SendMessage(lngHwndMsgBox, WM_NCDESTROY, 0&, 0&)
        lngRV = SendMessage(lngHwndMsgBox, WM_QUIT, 0&, 0&)
    
    End Sub

  6. #6
    PowerPoster
    Join Date
    Aug 2000
    Location
    India
    Posts
    2,288
    Any ideas. Do I need to put it in a Do..While loop

  7. #7
    Registered User Nucleus's Avatar
    Join Date
    Apr 2001
    Location
    So that's what you are up to ;)
    Posts
    2,530
    What do you want to do? If you want to click a button may use once you have the hwnd of the button:

    Private Declare Function PostMessage Lib _
    "user32" Alias "PostMessageA" (ByVal hWnd As Long, _
    ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) _
    As Long

    Private Const WM_LBUTTONDOWN = &H201
    Private Const WM_LBUTTONUP = &H202
    Private Const MK_LBUTTON = &H1
    Private Const WM_RBUTTONDOWN = &H204
    Private Const WM_RBUTTONUP = &H205
    Private Const MK_RBUTTON = &H2

  8. #8
    PowerPoster
    Join Date
    Aug 2000
    Location
    India
    Posts
    2,288
    Yes, thats certainly a way. I can even send a BM_CLICK message to the command button. But what i want to know is why does it work in some cases, while in others it doesn't.

  9. #9
    Registered User Nucleus's Avatar
    Join Date
    Apr 2001
    Location
    So that's what you are up to ;)
    Posts
    2,530
    I cam confirm the behaviour, and even tried it in a do while loop, but still no luck closing msgboxes using that approach.

  10. #10
    Registered User Nucleus's Avatar
    Join Date
    Apr 2001
    Location
    So that's what you are up to ;)
    Posts
    2,530
    amitabh,

    I found out why...

    Sending the wm_close to the window is the equivalent of clicking the "x" on the form.

    Now, check out the state of the "x" on a vbyesno message box...it is disabled, so you can't close such a message box this way.

    You will have to find the hwnd of the button and click either yes or no.

  11. #11
    PowerPoster
    Join Date
    Aug 2000
    Location
    India
    Posts
    2,288
    Oh good
    Thanks
    But what about WM_Quit, Wm_Destroy, WM_NCDestroy. Why aren't they working. Anyway
    I have implemented this through clicking of command buttons

  12. #12
    Registered User Nucleus's Avatar
    Join Date
    Apr 2001
    Location
    So that's what you are up to ;)
    Posts
    2,530
    Perhaps you could also use:

    Code:
    Private Declare Function TerminateProcess& Lib "kernel32" (ByVal hProcess As Long, ByVal uExitCode As Long)

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