# mouse values

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

## Recommended Posts

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?

##### Share on other sites

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.

##### Share on other sites

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.

##### Share on other sites

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

##### Share on other sites

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

##### Share on other sites

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).

##### Share on other sites

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

##### Share on other sites

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.

Edited by unbird

##### Share on other sites

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

##### Share on other sites
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.

##### Share on other sites

well I am now reading game programming 3rd edtion, by jonathan harbor.

##### Share on other sites
I've just diffed the code with the available one from your old post (mind the date). You haven't changed a single character. If this isn't intentional trolling it sure is wasting the time of the people trying to help you.

I'm done here.

Edit: Please excuse. I'm hereby taking the "trolling" back.

But still: More effort is due. Edited by unbird

##### Share on other sites

why do people always accuse me of trolling

##### Share on other sites

Phil,

I might not be the perfect person to say this, but listen carefully.

These forums are not just for people to do the work for you, they will assist you on the long journey of development. Programming takes time, and yes, you may post an issue you have, but you could at least show that you've put some effort into your work.

The reason why unbird acted as he did (Yes, maybe it was harsh, but, as he did not see any effort put into the work, so he wasn't sure whether you were actually interested in doing some progress, which could just mean that he was wasting his time, people have their own life too. ), ok I pretty much just stated that in the backets... (Unbird, I am no mind reader [YET!], so please add if you feel like it!)

One other thing that I noticed, is that you jump a lot, in the other thread. First you were making a tic-tac-toe game, then suddenly because it was a bit hard, you wanted to make apps (which is fine!), but, then after you wanted to make a simple calculator, etc... One crucial thing is that you have to STICK to something!

I would advise you to look over all your code, double TRIPLE check it, then debug it in detail, not just where you think you're wrong, but from start to end.

We will all gladly assist you in the near future, but you have to show some effort

Good Luck.

##### Share on other sites

I'm curious Phil, what is your current employment. You say you got a job using DX9?

##### Share on other sites

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

It's Beernutts.  Just a little correction ;)

Phil, ssn't it a little dishonest to truly take a job that your are fully unqualified for? Well, good job fooling someone into giving you that job (if you really did get hired).  Get as much out of it as possible until they figure out the problems you have.

Did you sumbit a resume for this job?  Did you have to answer technical questions?  From what I know, I can't imagine you getting any questions right.

Edited by BeerNutts

##### Share on other sites

Getting back on subject....

No, those values do not represent the proper mouse coordinates.  Check the documentation which says:

The low-order word specifies the x-coordinate of the cursor. The coordinate is relative to the upper-left corner of the client area.
The high-order word specifies the y-coordinate of the cursor. The coordinate is relative to the upper-left corner of the client area.

Remarks
Use the following code to obtain the horizontal and vertical position:
xPos = GET_X_LPARAM(lParam);
yPos = GET_Y_LPARAM(lParam);

Important  Do not use the LOWORD or HIWORD macros to extract the x- and y- coordinates of the cursor position because these macros return incorrect results on systems with multiple monitors. Systems with multiple monitors can have negative x- and y- coordinates, and LOWORD and HIWORD treat the coordinates as unsigned quantities.

Note the "Important" section. You are using those macros.

If you use the GET_X_LPARAM and GET_Y_LPARAM macros it will be the coordinate relative to the upper-left corner of the client area.

##### Share on other sites
The problem lies deeper, though, since (Windowsx.h):

#define GET_X_LPARAM(lp) ((int)(short)LOWORD(lp))
#define GET_Y_LPARAM(lp) ((int)(short)HIWORD(lp))

is (almost) equivalent to what he has.

It is what I suspected from the start, namely a common beginner pitfall: He uses the same dimension for the windows creation and for the D3D backbuffer. But for the latter one must use the client area of the window, e.g. optainable using GetClientRect.

@BeerNutts: Sorry for the typo. I actually watched the trailer once, so I should know better. Edited by unbird

##### Share on other sites

well honestly I don't know if the job is going to pan out, and yes I know I have problems and maybe I am not qualified but I have got to start somewhere it is only an entry  level position.I am unsure of what api or engine were going to be using. basically all the details are still up in the air. if I have offended anybody I apologize. also I know I have problems finishing projects as has also been told to me by my professors in college.

##### Share on other sites

well honestly I don't know if the job is going to pan out, and yes I know I have problems and maybe I am not qualified but I have got to start somewhere it is only an entry  level position.I am unsure of what api or engine were going to be using. basically all the details are still up in the air. if I have offended anybody I apologize. also I know I have problems finishing projects as has also been told to me by my professors in college.

Reading the thread I think people's issue is more with the fact you don't seem to be investigating and experimenting and most importantly -searching- about how the pieces of your code work and why they might be causing problems.

In short it seems like you just want the answer thrown infront of you, and like an artist having someone else draw for them, that isn't going to teach you how to approach a picture.

##### Share on other sites

I have on the drawing board breakout and pong and asteroids using opengl and pong and tic tac toe using dx9 what should I finish first and then later. or should I go back to learning c++.

##### Share on other sites

I have decided to work on my tic tac toe game some more. I have reworked some of my code, but it still puts an X in the spot adjacent to where I clicked the mouse button.

here is some of my code

int x_board = (x-left_edge)/width;
int y_board = (y-top_edge)/height;
RECT font_rect;
if(x_board==0 && y_board==0)
{
font_rect.left=310;
font_rect.top=235;
font_rect.right=330;
font_rect.bottom=255;
board_x[y_board][x_board]=true;
}
if(x_board==1 && y_board==0)
{
font_rect.left=360;
font_rect.top=235;
font_rect.right=380;
font_rect.bottom=255;
board_x[y_board][x_board]=true;
}


I have already stubbed out the code using the x_board and y_board variables and they seem to work correctly. I have also changed my mouse input code but I still get the same problem. I know I have already posted code similar to the above but I have made some changes since then.

##### Share on other sites

sounds like you should work on tic tac toe as its the easiest. and use directx, cause that's what you need to learn for work. forget openGL for now.

did you get the mouse working correctly yet?

can you display the coordinates of a mouse click, and are they correct? that's the first battle.

also sounds like you're running in windowed mode, and the difference between the size of the window, and the client area (the part inside the border that you draw in) might be giving you issues. i only work in fullscreen mode, so i can't help you there.

sounds like you got lucky and got your foot in the door at a gamedev shop. you'd better get up to speed super quick if you don't want to blow this opportunity.

get the mouse working in windowed mode and the rest is trivial.  like  4 lines of code trivial.

##### Share on other sites

how would I display the coordinates of the mouse click?

##### Share on other sites

I still think the mouse is not working properly.