Teen Programmers Unite  
 

 

Return to forum top

Drawing Lines

Posted by putang1080 [send private reply] at June 24, 2001, 02:46:35 PM

Hey, i finally got a window!!! newayz, now i want to draw lines, here's my code: HPEN pen_1 = CreatePen(PS_SOLID, 1, RGB(0, 225, 0));
SelectObject(hdc, pen_1);
HBRUSH brush_1 = CreateSolidBrush(RGB(0, 0, 255));
MoveToEx(hdc, 10, 20, NULL);
LineTo(hdc, 150, 150);
LineTo(hdc, 50, 100);
Ellipse(hdc, 90, 90, 100, 100);
SetPixel(hdc, 50, 60, RGB(255, 0, 0));
DeleteObject(pen_1);

nothing shows up....... i guess there's supposed to be a triange, and a circle, i just took the code from a book(well, i took several snippets of code at once to see whatd happen.) Its in the main event handle. i still get a window, but nothing inside. i don't xactly know where to place it, right now its at the end of the main event handle. If u have or are reading game programming for dummies by andre lamothe, its in chap. 5.

Posted by putang1080 [send private reply] at June 24, 2001, 05:16:17 PM

i figured it out, sometimes my brains dead. i had to put it in the case WM_PAINT statement. Anyways, now i just figured out how to draw lines, ellipses, and rectangles, but i don't get text: proportioned or fixed pitch.

Posted by nt543 [send private reply] at August 17, 2001, 12:35:04 PM

Use this code in your message handler:
LRESULT WndProc(HWND hWnd, UINT iMsg, WPARAM wParam, LPARAM lParam)
{

Posted by nt543 [send private reply] at August 17, 2001, 12:38:58 PM

Use this code in your message handler:
LRESULT WndProc(HWND hWnd, UINT iMsg, WPARAM wParam, LPARAM lParam)
{

HDC hDC = 0;
PAINTSTRUCT ps;

switch(iMsg)
{
case WM_PAINT:
{
hDC = BeginPaint(hWnd, &ps);
if(hDC)
{

/* Do painting with hDC here */

EndPaint(hWnd, &ps);
hDC = 0; /* be safe */
}
}

/* Handle other messages */

case WM_DESTROY:
PostQuitMessage(0);
return(0);
default:
break;
}
return(DefWindowProc(hWnd, iMsg, wParam, lParam));

}

Posted by eternaldisciple [send private reply] at August 17, 2001, 02:09:13 PM

2 month old topic

Posted by TheTutor [send private reply] at August 19, 2001, 11:35:07 AM

Quick thing -- When you do this, make sure you save off the HPEN that was selected into the device context, otherwise all the memory may not be freed

HPEN hpen = CreatePen(...);
HPEN old_pen = SelectObject(hdc,hpen);

// Draw and stuff

SelectObject(hdc,old_pen);
DeleteObject(hpen);

Posted by taubz [send private reply] at August 18, 2001, 05:36:01 PM

Your followup was *completely* unnecessary...

Posted by TheTutor [send private reply] at August 18, 2001, 06:02:02 PM

If you don't care about releasing memory it was

Posted by CHollman82 [send private reply] at October 01, 2001, 09:56:57 PM

You must be logged in to post messages and see which you have already read.

Log on
Username:
Password:
Save for later automatic logon

Register as a new user
 
Copyright TPU 2002. See the Credits and About TPU for more information.