program klika w pulpit tylko jeśli sam jest aktywny

0

witam to jest mój pierwszy program od kilku lat.
Program działa tylko wtedy gdy się myszką najedzie na niego samego.
W jaki sposób zrobićten program żeby cały czs klikało?
I żeby przy okazj dalej działałten hook na klawaiturę?

Program napiasny w console aplikation bez urzycia hooka działa prawidłowo.

 




#include <windows.h>
#include <stdlib.h>
#include <time.h>
#include <cstdio>
//#include <iostream>
#include <cstdlib>

#define _WIN32_WINNT 0x050

#define IDC_MAIN_BUTTON	101			// Button identifier
#define IDC_MAIN_EDIT	102			// Edit box identifier
#define IDC_MAIN_EDIT2	103			// Edit box identifier
#define IDC_MAIN_EDIT3	104			// Edit box identifier
#define IDC_MAIN_EDIT4	105			// Edit box identifier
#define IDC_MAIN_EDIT5	106			// Edit box identifier
#define IDC_MAIN_EDIT6	107			// Edit box identifier
#define IDC_MAIN_EDIT7	108			// Edit box identifier

HWND hEdit;
HWND hEdit2;
HWND hEdit3;
HWND hEdit4;
HWND hEdit5;
HWND hEdit6;
HWND hEdit7;
    char buffer1[256];//x1
    char buffer2[256];//y1
    char buffer3[256];//x2
    char buffer4[256];//y2
    char buffer5[256];//sleep ms
    char buffer6[256];//d³ugoœc wykonywania
    char buffer7[256];//ile rund

    int x1;//x1
    int y1;//y1
    int x2;//x2
    int y2;//y2
    int sleepTime;//sleep ms
    int duration;//d³ugoœc wykonywania
    int amount;//ile rund
    int j=0;

LRESULT CALLBACK WinProc(HWND hWnd,UINT message,WPARAM wParam,LPARAM lParam);

LRESULT CALLBACK LowLevelKeyboardProc(int nCode, WPARAM wParam, LPARAM lParam)
{
    BOOL fEatKeystroke = FALSE;
    if (nCode == HC_ACTION)
    {
        switch (wParam)
        {
        case WM_KEYDOWN:
            {
        KBDLLHOOKSTRUCT hooked_key =    *((KBDLLHOOKSTRUCT*)lParam);
       // DWORD dwMsg = 1;
        //dwMsg += hooked_key.scanCode << 16;
       // dwMsg += hooked_key.flags << 24;
       // char lpszKeyName[1024] = {0};

        //int i = GetKeyNameText(dwMsg,   (lpszKeyName+1),0xFF) + 1;

        int key = hooked_key.vkCode;
                if (key =='x'||key=='X')
                {
                   MessageBox(0, "pauza3", "Informacja3", 0);
                }
                break;
            }
        case WM_SYSKEYDOWN:
        case WM_KEYUP:
        case WM_SYSKEYUP:
            PKBDLLHOOKSTRUCT p = (PKBDLLHOOKSTRUCT)lParam;
            if (fEatKeystroke = (p->vkCode == 0x41)) {     //redirect a to b
            MessageBox(0, "pauza2", "Informacja2", 0);
            keybd_event('B', 0, 0, 0);
            keybd_event('B', 0, KEYEVENTF_KEYUP, 0);
            break;
            }
            break;
        }
    }
    return(fEatKeystroke ? 1 : CallNextHookEx(NULL, nCode, wParam, lParam));
}

static double diffclock(clock_t clock2,clock_t clock1)
{
    double diffticks=clock1-clock2;
    double diffms=(diffticks)/(CLOCKS_PER_SEC/1000);
    return diffms;
}

void click( int x, int y)
{
    SetCursorPos(x,y);
    mouse_event(MOUSEEVENTF_LEFTDOWN,0,0,0,0);
    Sleep( sleepTime );
    mouse_event(MOUSEEVENTF_LEFTUP,0,0,0,0);
}

void click2( int x, int y)
{
    SetCursorPos(x,y);
    mouse_event(MOUSEEVENTF_LEFTDOWN,0,0,0,0);
    Sleep(150);
    mouse_event(MOUSEEVENTF_LEFTUP,0,0,0,0);
}

void click3( int x, int y)
{
    SetCursorPos(x,y);
    mouse_event(MOUSEEVENTF_LEFTDOWN,0,0,0,0);
    Sleep(15);
    mouse_event(MOUSEEVENTF_LEFTUP,0,0,0,0);
}

int WINAPI WinMain(HINSTANCE hInst,HINSTANCE hPrevInst,LPSTR lpCmdLine,int nShowCmd)
{
	WNDCLASSEX wClass;
	ZeroMemory(&wClass,sizeof(WNDCLASSEX));
	wClass.cbClsExtra=NULL;
	wClass.cbSize=sizeof(WNDCLASSEX);
	wClass.cbWndExtra=NULL;
	wClass.hbrBackground=(HBRUSH)COLOR_WINDOW;
	wClass.hCursor=LoadCursor(NULL,IDC_ARROW);
	wClass.hIcon=NULL;
	wClass.hIconSm=NULL;
	wClass.hInstance=hInst;
	wClass.lpfnWndProc=(WNDPROC)WinProc;
	wClass.lpszClassName="Window Class1";
	wClass.lpszMenuName=NULL;
	wClass.style=CS_HREDRAW|CS_VREDRAW;

	if(!RegisterClassEx(&wClass))
	{
		int nResult=GetLastError();
		MessageBox(NULL,
			"Window class creation failed\r\n",
			"Window Class Failed",
			MB_ICONERROR);
	}

	HWND hWnd=CreateWindowEx(NULL,
			"Window Class1",
			"Windows application1",
			WS_OVERLAPPEDWINDOW,
			200,
			200,
			640,
			480,
			NULL,
			NULL,
			hInst,
			NULL);

    // Install the low-level keyboard & mouse hooks
    HHOOK hhkLowLevelKybd = SetWindowsHookEx(WH_KEYBOARD_LL, LowLevelKeyboardProc, 0, 0);



	if(!hWnd)
	{
		int nResult=GetLastError();

		MessageBox(NULL,
			"Window creation failed\r\n",
			"Window Creation Failed",
			MB_ICONERROR);
	}

    ShowWindow(hWnd,nShowCmd);

	MSG msg;
	ZeroMemory(&msg,sizeof(MSG));

    GetMessage(&msg,NULL,0,0);
    TranslateMessage(&msg);
    DispatchMessage(&msg);

   MessageBox(0, "poczatek", "Informacja6", 0);
    GetMessage(&msg,NULL,0,0);
    TranslateMessage(&msg);
    DispatchMessage(&msg);

   GetWindowText(hEdit, buffer1, 256);
   GetWindowText(hEdit2, buffer2, 256);
   GetWindowText(hEdit3, buffer3, 256);
   GetWindowText(hEdit4, buffer4, 256);
   GetWindowText(hEdit5, buffer5, 256);
   GetWindowText(hEdit6, buffer6, 256);
   GetWindowText(hEdit7, buffer7, 256);

//GetDlgItemText(hwnd, 123,  string);

    //konwencja
    x1=std::atoi(buffer1);//x1
    y1=std::atoi(buffer2);//y1
    x2=std::atoi(buffer3);//x2
    y2=std::atoi(buffer4);//y2
    sleepTime=std::atoi(buffer5);//sleep ms
    duration=std::atoi(buffer6);//dlugoœc wykonywania
    amount=std::atoi(buffer7);//ile rund

/*
char buffer11 [16] = "";
sprintf(buffer11, "%ld", x1);
char buffer12 [16] = "";
sprintf(buffer12, "%ld", y1);
char buffer13 [16] = "";
sprintf(buffer13, "%ld", x2);
char buffer14 [16] = "";
sprintf(buffer14, "%ld", y2);
char buffer15 [16] = "";
sprintf(buffer15, "%ld", sleepTime);
char buffer16 [16] = "";
sprintf(buffer16, "%ld", duration);
char buffer17 [16] = "";
sprintf(buffer17, "%ld", amount);
//LPARAM nr1=reinterpret_cast<LPARAM>(buffer11);
 MessageBox(NULL,buffer11,"Information1",MB_ICONINFORMATION);
 MessageBox(NULL,buffer12,"Information2",MB_ICONINFORMATION);
 MessageBox(NULL,buffer13,"Information3",MB_ICONINFORMATION);
 MessageBox(NULL,buffer14,"Information4",MB_ICONINFORMATION);
 MessageBox(NULL,buffer15,"Information5",MB_ICONINFORMATION);
 MessageBox(NULL,buffer16,"Information6",MB_ICONINFORMATION);
 MessageBox(NULL,buffer17,"Information7",MB_ICONINFORMATION);
*/

////////////////  główna pętla programu: /////////////////////////////////


    for ( int i = 0; i < amount; ++i )
	{
        clock_t start = clock();
        while ( diffclock( start, clock() ) <= duration)
        {
        GetMessage(&msg,NULL,0,0);
		TranslateMessage(&msg);
		DispatchMessage(&msg);
            Sleep(1);
            click(x1,y1);

            j++;
            if(j>=50)
            {
            j=0;
            Sleep(1);
            click2(x2,y2);
            }
        }
        MessageBox(0, "skonczyła się runda", "Informacja5", 0);
	}
    UnhookWindowsHookEx(hhkLowLevelKybd);
	return 0;
}

//////////////////////////////////////////////////////////////////



LRESULT CALLBACK WinProc(HWND hWnd,UINT msg,WPARAM wParam,LPARAM lParam)
{
    HINSTANCE hInst;
	switch(msg)
	{
		case WM_CREATE:
		{
			// Create an edit box
			hEdit=CreateWindowEx(WS_EX_CLIENTEDGE,
				"EDIT",
				"100",
				WS_CHILD|WS_VISIBLE|
				ES_MULTILINE|ES_AUTOVSCROLL|ES_AUTOHSCROLL,
				50,
				10,
				50,
				30,
				hWnd,
				(HMENU)IDC_MAIN_EDIT,
				GetModuleHandle(NULL),
				NULL);
			HGDIOBJ hfDefault=GetStockObject(DEFAULT_GUI_FONT);
            CreateWindow(TEXT("STATIC"), "x1=", WS_CHILD | WS_VISIBLE | SS_LEFT, 10, 10, 20, 30, hWnd, (HMENU) 1, hInst, NULL);

			hEdit2=CreateWindowEx(WS_EX_CLIENTEDGE,
				"EDIT",
				"200",
				WS_CHILD|WS_VISIBLE|
				ES_MULTILINE|ES_AUTOVSCROLL|ES_AUTOHSCROLL,
				50,
				50,
				50,
				30,
				hWnd,
				(HMENU)IDC_MAIN_EDIT2,
				GetModuleHandle(NULL),
				NULL);
			HGDIOBJ hfDefault2=GetStockObject(DEFAULT_GUI_FONT);
            CreateWindow(TEXT("STATIC"), "y1=", WS_CHILD | WS_VISIBLE | SS_LEFT, 10, 50, 20, 30, hWnd, (HMENU) 1, hInst, NULL);

			hEdit3=CreateWindowEx(WS_EX_CLIENTEDGE,
				"EDIT",
				"300",
				WS_CHILD|WS_VISIBLE|
				ES_MULTILINE|ES_AUTOVSCROLL|ES_AUTOHSCROLL,
				50,
				110,
				50,
				30,
				hWnd,
				(HMENU)IDC_MAIN_EDIT3,
				GetModuleHandle(NULL),
				NULL);
                HGDIOBJ hfDefault3=GetStockObject(DEFAULT_GUI_FONT);
                CreateWindow(TEXT("STATIC"), "x2=", WS_CHILD | WS_VISIBLE | SS_LEFT, 10, 110, 20, 30, hWnd, (HMENU) 1, hInst, NULL);

                hEdit4=CreateWindowEx(WS_EX_CLIENTEDGE,
				"EDIT",
				"400",
				WS_CHILD|WS_VISIBLE|
				ES_MULTILINE|ES_AUTOVSCROLL|ES_AUTOHSCROLL,
				50,
				150,
				50,
				30,
				hWnd,
				(HMENU)IDC_MAIN_EDIT4,
				GetModuleHandle(NULL),
				NULL);
			HGDIOBJ hfDefault4=GetStockObject(DEFAULT_GUI_FONT);
            CreateWindow(TEXT("STATIC"), "y3=", WS_CHILD | WS_VISIBLE | SS_LEFT, 10, 150, 20, 30, hWnd, (HMENU) 1, hInst, NULL);

                hEdit5=CreateWindowEx(WS_EX_CLIENTEDGE,
				"EDIT",
				"25",
				WS_CHILD|WS_VISIBLE|
				ES_MULTILINE|ES_AUTOVSCROLL|ES_AUTOHSCROLL,
				75,
				220,
				50,
				30,
				hWnd,
				(HMENU)IDC_MAIN_EDIT5,
				GetModuleHandle(NULL),
				NULL);
                HGDIOBJ hfDefault5=GetStockObject(DEFAULT_GUI_FONT);
                CreateWindow(TEXT("STATIC"), "sleep(ms)=", WS_CHILD | WS_VISIBLE | SS_LEFT, 10, 220, 65, 30, hWnd, (HMENU) 1, hInst, NULL);

                hEdit6=CreateWindowEx(WS_EX_CLIENTEDGE,
				"EDIT",
				"120000",
				WS_CHILD|WS_VISIBLE|
				ES_MULTILINE|ES_AUTOVSCROLL|ES_AUTOHSCROLL,
				120,
				260,
				90,
				30,
				hWnd,
				(HMENU)IDC_MAIN_EDIT6,
				GetModuleHandle(NULL),
				NULL);
                HGDIOBJ hfDefault6=GetStockObject(DEFAULT_GUI_FONT);
                CreateWindow(TEXT("STATIC"), "czas trwania(ms)=", WS_CHILD | WS_VISIBLE | SS_LEFT, 10, 260, 100, 30, hWnd, (HMENU) 1, hInst, NULL);

                hEdit7=CreateWindowEx(WS_EX_CLIENTEDGE,
				"EDIT",
				"7",
				WS_CHILD|WS_VISIBLE|
				ES_MULTILINE|ES_AUTOVSCROLL|ES_AUTOHSCROLL,
				85,
				300,
				50,
				30,
				hWnd,
				(HMENU)IDC_MAIN_EDIT7,
				GetModuleHandle(NULL),
				NULL);
			HGDIOBJ hfDefault7=GetStockObject(DEFAULT_GUI_FONT);
            CreateWindow(TEXT("STATIC"), "ile rund=", WS_CHILD | WS_VISIBLE | SS_LEFT, 10, 300, 70, 30, hWnd, (HMENU) 1, hInst, NULL);

			// Create a push button
			HWND hWndButton=CreateWindowEx(NULL,
				"BUTTON",
				"OK",
				WS_TABSTOP|WS_VISIBLE|
				WS_CHILD|BS_DEFPUSHBUTTON,
				250,
				220,
				100,
				24,
				hWnd,
				(HMENU)IDC_MAIN_BUTTON,
				GetModuleHandle(NULL),
				NULL);
			SendMessage(hWndButton,
				WM_SETFONT,
				(WPARAM)hfDefault,
				MAKELPARAM(FALSE,0));
			SendMessage(hWndButton,
				WM_SETFONT,
				(WPARAM)hfDefault2,
				MAKELPARAM(FALSE,0));

		}
		break;

		case WM_COMMAND:
		    {

		    }
			switch(LOWORD(wParam))
            {

				case IDC_MAIN_BUTTON:
				{
				    /*
					SendMessage(hEdit,
						WM_GETTEXT,
						sizeof(buffer1)/sizeof(buffer1[0]),
						reinterpret_cast<LPARAM>(buffer1));

                        SendMessage(hEdit2,
						WM_GETTEXT,
						sizeof(buffer2)/sizeof(buffer2[0]),
						reinterpret_cast<LPARAM>(buffer2));

                        SendMessage(hEdit3,
						WM_GETTEXT,
						sizeof(buffer3)/sizeof(buffer3[0]),
						reinterpret_cast<LPARAM>(buffer3));

                        SendMessage(hEdit4,
						WM_GETTEXT,
						sizeof(buffer4)/sizeof(buffer4[0]),
						reinterpret_cast<LPARAM>(buffer4));

                        SendMessage(hEdit5,
						WM_GETTEXT,
						sizeof(buffer5)/sizeof(buffer5[0]),
						reinterpret_cast<LPARAM>(buffer5));

                        SendMessage(hEdit6,
						WM_GETTEXT,
						sizeof(buffer6)/sizeof(buffer6[0]),
						reinterpret_cast<LPARAM>(buffer6));

                        SendMessage(hEdit7,
						WM_GETTEXT,
						sizeof(buffer7)/sizeof(buffer7[0]),
						reinterpret_cast<LPARAM>(buffer7));

						//konwencja
                        x1=std::atoi(buffer1);//x1
                        y1=std::atoi(buffer2);//y1
                        x2=std::atoi(buffer3);//x2
                        y2=std::atoi(buffer4);//y2
                        sleepTime=std::atoi(buffer5);//sleep ms
                        duration=std::atoi(buffer6);//d³ugoœc wykonywania
                        amount=std::atoi(buffer7);//ile rund
                        */
				}
				break;
			}
			break;

		case WM_DESTROY:
		{
			PostQuitMessage(0);
			return 0;
		}
		break;
	}

	return DefWindowProc(hWnd,msg,wParam,lParam);
}


0

tutaj jest inna wersja prostsza jak zrobić żeby klikało an pulpicie zawsze obojętnie czy aplikacje jest aktywna czy nie


#if defined(UNICODE) && !defined(_UNICODE)
    #define _UNICODE
#elif defined(_UNICODE) && !defined(UNICODE)
    #define UNICODE
#endif

#include <tchar.h>
#include <windows.h>

/*  Declare Windows procedure  */
LRESULT CALLBACK MainWndProc (HWND, UINT, WPARAM, LPARAM);

/*  Make the class name into a global variable  */
TCHAR szClassName[ ] = _T("CodeBlocksWindowsApp");

int WINAPI WinMain (HINSTANCE hThisInstance,
                     HINSTANCE hPrevInstance,
                     LPSTR lpszArgument,
                     int nCmdShow)
{
    HWND hwnd;               /* This is the handle for our window */
    MSG messages;            /* Here messages to the application are saved */
    WNDCLASSEX wincl;        /* Data structure for the windowclass */

    /* The Window structure */
    wincl.hInstance = hThisInstance;
    wincl.lpszClassName = szClassName;
    wincl.lpfnWndProc = MainWndProc;      /* This function is called by windows */
    wincl.style = CS_DBLCLKS;                 /* Catch double-clicks */
    wincl.cbSize = sizeof (WNDCLASSEX);

    /* Use default icon and mouse-pointer */
    wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
    wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
    wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
    wincl.lpszMenuName = NULL;                 /* No menu */
    wincl.cbClsExtra = 0;                      /* No extra bytes after the window class */
    wincl.cbWndExtra = 0;                      /* structure or the window instance */
    /* Use Windows's default colour as the background of the window */
    wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND;

    /* Register the window class, and if it fails quit the program */
    if (!RegisterClassEx (&wincl))
        return 0;

    /* The class is registered, let's create the program*/
    hwnd = CreateWindowEx (
           0,                   /* Extended possibilites for variation */
           szClassName,         /* Classname */
           _T("Code::Blocks Template Windows App"),       /* Title Text */
           WS_OVERLAPPEDWINDOW, /* default window */
           CW_USEDEFAULT,       /* Windows decides the position */
           CW_USEDEFAULT,       /* where the window ends up on the screen */
           544,                 /* The programs width */
           375,                 /* and height in pixels */
           HWND_DESKTOP,        /* The window is a child-window to desktop */
           NULL,                /* No menu */
           hThisInstance,       /* Program Instance handler */
           NULL                 /* No Window Creation data */
           );

    /* Make the window visible on the screen */
    ShowWindow (hwnd, nCmdShow);

    /* Run the message loop. It will run until GetMessage() returns 0 */
    while (GetMessage (&messages, NULL, 0, 0))
    {
        /* Translate virtual-key messages into character messages */
        TranslateMessage(&messages);
        /* Send message to WindowProcedure */
        DispatchMessage(&messages);

    SetCursorPos(3,3);
    mouse_event(MOUSEEVENTF_LEFTDOWN,0,0,0,0);
    Sleep( 50 );
    mouse_event(MOUSEEVENTF_LEFTUP,0,0,0,0);


    }

    /* The program return-value is 0 - The value that PostQuitMessage() gave */
    return messages.wParam;
}


/*  This function is called by the Windows function DispatchMessage()  */

/*  This function is called by the Windows function DispatchMessage()  */

LRESULT APIENTRY MainWndProc(HWND hwndMain, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
    HDC hdc;                       // handle to device context
    RECT rcClient;                 // client area rectangle
    POINT ptClientUL;              // client upper left corner
    POINT ptClientLR;              // client lower right corner
    static POINTS ptsBegin;        // beginning point
    static POINTS ptsEnd;          // new endpoint
    static POINTS ptsPrevEnd;      // previous endpoint
    static BOOL fPrevLine = FALSE; // previous line flag

    switch (uMsg)
    {
       case WM_LBUTTONDOWN:

            // Capture mouse input.

            SetCapture(hwndMain);

            // Retrieve the screen coordinates of the client area,
            // and convert them into client coordinates.

            GetClientRect(hwndMain, &rcClient);
            ptClientUL.x = rcClient.left;
            ptClientUL.y = rcClient.top;

            // Add one to the right and bottom sides, because the
            // coordinates retrieved by GetClientRect do not
            // include the far left and lowermost pixels.

            ptClientLR.x = rcClient.right + 1;
            ptClientLR.y = rcClient.bottom + 1;
            ClientToScreen(hwndMain, &ptClientUL);
            ClientToScreen(hwndMain, &ptClientLR);

            // Copy the client coordinates of the client area
            // to the rcClient structure. Confine the mouse cursor
            // to the client area by passing the rcClient structure
            // to the ClipCursor function.

            SetRect(&rcClient, ptClientUL.x, ptClientUL.y,
                ptClientLR.x, ptClientLR.y);
            ClipCursor(&rcClient);

            // Convert the cursor coordinates into a POINTS
            // structure, which defines the beginning point of the
            // line drawn during a WM_MOUSEMOVE message.

            ptsBegin = MAKEPOINTS(lParam);
            return 0;

        case WM_MOUSEMOVE:

            // When moving the mouse, the user must hold down
            // the left mouse button to draw lines.

            if (wParam & MK_LBUTTON)
            {

                // Retrieve a device context (DC) for the client area.

                hdc = GetDC(hwndMain);

                // The following function ensures that pixels of
                // the previously drawn line are set to white and
                // those of the new line are set to black.

                SetROP2(hdc, R2_NOTXORPEN);

                // If a line was drawn during an earlier WM_MOUSEMOVE
                // message, draw over it. This erases the line by
                // setting the color of its pixels to white.

                if (fPrevLine)
                {
                    MoveToEx(hdc, ptsBegin.x, ptsBegin.y,
                        (LPPOINT) NULL);
                    LineTo(hdc, ptsPrevEnd.x, ptsPrevEnd.y);
                }

                // Convert the current cursor coordinates to a
                // POINTS structure, and then draw a new line.

                ptsEnd = MAKEPOINTS(lParam);
                MoveToEx(hdc, ptsBegin.x, ptsBegin.y, (LPPOINT) NULL);
                LineTo(hdc, ptsEnd.x, ptsEnd.y);

                // Set the previous line flag, save the ending
                // point of the new line, and then release the DC.

                fPrevLine = TRUE;
                ptsPrevEnd = ptsEnd;
                ReleaseDC(hwndMain, hdc);
            }
            break;

        case WM_LBUTTONUP:

            // The user has finished drawing the line. Reset the
            // previous line flag, release the mouse cursor, and
            // release the mouse capture.

            fPrevLine = FALSE;
            ClipCursor(NULL);
            ReleaseCapture();
            return 0;

        case WM_DESTROY:
            PostQuitMessage(0);
            break;
        default:                      /* for messages that we don't deal with */
            return DefWindowProc (hwndMain, uMsg, wParam, lParam);
    }

    return 0;
}

 
0
  1. klasyczny błąd wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND zamiast (HBRUSH)(COLOR_BACKGROUND + 1)
  2. klasyczny błąd z podawaniem HWND_DESKTOP jako parentem do CreateWindow, zamiast NULL.
  3. wielki switch z długimi blokami kodu - podziel poszczególne komunikaty na osobne funkcje.
  4. WTF sleep i mouse_eventy wewnątrz pętli komunikatów - to jest zapewne przyczyna problemu.

Pamiętaj że GetMessage jest blokujące. Kiedy program jest nieaktywny, rzadko kiedy dostaje komunikaty (głównie broadcasty różne). Pętla stoi, i twoje eventy nie mają kiedy się odpalić.

Zrób je w timerze.

0

po dodaniu tych 2 lini jakoś działa jeszcze nie wiem czy wystarczająco szybko:
może jest jeszcze jakieś inne rozwiazanie?

        hwnd2 = GetForegroundWindow ();
        //oldproc = (WNDPROC)GetWindowLong (_hwnd, GWL_WNDPROC);
        //return CallWindowProc (oldproc, hwnd, msg, wParam, lParam);
        SetWindowLong (hwnd2, GWL_WNDPROC,(LONG) WinProc);

1 użytkowników online, w tym zalogowanych: 0, gości: 1