473,385 Members | 1,630 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Is looping FindWindow() ok?

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,
Jim
--------Popup Watcher/Acknowledger Application
code-------------------------------
[DllImport("user32.dll", EntryPoint = "FindWindow")]
public static extern IntPtr FindWindow(string lpClassName, string
lpWindowName);

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

[DllImport("user32.dll")]
static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr
hwndChildAfter,
string lpszClass, string lpszWindow);
static void StartApp()
{
timer1.Interval = 10;
timer1.Start();
FunctionLookingForThePopup()
}

Static void FunctionLookingForThePopup()
{
IntPtr hFrmMain = FindWindow("#32770", "Some dialog that pops up”
if (hFrmMain.ToString() != "0")
{
timer1.Stop();
IntPtr w5 = FindWindowEx(TargetWindowHandle, IntPtr.Zero,
"Button", "OK");
SendMessage(w5, 0x00F5, 0, 0);
timer1.Start();
}
}
-----------------------------------------------------------------------------------------------
Nov 3 '06 #1
0 1524

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

17
by: lauren quantrell | last post by:
I have an Access application with the name: MyAppName It has the "" symbol (ChrW$(&H00AE)) at the end of it. If I remane the application without the "" symbol, I can use FindWindow to close the...
5
by: Tony | last post by:
I need to send a message to a window in another application. The name of the window is known at design time and set in the constant App2_MONITOR_CAPTION. The message is defined as X_GenerateEvent....
5
by: victor | last post by:
Help .... This is my situation: I've made two apps, a Managed C# and an Unmanaged MFC. The C# app communicates with the MFC-app via (Win32-API) PostMessage, done with the P/Invoke method. One...
3
by: kd | last post by:
Hi All, I need to check whether an application is executing. I do not know the class name of the application; however, I know the window caption of the application. What would be the first...
3
by: Bob | last post by:
Hi, Trying to determine if a program is running or not. I implemented the example code below but I am getting handles returned regardless of whether a program exists or not. i.e. You can feed in a...
0
by: ntm | last post by:
Hi all you good m8 I try to make my first small program in vb, but im not very succesfull :D (Im using Visual Studio 2005) Form my own program i will like to set focus on an other running...
2
by: Alex | last post by:
Dear coleagues, I am trying to call FindWindow function but it seems not to be working. It returns a loooooong value even if the Window "SoftMaxPro GxP" is not started. I can't even find a...
1
by: musai | last post by:
Hi Members how to use findwindow API for outlook application let us example For excel we use to find excel FindWindow("XLMAIN", vbNullString)
2
by: MegaOctet | last post by:
Hello, Here is my script import win32gui as w HWND= w.FindWindow("Document - WordPad",None) and here is the traceback: Traceback (most recent call last): File "C:\Python26\essai1.py",...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.