By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,534 Members | 865 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,534 IT Pros & Developers. It's quick & easy.

If i send a WM_CLOSE message my program freezes

IronRazer
P: 83
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:
Expand|Select|Wrap|Line Numbers
  1.     Private Sub TSB_Close_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TSB_Close.Click
  2.         SendMessage(hWnd, WM_CLOSE, 0, 0)
  3.  
  4.         'It seems to freeze here if a popup Dlg window is created by the
  5.         'program that is recieving the close message. If no popup Dlg
  6.         'window is created then it continues with no problems.
  7.  
  8.         CheckForPopupDlgWindow(LB_Id.SelectedItem.ToString)
  9.     End Sub
  10.  
  11.     Private Sub CheckForPopupDlgWindow(ByVal parentID As String)
  12.         'This is the Class of the popup dialog window to find
  13.         Dim popupDlgclass As String = "#32770"
  14.  
  15.         'Get desktop handle
  16.         Dim hWnddesktop As IntPtr = IntPtr.Zero
  17.         hWnddesktop = GetDesktopWindow()
  18.  
  19.         'Find the first desktop child window with the same class as (popupclass)
  20.         Dim popuphandle As IntPtr = IntPtr.Zero
  21.         popuphandle = FindWindowEx(hWnddesktop, popuphandle, popupDlgclass, IntPtr.Zero)
  22.  
  23.         'if a (popuphandle) is found with the same class then check if it has same ID as (parentID)
  24.         While (Not popuphandle.Equals(IntPtr.Zero))
  25.  
  26.             'Get the ID for (popuphandle)
  27.             Dim foundProcID As UInt32 = Nothing
  28.             GetWindowThreadProcessId(popuphandle, foundProcID)
  29.  
  30.             'If the (popuphandle) has the same ID as the parentID then add it to listbox and stop looking
  31.             If foundProcID.ToString = parentId Then
  32.                 LB_DlgPopupWindows.Items.Add(popuphandle.ToString)
  33.                 Exit While
  34.             End If
  35.  
  36.             'Get the next desktop child window to check if one has not been found
  37.             popuphandle = FindWindowEx(hWnddesktop, popuphandle, popupDlgclass, IntPtr.Zero)
  38.         End While
  39.     End Sub
  40.  
Jan 31 '13 #1

✓ answered by tlhintoq

To be picky it doesn't freeze your program - it freezes that thread.
If your program is single threaded then you are fraked.

So you probably need to make it multi-threaded so it can continue to look for these new pop-ups and handle them.

Share this Question
Share on Google+
1 Reply


tlhintoq
Expert 2.5K+
P: 3,525
To be picky it doesn't freeze your program - it freezes that thread.
If your program is single threaded then you are fraked.

So you probably need to make it multi-threaded so it can continue to look for these new pop-ups and handle them.
Feb 1 '13 #2

Post your reply

Sign in to post your reply or Sign up for a free account.