Article ID: 150611
Article Last Modified on 11/1/2006
#include <windows.h>
HANDLE mainFrame;
extern LRESULT WINAPI DrawProc (HWND, UINT, WPARAM, LPARM);
int APIENTRY WinMain (HMODULE hModule, HINSTANCE hNULL, PSTR cmdLine,
int cmdShow)
{
MSG msg;
WNDCLASS wc;
memset (&wc, 0, sizeof (WNDCLASS));
wc.lpszClassName = "MAIN";
wc.hbrBackground = (void * ) (COLOR_WINDOW +1);
wc.style = CS_VREDRAW | CS_HREDRAW;
wc.lpfnWndProc = DrawProc;
if (!RegisterClass (&wc)) exit (-1);
if ( (mainFrame = CreateWindow ("MAIN", "Mca Test",
WS_OVERLAPPEDWINDOW, 0, 0, 300, 200, NULL,
NULL, 0, NULL) ) == NULL)
return (FALSE);
ShowWindow (mainFrame, SW_SHOW);
While (GetMessage (&msg, NULL, 0, 0) )
{
TranslateMessage (&msg);
DispatchMessage(&msg);
}
}
LRESULT WINAPI DrawProc (HWND hwnd, UINT msg, WPARM mp1, LPARAM mp2)
{
PAINTSTRUCT ps;
switch (msg)
{
case WM_CLOSE:
DestroyWindow (mainFrame);
return (0);
case WM_DESTROY:
PostQuitMessage (0);
return (0);
case WM_PAINT:
BeginPaint (hwnd, &ps);
BeginPath (ps.hdc);
EndPath (ps.hdc);
StrokeAndFillPath (ps.hdc); // Fillpath is the problem here
// since nothing has been drawn
BeginPath (ps.hdc);
MoveToEx (ps.hdc, 50, 50, NULL); //This is the failure point
LineTo (ps.hdc, 100, 100);
LineTo (ps.hdc, 150, 150);
EndPath (ps.hdc);
StrokeAndFillPath (ps.hdc);
MoveToEx (ps.hdc, 300, 300, NULL);
EndPaint (hwnd, &ps);
return (0);
}
return (DefWindowProc (hwnd, msg, mp1, mp2));
}
Keywords: KB150611