Solved

Drawing to the screen

Posted on 2000-03-17
7
243 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
Comment Utility
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
Comment Utility
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
Comment Utility
Why do you use GetWindowDc() instead of GetDC?

Is the window open and visible?
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Accepted Solution

by:
fmharr earned 15 total points
Comment Utility
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
Comment Utility
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
Comment Utility
What was the problem?
0
 

Author Comment

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

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

743 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

11 Experts available now in Live!

Get 1:1 Help Now