Solved

Making the coordinates of a DC match up with the coordinates of a CWnd in a CPropertyPage

Posted on 2003-11-13
3
333 Views
Last Modified: 2013-11-20
Hi there,

Here's my problem: I have a subclassed CListCtrl (LessonListCtrl) inside a CPropertyPage.  Part of the functionality of the LessonListCtrl is to draw little ticks or crosses to the left of the LessonListCtrl beside every item in it. (It's in report view).  However, I'm having trouble making the ticks and crosses lined up with the items.  I tried this:

* returns a CRect* giving the coordinates that the tick or cross will appear in */
CRect* LessonListCtrl::getBoxRect(int selMark) {
      CRect itemRect;
      GetItemRect(selMark, &itemRect, LVIR_BOUNDS);
      CRect windowRect;
      GetWindowRect(&windowRect);
      int top = itemRect.top + windowRect.top;
      int bottom = itemRect.bottom + windowRect.top;
      int right = itemRect.left + windowRect.left - parentRect.left - 5;
      int left = right - (itemRect.bottom - itemRect.top); //square
      CRect* boxRect = new CRect(left, top, right, bottom);
      return boxRect;
}

The DC is created in a method of the LessonListCtrl as CClientDC dc(GetParent());

Unfortunately it seems the coordinates of the CRect from getBoxRect() are relative to the screen, or the top-level window of the project, including title bar, menu bar etc while the coordinates of the DC are relative to only the rectangle inside the property page.  This means that the ticks and crosses appear a couple of rows too low down.

I can kinda solve this problem by using CClientDC dc(GetParent()->GetParent());
or CClientDC dc(NULL) which takes the DC up to the whoe screen, but I then have nasty issues with the ticks and crosses redrawing even when my project is not on top (and since immediately after the drawing the program starts up Explorer, this is a problem).

I think what I want to do is work out how high the stuff above the CPropertyPage is and then subtract this from my top amd bottom.  But I can't work out how to do that.  If someone could tell me how to do that, or some other solution to my problem, I would be very grateful.

Thank you.
0
Comment
Question by:wilsonian
  • 2
3 Comments
 
LVL 19

Accepted Solution

by:
Dexstar earned 125 total points
ID: 9742445
wilsonian:

> Unfortunately it seems the coordinates of the CRect from getBoxRect() are
> relative to the screen, or the top-level window of the project, including
> title bar, menu bar etc while the coordinates of the DC are relative to only
> the rectangle inside the property page.  This means that the ticks and crosses
> appear a couple of rows too low down.

You need to use CWnd's ClientToScreen and ScreenToClient functions.  They will do the adjustments for you.

ClientToScreen Info:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclib/html/_mfc_cwnd.3a3a.clienttoscreen.asp

ScreenToClient Info:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclib/html/_mfc_cwnd.3a3a.screentoclient.asp


Hope That Helps,
Dex*
0
 

Author Comment

by:wilsonian
ID: 9742672
Well that's sure the quickest I've ever had a question answered.

Thank you very much.
0
 
LVL 19

Expert Comment

by:Dexstar
ID: 9742690
No problem!  :)

Dex*
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

758 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now