1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
| #include <windows.h>
void ecris(HWND fenetre,int lettre)
{
PostMessage(fenetre,WM_KEYDOWN,lettre,0);
PostMessage(fenetre,WM_KEYUP,lettre,0);
}
LRESULT WINAPI Proc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
{
switch(Msg){
case WM_LBUTTONDOWN:
{
//HWND h = GetForegroundWindow();
HWND handle = FindWindow("WMPlayerApp",0);
SetForegroundWindow(handle);
Sleep(1);
ecris(handle,VK_SPACE);
//SetForegroundWindow(h);
}
return 0;
case WM_CREATE:
{
ShowWindow(hWnd, SW_SHOW);
SetWindowPos(hWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
}
return 0;
case WM_PAINT:
ValidateRect(hWnd, NULL);
return 0;
case WM_RBUTTONDOWN:
case WM_CLOSE:
case WM_DESTROY:
{
PostQuitMessage(0);
}
return 0;
}
return DefWindowProc(hWnd, Msg, wParam, lParam);
}
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrev, LPSTR lpCmdLine, int nShowCmd)
{
WNDCLASS wndClass = { 0, Proc, 0, 0, hInstance, NULL, LoadCursor(NULL, IDC_ARROW), 0, NULL, "fenetre" };
wndClass.hbrBackground = (HBRUSH) COLOR_BACKGROUND;
if(!RegisterClass(&wndClass)) return MessageBox(HWND_DESKTOP, "Cannot register class!", NULL, MB_ICONERROR | MB_OK);
HWND hWnd = CreateWindow("fenetre", NULL, WS_POPUP, 0, 0, 10, 10, HWND_DESKTOP, NULL, hInstance, NULL);
if(!hWnd) return MessageBox(HWND_DESKTOP, "Cannot create window!", NULL, MB_ICONERROR | MB_OK);
MSG Msg = { 0 };
while(Msg.message != WM_QUIT){
if(PeekMessage(&Msg, NULL, 0, 0, PM_REMOVE)){
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
Sleep(30);
}
return 0;
} |
Partager