VC图形时钟代码错误,找高手改下
#include<windows.h>#include<math.h>#defineID_TIMER1///定时器表识;#defineTWOPI(2*3.14159)//...
#include <windows.h>
#include <math.h>
#define ID_TIMER 1 ///定时器表识;
#define TWOPI (2 * 3.14159) //2PI
LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ;//回调函数
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
PSTR szCmdLine, int iCmdShow)
{
static TCHAR szAppName[] = TEXT (\\\"Clock\\\") ;
HWND hwnd;
MSG msg;
WNDCLASS wndclass ;//系统支持结构
wndclass.style = CS_HREDRAW | CS_VREDRAW ;//分隔 CS_HREDRAW当窗口水平方向的宽度变化时重绘整个窗口.
//CS_VREDRAW 当窗口垂直方向的宽度变化时重绘整个窗口.
wndclass.lpfnWndProc = WndProc ;//lpfnWndProc指向函数的长指针
wndclass.cbClsExtra = 0 ;
wndclass.cbWndExtra = 0 ;
wndclass.hInstance = hInstance ;
wndclass.hIcon = NULL ;
wndclass.hCursor = LoadCursor (NULL, IDC_ARROW) ;
wndclass.hbrBackground = (HBRUSH)GetStockObject (WHITE_BRUSH) ;//定义背景颜色
wndclass.lpszMenuName = NULL ;
wndclass.lpszClassName = szAppName ;
if (!RegisterClass (&wndclass))
{
MessageBox (NULL, TEXT (\\\"Program requires Windows NT!\\\"),
szAppName, MB_ICONERROR) ;
return 0 ;
}
hwnd = CreateWindow (szAppName, TEXT (\\\"模拟时钟\\\"),//hWnd是窗口句柄,通过它可以得到窗口的属性。
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT,
CW_USEDEFAULT, CW_USEDEFAULT,
NULL, NULL, hInstance, NULL) ;
ShowWindow (hwnd, iCmdShow) ;
UpdateWindow (hwnd) ;
while (GetMessage (&msg, NULL, 0, 0))//函数GetMessage 是 从调用线程的消息队列里取得一个消息并将其放于指定的结构。
{
TranslateMessage (&msg) ;
DispatchMessage (&msg) ;
}
return msg.wParam ;
}
void SetIsotropic (HDC hdc, int cxClient, int cyClient){
SetMapMode (hdc, MM_ISOTROPIC) ;//GetMapMode函数用于从设备环境得到当前的映射模 式,SetMapMode函数用于设置设备环境的映射模式。
SetWindowExtEx (hdc, 1000, 1000, NULL) ;//将一个逻辑单位映射为多少
SetViewportExtEx (hdc, cxClient / 2, -cyClient / 2, NULL) ;
SetViewportOrgEx (hdc, cxClient / 2, cyClient / 2, NULL) ;//设置视口原点;
}
void RotatePoint (POINT pt[], int iNum, int iAngle)
{
int i ;
POINT ptTemp ;
for (i = 0 ; i < iNum ; i++)
{
ptTemp.x = (int) (pt.x * cos (TWOPI * iAngle / 360) +//2pi*角度/360
pt.y * sin (TWOPI * iAngle / 360)) ;
ptTemp.y = (int) (pt.y * cos (TWOPI * iAngle / 360) -
pt.x * sin (TWOPI * iAngle / 360)) ;
pt = ptTemp ;
}
}
void DrawClock (HDC hdc) //作图 展开
#include <math.h>
#define ID_TIMER 1 ///定时器表识;
#define TWOPI (2 * 3.14159) //2PI
LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ;//回调函数
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
PSTR szCmdLine, int iCmdShow)
{
static TCHAR szAppName[] = TEXT (\\\"Clock\\\") ;
HWND hwnd;
MSG msg;
WNDCLASS wndclass ;//系统支持结构
wndclass.style = CS_HREDRAW | CS_VREDRAW ;//分隔 CS_HREDRAW当窗口水平方向的宽度变化时重绘整个窗口.
//CS_VREDRAW 当窗口垂直方向的宽度变化时重绘整个窗口.
wndclass.lpfnWndProc = WndProc ;//lpfnWndProc指向函数的长指针
wndclass.cbClsExtra = 0 ;
wndclass.cbWndExtra = 0 ;
wndclass.hInstance = hInstance ;
wndclass.hIcon = NULL ;
wndclass.hCursor = LoadCursor (NULL, IDC_ARROW) ;
wndclass.hbrBackground = (HBRUSH)GetStockObject (WHITE_BRUSH) ;//定义背景颜色
wndclass.lpszMenuName = NULL ;
wndclass.lpszClassName = szAppName ;
if (!RegisterClass (&wndclass))
{
MessageBox (NULL, TEXT (\\\"Program requires Windows NT!\\\"),
szAppName, MB_ICONERROR) ;
return 0 ;
}
hwnd = CreateWindow (szAppName, TEXT (\\\"模拟时钟\\\"),//hWnd是窗口句柄,通过它可以得到窗口的属性。
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT,
CW_USEDEFAULT, CW_USEDEFAULT,
NULL, NULL, hInstance, NULL) ;
ShowWindow (hwnd, iCmdShow) ;
UpdateWindow (hwnd) ;
while (GetMessage (&msg, NULL, 0, 0))//函数GetMessage 是 从调用线程的消息队列里取得一个消息并将其放于指定的结构。
{
TranslateMessage (&msg) ;
DispatchMessage (&msg) ;
}
return msg.wParam ;
}
void SetIsotropic (HDC hdc, int cxClient, int cyClient){
SetMapMode (hdc, MM_ISOTROPIC) ;//GetMapMode函数用于从设备环境得到当前的映射模 式,SetMapMode函数用于设置设备环境的映射模式。
SetWindowExtEx (hdc, 1000, 1000, NULL) ;//将一个逻辑单位映射为多少
SetViewportExtEx (hdc, cxClient / 2, -cyClient / 2, NULL) ;
SetViewportOrgEx (hdc, cxClient / 2, cyClient / 2, NULL) ;//设置视口原点;
}
void RotatePoint (POINT pt[], int iNum, int iAngle)
{
int i ;
POINT ptTemp ;
for (i = 0 ; i < iNum ; i++)
{
ptTemp.x = (int) (pt.x * cos (TWOPI * iAngle / 360) +//2pi*角度/360
pt.y * sin (TWOPI * iAngle / 360)) ;
ptTemp.y = (int) (pt.y * cos (TWOPI * iAngle / 360) -
pt.x * sin (TWOPI * iAngle / 360)) ;
pt = ptTemp ;
}
}
void DrawClock (HDC hdc) //作图 展开
2个回答
展开全部
{
int iAngle ;
POINT pt[3] ;//POINT(点)是一个结构,它定义了一个点的坐标(x,y)
for (iAngle = 0 ; iAngle < 360 ; iAngle += 6)//逐个画圆
{
pt[0].x = 0 ;
pt[0].y = 850 ;//半径
RotatePoint (pt, 1, iAngle) ;
pt[2].x = pt[2].y = iAngle % 5 ? 33 : 100 ;
pt[0].x -= pt[2].x /2;
pt[0].y -= pt[2].y /2;
pt[1].x = pt[0].x + pt[2].x;
pt[1].y = pt[0].y + pt[2].y ;
SelectObject (hdc, CreateSolidBrush(RGB(0,0,255)));//);GetStockObject (WHITE_BRUSH)) ;设定并返回刷子颜色
Ellipse (hdc, pt[0].x, pt[0].y, pt[1].x, pt[1].y) ;//画个椭圆,并用画刷进行填充;
}
}
void DrawHands (HDC hdc, SYSTEMTIME * pst, BOOL fChange)//HDC为句柄 代表这个
{
static POINT pt[3][5] = { 0, -50, 100, 0, 0, 600, -100, 0, 0, -50,
0, -20, 50, 0, 0, 800, -50, 0, 0, -20,
0, 0, 0, 0, 0, 0, 0, 0, 0, 800 } ;//指针各连线坐标
int i, iAngle[3] ;
POINT ptTemp[3][5] ;
iAngle[0] = (pst->wHour * 30) % 360 + pst->wMinute / 2 ;
iAngle[1] = pst->wMinute * 6+ pst->wSecond /10 ;
iAngle[2] = pst->wSecond * 6 ;
memcpy (ptTemp, pt, sizeof (pt)) ; //是什么意思?由pt所指内存区域复制ptTemp个字节到dest所指内存区域。
for (i = fChange ? 0 : 2 ; i < 3 ; i++)
{
RotatePoint (ptTemp, 5, iAngle) ;
Polyline (hdc, ptTemp, 5) ;
}
}
LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
static int cxClient, cyClient ;
static SYSTEMTIME stPrevious ;
BOOL fChange ;
HDC hdc ;
PAINTSTRUCT ps ;
SYSTEMTIME st ;//结构
switch (message) //窗口处理函数
{
case WM_CREATE :
SetTimer (hwnd, ID_TIMER, 1000, NULL) ;
GetLocalTime (&st) ;
stPrevious = st ;
return 0 ;
case WM_SIZE : //这是干吗用的?
cxClient = LOWORD (lParam) ; //获取客户区的高度和宽度
cyClient = HIWORD (lParam) ; //否则大小不可预计
return 0 ;
case WM_TIMER :
GetLocalTime (&st) ;//获取当地时间
fChange = st.wHour != stPrevious.wHour || //判断是否重画表针
st.wMinute != stPrevious.wMinute||
st.wSecond != stPrevious.wSecond;
hdc = GetDC (hwnd) ;
SetIsotropic (hdc, cxClient, cyClient) ;//原点移动
SelectObject (hdc, GetStockObject (WHITE_PEN)) ;//利用白色来覆盖原来的
//GetStockObject函数检索预定义的备用笔、刷子、字体或者调色板的句柄。
DrawHands (hdc, &stPrevious, fChange) ;
SelectObject (hdc, CreatePen(PS_SOLID,1,RGB(0,0,255)));//GetStockObject (//BLACK_PEN)) ;(实线画笔并规定颜色)
DrawHands (hdc, &st, TRUE) ;
ReleaseDC (hwnd, hdc) ;
stPrevious = st ;
return 0 ;
case WM_PAINT :
hdc = BeginPaint (hwnd, &ps) ;
SetIsotropic (hdc, cxClient, cyClient) ;
DrawClock (hdc) ;
DrawHands (hdc, &stPrevious, TRUE) ;
EndPaint (hwnd, &ps) ;
return 0 ;
case WM_DESTROY :
KillTimer (hwnd, ID_TIMER) ;
PostQuitMessage (0) ;
return 0 ;
}
return DefWindowProc (hwnd, message, wParam, lParam) ;
}
I:\1234\main.c|188|unterminated argument list invoking macro "TEXT"|
I:\1234\main.c||In function `WinMain':|
I:\1234\main.c|9|error: `TEXT' undeclared (first use in this function)|
I:\1234\main.c|9|error: (Each undeclared identifier is reported only once|
I:\1234\main.c|9|error: for each function it appears in.)|
I:\1234\main.c|9|error: syntax error at end of input|
I:\1234\main.c|9|warning: unused variable `szAppName'|
||=== 已完成构建: 5 个错误, 1 个警告 ===|
int iAngle ;
POINT pt[3] ;//POINT(点)是一个结构,它定义了一个点的坐标(x,y)
for (iAngle = 0 ; iAngle < 360 ; iAngle += 6)//逐个画圆
{
pt[0].x = 0 ;
pt[0].y = 850 ;//半径
RotatePoint (pt, 1, iAngle) ;
pt[2].x = pt[2].y = iAngle % 5 ? 33 : 100 ;
pt[0].x -= pt[2].x /2;
pt[0].y -= pt[2].y /2;
pt[1].x = pt[0].x + pt[2].x;
pt[1].y = pt[0].y + pt[2].y ;
SelectObject (hdc, CreateSolidBrush(RGB(0,0,255)));//);GetStockObject (WHITE_BRUSH)) ;设定并返回刷子颜色
Ellipse (hdc, pt[0].x, pt[0].y, pt[1].x, pt[1].y) ;//画个椭圆,并用画刷进行填充;
}
}
void DrawHands (HDC hdc, SYSTEMTIME * pst, BOOL fChange)//HDC为句柄 代表这个
{
static POINT pt[3][5] = { 0, -50, 100, 0, 0, 600, -100, 0, 0, -50,
0, -20, 50, 0, 0, 800, -50, 0, 0, -20,
0, 0, 0, 0, 0, 0, 0, 0, 0, 800 } ;//指针各连线坐标
int i, iAngle[3] ;
POINT ptTemp[3][5] ;
iAngle[0] = (pst->wHour * 30) % 360 + pst->wMinute / 2 ;
iAngle[1] = pst->wMinute * 6+ pst->wSecond /10 ;
iAngle[2] = pst->wSecond * 6 ;
memcpy (ptTemp, pt, sizeof (pt)) ; //是什么意思?由pt所指内存区域复制ptTemp个字节到dest所指内存区域。
for (i = fChange ? 0 : 2 ; i < 3 ; i++)
{
RotatePoint (ptTemp, 5, iAngle) ;
Polyline (hdc, ptTemp, 5) ;
}
}
LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
static int cxClient, cyClient ;
static SYSTEMTIME stPrevious ;
BOOL fChange ;
HDC hdc ;
PAINTSTRUCT ps ;
SYSTEMTIME st ;//结构
switch (message) //窗口处理函数
{
case WM_CREATE :
SetTimer (hwnd, ID_TIMER, 1000, NULL) ;
GetLocalTime (&st) ;
stPrevious = st ;
return 0 ;
case WM_SIZE : //这是干吗用的?
cxClient = LOWORD (lParam) ; //获取客户区的高度和宽度
cyClient = HIWORD (lParam) ; //否则大小不可预计
return 0 ;
case WM_TIMER :
GetLocalTime (&st) ;//获取当地时间
fChange = st.wHour != stPrevious.wHour || //判断是否重画表针
st.wMinute != stPrevious.wMinute||
st.wSecond != stPrevious.wSecond;
hdc = GetDC (hwnd) ;
SetIsotropic (hdc, cxClient, cyClient) ;//原点移动
SelectObject (hdc, GetStockObject (WHITE_PEN)) ;//利用白色来覆盖原来的
//GetStockObject函数检索预定义的备用笔、刷子、字体或者调色板的句柄。
DrawHands (hdc, &stPrevious, fChange) ;
SelectObject (hdc, CreatePen(PS_SOLID,1,RGB(0,0,255)));//GetStockObject (//BLACK_PEN)) ;(实线画笔并规定颜色)
DrawHands (hdc, &st, TRUE) ;
ReleaseDC (hwnd, hdc) ;
stPrevious = st ;
return 0 ;
case WM_PAINT :
hdc = BeginPaint (hwnd, &ps) ;
SetIsotropic (hdc, cxClient, cyClient) ;
DrawClock (hdc) ;
DrawHands (hdc, &stPrevious, TRUE) ;
EndPaint (hwnd, &ps) ;
return 0 ;
case WM_DESTROY :
KillTimer (hwnd, ID_TIMER) ;
PostQuitMessage (0) ;
return 0 ;
}
return DefWindowProc (hwnd, message, wParam, lParam) ;
}
I:\1234\main.c|188|unterminated argument list invoking macro "TEXT"|
I:\1234\main.c||In function `WinMain':|
I:\1234\main.c|9|error: `TEXT' undeclared (first use in this function)|
I:\1234\main.c|9|error: (Each undeclared identifier is reported only once|
I:\1234\main.c|9|error: for each function it appears in.)|
I:\1234\main.c|9|error: syntax error at end of input|
I:\1234\main.c|9|warning: unused variable `szAppName'|
||=== 已完成构建: 5 个错误, 1 个警告 ===|
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
天正软件
2024-08-02 广告
2024-08-02 广告
天正软件可以解决以下问题:1. 提供设计标准化:天正软件专注于勘察设计领域,为用户提供标准化、信息化、智能化的解决方案,以提高设计效率、优化设计流程、降低成本。2. 提高绘图效率:天正软件提供了一系列专业绘图工具,能够帮助设计师快速绘制图纸...
点击进入详情页
本回答由天正软件提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询