Solved

Drawing to the screen

Posted on 2000-03-17
7
249 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
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 

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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone 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

Suggested Solutions

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…
Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
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.

828 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