mouse values

Started by
35 comments, last by phil67rpg 10 years, 7 months ago

well I am using a mouse in a tic tac toe game, I am unsure of how the x and y values in this piece of code operate.

LRESULT
 
 
CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
 
 
int x=LOWORD(lParam);
 
 
int y=HIWORD(lParam);
 
 
 
switch(wParam)
{
 
 
case VK_ESCAPE:
{
PostQuitMessage(0);
 
 
return 0;
} 
 
break;
}
 
 
switch(message)
{
 
 
case WM_LBUTTONDOWN:
{
display_text_x(x,y);
 
 
return 0;
} 
 
break;
 
 
case WM_RBUTTONDOWN:
{
display_text_o(x,y);
 
 
return 0;
} 
 
break;
 
 
 
case WM_DESTROY:
{
PostQuitMessage(0);
 
 
return 0;
} 
 
break;
}
 
 
return DefWindowProc (hWnd, message, wParam, lParam);
}

do the values for x and y correspond to the tip of the mouse pointer?

Advertisement

Yes, it is known as the "hotspot" for the mouse pointer (different cursors can have different hotspots, you can define a hotspot in x, y pixel offsets from the top left of a cursor if you make a new one).

The value is usually relative to the client window (the area not including the title bar, menu, etc.) top left as well if I recall correctly.

"Most people think, great God will come from the sky, take away everything, and make everybody feel high" - Bob Marley

well then there is something wrong with my code, for some reason when you click the mouse in one box it effects the adjacent box.let me know if you need more code.

 
 
if(x>=300 && x <=350 && y>=225 && y <=275)
{
font_rect.left=310;
font_rect.top=235;
font_rect.right=330;
font_rect.bottom=255;
board_x[0][0]=
 
true;
}
 
 
if(x>=350 && x <=400 && y>=225 && y <=275)
{
font_rect.left=360;
font_rect.top=235;
font_rect.right=380;
font_rect.bottom=255;
board_x[0][1]=
 
true;
}

when I click on one spot near the edge of the line it draws an x or o in the adjacent spot.

kind of hard to tell. can you post more code?

Norm Barrows

Rockland Software Productions

"Building PC games since 1989"

rocklandsoftware.net

PLAY CAVEMAN NOW!

http://rocklandsoftware.net/beta.php

[attachment=17598:tictactoe (2).zip] here is my source code for tic tac toe

Trying that code shows you have more serious issues than your mouse. A proper render loop being one of which.

The pink/green flash also shows you don't know about the Direct3D Debug Runtime. I could go into more detail but I think most of the problems I see have been adressed already in older posts. Repeatedly.

And you have switched the graphics API. Again. *sigh*

I go with BearNutts: Use an easier framework. And maybe an easier language, too. (XNA, Löve, Pygame, take your pick).

well I got a job using dx9 so I need to learn it.

Well, then do get familiar with the debug runtimes (you have myriads of memory leaks and failing draw calls!) and learn to use PIX, the D3D debugger.

where do I find PIX and is it easy to use?

A painless Introduction to PIX

Judge yourself. Recommendation: Use PIX on some of the simpler SDK samples - or even games - to get familiar with.

And get Luna's book.

This topic is closed to new replies.

Advertisement