主题:小弟初识API,不才,请教一个画圆问题
{
HDC hDC;
RECT rect,rect1;
rect.left=rect.top=10;
rect.right=rect.bottom=100;
hDC=GetDC(hWnd);
GetClientRect(hWnd,&rect);
POINT pt;
pt.x=(rect.left+rect.right)/2;
pt.y=(rect.top+rect.bottom)/2;
rect1.left=pt.x-155;rect1.right=pt.x-145;
rect1.top=pt.y+5;rect1.bottom=pt.y-5;
static int dx=0,dy=0,flag=1;
switch (message)
{
case WM_COMMAND:
wmId = LOWORD(wParam);
wmEvent = HIWORD(wParam);
// Parse the menu selections:
switch (wmId)
{
case IDM_ABOUT:
DialogBox(hInst, (LPCTSTR)IDD_ABOUTBOX, hWnd, (DLGPROC)About);
break;
case IDM_EXIT:
DestroyWindow(hWnd);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
break;
case WM_PAINT:
hdc = BeginPaint(hWnd, &ps);
// TODO: Add any drawing code here...
RECT rt;
GetClientRect(hWnd, &rt);
DrawText(hdc, szHello, strlen(szHello), &rt, DT_CENTER);
EndPaint(hWnd, &ps);
break;
case WM_LBUTTONDOWN:
SetTimer(hWnd,WM_TIMER,10,NULL);
break;
case WM_TIMER:
if(flag)
{
OffsetRect(&rect1,dx,dy);
dy=(int)sqrt(pow(150,2)-pow((150-dx),2));
if(dx==300)
flag=0;
dx++;
}
else
{
OffsetRect(&rect1,dx,dy);
dy=-(int)sqrt(pow(150,2)-pow((150-dx),2));
if(dx==0)
flag=1;
dx--;
}
FillRect(hDC,&rect1,(HBRUSH)GetStockObject(BLACK_BRUSH));
break;
case WM_RBUTTONDOWN:
OffsetRect(&rect1,1,1);
FillRect(hDC,&rect1,(HBRUSH)GetStockObject(BLACK_BRUSH));
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}
// Mesage handler for about box.
LRESULT CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_INITDIALOG:
return TRUE;
case WM_COMMAND:
if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
{
EndDialog(hDlg, LOWORD(wParam));
return TRUE;
}
break;
}
return FALSE;
}
为什么有断点
HDC hDC;
RECT rect,rect1;
rect.left=rect.top=10;
rect.right=rect.bottom=100;
hDC=GetDC(hWnd);
GetClientRect(hWnd,&rect);
POINT pt;
pt.x=(rect.left+rect.right)/2;
pt.y=(rect.top+rect.bottom)/2;
rect1.left=pt.x-155;rect1.right=pt.x-145;
rect1.top=pt.y+5;rect1.bottom=pt.y-5;
static int dx=0,dy=0,flag=1;
switch (message)
{
case WM_COMMAND:
wmId = LOWORD(wParam);
wmEvent = HIWORD(wParam);
// Parse the menu selections:
switch (wmId)
{
case IDM_ABOUT:
DialogBox(hInst, (LPCTSTR)IDD_ABOUTBOX, hWnd, (DLGPROC)About);
break;
case IDM_EXIT:
DestroyWindow(hWnd);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
break;
case WM_PAINT:
hdc = BeginPaint(hWnd, &ps);
// TODO: Add any drawing code here...
RECT rt;
GetClientRect(hWnd, &rt);
DrawText(hdc, szHello, strlen(szHello), &rt, DT_CENTER);
EndPaint(hWnd, &ps);
break;
case WM_LBUTTONDOWN:
SetTimer(hWnd,WM_TIMER,10,NULL);
break;
case WM_TIMER:
if(flag)
{
OffsetRect(&rect1,dx,dy);
dy=(int)sqrt(pow(150,2)-pow((150-dx),2));
if(dx==300)
flag=0;
dx++;
}
else
{
OffsetRect(&rect1,dx,dy);
dy=-(int)sqrt(pow(150,2)-pow((150-dx),2));
if(dx==0)
flag=1;
dx--;
}
FillRect(hDC,&rect1,(HBRUSH)GetStockObject(BLACK_BRUSH));
break;
case WM_RBUTTONDOWN:
OffsetRect(&rect1,1,1);
FillRect(hDC,&rect1,(HBRUSH)GetStockObject(BLACK_BRUSH));
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}
// Mesage handler for about box.
LRESULT CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_INITDIALOG:
return TRUE;
case WM_COMMAND:
if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
{
EndDialog(hDlg, LOWORD(wParam));
return TRUE;
}
break;
}
return FALSE;
}
为什么有断点