Solved

Drawing to the screen

Posted on 2000-03-17
7
247 Views
Last Modified: 2010-04-02

I am in a dialog box.  the m_Picture is a Picture control (static).

CDC *testdc;
testdc = m_Picture.GetWindowDC();
testdc->SetMapMode(MM_HIENGLISH);
CPen pen5;
pen5.CreatePen(PS_SOLID, 1, RGB(255,0,0));
testdc->SelectObject(&pen5);
testdc->Rectangle(0,0,500,500);
CPen pen6;
pen6.CreatePen(PS_SOLID, 1, RGB(255,0,0));
testdc->SelectObject(&pen6);
CRect rec;
m_Picture.GetClientRect(&rec);
testdc->DPtoLP(&rec);  
//tried w/ & w/out
testdc->MoveTo(rec.top, rec.left);
testdc->LineTo(rec.bottom, rec.right);

Nothing comes out.  Am I doing something wrong.
0
Comment
Question by:jaiken
  • 4
  • 2
7 Comments
 
LVL 22

Expert Comment

by:nietod
ID: 2628828
The problem is the mapping mode.  In MM_HIENGLISH mode the Y value increases in the upward direction.  Bot the origin will be the upper-left corner of the window so the window lies in the negative Y portion of the XY plane.  But you are specifying coordinates that are positive Y, i.e. above the window.
0
 

Author Comment

by:jaiken
ID: 2629221
I did change the MoveTo and LineTo (because I had the x/y backwards) but looking at rec upon return from GetClientRect and DPtoLP the y.bottom is a negative value.  I get (0,0) and (2056, -2555).  NOTE:  I also got rid of the drawing of the rectangle to be more simple.


CDC *testdc;
testdc = m_Picture.GetWindowDC();
testdc->SetMapMode(MM_HIENGLISH);
CPen pen6;
pen6.CreatePen(PS_SOLID, 1, RGB(255,0,0));
testdc->SelectObject(&pen6);
CRect rec;
m_Picture.GetClientRect(&rec);
testdc->DPtoLP(&rec);
testdc->MoveTo(rec.left, rec.top);
testdc->LineTo(rec.right, rec.bottom);
 
0
 
LVL 22

Expert Comment

by:nietod
ID: 2629279
Why do you use GetWindowDc() instead of GetDC?

Is the window open and visible?
0
Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

 

Accepted Solution

by:
fmharr earned 15 total points
ID: 2629570
Get rid of the GetWindowDC and use:

testdc = m_Picture.GetDC();

get rid of the SetMapMode

get rid of the DPtoLP

all the rest is fine... the default system is 0,0 == top/left and +,+ values going down and right.

with the above changes you should have a line from the top-left to the bottom-right in red!

also, you need to put the code in the OnDraw() function or some button function and not in the InitDialog() event!  You also need to save/restore the DC so you wont have resource leeks!

0
 
LVL 22

Expert Comment

by:nietod
ID: 2629620
I already pointed out that he should PROBABLY be using GetDC().  I don't think there is any evidence that the code is in InitDialog().
0
 
LVL 22

Expert Comment

by:nietod
ID: 2629874
What was the problem?
0
 

Author Comment

by:jaiken
ID: 2635735
I didn't have the code in the right place (OnDraw) function.
0

Featured Post

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

Suggested Solutions

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…

777 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