博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
win32可以自定义消息
阅读量:4977 次
发布时间:2019-06-12

本文共 3287 字,大约阅读时间需要 10 分钟。

#include 
#include
#include
#define CLSNAME "Bigjob1"#define WNDNAME "yanshi"#define REP 1000000#define STATUS_READY 0#define STATUS_WORKING 1#define STATUS_DONE 2#define WM_CALC_DONE (WM_USER+0)#define WM_CALC_ABORTED (WM_USER+1)typedef struct{ HWND hwnd; BOOL bContinue;}PARAMS,*PPARAMS;LRESULT APIENTRY WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam );int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow){ static TCHAR clsname[] = TEXT(CLSNAME); WNDCLASS wndclass; wndclass.style = CS_HREDRAW | CS_VREDRAW ; wndclass.lpfnWndProc = WindowProc ; 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 = clsname ; if(!::RegisterClass(&wndclass)) { MessageBox ( NULL, TEXT ("This program requires Windows NT!"), clsname, MB_ICONERROR) ; return 0 ; } HWND hwnd; hwnd = ::CreateWindow(clsname,TEXT(WNDNAME), WS_OVERLAPPEDWINDOW, CW_USEDEFAULT,CW_USEDEFAULT, CW_USEDEFAULT,CW_USEDEFAULT, NULL,NULL,hInstance,NULL); ::ShowWindow(hwnd,SW_SHOW); ::UpdateWindow(hwnd); MSG msg; while(::GetMessage(&msg,NULL,0,0)){ ::TranslateMessage(&msg); ::DispatchMessage(&msg); } return msg.wParam;}VOID Thread(PVOID pvoid){ double A = 1.0; INT i; LONG lTime; volatile PPARAMS pparams; pparams = (PPARAMS)pvoid; lTime = ::GetCurrentTime(); for(i=0; i
bContinue; i++) A = ::tan(atan(exp(log(sqrt(A*A)))))+1.0; if(i == REP) { lTime = ::GetCurrentTime(); ::SendMessage(pparams->hwnd,WM_CALC_DONE,0,lTime); } else ::SendMessage(pparams->hwnd,WM_CALC_ABORTED,0,0); ::_endthread();}LRESULT APIENTRY WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam ){ static INT iStatus; static LONG lTime; static PARAMS params; static TCHAR * szMessage[] = {TEXT("ready(left mouse button begins)"), TEXT("working(right mouse button ends)"), TEXT("%d repetitions in %d msec")}; HDC hdc; PAINTSTRUCT ps; RECT rect; TCHAR szBuffer[64]; switch(uMsg) { case WM_LBUTTONDOWN: if(iStatus == STATUS_WORKING) { ::MessageBeep(0); return 0; } iStatus = STATUS_WORKING; params.hwnd = hwnd; params.bContinue = TRUE; ::_beginthread(Thread,0,&params); ::InvalidateRect(hwnd,NULL,TRUE); return 0; case WM_RBUTTONDOWN: params.bContinue = FALSE; return 0; case WM_CALC_DONE: lTime =lParam; iStatus = STATUS_DONE; ::InvalidateRect(hwnd,NULL,TRUE); return 0; case WM_CALC_ABORTED: iStatus = STATUS_READY; ::InvalidateRect(hwnd,NULL,TRUE); return 0; case WM_DESTROY: ::PostQuitMessage(0); return 0; case WM_PAINT: hdc = ::BeginPaint(hwnd,&ps); ::GetClientRect(hwnd,&rect); ::wsprintf(szBuffer,szMessage[iStatus],REP,lTime); ::DrawText(hdc,szBuffer,-1,&rect,DT_SINGLELINE| DT_CENTER|DT_VCENTER); ::EndPaint(hwnd,&ps); return 0; } return ::DefWindowProc(hwnd,uMsg,wParam,lParam);}

#define WM_CALC_DONE (WM_USER+0)

#define WM_CALC_ABORTED (WM_USER+1)

这两句已经很明显了,可以自定义消息那改多有趣啊!!

转载于:https://www.cnblogs.com/daoluanxiaozi/archive/2011/10/16/2214336.html

你可能感兴趣的文章
[Git] 005 初识 Git 与 GitHub 之分支
查看>>
【自定义异常】
查看>>
pip install 后 importError no module named "*"
查看>>
springmvc跳转方式
查看>>
IOS 第三方管理库管理 CocoaPods
查看>>
背景色渐变(兼容各浏览器)
查看>>
MariaDB 和 MySQL 比较
查看>>
MYSQL: 1292 - Truncated incorrect DOUBLE value: '184B3C0A-C411-47F7-BE45-CE7C0818F420'
查看>>
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
查看>>
springMVC Controller 参数映射
查看>>
【bzoj题解】2186 莎拉公主的困惑
查看>>
Protocol Buffer学习笔记
查看>>
Update 语句
查看>>
HBuilder打包Android apk 支付不了问题解决
查看>>
poj2594——最小路径覆盖
查看>>
欧拉函数
查看>>
关于SQL2008 “不允许保存更改。您所做的更改要求删除并重新创建以下表。您对无法重新创建的标进行了更改或者启用了‘阻止保存要求重新创建表的更改’” 解决方案...
查看>>
php文件操作(上传文件)2
查看>>
linux内核驱动模型
查看>>
给WebApp加一个“壳”,实现Andriod系统添加到桌面
查看>>