I write a sapper on winApi.
There is an array of buttons, and it is necessary for each button to install a handler for clicking the right mouse button on it. Can this be realized? How?
I write a sapper on winApi.
There is an array of buttons, and it is necessary for each button to install a handler for clicking the right mouse button on it. Can this be realized? How?
It depends on the button.
If the button is a separate window , then process the mouse messages in WndProc . Create an array of type HWND and fill it with windows (which you will use as buttons) with one common WndProc Identify which button is pressed using a loop. Below is the code
HWND hwnds[100]={NULL}; hwnds[0]=CreateWindow(...); hwnds[1]=CreateWindow(...); LRESULT CALLBACK WndProc(HWND hwnd,UINT message,WPARAM wp,LPARAM lp) { switch(message) { case WM_RBUTTONDOWN: for(int i(0);i<100;i++) if(hwnds[i]==NULL) { break; } else if(hwnd==hwnds[i]) { ...//Окно найдено } break; } } If the button is standard, Shindousovskaya (but this is also a window, as far as I remember), then through WM_COMMAND. But I will give the link http://www.firststeps.ru/mfc/winapi/r.php?62
Bonus
Draw a rectangle that will be your button. When you click on the window (on which you drew a rectangle) you process WM_RBUTTONDOWN\UP . If the click coordinates are appropriate, then the button is pressed. How to do it:
LRESULT CALLBACK WndProc(HWND hwnd,UINT message,WPARAM wp,LPARAM lp) { POINT cp; GetCursorPos(&cp);//ну Вы поняли switch(message) { case WM_PAINT: ... Rectangle(hdc,10,10,50,30); ... break; case WM_RBUTTONUP: {//не забудьте про скобки, если хотите объявить переменные внутри case`a RECT r; GetWindowRect(hwnd,&r); int x=cp.xr.left;//делаем координаты клика, относительно окна int y=cp.yr.top;//делаем координаты клика, относительно окна if(x>10 && x<50 && y>10 && y<30) { ...//тык } } break; } } Source: https://ru.stackoverflow.com/questions/512088/
All Articles