Search code examples
cwindowswinapisystem-tray

Win32: Returning a minimized and hidden window to top


I'm unable to restore a window after "minimizing" a window to tray, by doing this in wndproc:

case WM_SIZE:
  if (wparam==SIZE_MINIMIZED) {
    ShowWindow(hwnd,SW_HIDE);
  }
  break;

The tray message handler looks like this:

case TRAY_ICON_MESSAGE:
  switch(lparam) {
  case WM_LBUTTONDOWN:
    ShowWindow(hwnd, SW_RESTORE);
    BringWindowToTop(hwnd);
    SetFocus(hwnd);
    break;
  // ...

The window does re-appear, but is always hidden beneath other windows and doesn't come to the top. Neither SetFocus() nor BringWindowToTop() appear to have any effect.


Solution

  • Could you have a look if the functions return any errors?

    You could also have a look at SetForegroundWindow