|
-
February 24th, 2010, 05:01 AM
#1
Line Drawing
I want to draw vertical and horizontal straight lines in WM_PAINT, How can I do it useing CDC?
Last edited by maverick786us; February 24th, 2010 at 05:25 AM.
-
February 24th, 2010, 05:46 AM
#2
Re: Line Drawing
CDC is for MFC if I am not wrong, and WM_PAINT is for programs that don't use MFC, if I am not wrong.
Here is a solution, not for MFC:
Code:
int paint_line(HWND hwnd, HDC hdc, int x0, int y0, int x9, int y9, int thickness, COLORREF rgb)
{
HBRUSH hbr; HPEN hpen, hpen_sav;
// int rop2_sav;
// rop2_sav = SetROP2(hdc, R2_NOTXORPEN);
hpen = CreatePen(PS_SOLID, thickness, rgb);
hpen_sav = (HPEN) SelectObject(hdc, hpen);
hbr = (HBRUSH)SelectObject(hdc, GetStockObject(NULL_BRUSH));
MoveToEx(hdc, x0, y0, NULL);
LineTo(hdc, x9, y9);
DeleteObject(SelectObject(hdc, hbr));
SelectObject(hdc, hpen_sav);
DeleteObject(hpen);
return 0;
}
-
February 24th, 2010, 05:55 AM
#3
Re: Line Drawing
Sorry I ean OnDraw. The way you can draw Rectangle and Ellipse, I want to draw lines
-
February 24th, 2010, 10:15 AM
#4
Re: Line Drawing
MoveTo(x,y) moves the pen to position and LineTo(x,y) draws the line from MoveTo position to LineTo position
-
February 24th, 2010, 10:43 AM
#5
Re: Line Drawing
this code draws grey lines,horizontal and vertical in center of screen
Code:
OnDraw()
{
CRect rect;
GetClientRect(rect);
CPen penGrey; // Construct it, then initialize
if( penGrey.CreatePen( PS_SOLID, 0, RGB(200,200,200) ) )
{
// Select it into the device context
// Save the old pen at the same time
CPen* pOldPen = pDC->SelectObject( &penGrey );
// Draw with the pen
//draws axis
pDC->MoveTo(rect.right/2,rect.top);
pDC->LineTo(rect.right/2,rect.bottom);
pDC->MoveTo(rect.right,rect.bottom/2);
pDC->LineTo(rect.left,rect.bottom/2);
// Restore the old pen to the device context
pDC->SelectObject( pOldPen );
}
else
{
MessageBox("Resources are running low\nPlease close one or more applications");
}
}
-
February 24th, 2010, 10:49 AM
#6
Re: Line Drawing
MSDN knows everything about the CDC object.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|