There is a Win32 application: a window and a single TextBox. In the while(GetMessage(... some event is checked. If it is set, the text is updated in the TextBox (taken from the Mapped area, but this, I think, does not matter)).

The problem is this: if the window is in the background, then the update does not occur. As soon as I click on the window, everything is updated normally. Question: Is it possible to make it happen always, even in the background.

I tried at the end of the while(GetMessage(... (already after TranslateMessage and DispatchMessage )) to send WM_USER to myself, but it did not help.

  • Normal UpdateWindow tried? - Duracell
  • Does not help. But the text is not updated when the window is activated, but even if by textBox (I recall, the window in the background) to hold the mouse cursor - Alexey Sarovsky
  • so by condition update in a separate thread, for example, check if the window is not active, then update: if (GetForegroundWindow() != ваш_hwnd)UpdateWindow(ваш_HWND) - Duracell
  • Hmm, I thought about something like that, but it seemed to be from the category "From a cannon on a sparrow." Looks like I was mistaken (Thanks, I will try. - Alexey Sarovsky
  • I proceeded from your goals), perhaps there are more solutions to the problem))), but this is what came to my mind from the very beginning. - Duracell

1 answer 1

Since I do not quite understand the essence of the question, so I will offer 3 different options.

The whole thing will have to be put into a separate thread, because the window's event handler will not catch the "inactivity" events (events when the window is not active)!

If to brake a cycle in a stream in which all this magic Sleep(1); will be executed Sleep(1); - it will be quite economical for your needs.

To update the textBox , you need to pass it to HWND!

Option 1:

 if (GetForegroundWindow() != ваш_hwnd)UpdateWindow(ваш_HWND) 

Option 2:

 //Использовать MoveWindow, с флагом true MoveWindow(hwnd, (int)position.x, (int)position.y, (int)position.w, (int)position.h, true); //Получить тукущую позицию окна: RECT WindowRect{}; GetWindowRect(hwnd, &WindowRect) 

Option 3:

 RedrawWindow//с нужными вам флагами 
  • Thank you very much, I will try. But the question remains: why is the non-active window nevertheless updated, if the cursor is “run” through it? - Alexey Sarovsky
  • one
    @ Alexey Sarovsky, this is a normal window handler event, triggered by an event filter with the WM_MOUSEMOVE flag, if I'm not mistaken, you can check this: LRESULT CALLBACK WindowProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { switch (message) { case WM_MOUSEMOVE: printf_s("Событие!\n");break; default: return 0; } return 0; } LRESULT CALLBACK WindowProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { switch (message) { case WM_MOUSEMOVE: printf_s("Событие!\n");break; default: return 0; } return 0; } LRESULT CALLBACK WindowProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { switch (message) { case WM_MOUSEMOVE: printf_s("Событие!\n");break; default: return 0; } return 0; } - Duracell