I was trying to create two windows using WinAPI. I created a window wrapper class, which seems to work alright, handling window registeration and creation.
"Functionality executes fast, everything works fine... But hey, wait a minute! What's up with the window size!?"
That's what I though when I saw my two windows pop up. No, the windows didn't have wierd look and no, their position wasn't incorrect, but the size... yeah... ...it was all wrong.
OK, enough literature. To put it bluntly, window size was like "squared". I can't find words effective enough to describe it short, but an example would be nice - right?
So, I gave my first width 800 in pixels and height 600 in pixels. However, it turns out these values have somehow magically changed to 700, an average of these two values. What!? Why!?
Do you know the answer? For me, this is just plain stupid. How did this happen? What's going on?
You're not specifying the size you think you are. If you tell it to make a window that is 800x600, that's what it'll do.
double-check the following:
1) Put a breakpoint on your window creation code (or wherever you're specifying the size of your window) and make sure you are in fact giving it 800x600.
2) Take a snapshot of the window (alt+printscreen as its running), paste it into paint, and see if the dimensions are in fact 800x600
Unless you are resizing the window later, that above code should have just proved they are sized correctly.
Another thing you can try is put the GetWindowRect confirmation somewhere where it can be triggered. So after you see the window, when you press 'space' or something, check the window size again and confirm it is still correct.
If it's correct, it's your eyes playing tricks on you.
If it's incorrect, you are resizing the window somewhere, and that's what you need to find and fix.
On the off chance that this is the case.. Henri, are you sizing the window with the expectation of the client window being 800x600? If that's the case the window size is based on the entire window, not the client window.
The client window is the space within the border of your entire window. When you create a window and give it a width and height, this includes the border, title bar, etc. not just the space within the border.
There's a function called GetClientRect which returns the current size of the client window. You can use that with GetWindowRect to re-adjust the window size accordingly after it's been created. I can give you a function that does this but will only do so if you ask for it incase you'd rather do the problem solving yourself.
Edit:
Looks like the issue is more likely to be what Disch pointed out. Are you absolutely sure that _m_uiSize[0] == 800, and _m_uiSize[1] == 600 ?
Serves you right for compounding statements like that ;P (j/k of course)
EDIT:
Also.. don't want to sound like a "told you so"....
I in my first reply wrote:
double-check the following:
1) Put a breakpoint on your window creation code (or wherever you're specifying the size of your window) and make sure you are in fact giving it 800x600.
Had you done this at the start, you would have seen you weren't passing 800 and 600 like you thought, and would have found the problem sooner.
Thank you, Disch! I was already aware of this prefix and posfix feature of decreasement and increasement operator and what's the difference between the two, so I'm surprised I didn't notice that kind of mistake in my code. Thanks for pointing it out, Disch!