有错误,无法编译
题目:设计一个秒表及时钟程序,按“1”显示时钟,按“2”开始计时,按“3”停止计时,按“4”表清零,按“5”执行程序退出
#ifndef UNICODE
#define UNICODE
#endif
#include<math.h>
#include <windows.h>
LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR pCmdLine, int nCmdShow)
{
const wchar_t CLASS_NAME[] = L"Sample Window Class";
WNDCLASS wc = { 0};
wc.lpfnWndProc = WindowProc;
wc.hInstance = hInstance;
wc.lpszClassName = CLASS_NAME;
wc.hbrBackground = GetStockObject(WHITE_BRUSH);
RegisterClass(&wc);
// Create the window.
RECT r;
r.left = 0;
r.top = 0;
r.bottom = 400;
r.right = 400;
srand(GetTickCount());
AdjustWindowRectEx(&r, WS_OVERLAPPEDWINDOW ^ WS_THICKFRAME ^ WS_MAXIMIZEBOX,0,0);
HWND hwnd = CreateWindowEx(
0, // Optional window styles.
CLASS_NAME, // Window class
L"Learn to Program Windows", // Window text
WS_OVERLAPPEDWINDOW^WS_THICKFRAME^ WS_MAXIMIZEBOX, // Window style
// Size and position
CW_USEDEFAULT, CW_USEDEFAULT, r.right- r.left,r.bottom- r.top,
NULL, // Parent window
NULL, // Menu
hInstance, // Instance handle
NULL // Additional application data
);
if (hwnd == NULL)
{
return 0;
}
ShowWindow(hwnd, nCmdShow);
MSG msg = {0 };
while (GetMessage(&msg, NULL, 0, 0) > 0)
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;
}
HWND hwnd_;
int zhon = 0;
int isMin = 0;
int min = 0;
void vRotationTransform(double dX, double dY, double dAngle, double* dbNewX, double* dbNewY);
void huat() {
RECT r;
SYSTEMTIME time;
double x, y;
char date[128];
int i;
LOGFONT logfont;
ZeroMemory(&logfont, sizeof(LOGFONT));
logfont.lfCharSet = GB2312_CHARSET;
logfont.lfHeight = 50;
HFONT hFont = CreateFontIndirectA(&logfont);
HDC hdc = GetDC(hwnd_);
SelectObject(hdc, hFont);
GetLocalTime(&time);
if (zhon)
{
Ellipse(hdc, 125, 25, 275, 175);
for (i = 1; i <= 12; i++)
{
vRotationTransform(0, 70, 0.0 - ((i / 12.0 * 360.0) / 57.29578), &x, &y);
MoveToEx(hdc, 200 + (int)x, 100 - (int)y, 0);
vRotationTransform(0, 75, 0.0 - ((i / 12.0 * 360.0) / 57.29578), &x, &y);
LineTo(hdc, 200 + (int)x, 100 - (int)y);
}
MoveToEx(hdc, 200, 100, 0);
vRotationTransform(0, 60, 0.0 - ((time.wHour / 12.0 * 360.0) / 57.29578), &x, &y);
LineTo(hdc, 200 + (int)x, 100 - (int)y);
MoveToEx(hdc, 200, 100, 0);
vRotationTransform(0, 55, 0.0 - ((time.wMinute / 60.0 * 360.0) / 57.29578), &x, &y);
LineTo(hdc, 200 + (int)x, 100 - (int)y);
MoveToEx(hdc, 200, 100, 0);
vRotationTransform(0, 50, 0.0 - ((time.wSecond / 60.0 * 360.0) / 57.29578), &x, &y);
LineTo(hdc, 200 + (int)x, 100 - (int)y);
}
wsprintfA(date, "%.2d:%.2d:%.2d", min / 60 / 60, min / 60 % 60, min % 60);
r.left = 0;
r.top = 200;
r.right = 400;
r.bottom = 400;
DrawTextA(hdc, date, -1, &r, DT_VCENTER | DT_CENTER | DT_SINGLELINE);
}
VOID CALLBACK timerproc(HWND hwnd, UINT a, UINT_PTR b, DWORD c) {
if (isMin)
{
min +=1;
}
huat();
}
LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch (uMsg)
{
case WM_CREATE:
SetTimer(0, 0, 1000, timerproc);
hwnd_ = hwnd;
return 0;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
case WM_PAINT:
{
double x, y;
PAINTSTRUCT ps;
HDC hdc = BeginPaint(hwnd, &ps);
huat();
EndPaint(hwnd, &ps);
}
return 0;
case WM_TIMER:
return 0;
case WM_KEYDOWN:
if (wParam=='1'|| wParam == 0x61)
{
zhon = !zhon;
InvalidateRect(hwnd, 0, 1);
}
else if(wParam == '2'|| wParam == 0x62){
isMin = 1;
InvalidateRect(hwnd, 0, 1);
}
else if (wParam == '3' || wParam == 0x63) {
isMin = 0;
InvalidateRect(hwnd, 0, 1);
}
else if (wParam == '4' || wParam == 0x64) {
isMin = 0;
min = 0;
InvalidateRect(hwnd, 0, 1);
}
else if (wParam == '5' || wParam == 0x65) {
ExitProcess(0);
}
return 0;
case WM_KEYUP:
return 0;
}
return DefWindowProc(hwnd, uMsg, wParam, lParam);
}
void vRotationTransform(double dX, double dY, double dAngle, double*dbNewX, double*dbNewY)
{
*dbNewX = dX * cos(dAngle) - dY * sin(dAngle);
*dbNewY = dX * sin(dAngle) + dY * cos(dAngle);
}
进行修改,在不改变.c文件格式的条件下运行
写得差不多了吖
错误提示