struct {
int x,y;
BOOL Move;
} Line[10000];
int index=0;
LRESULT CALLBACK WndProc(HWND hWnd,UINT iMessage,WPARAM wParam,LPARAM lParam)
{
static BOOL bNowDraw=FALSE;
/* static int x;
static int y; */
// static int sx,sy,oldx,oldy;
switch (iMessage) {
case WM_DESTROY:
PostQuitMessage(0);
return 0;
case WM_LBUTTONDOWN:
bNowDraw=TRUE;
Line[index].x=LOWORD(lParam);
Line[index].y=HIWORD(lParam);
Line[index].Move=TRUE;
index++;
/* x=LOWORD(lParam);
y=HIWORD(lParam); */
return 0;
case WM_LBUTTONUP:
bNowDraw=FALSE;
return 0;
case WM_MOUSEMOVE:
if (bNowDraw==TRUE) {
HDC hdc;
hdc=GetDC(hWnd);
MoveToEx(hdc,Line[index-1].x,Line[index-1].y,NULL);
Line[index].x=LOWORD(lParam);
Line[index].y=HIWORD(lParam);
Line[index].Move=FALSE;
LineTo(hdc,Line[index].x,Line[index].y);
index++;
/*
MoveToEx(hdc,x,y,NULL);
x=LOWORD(lParam);
y=HIWORD(lParam);
LineTo(hdc,x,y); */
ReleaseDC(hWnd,hdc);
}
return 0;
/* 직선인 경우
case WM_LBUTTONDOWN:
sx = LOWORD(lParam);
sy = HIWORD(lParam);
oldx = sx;
oldy = sy;
bNowDraw = TRUE;
return 0;
case WM_LBUTTONUP:
bNowDraw = FALSE;
hdc=GetDC(hWnd);
MoveToEx(hdc,sx,sy,NULL);
LineTo(hdc,oldx,oldy);
ReleaseDC(hWnd, hdc);
return 0;
case WM_MOUSEMOVE:
if (bNowDraw) {
hdc=GetDC(hWnd);
SetROP2(hdc,R2_NOT);
MoveToEx(hdc,sx,sy,NULL);
LineTo(hdc,oldx,oldy);
oldx=LOWORD(lParam);
oldy=HIWORD(lParam);
MoveToEx(hdc,sx,sy,NULL);
LineTo(hdc,oldx,oldy);
ReleaseDC(hWnd,hdc);
}
return 0;
*/
case WM_PAINT: {
HDC hdc;
PAINTSTRUCT ps;
int i;
hdc=BeginPaint(hWnd, &ps);
for (i=0;i<index;i++) {
if (Line[i].Move == TRUE) {
MoveToEx(hdc,Line[i].x, Line[i].y, NULL);
} else {
LineTo(hdc,Line[i].x, Line[i].y);
}
}
EndPaint(hWnd, &ps);
}
return 0;
}
return(DefWindowProc(hWnd,iMessage,wParam,lParam));
}