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

Is looping FindWindow() ok?

P: n/a
Is looping FindWindow() ok?

We have a simple little c# 2.0 app that’s sole purpose is to look for a
dialog box from another app to pop up and then click it’s OK button. To do
this we use a form with a timer control and some unmanaged code. The app
works perfectly in test but I’m concerned about long term problems/leaks
caused by frequent FindWindow calls (10 per second)? Although the popups
might only occur 50-100 times a day, the “watcher” application (below) is
running 24/7 – interrupted only by infrequent logoff/restarts. Is there a
better way to accomplish this or is this ok.
Thanks for any help,
--------Popup Watcher/Acknowledger Application
[DllImport("user32.dll", EntryPoint = "FindWindow")]
public static extern IntPtr FindWindow(string lpClassName, string

[DllImport("user32.dll", CharSet = CharSet.Auto)]
static extern IntPtr SendMessage(IntPtr hWnd,
uint Msg, int wParam, string lParam);

static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr
string lpszClass, string lpszWindow);
static void StartApp()
timer1.Interval = 10;

Static void FunctionLookingForThePopup()
IntPtr hFrmMain = FindWindow("#32770", "Some dialog that pops up”
if (hFrmMain.ToString() != "0")
IntPtr w5 = FindWindowEx(TargetWindowHandle, IntPtr.Zero,
"Button", "OK");
SendMessage(w5, 0x00F5, 0, 0);
Nov 3 '06 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.