Yes I am a newbie but dont hold it against me! The code is there to draw =
a pixel not a line. I just drew it multiple times so you could see it. =
And yes it doesnt clear up and stuff but this is just a small part of =
the code specifically designed to test plotting a pixel, not to promote =
good programming practice.
-----Original Message-----
From: David Nebinger <dne...@mi...>
To: dev...@li... =
<dev...@li...>
Date: Monday, November 05, 2001 10:59 PM
Subject: [Dev-C++] Drawing Lines (Let's put an end to this =
thread)...
=20
=20
OK, it's obvious that the person that coded:
=20
> case WM_PAINT:
> SetPixel(GetDC(hwnd),100,100,0x00FF0000);
> SetPixel(GetDC(hwnd),101,100,0x00FF0000);
> SetPixel(GetDC(hwnd),102,100,0x00FF0000);
> SetPixel(GetDC(hwnd),103,100,0x00FF0000);
> SetPixel(GetDC(hwnd),104,100,0x00FF0000);
> break;
=20
is really a newbie. Multiple calls to GetDC() with no handle reuse, =
no ReleaseDC() calls, and trying to plot pixels rather than the =
MoveToEx()/LineTo() calls.
=20
In case he's wondering, here's the code to do what he wanted:
=20
case WM_PAINT:
{
HDC hdc;
PAINTSTRUCT ps;
HBRUSH hbr,oldBrush;
=20
hdc=3DBeginPaint(hwnd,&ps); // get the device context during =
a WM_PAINT message
hbr =3D CreateSolidBrush(RGB(0,0,0xff)); // create a brush =
for drawing
oldBrush =3D (HBRUSH) SelectObject(hdc,hbr); // select the =
brush into the DC
MoveToEx(hdc,100,100,NULL); // Move to the specified =
position
LineTo(hdc,104,100); // draw the line
SelectObject(hdc,oldBrush); // select the old brush back to =
the dc
DeleteObject(hbr); // delete our temporary brush
EndPaint(hwnd,&ps); // end the paint session
}
break;
=20
Now all of these functions are documented either in the Win32 SDK =
help file previously mentioned at =
ftp://ftp.cs.virginia.edu/pub/lcc-win32/win32hlp.exe site.
=20
Of course there's always the definitive source at Microsoft's MSDN =
site: http://msdn.microsoft.com/library/ where you'll find all of the =
info from the Win32 help file and then some.
=20
I would suggest that the person trying to figure out how to plot =
pixels should pick up an introductory book to programming Win32 in C/C++ =
(Charles Petzold did a marvelous job in Programming Windows 95; it's C & =
C++ (but avoids MFC), explains all about how to use the Windows API for =
drawing), and then come back when he runs into a problem...
=20
Dave
|