Jump to content
  • Advertisement
Sign in to follow this  
ChurchSkiz

Window Sizes and GDI in C++

This topic is 4857 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I'm writing my first game (crappy pong knockoff) using simple GDI stuff in C++. One problem I'm having is that the right part of the window and the bottom part of the window appear to be cutoff. The game is running at 640x480 and there's about 10 pixels on the right and 20 pixels on the bottom that don't show in the window. It messes up my collision detection cause the ball disappears before it comes back up or to the left. Is there a standard cutoff on these windows? Am I doing something wrong? Let me know what I need to include to show you what's going on. I included a link to the source in a text file. Right now the program doesn't do anything but show the ball path with some paddles drawn in. http://www.geocities.com/adamskiz/Programming/Bounce.txt Thanks, Church

Share this post


Link to post
Share on other sites
Advertisement
It sounds like you haven't taken the size of the window border and title bar into account. CreateWindow() will create a window with a total width and height given, whereas the actual usable area (the "client area") will be smaller.

Share this post


Link to post
Share on other sites
You can use the GetClientRect() API call to find the size of the client area. I have it stuck in my mind that there's a way to guarantee that the client area will be the correct size automatically, but I can't for the life of me remember what it is...

Share this post


Link to post
Share on other sites
You can use GetSystemMetrics() calls to figure the correct width and height
to create your window with.

Here a code snippet for setting an 800x600 client rect area.
If you use different window creation flags, you may need different calls.


ws_flags = WS_OVERLAPPED|WS_CAPTION|WS_SYSMENU;
//NOTE: We use system metrics to get the exact client area we want
int w_x = CW_USEDEFAULT;
int w_w = 800 + (GetSystemMetrics(SM_CXFIXEDFRAME)*2) ;
int w_y = CW_USEDEFAULT;
int w_h = 600 +GetSystemMetrics(SM_CYCAPTION)+ (GetSystemMetrics(SM_CYFIXEDFRAME)*2)+ GetSystemMetrics(SM_CYMENU);

Share this post


Link to post
Share on other sites
Or you can use AdjustWindowRect which is meant specifically for the purpose of figuring out the overall window size given the size of the client area...

And just to be annoyingly nitpicky, this has nothing to do with GDI. Messing around with the sizes of windows is the domain of USER.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!