Now I want to set the value of focus_id to the 'id number' of the focused window whenever there's a mouseclick inside one of the windows.
So when I click inside numbox[32], focus_id should be 32.
What would be the most straightforward method to check for this 'id number'? I thought the hMenu specification in CreateWindow could help me, but couldn't figure out how.
GetFocus() returns a HWND type, so I guess this is useless here.
Well, when you click on one of your Edit controls it will handle the WM_LBUTTONDOWN message itself. So if you need to do custom handling of this message you will need to use subclassing.
But when you click on an Edit control it will be given the keyboard focuses which causes it to send its parent window a WM_COMMAND message with the EN_SETFOCUS notification code, plus its control ID and HWND.
So this sort of thing might work in your case.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
case WM_COMMAND:
{
// get command ID and notification code
int id = LOWORD(wParam);
int code = HIWORD(wParam);
if((start_id <= id) && (id < (start_id + ctrl_count)))
{
if(code == EN_SETFOCUS)
{
focus_id = (id - start_id);
return 0;
}
}
}
break;
(where the meaning of the variables start_id and ctrl_count is hopefully clear enough?)
But the real problem is that I don't know when to call this. It has to happen exactly when focus is changed to another window. I thought the message WM_SETFOCUS is called whenever I click inside one of the text edit windows, but it turns out it's only called once, at the program's startup.