Solved

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

Posted on 2003-11-13
3
337 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
xyBalance chalenge 58 102
How to know only "File created" with EventLog 3 35
sameEnds challenge 3 187
how to split multiple lines delimiter : 8 119
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: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
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.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

756 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