干脆弄清楚一点,这是我的代码
LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
PAINTSTRUCT ps;
HDC hdc;
RECT lprc;
HFONT hFont;
switch(msg)
{
case WM_CLOSE:
DestroyWindow(hWnd);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
case WM_PAINT:
{
int x=40,y=40;
hdc = BeginPaint(hWnd, &ps);
HPEN hPen=CreatePen(PS_SOLID,3,RGB(0,0,0)),
hPenOld=CreatePen(PS_SOLID,1,RGB(0,0,0));
for (int i=0;i<10;++i)
{
if (i==3||i==6)
{
SelectObject(hdc,hPen);
MoveToEx(hdc,x,y,NULL);
LineTo(hdc,x+450, y);
y+=50;x=40;
}
else
{
SelectObject(hdc,hPenOld);
MoveToEx(hdc,x,y,NULL);
LineTo(hdc,x+450, y);
y+=50;x=40;
}
}
x=40;y=40;
for (int i=0;i<10;++i)
{
if (i==3||i==6)
{
SelectObject(hdc,hPen);
MoveToEx(hdc,x,y,NULL);
LineTo(hdc,x, y+450);
x+=50;y=40;
}
else
{
SelectObject(hdc, hPenOld);
MoveToEx(hdc, x, y, NULL);
LineTo(hdc, x, y+450);
x+=50;y=40;
}
}
DeleteObject(hPen);
DeleteObject(hPenOld);
EndPaint(hWnd, &ps);
}
break;
case WM_LBUTTONDOWN :
{
if(LOWORD(lParam)>40&&LOWORD(lParam)<490
&&HIWORD(lParam)>40&&HIWORD(lParam)<490)
{
int n1=(LOWORD(lParam)-42)/50;
int n2=(HIWORD(lParam)-42)/50;
hFont= CreateFont(40,20,0,0,0,0,0,0,0,0,0,0,0,0);
hdc=GetDC(hWnd);
SelectObject(hdc,hFont);
SetRect(&lprc,42+50*n1, 42+50*n2, 88+50*n1, 88+50*n2);
DrawText(hdc,"4",-1,&lprc,DT_CENTER|DT_VCENTER|DT_SINGLELINE);
DeleteObject(hFont);
}
}
break;
default:
return DefWindowProc(hWnd, msg, wParam, lParam);
}
return 0;
}