Link to home
Start Free TrialLog in
Avatar of jaiken
jaiken

asked on

Drawing to the screen


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.
Avatar of nietod
nietod

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.
Avatar of jaiken

ASKER

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);
 
Why do you use GetWindowDc() instead of GetDC?

Is the window open and visible?
ASKER CERTIFIED SOLUTION
Avatar of fmharr
fmharr

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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().
What was the problem?
Avatar of jaiken

ASKER

I didn't have the code in the right place (OnDraw) function.