Solved

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

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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 …
In this post we will learn different types of Android Layout and some basics of an Android App.
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.
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…

729 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