Dealing with Windowed-Mode programs/games
Hello!
Im trying to make a game/program using Direct X in Windowed mode, in C/C++. Everything is fine (well, not really, but that makes me think Ill finish the game/program ), it is working fine, but there is a small problem that, depending on the player''s Windows configuration, may get bigger.
Im talking about my window''s border/menu. As I use DX, I have access to the whole screen, and to write properly to inside my window I use the GetWindowRect function, so I can have a RECT with the 4 boundaries of my window. But then Im using some mouse-dealing messages (WM_LBUTTONDBLCLK or something), which return, when the user clicks my window, the x/y coordinates of my window, not the whole screen. But if it was just that, it would be fine, as I could compare the relative values from the window rect and the returned by the mouse-message.
As I said, it''s not just that, cause the screen coords I receive from the message are from the client part of my window (or whatever it is called), the part excluding the borders/menus/etc. So when I receive the message saying the user clicked on 0,0, it hasnt clicked on the 0,0 of my window rect, but something close to 3,20 (supposing its 3 pixels wide the left border and 20 that blue bar which has the title and the minimize/maximize/close icons).
I could just go and subtract 3 and 20 from the mouse imput, but I suppose that tickness is customizable somewhere in Control Panel, so I think theres an easier way to find out where is the client part of my window. Maybe "GetClientRect" or something =]
Could someone help me out? I know I said too much about a simple problem that could be explained in a couple lines to people who have had that problem in past, but many people dont even know Windows programming (well Im almost one of them), so this will make them think about future problems they may have when starting in Windows programming
Thanks a lot,
-RoTTer
LOL!
That "Maybe "GetClientRect" or something =]" was a joke/guess!
And GetClientRect does really exist! I cant believe this! I was really kidding/guessing! Ok GetClientRect doesnt seem to do exactly what I wanted it to (I wante it to return to me a RECT with the coords of the client area in absolute values (or relative to the whole screen), and it seems to return a RECT relative to the current window).
Thanks for reading my msg, tho
Cya,
-RoTTer
That "Maybe "GetClientRect" or something =]" was a joke/guess!
And GetClientRect does really exist! I cant believe this! I was really kidding/guessing! Ok GetClientRect doesnt seem to do exactly what I wanted it to (I wante it to return to me a RECT with the coords of the client area in absolute values (or relative to the whole screen), and it seems to return a RECT relative to the current window).
Thanks for reading my msg, tho
Cya,
-RoTTer
You can use ClientToScreen() to convert the client rect to screen coordinates like this:
RECT Rect;
GetClientRect(hWnd, &Rect);
ClientToScreen(hWnd, (POINT*)&(Rect.left));
ClientToScreen(hWnd, (POINT*)&(Rect.right));
- WitchLord
RECT Rect;
GetClientRect(hWnd, &Rect);
ClientToScreen(hWnd, (POINT*)&(Rect.left));
ClientToScreen(hWnd, (POINT*)&(Rect.right));
- WitchLord
AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game
The VC docs say that the xPos and yPos obtained from the WM_LBUTTONDBLCLK message are already relative to the client area, which means that 3,20 on the screen would give you message parameters of 0,0. Why are you subtracting it? It think you mean something else.
To convert your point from, 0,0 (client) to say, 3,20 (screen), just make a POINT structure from the relative x and y coordinates that you get from the WM_* messages. Then call ClientToScreen() to convert the POINT to screen coordinates. BTW, POINT is just a struct with only two members, x and y.
- null_pointer
Sabre Multimedia
To convert your point from, 0,0 (client) to say, 3,20 (screen), just make a POINT structure from the relative x and y coordinates that you get from the WM_* messages. Then call ClientToScreen() to convert the POINT to screen coordinates. BTW, POINT is just a struct with only two members, x and y.
case WM_LBUTTONDBLCLK:
POINT p = { LOWORD(lParam), HIWORD(lParam) };
ClientToScreen(hWnd, &p);
break;
- null_pointer
Sabre Multimedia
Hey,
Sorry, I didnt see these messages before!
I have managed already to do that (not exatcly the way you guys said but Ill use that ClientToScreen function next time, thanks!). Null, I wanted to add/subtract the values from the title bar cause I was (and still am) using GetWindowRect function, that gives me the rect of the whole window, not only the client rect. So I had to calculate the title bar height so I could add to both values (the x/y of the top left of my window and the point I wanted to calculate in the client area of the window).
That was it. Thanks again and sorry for the delay
Cya,
-RoTTer
Sorry, I didnt see these messages before!
I have managed already to do that (not exatcly the way you guys said but Ill use that ClientToScreen function next time, thanks!). Null, I wanted to add/subtract the values from the title bar cause I was (and still am) using GetWindowRect function, that gives me the rect of the whole window, not only the client rect. So I had to calculate the title bar height so I could add to both values (the x/y of the top left of my window and the point I wanted to calculate in the client area of the window).
That was it. Thanks again and sorry for the delay
Cya,
-RoTTer
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement