#include <windows.h>
#include <math.h>
#define TWOPI (2 * 3.14159)
#define ID_TIMER1 5
LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ;
VOID CALLBACK TimerProc(HWND, UINT, UINT, DWORD);
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
PSTR szCmdLine, int iCmdShow)
{
static TCHAR szAppName[] = TEXT ("RunningBall") ;
HWND hwnd ;
MSG msg ;
WNDCLASS wndclass ;
wndclass.style = CS_HREDRAW | CS_VREDRAW ;
wndclass.lpfnWndProc = WndProc ;
wndclass.cbClsExtra = 0 ;
wndclass.cbWndExtra = 0 ;
wndclass.hInstance = hInstance ;
wndclass.hIcon = LoadIcon (NULL, IDI_APPLICATION) ;
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 ("RunningBall"),
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))
{
TranslateMessage (&msg) ;
DispatchMessage (&msg) ;
}
return msg.wParam ;
}
// 输出消息的文本函数
void fucDrawText(HWND hwnd,INT tt,INT xa,INT xb)
{
HDC hdc;
RECT textRect, rect;
TCHAR buf[40];
// 用于输出文本的矩形
GetClientRect(hwnd, &rect);
textRect.left = rect.left;
textRect.right = rect.right;
textRect.top = rect.top + 50;
textRect.bottom = rect.top + 200;
hdc = GetDC(hwnd);
SetTextColor(hdc, RGB(0, 0, 0));
SelectObject(hdc, GetStockObject(NULL_PEN));
SelectObject(hdc, GetStockObject(WHITE_BRUSH));
Rectangle(hdc, textRect.left, textRect.top, textRect.right, textRect.bottom);
wsprintf(buf, "测试时间:%d秒\n\n按键轮击次数: %d\n\n不合法按键次数:%d",tt, xa, xb);
DrawText(hdc, buf, -1, &textRect, DT_CENTER | DT_VCENTER);
DeleteDC(hdc);
}
LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
HDC hdc ;
HINSTANCE hInst; // 程序实例句柄
PAINTSTRUCT ps ;
static SIZE size ;
static int cxClient, cyClient, j;
static int tt=5,xa,xb,recent; //记录时间,记录鼠标按键次数,recent为1是左键,为0是右键
switch (message)
{
xa = 0;
xb = 0;
recent = 1;
case WM_CREATE:
hdc = GetDC(hwnd);
// 设置计时器
SetTimer(hwnd, ID_TIMER1, 1000, NULL);
hInst = ((LPCREATESTRUCT)lParam)->hInstance;
return 0 ;
case WM_SIZE:
cxClient = LOWORD(lParam);
cyClient = HIWORD(lParam);
return 0;
case WM_PAINT:
hdc = BeginPaint (hwnd, &ps) ;
fucDrawText(hwnd,tt,xa,xb);
EndPaint(hwnd, &ps);
return 0 ;
case WM_TIMER: // 接收第一个计时器消息
switch(wParam)
{
case ID_TIMER1:
if (tt>0)
tt --;
break;
}
return 0;
case WM_LBUTTONDOWN:
if (tt == 0)
{fucDrawText(hwnd,tt,xa,xb);break;}
else if (recent != 0)
{xb ++;recent=1;}
else
{recent=1;}
fucDrawText(hwnd,tt,xa,xb);
return 0;
case WM_RBUTTONDOWN:
if (tt == 0)
{fucDrawText(hwnd,tt,xa,xb);break;}
else if (recent != 1)
{xb ++;recent = 0;}
else
{xa ++;recent = 0;}
fucDrawText(hwnd,tt,xa,xb);
return 0;
case WM_DESTROY:
KillTimer(hwnd, ID_TIMER1); // 清除计时器1
PostQuitMessage(0) ;
return 0 ;
}
return DefWindowProc (hwnd, message, wParam, lParam) ;
}
没有合适的资源?快使用搜索试试~ 我知道了~
Windows编程鼠标按键练习
共14个文件
pdb:2个
dsw:1个
dsp:1个
5星 · 超过95%的资源 需积分: 9 8 下载量 140 浏览量
2011-12-26
20:05:45
上传
评论
收藏 1.12MB RAR 举报
温馨提示
Windows编程鼠标按键练习 记录鼠标交替按键次数的联系,并会记录非法按键次数 开发环境:visual c++
资源推荐
资源详情
资源评论
收起资源包目录
Four1Mouse.rar (14个子文件)
Four1Mouse
main.asp 0B
main.cpp 4KB
Four1.dsp 4KB
Four1.opt 48KB
Debug
Four1.exe 172KB
Four1.pdb 417KB
vc60.pdb 76KB
Four1.ilk 197KB
vc60.idb 137KB
main.obj 17KB
Four1.pch 3.41MB
Four1.plg 855B
Four1.dsw 535B
Four1.ncb 41KB
共 14 条
- 1
资源评论
- sodaqiqi2015-06-19不错的案例。
- achaoge20122014-10-21非常实用,可以用来入门
annieforever21
- 粉丝: 0
- 资源: 3
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功