Sign in to follow this  

RECT not working properly

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm trying to use the following:

a rect structure: [url="http://msdn.microsoft.com/en-us/library/windows/desktop/dd162897(v=vs.85).aspx"]Click to acces page[/url]
and the function for a rect structure called PtInRect: [url="http://msdn.microsoft.com/en-us/library/windows/desktop/dd162882(v=vs.85).aspx"]Click to acces page[/url]

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? Edited by noatom

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

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

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this