views:

337

answers:

3

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.

A: 

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

You could also have a look at SetForegroundWindow

schnaader
SetForegroundWindow does the trick. Thanks!
TrayMan
A: 

if (::IsIconic(hwnd))
ShowWindow(hwnd, SW_RESTORE);

::SetForegroundWindow(hwnd);
::BringWindowToTop(hwnd);

SAMills
A: 

Never use SetForeground.

See Msdn remarks.

Which ones? The documentation seems to suggest it is perfectly ok to use in certain circumstances
1800 INFORMATION