0
votes

Sorry but my english is very bad.

I am writing a winapi program in c and I have a problem. The program has a main window and NO DIALOG child windows (controls). The controls are directly attached to the main window. When I switch the application to another application and back again, the focus is set to the main window and not to the control that owns the focus before switching.

My message loop is:

while ((rGetMessage = GetMessage(&msg, NULL, 0, 0)) != 0 && rGetMessage != -1)
{
    if(!IsDialogMessage(hwnd_principal, &msg))
    {
        TranslateMessage(&msg);
        DispatchMessage(&msg);
    }
}

What is my error?

I use the IsDialogMessage function for that various keys work on (like TAB key in the controls).

1
Why are you calling IsDialogMessage if there's no dialog? This is unguessable from the provided info.Hans Passant

1 Answers

0
votes

When you switch back to your application, Windows will by default set the keyboard focus to its main window, regardless of which window had the focus when it was deactivated. If you want to do something different you need to handle WM_ACTIVATE and use SetFocus() to restore the focus to the control.