I am working on a program that sends keys, button clicks, and so on to external windows. If i send a close command to notepad or wordpad and it pops up the (save file dialog window) it freezes my program. I can`t even click on my program window to bring it back into focus until i click yes, no, or cancel on the (save file dialog window). This stops my program from finding the dialog window so i can send it a button click. Why is it freezing my program ?
This is an example of my code:
This is an example of my code:
Code:
Private Sub TSB_Close_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TSB_Close.Click SendMessage(hWnd, WM_CLOSE, 0, 0) 'It seems to freeze here if a popup Dlg window is created by the 'program that is recieving the close message. If no popup Dlg 'window is created then it continues with no problems. CheckForPopupDlgWindow(LB_Id.SelectedItem.ToString) End Sub Private Sub CheckForPopupDlgWindow(ByVal parentID As String) 'This is the Class of the popup dialog window to find Dim popupDlgclass As String = "#32770" 'Get desktop handle Dim hWnddesktop As IntPtr = IntPtr.Zero hWnddesktop = GetDesktopWindow() 'Find the first desktop child window with the same class as (popupclass) Dim popuphandle As IntPtr = IntPtr.Zero popuphandle = FindWindowEx(hWnddesktop, popuphandle, popupDlgclass, IntPtr.Zero) 'if a (popuphandle) is found with the same class then check if it has same ID as (parentID) While (Not popuphandle.Equals(IntPtr.Zero)) 'Get the ID for (popuphandle) Dim foundProcID As UInt32 = Nothing GetWindowThreadProcessId(popuphandle, foundProcID) 'If the (popuphandle) has the same ID as the parentID then add it to listbox and stop looking If foundProcID.ToString = parentId Then LB_DlgPopupWindows.Items.Add(popuphandle.ToString) Exit While End If 'Get the next desktop child window to check if one has not been found popuphandle = FindWindowEx(hWnddesktop, popuphandle, popupDlgclass, IntPtr.Zero) End While End Sub
Comment