Win32:将最小化和隐藏的窗口返回到顶部

时间:2009-02-14 19:37:13

标签: c windows winapi system-tray

通过在wndproc中执行此操作,在“最小化”窗口到托盘后,我无法恢复窗口:

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

托盘消息处理程序如下所示:

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

窗口会重新出现,但始终隐藏在其他窗口下方,并且不会显示在顶部。无论是SetFocus()还是BringWindowToTop()都没有任何效果。

3 个答案:

答案 0 :(得分:2)

如果函数返回任何错误,你能看看吗?

您还可以查看SetForegroundWindow

答案 1 :(得分:0)

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

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

答案 2 :(得分:-1)

永远不要使用SetForeground。

见Msdn评论。

相关问题