?
Solved

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

Posted on 2003-11-13
3
Medium Priority
?
346 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 19

Accepted Solution

by:
Dexstar earned 500 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: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
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…
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 is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Suggested Courses

752 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