Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Drawing in Dialogs Windows

Status
Not open for further replies.

mvillara

Programmer
May 18, 2002
24
ES
Does anyone know how to draw the typical shapes such as circles, lines, etc... in a CDialog Window? How can I create a Device Context that point to that Dialog?

If you know too, how can I obtain a device context that point to a CButton Area of Drawing within the class?

Thanks.
 
Graphics:

CClient dlgDC;//'dlgDC' is the name of the device context

//***Create a pen***
//draws a solid red line of width 2
CPen penRed(PS_SOLID, 2, RGB(255, 0, 0));
CPen *pOldPen = NULL;
//Select a Pen
pOldPen = dlgDC.SelectObject(&penRed);

//***Create a Brush***
//fills with Blue
CBrush brBlue(RGB(0, 0, 255));
CBrush *pOldBrush = NULL;
//select brush
pOldBrush = dlgDC.SelectObject(&brBlue);

//***Draw Shapes***
//Set a Pixel
dlgDC.SetPixel(x, y, RGB(255, 0, 0));
//Draw a line from 'Start Point' to (x, y)
dlgDC.LineTo(x, y);
//Draw a Rectangle
dlgDC.Rectangle(x1, y1, x2, y2);
//Draw a Rectangle with round corners
dlgDC.RoundRect(x1, y1, x2, y2, radius1, radius2);
//Draw Circle
dlgDC.Ellipse(x1, y1, x2, y2);
//Draw a Chord
dlgDC.Chord(x1, y1, x2, y2, line_x1, line_y1, line_x2,
line_y2);
//Move to a spot, can be used with 'LineTo' to create a
'Start Point'
dlgDC.MoveTo(x, y);

Hope this Helps.
 
Thanks for your time DrkPaladin.

The problem is that CClientDC needs to be invoked by its default constructor that is the next one:

CClientDC::CClientDC( CWnd * )

So, my problem is that I can not find a function that can supply me a handle (CWnd *) that point to a Dialog Box Window.

If you want to try it, create a simple Hello Application with Dialogs, and then try to write into the MyCDialog source code a small code that try to paint a line in that window.... you will see that its not so easy as I thought. Please such as if you find the solution or not, please could you answer me?

Thanks.

 
1) create MFC-based dialog application;
2) catch WM_PAINT message (do it with ClassWizard);
3) put code written by DrkPalladin in function OnPaint...

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top