Win32 GUI: change blur control

I have a window with an edit control as its child. The control is in focus. Every time I switch to another application, the control loses focus (blurs). Do I have to track focused control so that I can manually go back again when I return the application? Or am I doing something wrong? I would expect Windows to track such things automatically, but who knows?

I am using Win32 using simple C. Example:

#include <windows.h>

#define NAME "test"

LRESULT CALLBACK WinProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
    HWND edit1, edit2;
    switch (msg)
    {
        case WM_CREATE:
            edit1 = CreateWindow("edit", "", WS_CHILD|WS_VISIBLE, 0, 0, 200, 50, hWnd, NULL, NULL, NULL);
            edit2 = CreateWindow("edit", "", WS_CHILD|WS_VISIBLE, 250, 0, 200, 50, hWnd, NULL, NULL, NULL);
            return 0;

        case WM_CLOSE:
            DestroyWindow(hWnd);
            return 0;

        case WM_DESTROY:
            PostQuitMessage(0);
            return 0;
    }
    return DefWindowProc(hWnd, msg, wParam, lParam);
}

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
    WNDCLASS wc;
    wc.style = 0;
    wc.lpfnWndProc = WinProc;
    wc.cbClsExtra = 0;
    wc.cbWndExtra = 0;
    wc.hInstance = hInstance;
    wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
    wc.hCursor = LoadCursor(NULL, IDC_ARROW);
    wc.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
    wc.lpszMenuName = NAME;
    wc.lpszClassName = NAME;
    RegisterClass(&wc);

    HWND win;
    win = CreateWindow(NAME, "test", WS_OVERLAPPEDWINDOW, 0, 0, 500, 500, NULL, NULL, hInstance, NULL);

    ShowWindow(win, nCmdShow);
    UpdateWindow(win);

    MSG msg;
    while(GetMessage(&msg, NULL, 0, 0) > 0)
    {
        TranslateMessage(&msg);
        DispatchMessage(&msg);
    }
    return msg.wParam;
}
+3
source share
1 answer

, WM_ACTIVATE ( wParam WA_INACTIVE).

, WM_ACTIVATE, wParam WA_ACTIVE WA_CLICKACTIVE

, .

, Spy ++ , , . *

+3

Source: https://habr.com/ru/post/1732105/


All Articles