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!
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)
Thank you Novocain!
Yes i have the picture size.
So i should pass Rect.right and Rect.botton to SetWindowPos() ?
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.
If i call AdjustWindowRect it gives me:
I dont understand whats that mean.
cout << "left: " << rect.left << endl;
cout << "top: " << rect.top << endl;
cout << "right: " << rect.right << endl;
cout << "bottom: " << rect.bottom << endl;
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).
But why the minus sign (-8, -30) ?
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.)
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.
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:
- You decide how big your picture is and where you want it.
- You send those coordinates off to SetWindowPos.
- It's broken because you didn't adjust for all the automatic bits Windows adds.
- You send those coordinates off to AdjustWindowRect instead, and get back better coordinates.
- 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.
In windows there are 'screen', 'client' and 'window' coordinates.
Originally Posted by Ducky
'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.
Thank you Novacain for taking the time and clarifying it to me, really appreciate it.
I understand now, thanks.