I have a delphi app that tries to open a webcam. Under Windows 7 it fails occasionally (that's another story/question/thread) but the webcam driver also pops up a dialog titled "Video Source" inviting me to select one. If I try to open the driver repeatedly in a loop and close the dialog manually each time it appears, I can get going. So I would like to close the dialog from my app. A FindWindow (nil, 'Video Source') doesn't find it. If I look with process explorer the dialog is shown as belonging to my app. If I force close it from PE it closes my app!. How to I close this dialog? I have a suspicion (confirmed) that my app is hanging while this dialog is open, which will make it pretty difficult to execute any code to close the dialog.
Asked
Active
Viewed 739 times
1 Answers
1
If your main application thread is stalled waiting for a user input due to this popup dialog then the only solution is to have another thread running which regularly attempts to locate this popup. When it does find it then use PostMessage to uses a WM_CLOSE or similar to the popup handle. You might have to send either mousedown/mouseup messages to the button on the popup.
Further, I would write a small debug application that uses the Windows API WindowFromPoint to find out about the popup window, ie. not just it's visible caption but also it's class. You can also use this debug program to get the FindWindow to work correctly.

Steve
- 1,769
- 2
- 22
- 33
-
You can also use WinSpy or Spy++ to find out information about it, including its class. No need to write your own app to do it. – David Dec 01 '10 at 22:55
-
Main thread was stalled but timer events still fired. Wrote a quick and dirty to enumerate all windows and on the basis of what I learned I then added 1 sec timer routine to my app that looked for class = '#32770' and title = 'Video Source', then issued a WM_CLOSE. That in conjunction with a loop to retry opening got me going, but it's not very pretty. Seems to be a known issue with Windows 7. – rossmcm Dec 02 '10 at 07:53