Thread: CreateWindow nHeight

  1. #1
    Registered User
    Join Date
    Dec 2007
    Posts
    930

    CreateWindow nHeight

    Does the height of the window includes the title bar?

    Im asking this because im using SetWindowPos() to reset the size of the window and when i
    put an image in it, it chopped off slightly, i would say the height of the title bar less.

    Edit: Never mind i found the answer = yes it includes!
    Last edited by Ducky; 06-15-2011 at 01:22 PM.
    Using Windows 10 with Code Blocks and MingW.

  2. #2
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    If you know the image size (ie the size of the client area) you can call AdjustWindowRect() to get the required total window size based on the windows style (menu, toolbar etc) and pass that to your SetWindowPos() call.

    AdjustWindowRect Function (Windows)
    "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
    Registered User
    Join Date
    Dec 2007
    Posts
    930
    Thank you Novocain!

    Yes i have the picture size.
    So i should pass Rect.right and Rect.botton to SetWindowPos() ?
    Using Windows 10 with Code Blocks and MingW.

  4. #4
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    If using CRect or Rectangle (C++ classes) then use the Width/Height members.

    If using RECT (C struct) then use (right-left) and (bottom-top).

    This is because the RECT may be in screen coords or some other format where top and/or left are not zero.
    "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

  5. #5
    Registered User
    Join Date
    Dec 2007
    Posts
    930
    If i call AdjustWindowRect it gives me:
    -8
    -30
    8
    8

    I dont understand whats that mean.

    Code:
        cout << "left:   " << rect.left << endl;
        cout << "top:    " << rect.top << endl;
        cout << "right:  " << rect.right << endl;
        cout << "bottom: " << rect.bottom << endl;
    Last edited by Ducky; 06-17-2011 at 09:46 AM.
    Using Windows 10 with Code Blocks and MingW.

  6. #6
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    That means the top left corner of your window should be at (-8, -30) and the bottom right corner of your window should be at (8,8) in order for the drawable part of the window to accommodate the parts you wanted it to (or at least passed in to the function as the parts you wanted to cover).

  7. #7
    Registered User
    Join Date
    Dec 2007
    Posts
    930
    But why the minus sign (-8, -30) ?
    Using Windows 10 with Code Blocks and MingW.

  8. #8
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Did you ask for your picture to be at the upper left corner of the screen? If so, then the window itself will have to start off the screen, so that there's room for the title bar and the border and such.

    (EDIT: In fact, it looks like you passed in all zeroes. You should pass in where you want your picture to live (top left, bottom right), and then adjustwindow will give you something you can send off to setwindow. Although why I typed all that when it's in novacain's post I don't know.)
    Last edited by tabstop; 06-17-2011 at 12:13 PM.

  9. #9
    Registered User
    Join Date
    Dec 2007
    Posts
    930
    Its not Novocain's post its mine.

    And thanks for typing all that.

    "You should pass in where you want your picture to live (top left, bottom right), and then adjustwindow will give you something you can send off to setwindow."

    So i just might as well pass it directly to SetWindowPos, i cant see the point to pass it to AdjustWindowRect.
    Last edited by Ducky; 06-17-2011 at 01:49 PM.
    Using Windows 10 with Code Blocks and MingW.

  10. #10
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    The point of passing it to AdjustWindowRect is so that you have something to pass to SetWindowPos, which currently you don't. It goes something like this:
    1. You decide how big your picture is and where you want it.
    2. You send those coordinates off to SetWindowPos.
    3. It's broken because you didn't adjust for all the automatic bits Windows adds.
    4. You send those coordinates off to AdjustWindowRect instead, and get back better coordinates.
    5. You send the better coordinates off to SetWindowPos, and you get back a window that allows you to draw your picture without it being broken.

  11. #11
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    Quote Originally Posted by Ducky View Post
    But why the minus sign (-8, -30) ?
    In windows there are 'screen', 'client' and 'window' coordinates.

    'Screen' are always relative to the top left of the whole screen (the top left corner of the monitor is 0,0 and the bottom right corner is equal to the resolution).

    'Window' are relative to the dialog or windows top left. No matter where your dialog is on the whole screen, the dialog's top left is 0,0 and right bottom is width, height.

    'Client' are the same as 'window' but only include the area of a window/dialog that you can 'use' (ie exclude the border, menu, toolbar and system menu/title bar) 'Client' are relative to the dialog or windows client areas top left.

    The border, menu, toolbar and system menu/title bar are called 'non client' area. You can modify the NC_ series messages to create custom window styles but not many bother.

    So your -8,-30, 8, 8 is in 'client' coords (did you send AdjustWindowRect() a 0 height and 0 width?).
    It means the styles you have chosen for the window/dialog have added a 8 pixel border around the window and an extra 22 pixel high menu/toolbar at the top (for a total of 30 at the top).

    If you called AdjustWindowRect() with an image of 600x400 and your windows style you should get back -8,-30,608,408.

    To keep your window's center in the same place on the whole screen, you must create the window with the top left corner 8 more pixels to the right and 30 pixels higher. You must also create the bottom right corner 8 to the right and 8 lower.

    To convert between the different coords you can call ClientToScreen() or ScreenToClient(). This is sometimes required as differing WIN32 API calls require diff coords.
    Last edited by novacain; 06-19-2011 at 12:02 AM. Reason: clarity in 'window' and 'client'
    "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

  12. #12
    Registered User
    Join Date
    Dec 2007
    Posts
    930
    Thank you Novacain for taking the time and clarifying it to me, really appreciate it.

    @Tabstop
    I understand now, thanks.
    Last edited by Ducky; 06-20-2011 at 02:20 PM.
    Using Windows 10 with Code Blocks and MingW.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. help with MDI CreateWindow
    By abachler in forum Windows Programming
    Replies: 3
    Last Post: 06-13-2007, 01:54 AM
  2. CreateWindow
    By RevengerPT in forum C Programming
    Replies: 3
    Last Post: 11-25-2005, 03:15 PM
  3. getting fed up with CreateWindow
    By ... in forum Windows Programming
    Replies: 2
    Last Post: 10-01-2003, 03:42 PM
  4. CreateWindow() help!
    By nextus in forum Windows Programming
    Replies: 3
    Last Post: 03-05-2003, 02:56 AM