10

I am creating a program that displays a popup at certain times (just like some chat clients for example) on which the user can click. However, I do not want to take away the focus from the current application.

The way I'm doing it now is by using a HWND with WS_POPUPWINDOW and minimizing and then restoring the window. However, this steals the focus from the current application. Setting foreground or hiding and showing a window did not make it appear on the foreground. I would like to be able to keep using a HWND so I can use other elements in this window, but I have no idea how to give it foreground without stealing focus.

I use win32 and c++.

RichieHindle
  • 272,464
  • 47
  • 358
  • 399

2 Answers2

25

To show without activating:

ShowWindow(hwnd, SW_SHOWNOACTIVATE);

To raise without activating:

SetWindowPos(hwnd, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE);
RichieHindle
  • 272,464
  • 47
  • 358
  • 399
0

Unfortunately this is not working for me. The window is created with CreateWindowExA and is showed using ShowWindow(hwnd, SW_SHOWNOACTIVATE) however the keyboard focus is still stolen from the window which has the focus at the moment of the creation. (The window is created with layered and trasparent attributes by using SetWindowLong() and SetLayeredWindowAttributes() ).

PS: The window which has the focus is not parent of the new created window.

Solved: It worked when I removed the SetForegroundWindow call. This function cause the window passed as parameter to be activated.

Bemipefe
  • 1,397
  • 4
  • 17
  • 30