Solved

Drawing to the screen

Posted on 2000-03-17
7
244 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

863 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

26 Experts available now in Live!

Get 1:1 Help Now