Есть два приложения. Мне нужно нажать программно нажать кнопку в другом. Я ищу окно нужного мне приложения, ищу нужную кнопки и делаю SendMessage. Что я не так делаю? Нажиматель:
| Код | #include <windows.h>
INT WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInst, PTSTR lpCmdLine, INT nCmdShow) { HWND hWnd = FindWindow("ButtonApp", NULL); if (hWnd) { MessageBox(NULL, "I Found it", "Message", 0); if (hButton) { MessageBox(NULL, "I ''l press you", "Message", 0); SendMessage(hButton, WM_COMMAND, MAKEWPARAM(1,1000), 0); } } return 0; }
|
Нажимаемое :
| Код | #include <windows.h> #define APPNAME "ButtonApp"
LONG WINAPI WndProc(HWND hWnd, UINT msg, WPARAM wPar, LPARAM lPar);
INT WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPTSTR lpCmdLine, INT nCmdShow) { WNDCLASS wnd; memset(&wnd, 0, sizeof(wnd)); wnd.hbrBackground = (HBRUSH)COLOR_WINDOW; wnd.hCursor = LoadCursor(NULL, IDC_ARROW); wnd.hIcon = LoadIcon(NULL, IDI_APPLICATION); wnd.hInstance = hInst; wnd.lpfnWndProc = WndProc; wnd.lpszClassName = APPNAME; wnd.style = CS_VREDRAW|CS_HREDRAW;
RegisterClass(&wnd);
HWND hWnd = CreateWindow(APPNAME, APPNAME, WS_OVERLAPPEDWINDOW, 10, 10, 500, 500, NULL, NULL, hInst, NULL); HWND hBut = CreateWindow("BUTTON", "Next", WS_VISIBLE|WS_CHILD, 20, 20, 100, 25, hWnd, (HMENU)1000, NULL, NULL); ShowWindow(hWnd, nCmdShow); UpdateWindow(hWnd); MSG msg;
while (GetMessage(&msg, NULL, 0, 0)) { TranslateMessage(&msg); DispatchMessage(&msg); } return msg.lParam; }
LONG WINAPI WndProc(HWND hWnd, UINT msg, WPARAM wPar, LPARAM lPar) { switch(msg) { case WM_DESTROY: PostQuitMessage(0); break; case WM_COMMAND: MessageBox(hWnd, "Hello World", "Message", MB_OK|MB_ICONINFORMATION); break; default: return DefWindowProc(hWnd, msg, wPar, lPar); } return 0; }
| |