Archived

This topic is now archived and is closed to further replies.

Drastick

Mouse (x,y) not relitive to back buffer (x,y) ..what to do?

Recommended Posts

I am having a problem using the mouse over a direct x back buffer. I am running the program in windowed mode the window is set to 800x600 (it has a menu bar attached) the back buffer is 800x600. What is going on is that which I click something, the point I click in the window is not relitive to the objects position on the back buffer. It seems that the whole window is 800X600 while the back buffer is getting smushed down into the actual work area of the window causing the image to be out of proportion. What is normaly done about this?

Share this post


Link to post
Share on other sites
I'm not real knowledgeable about Windows programming anymore, but can you query system metrics to get the height of the menu bar, and add this value to the size you request the window to be? Tack on an extra few pixels, in other words. You might need/want to take into account window borders as well, if you have to.

EDIT: Found this reference page at MSDN, for the GetSystemMetrics() function. Might be what you'd need for this. Of course, there may be some other method of creating a window, wherein you specify the size of the client area desired, and Windows itself handles all the proper sizing. I don't know, as this is out of my expertise.

Josh
vertexnormal AT linuxmail DOT org


Check out Golem: Lands of Shadow, an isometrically rendered hack-and-slash inspired equally by Nethack and Diablo.

[edited by - VertexNormal on October 7, 2003 1:25:21 AM]

Share this post


Link to post
Share on other sites
When you request a window to be created at a certain dimension, it will include all of the components the window uses - title bar, menu bar, & borders. All of that takes up pixel real estate. Creating a popup window aovids this because it doesn''t have the decorations. That''s why it is common practice to use popups for fullscreen. You would most likely annoy your players if you did the same for windowed mode however.

There are a couple of ways you can fix this:

1) Windows provides a function called GetClientRect. This gives you the dimensions of the actual drawable surface of the window - the area contained inside the decorations. So you might get 768x580 for an 800x600 window (just a random figure - but the actual result will vary depending upon border style, menu, etc...). It''s a simple thing to create a backbuffer the size of the client rectangle, but because of the funky dimension sizes it is not always the best solution.

2) The second option is to tell Windows that you want the *client area* to be 800x600, not the window itself. You can do this before or after you call CreateWindow by using the function AdjustWindowRect (AdjustWindowRectEx is you used extended styles with CreateWindowEx). If you call this after creating the window you will also need to make a call to MoveWindow for the changes to take effect. If you call it before you create the window, then you will use the adjusted dimensions in place of 800x600 when you call CreateWindow. You can find examples of this in several DirectX books, the DX SDK sample code, and over at NeHe''s OpenGL site (yes, this technique is also needed for OpenGL) among other places.

Share this post


Link to post
Share on other sites