CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 11 of 11

Thread: Display issues

  1. #1
    Join Date
    Nov 2014
    Posts
    37

    Display issues

    This has been driving me crazy for a couple of days and I cannot find the problem.
    All the c/c++ compilers I have (PellesC,TDM-GCC,NUWEN,Tiny C)display this code the same except Visual Studio 2015 Community.
    VS chops the bottom and right side of the window.

    James

    Code:
    #include <windows.h>
    #pragma comment(lib,"User32.lib")
    #pragma comment(lib,"gdi32.lib")
    #define cSizeOfDefaultString 2048
    
    #define IDC_OK 1001
    #define IDC_CANCEL 1002
    #define IDC_TEXT 1003
    
    static HWND    hText;
    static HWND    hOk;
    static HWND    hCancel;
    
    int     WINAPI WinMain (HINSTANCE, HINSTANCE, LPSTR, int);
    LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM);
    
    
    int WINAPI WinMain (HINSTANCE hInst, HINSTANCE hPrev, LPSTR CmdLine, int CmdShow)
    {
        WNDCLASSEX  wcx = {0};
        MSG      uMsg = {0};
        HWND     hWin = {0};
        DWORD    dwStyle = {0};
        DWORD    dwStyleEx = {0};
        HFONT    hFont = {0};
        hFont = ( HFONT) GetStockObject( DEFAULT_GUI_FONT);
        char     szClassName[] = "MyClassName";
        wcx.cbSize = sizeof( wcx);
        wcx.style = CS_HREDRAW | CS_VREDRAW;
        wcx.lpfnWndProc = WndProc;
        wcx.cbClsExtra = 0;
        wcx.cbWndExtra = 0;
        wcx.hInstance = hInst;
        wcx.hIcon = LoadIcon( NULL, IDI_APPLICATION);
        wcx.hCursor = LoadCursor( NULL, IDC_ARROW);
        wcx.hbrBackground = ( HBRUSH)( COLOR_BTNFACE + 1);
        wcx.lpszMenuName = 0;
        wcx.lpszClassName = szClassName;
        wcx.hIconSm = LoadIcon( NULL, IDI_APPLICATION);
        RegisterClassEx( &wcx);
    
        dwStyle = WS_POPUP | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CAPTION;
        dwStyleEx = WS_EX_DLGMODALFRAME | WS_EX_CONTROLPARENT | WS_EX_WINDOWEDGE;
        hWin = CreateWindowEx( dwStyleEx, szClassName, "What is your name? ", dwStyle, ( GetSystemMetrics( SM_CXSCREEN) - 246) / 2, ( GetSystemMetrics( SM_CYSCREEN) - 110) / 2, 246, 110, 0, (HMENU) 0, hInst, NULL);
        hText = CreateWindowEx( WS_EX_CLIENTEDGE, "Edit", "", WS_CHILD | WS_VISIBLE | WS_TABSTOP | ES_AUTOHSCROLL, 21, 20, 201, 19, hWin, (HMENU) IDC_TEXT, hInst, NULL);
        SendMessage(hText, (UINT)WM_SETFONT, (WPARAM)hFont, (LPARAM)0);
        hOk = CreateWindowEx( 0, "Button", "OK", WS_CHILD | WS_VISIBLE | WS_TABSTOP, 51, 52, 60, 23, hWin, (HMENU) IDC_OK, hInst, NULL);
        SendMessage(hOk, (UINT)WM_SETFONT, (WPARAM)hFont, (LPARAM)0);
        hCancel = CreateWindowEx( 0, "Button", "Cancel", WS_CHILD | WS_VISIBLE | WS_TABSTOP, 126, 52, 60, 23, hWin, (HMENU) IDC_CANCEL, hInst, NULL);
        SendMessage(hCancel, (UINT)WM_SETFONT, (WPARAM)hFont, (LPARAM)1);
        SetFocus(hText);
        ShowWindow(hWin, SW_SHOW);
        while(GetMessage( &uMsg, NULL, 0, 0))
        {
            if(IsDialogMessage(hWin, &uMsg))
            {
                continue;
            }
            TranslateMessage( &uMsg);
            DispatchMessage( &uMsg);
        }
    
        return uMsg.wParam;
    }
    
    
    LRESULT CALLBACK WndProc (HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
    {
        switch(Msg)
        {
        case WM_DESTROY:
            PostQuitMessage(0);
            return 0;
        case WM_COMMAND:
            if((HWND)lParam == hCancel )
            {
                SendMessage(hWnd, (UINT)WM_CLOSE, (WPARAM)0, (LPARAM)0);
            }
        }
        return DefWindowProc(hWnd, Msg, wParam, lParam);
    }
    Attached Images Attached Images   

  2. #2
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,824

    Re: Display issues

    Has this code been compiled with these compilers using exactly the same version of the .lib/.h files - ie with the same version of the Windows SDK installed (which version?) and used by the compilers? Has the code been tried on the same version of Windows (which version?) with the same hotfixes applied etc.
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

  3. #3
    Join Date
    Nov 2014
    Posts
    37

    Re: Display issues

    I'm really not sure what you mean?
    All the compilers reside on the same Windows 10 computer including Visual Studio 2015 Community.
    They all contain their own lib and include files.
    I rely on the Nuwen distro for testing as it is maintained by an MS employee on his own personal site.
    https://nuwen.net/mingw.html
    I just did an update to Visual Studio and it made no difference.
    I also compiled on a Win7 box and it was the same there.
    I compile from the command line.

    Does the code display correctly on your machine?

    James

  4. #4
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,824

    Re: Display issues

    Using VS2015 with Windows 7 I get the same chopped bottom and side.
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

  5. #5
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,824

    Re: Display issues

    To get the same display, the size of the window needs to be 266 and 130 which is 20 more than in the test code. But I get a different border to that shown with rounded corners and thicker bottom and sides - which probably accounts for the extra 10 at each side.
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

  6. #6
    Join Date
    Nov 2014
    Posts
    37

    Re: Display issues

    Thanks 2kaud,
    Where is this behavior documented? Not in CreateWindowEx
    If I request a window X by Y I want a Window X by Y.
    As I said all other c/c++ compilers I use do this along with PowerBASIC and FreeBasic which I also use often.
    I'd be curious about Delphi and OpenPascal.

    James

  7. #7
    Join Date
    Nov 2014
    Posts
    37

    Re: Display issues

    I was just coached to always base your windows on client area and use this code to create your window:

    Code:
        dwStyle = WS_POPUP | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CAPTION;
        dwStyleEx = WS_EX_DLGMODALFRAME | WS_EX_CONTROLPARENT | WS_EX_WINDOWEDGE;
        
        RECT lpr = { 0 };
        SetRect(&lpr, 0, 0, 240, 81);
        AdjustWindowRectEx(&lpr, dwStyle, FALSE, dwStyleEx);
        long w = lpr.right - lpr.left;
        long h = lpr.bottom - lpr.top;
        long x = max((GetSystemMetrics(SM_CXSCREEN) - w) / 2, 0);
        long y = max((GetSystemMetrics(SM_CYSCREEN) - h) / 2, 0);
    
        hWin = CreateWindowEx( dwStyleEx, szClassName, L"What is your name? ", dwStyle, x, y, w, h, 0, (HMENU) 0, hInst, NULL);

  8. #8
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,824

    Re: Display issues

    That code produces the required sized window!

    I think the issue between the compiles is to what version of the .dll's is being linked. VS2015 has manifest files which can include required version numbers of the .dlls. Different versions produce different 'types' of window display. I suspect that VS2015 is defaulting to a particular version (the latest?) and that the other non-Microsoft compilers use a different one - hence the differing display.

    Can any guru shed some more light on this?
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

  9. #9
    Join Date
    Nov 2014
    Posts
    37

    Re: Display issues

    Here is an alternative (thanks to José Roca). Use zeros for width and height and then call this.
    Can also be used for dpi aware app's.
    I still would like to know what is going on!!
    James

    Code:
    void    SetClientSize (HWND, long, int, float = 1, float = 1);
    
    void SetClientSize (HWND hwnd, long nWidth, int nHeight, float rxRatio, float ryRatio)
    {
        RECT     rc = {0};
        RECT     rcTemp = {0};
        // Convert the client rectangle to a window rectangle.
        // The AdjustWindowRectEx function cannot take menu wrapping into account
        // because it doesn't know which menu we are using.
        SetRect( &rc, 0, 0, nWidth * rxRatio, nHeight * ryRatio);
        HANDLE   hMenu = GetMenu(hwnd);
        DWORD    dwStyle = GetWindowLongPtr(hwnd, GWL_STYLE);
        AdjustWindowRectEx( &rc, dwStyle, (hMenu != NULL), GetWindowLongPtr(hwnd, GWL_EXSTYLE));
    
        // If there is a menu, we need to check how much wrapping occurs when we set
        // the window to the width specified by AdjustWindowRectEX and an infinite
        // amount of height. An infinite height allows us to see every single menu wrap.
    
        if(hMenu != NULL )
        {
            rcTemp = rc;
            rcTemp.bottom = 0x7FFF;	// "Infinite" height
            SendMessage(hwnd, (UINT)WM_NCCALCSIZE, (WPARAM)0, (LPARAM)&rcTemp);
            // Adjust our previous calculation to compensate for menu wrapping.
            rc.bottom +=   rcTemp.top;
        }
    
        // The AdjustWindowRectEx function does not take the WS_VSCROLL or WS_HSCROLL
        // styles into account. To account for the scroll bars, we need to call the
        // GetSystemMetrics function with SM_CXVSCROLL or SM_CYHSCROLL.
    
        if((dwStyle & WS_HSCROLL) == WS_HSCROLL )
        {
            rc.bottom = rc.bottom + GetSystemMetrics( SM_CYHSCROLL);
        }
        if((dwStyle & WS_VSCROLL) == WS_VSCROLL )
        {
            rc.right = rc.right + GetSystemMetrics( SM_CXVSCROLL);
        }
        long     cx = rc.right - rc.left;
        long     cy = rc.bottom - rc.top;
        SetWindowPos(hwnd, NULL, 0, 0, cx, cy, SWP_NOZORDER | SWP_NOMOVE | SWP_NOACTIVATE);
    }

  10. #10
    Join Date
    Nov 2014
    Posts
    37

    Re: Display issues

    More information.

    http://stackoverflow.com/questions/1...ect-size-of-wi
    http://stackoverflow.com/questions/2...-ws-overlapped

    When in aero mode, see also https://msdn.microsoft.com/en-us/lib...(v=vs.85).aspx

    Windows 10 has thin invisible borders on left, right, and bottom, it is used to grip the mouse for resizing.
    The borders might look like this: 7,0,7,7 (left, top, right, bottom)
    http://stackoverflow.com/questions/3...isible-borders

  11. #11

    Re: Display issues

    I have not problem with your code. Using VS2015 with Windows 8.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured