Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


Multi-monitor problem with CRect and CPoint

Posted on 2007-09-28
Medium Priority
Last Modified: 2013-12-14
I've just been alerted to some wierd behaviour (bug in op system / MFC code ?)

I have a user that has a two monitor system (in Europe) and, for some reason, has the primary monitor defined as the monitor on the right and the secondary monitor is on the left.  So the system thinks the top left of the primary monitor is 0, 0
This, of course, means the co-ordinates on the left hand monitor are 'strange'.

I am performing a hit test on a control drawn into the NC area of an edit box.  It isn't responding to the mouse.  basically       return rectButton.PtInRect(ptTest);
rectButton is a CRect and ptTest is a CPoint.
The value in ptTest has an x-co-ordinate of 64786 and in the rectButton the l, r is -761, -744
So the PtInRect call is failing - despite the mouse being in the rectangle the return is false.

Is there a flag/function to make it compare the signed/unsigned values correctly or do I have to code some sort of hack?
Question by:AndyAinscow
  • 3
LVL 14

Accepted Solution

RichieHindle earned 1500 total points
ID: 19981996
The X values for the left-hand monitor are negative, which MFC should cope with.  Is it possible that somewhere you are stripping the sign, by using an unsigned variable to store an intermediate value, for instance?  Where is ptTest coming from?  (Show us some code!)
LVL 45

Author Comment

ID: 19983122
BOOL CMyEdit::HitButtonTest(CPoint ptTest)

            return FALSE;

      CRect rectButton=CalcButtonRect();
      return rectButton.PtInRect(ptTest);


CRect CMyEdit::CalcButtonRect() const

      CRect rect(0,0,0,0);


      return rect;

AND in the WindowProc of the custom edit

LRESULT CMyEdit::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
                  LRESULT lResult=CEdit::WindowProc(message, wParam, lParam);
                  if(!IsWindowEnabled() || (GetStyle()&ES_READONLY))
                        return lResult;

LVL 45

Author Comment

ID: 19983142
I think the problem is the CPoint and CRect are using LONG variables internally.
I suspect I am going to have to do a hack.
LVL 45

Author Comment

ID: 19983157
Oh bleep

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.
The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.
Suggested Courses

571 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question