Thread: Width of window border

  1. #1
    Registered User Tonto's Avatar
    Join Date
    Jun 2005
    Location
    New York
    Posts
    1,465

    Width of window border

    Trying to get the width of a window border to accurately make a window's client area centered on the screen. Stumbled upon SystemParametersInfo + SPI_GETNONCLIENTMETRICS / SPI_GETBORDER. In both cases, it returns to me that the border is only one pixel. Which I have a hard time believing. I use this code:

    Code:
    int CenterWindow(HWND hwnd, int width, int height)
    {
        NONCLIENTMETRICS ncm;
        
        rect scrrect;
        int ret = 0;
        
        ncm.cbSize = sizeof(NONCLIENTMETRICS);
        ret = ::SystemParametersInfo(SPI_GETWORKAREA, 0, &scrrect, 
                                     SPIF_UPDATEINIFILE);
        
        if(!ret)
            return 0;
        
        point center(scrrect.bx() / 2, scrrect.by() / 2);           
        point tl(center.x() - width / 2, center.y() - height / 2);
        
        ::SystemParametersInfo(SPI_GETNONCLIENTMETRICS, 
                              sizeof(NONCLIENTMETRICS), &ncm, 0);
    
        
        ret = ::MoveWindow(hwnd, tl.x() - ncm.iBorderWidth, tl.y() - 
                           ncm.iCaptionHeight, width + ncm.iBorderWidth, 
                           height + ncm.iBorderWidth, TRUE);
    
        return ret;
    }
    I call it with the width and height being the dimensions of the client area that I want. When the function is done, I call GetClientRect, and the bottom and right members of the RECT structure end up being 493 and 567. Is there another way I should be retrieving this sort of info? Is the computer LYING?

  2. #2
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    Why not use the WS_CENTER style?

    Or use the difference between GetWindowRect() and GetClientRect() to find the non client area?

    ScreenToClient() may also help.
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  3. #3
    ... arjunajay's Avatar
    Join Date
    May 2005
    Posts
    203
    I am not sure about what you are asking but
    GetSystemMetrics(SM_CXBORDER);
    GetSystemMetrics(SM_CXEDGE);
    GetSystemMetrics(SM_CXFIZEDFRAME);
    Might help ???

  4. #4
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    Also, have a look at the AdjustWindowRect function.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. 6 measly errors
    By beene in forum Game Programming
    Replies: 11
    Last Post: 11-14-2006, 11:06 AM
  2. Linking OpenGL in Dev-C++
    By linkofazeroth in forum Game Programming
    Replies: 4
    Last Post: 09-13-2005, 10:17 AM
  3. OpenGL Window
    By Morgul in forum Game Programming
    Replies: 1
    Last Post: 05-15-2005, 12:34 PM
  4. problem with open gl engine.
    By gell10 in forum Game Programming
    Replies: 1
    Last Post: 08-21-2003, 04:10 AM
  5. opengl code not working
    By Unregistered in forum Windows Programming
    Replies: 4
    Last Post: 02-14-2002, 10:01 PM