Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

Using SendMessage(hWnd, WM_CLOSE, 0, 0) Freezes My Program

$
0
0
Hello Everybody,
I am making a program in VB 2008 using API functions to find all the windows that are opened and get
there handles, classes, Id, and so on and put it into listboxes. Then whatever one i choose in the list
i can send keys, button clicks, and other stuff. Everything is working good until i get to sending a
WM_CLOSE message to programs like notepad that pop up the (save file dialog). When it pops up my program
freezes and will not respond until i manually click (yes, no, or cancel). I want to have my program find
the new popup and send the button click to it. I tried setting focus back to my program but it will not
continue to the focus command. Do i need to set a hook or set my program as the parent or something ?

This is the close button code :
    Private Sub TSB_Close_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TSB_Close.Click
        SetForegroundWindow(hWnd)
        SendMessage(hWnd, WM_SETFOCUS, IntPtr.Zero, IntPtr.Zero)
        SendMessage(hWnd, WM_CLOSE, 0, 0)

        'It Freezes here and will not continue or respond until
        'i manually click (yes, no, or cancel) with the mouse.

        Me.BringToFront()
        Me.Focus()
        selhdl = ""
        ListDesktopWindows()
    End Sub


Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>