Skip to main content
GameDev.net gamedev.net
🔒 Locked

RECT not working properly

Started by noatom Oct 20, 2012 at 10:06 AM 1 replies 1k views
Original Post
noatom
noatom
I'm trying to use the following:

a rect structure: Click to acces page
and the function for a rect structure called PtInRect: Click to acces page

So I have the following code:

[source lang="cpp"]RECT test

test.bottom = 0;
test.top = height_of_window;
test.right = width_of_window / 2;
test.left = -width_of_window / 2;



void OnMouseDown(WPARAM btnState, int x, int y)
{
mLastMousePos.x = x;
mLastMousePos.y = y;

SetCapture(mhMainWnd);
POINT xa;
xa.x = mLastMousePos.x;
xa.y = mLastMousePos.y;
if(PtInRect(&test,xa))
MessageBox(NULL,L"FOUND",L"FOUND",NULL);
}[/source]

First: I tested the mousedown function,when a button just clicks,it works properly!

As you can see I created a rectangle half of the height of the screen,and full width of the screen.The above code should make any click in the upper part of the screen show a messagebox,however,this doesn't happent!

What am I doing wrong?
Aardvajk
Aardvajk
You've got your rect coords wrong. Screen coords run from 0 to height down the screen and 0 to width across.

Top half of screen rect would be:

top = 0
left = 0
right = width
bottom = height / 2

HTH
noatom
noatom
thanks,it worked

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.