Click here to Skip to main content
15,903,725 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
Dear all,

I have a window with WindowProc, I want that when user click on minimize button (title bar), My window will be hided instead of minimize. In WindowProc:

C++
LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    switch (message)
    {
    case WM_SYSCOMMAND:
           switch(wParam)
          {
                  case SC_MINIMIZE:
                           ShowWindow(hwnd, SW_HIDE); // <== Hide window instead of minimize
                          break;
          }
          break;
        
    case WM_DESTROY:
        PostQuitMessage (0);
        return (0);
    }
    return DefWindowProc (hwnd, message, wParam, lParam);
}


It works well when I click on minimize button (it will hide), but I cannot move or maximize or close window. What's happen??

Do you have any comment?

Thank you
Posted
Comments
Chuck O'Toole 28-Nov-11 20:24pm    
When do you try to "but I cannot move or maximize or close window"? Before or After it is hidden? Before should work just fine. As for after, well seriously, once you hide it how do you expect to click on it again or bring it back?
Sergey Alexandrovich Kryukov 28-Nov-11 20:50pm    
Yes, this is what it is; I think the question is answered...
--SA
SVPro 28-Nov-11 20:58pm    
Dear Chuck O'Toole, SAkryukov

Before the window is hidden, I cannot move, maximize or close this window, I ONLY minimize it and it's hidden when I minimize.
Chuck O'Toole 28-Nov-11 23:21pm    
perform a simple "problem isolation" experiment. Reduce your WndProc() to be just the "return DefWindowProc()" statement. If everything is working then, it's your code not getting to that on non-minimize messages. If it still doesn't move or maximize, then there's another problem. Step one is to determine where to look.
Mohibur Rashid 28-Nov-11 22:03pm    
In this case its important to see the CreateWindow function specially what style you have used. Its also important to see what you did WM_SIZE message

I believe there is a typo in your code as posted. If I run that code as my window proc, everything works properly because the last thing that is always performed is DefWindowProc.


I believe the problem you are seeing is caused by not processing the DefWindowProc in the WM_SYSCOMMAND case.

Change the code posted above to the following and it should do what you are asking for. I have placed a default handler in both of your switch statements to make sure DefWindowProc is called appropriately:
C++
LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
  LRESULT lResult = 0;
  switch (message)
  {
  case WM_SYSCOMMAND:
    switch(wParam)
    {
    case SC_MINIMIZE:
      ShowWindow(hwnd, SW_HIDE); // <== Hide window instead of minimize
      break;
    default:
      lResult = DefWindowProc (hwnd, message, wParam, lParam);
    }

    break;

  case WM_DESTROY:
    PostQuitMessage (0);
    return (0);
  default:
    lResult = DefWindowProc (hwnd, message, wParam, lParam);
  }

  return lResult;
}



Something like this would cause the issue you are describing:

C++
switch(wParam)
case WM_SYSCOMMAND:
  switch (message)
  {
  case SC_MINIMIZE:
    ShowWindow(hwnd, SW_HIDE); // <== Hide window instead of minimize
    break;
  default:
    // If you don't call DefWindowProc for the other WM_SYSCOMMAND messages, 
    // Those modes will cease to function.
    // lResult = DefWindowProc (hwnd, message, wParam, lParam);
    return 0;
  }


Regards,
Paul
 
Share this answer
 
Comments
SVPro 30-Nov-11 6:03am    
Dear Paul Watt,

Very impressive, your solution is good!

Thank you!

@All: I also appreciate your suggestions
Hi,


I've learned on peple comments of this msdn page that it is recommanded to use
ShowWindowAsync
instead of
ShowWindow
, according to people experiments:

ShowWindow msdn ref[^]

They also described an unexspected behavior when trying to bring the window foreground manually, they recommand to make it programmatically using
SetForegroundWindow(hwnd)

Take a look at people comments according to their use of this function, it is interesting for you.

Best regards.
EL GAABEB.
 
Share this answer
 
v2
you need to handle these other WM_SYSCOMMAND messages. Write a default with trace statements to see them...
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900