LRESULT CALLBACK MainWndProc(HWND hWnd,UINT wMsg,WPARAM wParam,LPARAM lParam)
{
HDC hdc;
HPEN oldPen,newPen;
RECT rt;
PAINTSTRUCT ps;
switch(wMsg)
{
case WM_CREATE:
GetClientRect(hWnd,&rt);
newPen=CreatePen(PS_SOLID,1,RGB(255,0,0));
return 0;
case WM_PAINT:
hdc=BeginPaint(hWnd, &ps);
oldPen=(HPEN)SelectObject(hdc,newPen);
Ellipse(hdc,10,10,30,30);
DrawText(hdc, L"ABCDE",strlen("ABCDE"),&rt,DT_SINGLELINE|DT_CENTER|DT_VCENTER);
SelectObject(hdc,oldPen);
EndPaint(hWnd, &ps);
return 0;
case WM_DESTROY:
DeleteObject(newPen);
return 0;
}
return DefWindowProc(hWnd,wMsg,wParam,lParam) ;
}
复制代码
不用每次都创建pen, 另外将LPPAINTSTRUCT ps ---->>>> PAINTSTRUCT ps