NO

Author Topic: While-loop is not running correct  (Read 2417 times)

pitter2206

  • Guest
While-loop is not running correct
« on: February 18, 2010, 09:21:01 PM »
Hi,

I´ve got a Problem and I don´t know what is wrong with it.

My code has to start an endless loop to look for a named window.
If the window is there, I want to click.

But it does not do that... the window which has to be closed is still on top...

Please help me for that...

Code: [Select]
#include <windows.h>

int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpszCmdLine, int nCmdShow)
{
POINT p ;
int m1 = 65535 / 480;
int m2 = 65535 / 272;
p.x = 460;
p.y = 255;
int x = m1 * p.x;
int y = m2 * p.y;   
HWND hwnd;

/* Always check first if program is already running */
hwnd = FindWindow( NULL, L"Prototype");
if (hwnd)
{
DestroyWindow(hwnd);
}
while(1)
{
hwnd = FindWindow(NULL, L"GoPalSettings_np");
if (hwnd)
{
Sleep(3000);
mouse_event(MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_ABSOLUTE, x, y, 0, 0);
Sleep(100);
mouse_event(MOUSEEVENTF_LEFTUP | MOUSEEVENTF_ABSOLUTE, x, y, 0, 0);
}
else
{
Sleep(5000);
}
}
return 0;
}

pitter2206

  • Guest
Re: While-loop is not running correct
« Reply #1 on: February 19, 2010, 11:10:30 AM »
OK, I found this mistake...  ;)

Sometimes it would be fine, to write the wright window-name...  :'(

I found another problem which I could fix...

Unfortunately the same window-name is token for another settings-window coming from the same EXE and the click at this position would be unfortunately...

So I had to look for the differences of these windows.

I thought to look for two pixel-colors, because they are some different in these windows.

...and it works so far...

If you would have a look at the script... would it be fine this way or is there another, better way to write that script?

Code: [Select]
#include <windows.h>

int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpszCmdLine, int nCmdShow)
{
POINT p ;
int m1 = 65535 / 480;
int m2 = 65535 / 272;
p.x = 460;
p.y = 255;
int x = m1 * p.x;
int y = m2 * p.y;  
HWND hwnd;
HDC dc = GetDC(NULL);

/* Look if programm is running */
hwnd = FindWindow( NULL, L"Prototype");
if (hwnd)
{
DestroyWindow(hwnd);
}

/* Endless loop, to wait for GoPalSettings */
while(1)
{
hwnd=FindWindow(NULL, L"GoPalSettings");
if(hwnd)
{
if (GetPixel(dc, 462, 236) == GetPixel(dc, 462, 250))
{
Sleep(3000);
mouse_event(MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_ABSOLUTE, x, y, 0, 0);
Sleep(100);
mouse_event(MOUSEEVENTF_LEFTUP | MOUSEEVENTF_ABSOLUTE, x, y, 0, 0);
hwnd = NULL;
Sleep(5000);
}
else /* else for minimizing CPU usage*/
{
Sleep(5000);
}
}
else /* else for minimizing CPU usage*/
{
Sleep(5000);
}
}

return 0;
}

« Last Edit: February 19, 2010, 11:13:07 AM by pitter2206 »