Credits tally123
Thread discussion
http://www.uc-forum.com/forum/showthread.php?t=55564
My main reason for posting this is the fix I came up with for running your game in a window. Basically, however far off the games window would be from 0,0 on the screen, that is how much your cursor would be offset to the bottom right.
If my window was 100 pixels away from 0, 0 (top left of screen) my cursor would be off by 100 pixels, this is a nice fix and a working code snippet.
For anyone asking about mouse menus/GUI's, have fun
Code:
POINT Pos;
RECT wRect;
bool showMenu = false;
int cursorx, cursory;
__inline void DoMenu()
{
if(GetAsyncKeyState(VK_DELETE)&1)
{
showMenu = !showMenu;
}
if(showMenu)
{
//Our ghetto menu item
Renderer.FillRectD3D(60, 60, 20, 20, 0xFFFFFF00);
/* This is to correct for a problem with getcursorpos and windowed mode */
GetWindowRect(hWnd, &wRect);
//Cursor pos (Pos.x/Pos.y)
GetCursorPos(&Pos);
//Windowed correction
cursorx = Pos.x - wRect.left;
cursory = Pos.y - wRect.top;
//Draw cursor
Renderer.DrawTextD3D(cursorx, cursory, 0xFFFF0000, "+", DT_CENTER | DT_VCENTER, 0);
//Mouse 1
if(GetAsyncKeyState(0x1)&1)
{
if(cursorx > 60 && cursory > 60
&& cursorx < 80 && cursory < 80)
{
//Toggle/Action here
}
}
}
}