Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Detecting pop up window

Status
Not open for further replies.

ViperInc

Programmer
Mar 13, 2001
24
0
0
AU
Hi,

I'm currently trying to write a program which will detect a pop up or new window and print the related co-ordinates to a file. Looking the msdn API i have put together the following code. Being totally inexperienced at C I'm at a loss as how to implement the code below, or even if it will do what I hope.

#include "stdafx.h"
#include "Winuser.h"
#include "Windows.h"

int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
//for(!stop) - loop until stopped, maybe with button?

typedef struct coOrd { LONG left;
LONG top;
LONG right;
LONG bottom;
} RECT, *PRECT;

BOOL GetClientRect(HWND GetForegroundWindow(VOID),LPRECT coOrd);
}


now, from what ive gathered, it will create the coOrd structure, and then put the forground co-orinated into it.

how can i access these co-ordinates, and put them into a file. how easy is it to add a go/stop button or add a timer.

i am very un-skilled at c, any help would be greatly appreciated.

thank-you
VPR
 
I'd say you should work on learning the basics of C++ before trying to do anything using Windows API. That said, here is some code that should do something like what you want to accomplish:

Code:
#include <windows.h>
#include <fstream>
using namespace std;

int main()
{
	// Get the window that currently has focus
	HWND hwndInitial = GetForegroundWindow();
	HWND hwndForeground;
	
	// Loop until a new window has focus
	bool bFoundNewWindow = false;
	while(!bFoundNewWindow)
	{
		hwndForeground = GetForegroundWindow();
		if(hwndForeground != hwndInitial)
			bFoundNewWindow = true;
		else
			Sleep(50);
	}

	// Get the rect of the new window
	RECT rc;
	GetWindowRect(hwndForeground, &rc);

	// Write the coordinates to a file
	ofstream file("file.txt");
	file << rc.left << " " << rc.top << " " << rc.right << " " << rc.bottom << endl;
	file.close();

	return 0;
}
 
holy crap!

thank-you so so much timmay!!!

exactly what i needed!

and yes, im am totaly crap at c, so thankfully im learning it this yr at uni.

once again, thank-you!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top