1
votes

CreateWindowEx API really posts WM_SIZE message?

When I create a window via CreateWindowEx as full screen mode,

CreateWindowEx posts WM_SIZE but window mode doesn't.

My code sets the window style like this :

if(bFullscr)
{
    //When the window is in full screen mode.
    nStyle = WS_POPUP;
    nExtraStyle = WS_EX_APPWINDOW;
}
else
{
    //Otherwise.
    nStyle = WS_OVERLAPPEDWINDOW;
    nExtraStyle = (WS_EX_APPWINDOW | WS_EX_WINDOWEDGE);
}

And changes display settings like this (full screen mode only) :

if(bFullscr)
{
    DEVMODE sScrSet;
    memset(&sScrSet, 0, sizeof(DEVMODE));
    sScrSet.dmSize = sizeof(DEVMODE);
    sScrSet.dmPelsWidth = nWidth;
    sScrSet.dmPelsHeight = nHeight;
    sScrSet.dmBitsPerPel = nColorBit;
    sScrSet.dmFields = (DM_BITSPERPEL | DM_PELSHEIGHT | DM_PELSWIDTH);

    if(ChangeDisplaySettings(&sScrSet, CDS_FULLSCREEN) != DISP_CHANGE_SUCCESSFUL)
    {
        //Error routine.
    }  
}

I'm really wonder why CreateWindowEx posts WM_SIZE message selectively.

1

1 Answers

0
votes

If you simply want to resize the window, somewhere in your code you should have ShowWindow(hWnd, nCmdShow); change it as follows:

ShowWindow(hWnd, SW_SHOWDEFAULT);//show normal
ShowWindow(hWnd, SW_SHOWMAXIMIZED);//show maximized (full screen)
SetWindowPos(hWnd, NULL, 10, 10, 300, 300, SWP_SHOWWINDOW);//show at specific position

Also you could use WS_MAXIMIZE in CreateWindow, but that could complicate things. Window usually has WS_OVERLAPPEDWINDOW or WS_POPUP|WS_CAPTION|WS_SYSMENU. You should pick one and keep it simple.

When Window size changes, it receives WM_SIZE, you can catch that and examine it.