win32 时钟

#include
#include
#include


#define TWO_PI (3.1415926)


LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);
VOID WINAPI ThreadPionter(PVOID param);


int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,PSTR szCmdLine,int iCmdShow){
static TCHAR szAppName[] = TEXT("Ball");
HWND hwnd;
MSG msg;
WNDCLASS wndclass;


wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = 0;
wndclass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
wndclass.hCursor = LoadCursor(NULL,IDC_ARROW);
wndclass.hIcon = LoadIcon(NULL,IDI_APPLICATION);
wndclass.hInstance = hInstance;
wndclass.lpfnWndProc = WndProc;
wndclass.lpszClassName = szAppName;
wndclass.lpszMenuName = NULL;
wndclass.style = CS_HREDRAW | CS_VREDRAW;


if(!RegisterClass(&wndclass)){
MessageBox(NULL,TEXT("WIN NT!"),szAppName,MB_ICONERROR);
return 0;
}


hwnd = CreateWindow(szAppName,TEXT("Big Ball"),
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,CW_USEDEFAULT,
CW_USEDEFAULT,CW_USEDEFAULT,
NULL,NULL,hInstance,NULL);
ShowWindow(hwnd,iCmdShow);
UpdateWindow(hwnd);


HANDLE Thread = (HANDLE)_beginthread((void(__cdecl*)(void*))ThreadPionter,0,&hwnd);
while(GetMessage(&msg,NULL,NULL,NULL)){
TranslateMessage(&msg);
DispatchMessage(&msg);
}


return msg.wParam;
}


static int xTemp,yTemp;


LRESULT CALLBACK WndProc(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam){
static int cxClient,cyClient;
HDC hdc;
PAINTSTRUCT ps;


switch(message){
case WM_SIZE:
cxClient = LOWORD(lParam);
cyClient = HIWORD(lParam);
xTemp = cxClient/2;
yTemp = cyClient/2;
return 0;
case WM_PAINT:
hdc = BeginPaint(hwnd,&ps);
Ellipse(hdc,xTemp-200,yTemp-200,xTemp+200,yTemp+200);
//MoveToEx(hdc,xTemp,yTemp,NULL);
//LineTo(hdc,(int)xTemp+190*cos(TWO_PI*3/2),(int)yTemp+190*sin(TWO_PI*3/2));
EndPaint(hwnd,&ps);
return 0;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
}
return DefWindowProc(hwnd,message,wParam,lParam);
}


VOID WINAPI ThreadPionter(PVOID param){
double x=TWO_PI*3/2,y=TWO_PI*3/2;
HWND *hwnd = (HWND*) param;
HDC hdc = GetDC(*hwnd);
MoveToEx(hdc,xTemp,yTemp,NULL);
LineTo(hdc,(int)xTemp+190*cos(TWO_PI*3/2),(int)yTemp+190*sin(TWO_PI*3/2));
ReleaseDC(*hwnd,hdc);
while(1){
Sleep(1000);
//MessageBox(NULL,TEXT("111"),NULL,MB_OK);
HDC hdc = GetDC(*hwnd);
MoveToEx(hdc,xTemp,yTemp,NULL);
SelectObject(hdc,CreatePen(0,0,RGB(255,255,255)));
LineTo(hdc,(int)xTemp+190*cos(x),(int)yTemp+190*sin(y));
SelectObject(hdc,CreatePen(0,0,RGB(0,0,0)));
MoveToEx(hdc,xTemp,yTemp,NULL);
x+=(TWO_PI/30);
y+=(TWO_PI/30);
LineTo(hdc,(int)xTemp+190*cos(x),(int)yTemp+190*sin(y));
ReleaseDC(*hwnd,hdc);
}
}

你可能感兴趣的:(win32 时钟)