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_HIEN
CPen pen5;
pen5.CreatePen(PS_SOLID, 1, RGB(255,0,0));
testdc->SelectObject(&pen5
testdc->Rectangle(0,0,500,
CPen pen6;
pen6.CreatePen(PS_SOLID, 1, RGB(255,0,0));
testdc->SelectObject(&pen6
CRect rec;
m_Picture.GetClientRect(&r
testdc->DPtoLP(&rec);
//tried w/ & w/out
testdc->MoveTo(rec.top, rec.left);
testdc->LineTo(rec.bottom,
Nothing comes out. Am I doing something wrong.
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.
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_HIEN GLISH);
CPen pen6;
pen6.CreatePen(PS_SOLID, 1, RGB(255,0,0));
testdc->SelectObject(&pen6 );
CRect rec;
m_Picture.GetClientRect(&r ec);
testdc->DPtoLP(&rec);
testdc->MoveTo(rec.left, rec.top);
testdc->LineTo(rec.right, rec.bottom);
CDC *testdc;
testdc = m_Picture.GetWindowDC();
testdc->SetMapMode(MM_HIEN
CPen pen6;
pen6.CreatePen(PS_SOLID, 1, RGB(255,0,0));
testdc->SelectObject(&pen6
CRect rec;
m_Picture.GetClientRect(&r
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?
Is the window open and visible?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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?
ASKER
I didn't have the code in the right place (OnDraw) function.