none
SW_MAXIMIZE is same as fullscreen?

    Question

  • Hi!

    I'm using "ShowWindow( hWnd, SW_MAXIMIZE )" to maximize a window but it displays more like a fullscreen window than a normal maximized one.  It takes up the entire screen hiding the main taskbar.  This is not normal behaviour for a maximized window - it should be taking up the entire screen excluding the main taskbar.

    What can I do to get normal behaviour of maximizing a window?

    Thanx!

    , Espen
    Thursday, February 19, 2009 10:58 PM

Answers

  • To conclude this topic here's how you can maximize a window created as WS_POPUP:

    1 // Declared and initialized in adnvance  
    2 RECT WorkArea, WindowSizeNormal, WindowSizeCurrent;  
    3  
    4 ...  
    5  
    6 // Get window size and position as maximized  
    7 SystemParametersInfo( SPI_GETWORKAREA, 0, &WorkArea, 0 );  
    8  
    9 // Store the current position for use when normalizing the window   
    10 WindowSizeNormal.left = WindowSizeCurent.left;   
    11 WindowSizeNormal.top = WindowSizeCurent.top;   
    12 WindowSizeNormal.right = WindowSizeCurent.right;   
    13 WindowSizeNormal.bottom = WindowSizeCurent.bottom;   
    14  
    15 // Set new window size and position as maximized   
    16 SetWindowPos( hWnd, NULL, WorkArea.left, WorkArea.top, WorkArea.right, WorkArea.bottom, NULL );  

    This is not anywhere near being a full code as to how to do this.  If any, it is no more than pseudo code.  Anyway, it can help regarding this issue and it is the closest I have been to a solution - it may even be the only solution to maximizing a WS_POPUP.

    Thanx for all the help to everyone who contributed.

    , Espen
    Monday, February 23, 2009 10:11 PM
  • I also didn't find anything about SW_MAXIMIZE on that newsgroup.  Anyway, I think I have found the right and easy way to this little problem.  Just call "ShowWindow( hWnd, SW_MAXIMIZE )" as normally where you want to maximize your window.  And then add this little code to your WinProc:

    1  
    2    case WM_GETMINMAXINFO:  
    3  
    4       {  
    5  
    6          RECT WorkArea; SystemParametersInfo( SPI_GETWORKAREA, 0, &WorkArea, 0 );  
    7  
    8          ( ( MINMAXINFO * )lParam )->ptMaxSize.x = ( WorkArea.right - WorkArea.left );  
    9          ( ( MINMAXINFO * )lParam )->ptMaxSize.y = ( WorkArea.bottom - WorkArea.top );  
    10          ( ( MINMAXINFO * )lParam )->ptMaxPosition.x = WorkArea.left;  
    11          ( ( MINMAXINFO * )lParam )->ptMaxPosition.y = WorkArea.top;  
    12  
    13          return 0;  
    14  
    15       }  
    16  
    17  

    This will assure that no matter why, who or how your window is maximized is will always be within the workarea...

    , Espen
    Tuesday, March 03, 2009 7:42 AM

All replies

  • How are you creating the window? With what styles I mean.
    http://blog.voidnish.com
    Thursday, February 19, 2009 11:22 PM
  • If you create your window like this

    CreateWindow("classname", "title", WS_POPUP, 0, 0, 0, 0, NULL, NULL, hInstance, 0)

    i.e., a window without dimensions and with the style WS_POPUP and show the window with

    ShowWindow(hWnd, SW_MAXIMIZE)

    it will take the entire screen.

    Actually, if you create a WS_POPUP window, even with non-null coordinates and sizes, with hWndParent = NULL and show it with SW_MAXIMIZE, you'll get a window occupying the whole screen !!
    Friday, February 20, 2009 12:23 AM
  • As Nishant Says show your code here so that anyone can help you ,is it a Wind32 Application or anything else .Anyway here is a dummy code for a simply win32 Application.Anyway there is nothing much in the code it's a simple win32 application.And remember it's just a dummy code don't forget to check it at your side.

    MyApp.h

    #include<afxwin.h> 
    class MyApp:public CWinApp 
        BOOL InitInstance(); 
    }; 
    MyApp a; 

    MyApp.cpp

    #include "MyApp.h" 
    #include "MyFrame.h" 
    BOOL MyApp::InitInstance() 
        MyFrame *p; 
        p=new MyFrame; 
        m_pMainWnd =p; 
        p->ShowWindow(3);//or you can use ShowWindow(SW_MAXIMIZE) 
        return 1; 

    MyFrame.h

    #include <afxwin.h> 
    class MyFrame:public CFrameWnd 
    public: 
       MyFrame(); 

       DECLARE_MESSAGE_MAP() 
    }; 

    MyFrame.cpp

    #include "MyFrame.h" 
     
    MyFrame::MyFrame() 
        Create(0,"Helo",WS_VISIBLE|WS_OVERLAPPEDWINDOW,rectDefault,this,NULL); 
     
    BEGIN_MESSAGE_MAP(MyFrame,CFrameWnd) 
    END_MESSAGE_MAP() 

    Thanks

    Rupesh Shukla
    Friday, February 20, 2009 3:20 AM
  • Thanx guys.  Then it's the WS_POPUP that gives me a fullscreen.  Annoying as I need it since I want a clear/all-client area window where I do my own graphics.  But is it possible to set hWndParent to the desktop/explorer and thereby have my application maximize correctly?

    , Espen
    Friday, February 20, 2009 7:17 AM
  • Even with hWndParent = GetDesktopWindow() you'll get a full size screen window.
    Friday, February 20, 2009 10:04 AM
  • Try CreateWindowEx() with dwExStyle = WS_EX_APPWINDOW and dwStyle = WS_POPUP !
    Friday, February 20, 2009 10:22 AM
  • I allready have CreateWindowEx() with dwExStyle = WS_EX_APPWINDOW and dwStyle = WS_POPUP.  Here's my code:

    1  
    2    {  
    3  
    4       WNDCLASSEX FrameClassEx;  
    5  
    6       FrameClassEx.cbSize        = sizeof( WNDCLASSEX );  
    7       FrameClassEx.style         = NULL;  
    8       FrameClassEx.lpfnWndProc   = WndProcFrame;  
    9       FrameClassEx.cbClsExtra    = NULL;  
    10       FrameClassEx.cbWndExtra    = NULL;  
    11       FrameClassEx.hInstance     = hInstance;  
    12       FrameClassEx.hIcon         = LoadIcon( NULL, MAKEINTRESOURCE( IDI_APP_ICON ) );  
    13       FrameClassEx.hCursor       = LoadCursor( NULL, IDC_ARROW );  
    14       FrameClassEx.hbrBackground = ( HBRUSH )GetStockObject( LTGRAY_BRUSH );  
    15       FrameClassEx.lpszMenuName  = NULL;  
    16       FrameClassEx.lpszClassName = TEXT( "FrameClassEx" );  
    17       FrameClassEx.hIconSm       = NULL;  
    18  
    19       RegisterClassEx( &FrameClassEx );  
    20  
    21    }  
    22  
    23    HWND hWndFrame = CreateWindowEx(  
    24  
    25       WS_EX_APPWINDOW,  
    26       TEXT( "FrameClassEx" ),  
    27       TEXT( "AppName" ),  
    28       WS_POPUP,  
    29       112,  
    30       100,  
    31       800,  
    32       400,  
    33       NULL,  
    34       NULL,  
    35       hInstance,  
    36       NULL  
    37  
    38    );  
    39  
    40    ShowWindow( hWndFrame, SW_SHOWNORMAL ); UpdateWindow( hWndFrame );  
    41  
    42    MSG msg;  
    43  
    44    while( GetMessage( &msg, NULL, NULL, NULL ) ) {  
    45  
    46       DispatchMessage( &msg );  
    47  
    48    }  
    49  
    50    DestroyWindow( hWndFrame );  
    51  
    52    return msg.wParam;  
    53  

    So it seems difficult to get what I want since I need to have dwStyle = WS_POPUP.  I'm trying to do my own GUI and I need a clear window and using dwStyle = WS_POPUP is the only way I found.

    If you like to see what I'm trying to do and why I need a clear window:

    http://cid-7f039c7d2c372166.skydrive.live.com/self.aspx/Programming/AppName.png

    Anyway, it can't be that hard.  Lots of programs from iTunes to Google Chrome have designed their own GUI from scratch.  And they have no problem when maximizing their window.

    Any more help regarding anything about this or creating a customized GUI is appreciated.

    Thanx!

    , Espen
    Friday, February 20, 2009 5:27 PM
  • In addition to WS_POPUP, try adding WS_THICKFRAME too.

    (WS_POPUP | WS_THICKFRAME) 

    http://blog.voidnish.com
    Friday, February 20, 2009 5:41 PM
  •  (WS_POPUP | WS_THICKFRAME)  won't work either.

    But I think I found a work-around. Create a window that will be the owner of your popup window, and call it hMainWnd. Then ShowWindow(hMainWnd, SW_HIDE) . This way the only visible window in your application will be your popup window. And hopefully hMainWnd will always be shown on the task bar, even when the popup is maximized.

    The key point here is that the combination WS_POPUP and hWndParent = NULL will always make the maximized window occupy the whole screen. By creating an owned popup window, I hope this effect will be annulled.
    Friday, February 20, 2009 6:08 PM
  • Espen Ruud Schultz said:

    It takes up the entire screen hiding the main taskbar. This is not normal behaviour for a maximized window - it should be taking up the entire screen excluding the main taskbar.

    I think you mean that it should be taking up the entire screen and including the main taskbar; is that what you mean? Are you saying that if it is not maximized then it has a taskbar - oh wait, you said taskbar; do you mean the thing that is at the bottom of the desktop? I think there are two or more ways to maximize a window and the old way covers the taskbar and the new way does not. I don't know how to do it the new way; perhaps you need to do it that way though.

    Espen Ruud Schultz said:

    Thanx guys.  Then it's the WS_POPUP that gives me a fullscreen.  Annoying as I need it since I want a clear/all-client area window where I do my own graphics.  But is it possible to set hWndParent to the desktop/explorer and thereby have my application maximize correctly?


    I doubt that WS_POPUP is the problem. You can use Spy++ to do a little investigating; perhaps you can find something that the other applications are doing. Also look at the relevant portions of the Windows documentation; the answer is probably there. Also try forums in other sites and/or the Microsoft newsgroup for Windows UI as described in Sticky: The scope of this forum; the VC Language forum Sticky: Visual C++ Language forum: The scope, tips and pointers has a more direct link to the UI newsgroup. There are many other sites with forums for Windows UI questions. I suggest the newsgroup and other forums since I doubt that WS_POPUP is the problem and Windows programming is officially off-topic for here.

    Sam Hobbs; see my SimpleSamples.Info
    Sunday, February 22, 2009 4:55 AM
  • The problem is the combination of the styles WS_POPUP | WS_MAXIMIZE , which is equivalent to the style WS_POPUP and ShowWindow(hWnd, WS_SHOWMAXIMIZED).

    Notice that WS_OVERLAPPED | WS_MAXIMIZE has the same problem. But here at least, you can replace WS_OVERLAPPED by WS_OVERLAPPEDWINDOW, and the window will be shown on the task bar.

    It's really intriguing how Google Chrome has done it. I have not been able to reproduce that, i.e., a maximized popup window that shows on the task bar !
    • Edited by Belloc Sunday, February 22, 2009 12:01 PM typo
    Sunday, February 22, 2009 11:50 AM
  • Simple Samples said:

    Also look at the relevant portions of the Windows documentation; the answer is probably there. Also try forums in other sites and/or the Microsoft newsgroup for Windows UI as described in Sticky: The scope of this forum; the VC Language forum Sticky: Visual C++ Language forum: The scope, tips and pointers has a more direct link to the UI newsgroup. There are many other sites with forums for Windows UI questions. I suggest the newsgroup and other forums since I doubt that WS_POPUP is the problem and Windows programming is officially off-topic for here.

    Sam Hobbs; see my SimpleSamples.Info

    Actually I once asked, in Where is the forums for...?, where to find a forum for Windows API and got the answer that C++ General Forum covers Windows API and libraries.  The UI Programming forum is nowhere near as busy as these forums and it kinda looks old and outdated which I normally try to avoid since I want more hits on my questions.  Anyway I'm gonna try to post there to see if it might produce some answers.


    Belloc said:

    The problem is the combination of the styles WS_POPUP | WS_MAXIMIZE , which is equivalent to the style WS_POPUP and ShowWindow(hWnd, WS_SHOWMAXIMIZED).

    Notice that WS_OVERLAPPED | WS_MAXIMIZE has the same problem. But here at least, you can replace WS_OVERLAPPED by WS_OVERLAPPEDWINDOW, and the window will be shown on the task bar.

    It's really intriguing how Google Chrome has done it. I have not been able to reproduce that, i.e., a maximized popup window that shows on the task bar !

    I've been doing some OpenGL and 3D programming where the trick to get it running in fullscreen is no simpler that setting the dwStyle to WS_POPUP.  When going through some of my old codes yesterday I figured this one out.  I wish I did this sooner.

    I will figure this one out because I know it can be done.

    Thanx!

    , Espen
    Sunday, February 22, 2009 7:31 PM
  •  After dozens of trials, I finally found out how to do it :

    ix = GetSystemMetrics(SM_CXSCREEN);

    iy = GetSystemMetrics(SM_CYSCREEN);

    hWnd = CreateWindow( _T("Window class name"), NULL, WS_POPUP, 0, 0, ix, iy - 1, NULL, NULL, hInstance, NULL);

    ShowWindow(hWnd, SW_SHOW);        //    Don't maximize !

    As you can see the problem is really with the WS_POPUP | WS_MAXIMIZE styles. If you don't decrease 1 from iy above, the window will cover the hole screen. Who knows why ?????

    Sunday, February 22, 2009 7:39 PM
  • Belloc said:

     After dozens of trials, I finally found out how to do it :

    ix = GetSystemMetrics(SM_CXSCREEN);

    iy = GetSystemMetrics(SM_CYSCREEN);

    hWnd = CreateWindow( _T("Window class name"), NULL, WS_POPUP, 0, 0, ix, iy - 1, NULL, NULL, hInstance, NULL);

    ShowWindow(hWnd, SW_SHOW);        //    Don't maximize !

    As you can see the problem is really with the WS_POPUP | WS_MAXIMIZE styles. If you don't decrease 1 from iy above, the window will cover the hole screen. Who knows why ?????

    Yeah, I was thinking I had to abandon WS_MAXIMIZE and just go for a resize instead when maximizing the window.  Thanx to you and everyone who contributed to this problem.  Though I wont give up on the original problem that maximizing the window through Windows API should work somehow.  This is Windows and maximizing a window is part of the main attributes.  Why the number one OS in the world doesn't know how to do this right is beyond my knowledge.  It seems like one shouldn't go beyond Windows own GUI, like making your own, or bad things will happen.

    Thanx again!

    , Espen
    Sunday, February 22, 2009 8:06 PM
  • I think they just wanted to leave the window (sorry for the redundancy) open for someone who wants to work in full screen
    • Edited by Belloc Sunday, February 22, 2009 8:15 PM typo
    Sunday, February 22, 2009 8:12 PM
  • Belloc said:

    After dozens of trials, I finally found out how to do it :

    ix = GetSystemMetrics(SM_CXSCREEN);

    iy = GetSystemMetrics(SM_CYSCREEN);

    hWnd = CreateWindow( _T("Window class name"), NULL, WS_POPUP, 0, 0, ix, iy - 1, NULL, NULL, hInstance, NULL);

    ShowWindow(hWnd, SW_SHOW);        //    Don't maximize !

    As you can see the problem is really with the WS_POPUP | WS_MAXIMIZE styles. If you don't decrease 1 from iy above, the window will cover the hole screen. Who knows why ?????

    By doing my own research i found that using SystemParametersInfo with SPI_GETWORKAREA is the best bet to resize a window to simulate maximized.  This way you don't have to decrease height by one not to hide the Windows taskbar.  And even where the taskbar is located on screen - it could be on any of the four edges on screen, or with multiple applications own taskbars - like offices own taskbar, you will get a perfect maximized application - hopefully.

    Also, the way you describe where you set the size of the window to screen size - 1.  This will make it so that the taskbar actually hides some of the programs window - you would like to have the lower side to be aligned to the taskbar and not beneath it.

    On a side note, check this one out:
    ... just fun to see it the other way around.  :-)

    , Espen
    Sunday, February 22, 2009 8:58 PM
  • The link you posted above is still confusing, for it says :

    "To cover the taskbar you must set the size of the full-screen explicitly. You can not just maximize the window. A maximized window takes up the workspace area, which doesn't include the taskbar."

    and this is wrong, for if you call

    CreateWindow(_T("class"), NULL, WS_POPUP | WS_MAXIMIZE, 0, 0, 0, 0, NULL, NULL, hInstance, NULL)

    the window will cover the whole screen !

     

    Anyway, thanks for the SystemParametersInfo with SPI_GETWORKAREA. I've never heard about this function before.

    Sunday, February 22, 2009 9:09 PM
  • Belloc said:

    The link you posted above is still confusing, for it says :

    "To cover the taskbar you must set the size of the full-screen explicitly. You can not just maximize the window. A maximized window takes up the workspace area, which doesn't include the taskbar."

    and this is wrong, for if you call

    CreateWindow(_T("class"), NULL, WS_POPUP | WS_MAXIMIZE, 0, 0, 0, 0, NULL, NULL, hInstance, NULL)

    the window will cover the whole screen !

     

    Anyway, thanks for the SystemParametersInfo with SPI_GETWORKAREA. I've never heard about this function before.



    Yeah, I saw that one.  Must only apply to a window where the GUI is controlled by Windows and DefWindowProc.  I was kinda hoping to be able to post a follow up question but that knowledge base is not supported anymore.


    Belloc said:

    Anyway, thanks for the SystemParametersInfo with SPI_GETWORKAREA. I've never heard about this function before.

    Hehe.  You put me up to it.  I was searching for SM_CXSCREEN just to get the specifics on it and I found SPI_GETWORKAREA...

    , Espen
    Monday, February 23, 2009 7:07 AM
  • To conclude this topic here's how you can maximize a window created as WS_POPUP:

    1 // Declared and initialized in adnvance  
    2 RECT WorkArea, WindowSizeNormal, WindowSizeCurrent;  
    3  
    4 ...  
    5  
    6 // Get window size and position as maximized  
    7 SystemParametersInfo( SPI_GETWORKAREA, 0, &WorkArea, 0 );  
    8  
    9 // Store the current position for use when normalizing the window   
    10 WindowSizeNormal.left = WindowSizeCurent.left;   
    11 WindowSizeNormal.top = WindowSizeCurent.top;   
    12 WindowSizeNormal.right = WindowSizeCurent.right;   
    13 WindowSizeNormal.bottom = WindowSizeCurent.bottom;   
    14  
    15 // Set new window size and position as maximized   
    16 SetWindowPos( hWnd, NULL, WorkArea.left, WorkArea.top, WorkArea.right, WorkArea.bottom, NULL );  

    This is not anywhere near being a full code as to how to do this.  If any, it is no more than pseudo code.  Anyway, it can help regarding this issue and it is the closest I have been to a solution - it may even be the only solution to maximizing a WS_POPUP.

    Thanx for all the help to everyone who contributed.

    , Espen
    Monday, February 23, 2009 10:11 PM
  • Someone asked this question in the microsoft.public.win32.programmer.ui newsgroup, and I assume it is the same person that asked this question here. So I did a little research myself.

    I was unable to get my simple sample program to not cover the taskbar when maximixed, and other programs, such as VS, also covered the taskbar when maximixed. This is the opposite of what the documentation says happens when windows are maximized.

    If however I change the taskbar properties to enable "Keep the taskbar on top of other windows" then my small sample and also other windows behave in the manner described in the documentation and in the manner that Espen wants. It works regardless of whether the WS_POPUPWINDOW style or the WS_OVERLAPPEDWINDOW style is used.

    So I would say that there should not be extra code to allow the taskbar to be shown. The behavior of a maximized window depends on what the user has chosen and the program should let Windows do it the way the user has chosen.



    Sam Hobbs; see my SimpleSamples.Info
    Wednesday, February 25, 2009 8:24 AM
  • Simple Samples said:

    Someone asked this question in the microsoft.public.win32.programmer.ui newsgroup, and I assume it is the same person that asked this question here. So I did a little research myself.

    I was unable to get my simple sample program to not cover the taskbar when maximixed, and other programs, such as VS, also covered the taskbar when maximixed. This is the opposite of what the documentation says happens when windows are maximized.

    If however I change the taskbar properties to enable "Keep the taskbar on top of other windows" then my small sample and also other windows behave in the manner described in the documentation and in the manner that Espen wants. It works regardless of whether the WS_POPUPWINDOW style or the WS_OVERLAPPEDWINDOW style is used.

    So I would say that there should not be extra code to allow the taskbar to be shown. The behavior of a maximized window depends on what the user has chosen and the program should let Windows do it the way the user has chosen.



    Sam Hobbs; see my SimpleSamples.Info



    I still have the problem with the program covering the taskbar even if "Keep the taskbar ontop of other windows" is enabled.  But this might be a problem with Windows versions though.  I'm on Windows XP where this problem applies.  Maybe on Windows Vista this is not a problem.

    Anyway.  You say that this is the opposite of what the documentation says.  This little info from the knowledge base says something else.  ( http://support.microsoft.com/kb/179363 )  This is however not about maximizing a window, it only applies to window sizing - which is what maximizing is though.  Anyway, I have seen no documentation on how the function "ShowWindow( hWnd, SW_MAXIMIZE )" is suppose to behave other than it will maximize the window.  But how it works on my machine, and others also it seems due to the replies in this thread, is that a window is maximized to the full screen size and so hides the taskbar.

    , Espen
    Wednesday, February 25, 2009 4:12 PM
  • Look at the newsgroup reply.
    Sam Hobbs; see my SimpleSamples.Info
    Wednesday, February 25, 2009 9:28 PM
  • > Anyway, it can help regarding this issue and it is the closest I have been to a solution - it may even be the only solution to maximizing a WS_POPUP

    No, see on win32 api group for the right method to use SW_MAXIMIZE without covering the taskbar
    (it's a very classic question ... since 1995)

    Sunday, March 01, 2009 11:31 AM
  • carly3 said:

    No, see on win32 api group for the right method to use SW_MAXIMIZE without covering the taskbar
    (it's a very classic question ... since 1995)



    Couldn't find anything on this link related to SW_MAXIMIZE
    Sunday, March 01, 2009 12:19 PM
  • I also didn't find anything about SW_MAXIMIZE on that newsgroup.  Anyway, I think I have found the right and easy way to this little problem.  Just call "ShowWindow( hWnd, SW_MAXIMIZE )" as normally where you want to maximize your window.  And then add this little code to your WinProc:

    1  
    2    case WM_GETMINMAXINFO:  
    3  
    4       {  
    5  
    6          RECT WorkArea; SystemParametersInfo( SPI_GETWORKAREA, 0, &WorkArea, 0 );  
    7  
    8          ( ( MINMAXINFO * )lParam )->ptMaxSize.x = ( WorkArea.right - WorkArea.left );  
    9          ( ( MINMAXINFO * )lParam )->ptMaxSize.y = ( WorkArea.bottom - WorkArea.top );  
    10          ( ( MINMAXINFO * )lParam )->ptMaxPosition.x = WorkArea.left;  
    11          ( ( MINMAXINFO * )lParam )->ptMaxPosition.y = WorkArea.top;  
    12  
    13          return 0;  
    14  
    15       }  
    16  
    17  

    This will assure that no matter why, who or how your window is maximized is will always be within the workarea...

    , Espen
    Tuesday, March 03, 2009 7:42 AM
  • Thanks for posting this solution; surprisingly it's the only one that I've found searching, even now in 2012.

    This solution works well for single-monitor setups, but it runs into trouble if the user attempts to maximize the window on a secondary monitor, as SystemParametersInfo only gets the work area for the primary monitor.  What happens is that the window will maximize on the secondary monitor as though there were a taskbar there.

    I've amended your solution to take multiple monitors into account.  I realize that this thread has long since been resolved, but this is for any future souls running into the same problem.

    	case WM_GETMINMAXINFO:
    		{
    			HMONITOR hMonitor = MonitorFromWindow(hWnd, MONITOR_DEFAULTTONEAREST);
    
    			MONITORINFO monitorInfo = {0};
    			monitorInfo.cbSize = sizeof(MONITORINFO);
    			GetMonitorInfo(hMonitor, &monitorInfo);
    
    			MINMAXINFO* pMinMax = (MINMAXINFO*)lParam;
    			pMinMax->ptMaxSize.x = monitorInfo.rcWork.right - monitorInfo.rcWork.left;
    			pMinMax->ptMaxSize.y = monitorInfo.rcWork.bottom - monitorInfo.rcWork.top;
    			pMinMax->ptMaxPosition.x = monitorInfo.rcWork.left - monitorInfo.rcMonitor.left;
    			pMinMax->ptMaxPosition.y = monitorInfo.rcWork.bottom - monitorInfo.rcMonitor.bottom;
    		}
    		return 0;


    • Proposed as answer by Justin Arruda Thursday, May 10, 2012 9:27 PM
    Thursday, May 10, 2012 9:24 PM
  • Justin's modification is a huge step for the multi-monitor setup. However, there is an error in the last line of code before the return statement. The line is

    pMinMax->ptMaxPosition.y = monitorInfo.rcWork.bottom - monitorInfo.rcMonitor.bottom;

    This line should be as follows:

    pMinMaxInfo->ptMaxPosition.y = monitorinfo.rcWork.top - monitorinfo.rcMonitor.top;

    Look closely and you'll notice. Placing .bottom results in a scenario where y has a negative value (if the secondary monitor has a taskbar) and so the window's title bar is hidden ABOVE the window. The bug is not seen if the secondary monitor has no taskbar.

    Thursday, April 24, 2014 1:34 PM
  • Therefore, the proper solution which factor in a multi-monitor setup is as follows:

    case WM_GETMINMAXINFO:
    		{
    			HMONITOR hMonitor = MonitorFromWindow(hWnd, MONITOR_DEFAULTTONEAREST);
    
    			MONITORINFO monitorInfo = {0};
    			monitorInfo.cbSize = sizeof(MONITORINFO);
    			GetMonitorInfo(hMonitor, &monitorInfo);
    
    			MINMAXINFO* pMinMax = (MINMAXINFO*)lParam;
    			pMinMax->ptMaxSize.x = monitorInfo.rcWork.right - monitorInfo.rcWork.left;
    			pMinMax->ptMaxSize.y = monitorInfo.rcWork.bottom - monitorInfo.rcWork.top;
    			pMinMax->ptMaxPosition.x = monitorInfo.rcWork.left - monitorInfo.rcMonitor.left;
    			pMinMax->ptMaxPosition.y = monitorInfo.rcWork.top - monitorInfo.rcMonitor.top;
    		}
    		return 0;

    • Proposed as answer by alecmus Thursday, April 24, 2014 1:38 PM
    Thursday, April 24, 2014 1:38 PM