Thread: Getting interior window size

  1. #1
    Math wizard
    Join Date
    Dec 2006
    Location
    USA
    Posts
    582

    Getting interior window size

    With a function like "CreateWindow", the size you specify is for the whole window as opposed to the interior space. For example, BitBlt a 1024x768 image into the window of this same size and you'll see a little bit chopped off on the right and quite a bit chopped off on the bottom. This is because the window itself is 1024x768 rather than the interior space and elements like the title bar, menu, and even borders take away some of this. If it was the interior space, the whole image will fill the whole interior without any waste or chopping. How do I determine this interior space? Is there a function I can use, or, as I currently do, I have to repeatedly use "GetSystemMetrics" to find the sizes of these things then add them onto the window's size to get the actual result? If there's a predefined Windows function, I would like to know what this function is so I can get a window, with greater ease, of the intended interior size. Thanks.
    Last edited by ulillillia; 03-21-2009 at 02:21 AM. Reason: GetSystemMetrics, not GetSystemInfo
    High elevation is the best elevation. The higher, the better the view!
    My computer: XP Pro SP3, 3.4 GHz i7-2600K CPU (OC'd to 4 GHz), 4 GB DDR3 RAM, X-Fi Platinum sound, GeForce 460, 1920x1440 resolution, 1250 GB HDD space, Visual C++ 2008 Express

  2. #2
    Registered User
    Join Date
    Mar 2005
    Location
    Juneda
    Posts
    291
    You can use GetClientRect to get the 'interior' area, but you have to calc manually the other elements areas (usually the toolbar and status areas) from the wm_size msg, and rest it to the window's interior area; first set the position for all the static elements, then get their external window area (GetWindowRect), get the parent window client rect (interior area), and then rest the header and footer element's area (and lateral elements if that's the case).

    I.e. if you have a toolbar and a status, you will set their position, and then rest its external area from the parent area:

    Code:
    //hwnd means the parent window handle
    case WM_SIZE:
        {
        RECT area,r_toolbar,r_status;
    
        SendMessage(toolbar,TB_AUTOSIZE,0,0);//posite the static elements
        SendMessage(status,WM_SIZE,0,0);
        
        GetWindowRect(toolbar,&r_toolbar);//get the areas
        GetWindowRect(status,&r_status);
        GetClientRect(hwnd,&area);
        
        area.top=r_toolbar.bottom-r_toolbar.top;//calc the 'free' space
        area.bottom-=(r_status.bottom-r_status.top);
        area.bottom-=area.top;
        
        //you got it :)
        }
    break;
    Hope that helps
    Niara
    Last edited by Niara; 03-21-2009 at 06:50 AM.

  3. #3
    'Allo, 'Allo, Allo
    Join Date
    Apr 2008
    Posts
    639
    AdjustWindowRect(Ex) will calculate the dimensions you need to pass to CreateWindow to get a desired client area.

  4. #4
    Math wizard
    Join Date
    Dec 2006
    Location
    USA
    Posts
    582
    GetClientRect - I saw that function before I asked here, but couldn't tell if that was what I needed. It's probably the word "client" that made it questioned. Thanks though for the help. I can clean out more variables now.
    High elevation is the best elevation. The higher, the better the view!
    My computer: XP Pro SP3, 3.4 GHz i7-2600K CPU (OC'd to 4 GHz), 4 GB DDR3 RAM, X-Fi Platinum sound, GeForce 460, 1920x1440 resolution, 1250 GB HDD space, Visual C++ 2008 Express

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Code review
    By Elysia in forum C++ Programming
    Replies: 71
    Last Post: 05-13-2008, 09:42 PM
  2. Pointer Size Relative To Integers?
    By SMurf in forum C Programming
    Replies: 1
    Last Post: 04-18-2006, 06:58 AM
  3. Invalid conversion from 'void*' to 'BYTE' help
    By bikr692002 in forum C++ Programming
    Replies: 9
    Last Post: 02-22-2006, 11:27 AM
  4. An exercise in optimization
    By Prelude in forum Contests Board
    Replies: 10
    Last Post: 04-29-2005, 03:06 PM

Tags for this Thread