/*----------------------------------------
BIGJOB1.C -- Multithreading Demo
(c) Charles Petzold, 1998
----------------------------------------*/
#include <windows.h>
#include <math.h>
#include <process.h>
#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 WndProc (HWND, UINT, WPARAM, LPARAM) ;
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
PSTR szCmdLine, int iCmdShow)
{
static TCHAR szAppName[] = TEXT ("BigJob1") ;
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 ("This program requires Windows NT!"),
szAppName, MB_ICONERROR) ;
return 0 ;
}
hwnd = CreateWindow (szAppName, TEXT ("Multithreading Demo"),
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 Thread (PVOID pvoid)
{
double A = 1.0 ;
INT i ;
LONG lTime ;
volatile PPARAMS pparams ;
pparams = (PPARAMS) pvoid ;
lTime = GetCurrentTime () ;
for (i = 0 ; i < REP && pparams->bContinue ; i++)
A = tan (atan (exp (log (sqrt (A * A))))) + 1.0 ;
if (i == REP)
{
lTime = GetCurrentTime () - lTime ;
SendMessage (pparams->hwnd, WM_CALC_DONE, 0, lTime) ;
}
else
SendMessage (pparams->hwnd, WM_CALC_ABORTED, 0, 0) ;
_endthread () ;
}
LRESULT CALLBACK WndProc (HWND hwnd, UINT message, 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 %ld msec") } ;
HDC hdc ;
PAINTSTRUCT ps ;
RECT rect ;
TCHAR szBuffer[64] ;
switch (message)
{
case WM_LBUTTONDOWN:
if (iStatus == STATUS_WORKING)
{
MessageBeep (0) ;
return 0 ;
}
iStatus = STATUS_WORKING ;
params.hwnd = hwnd ;
params.bContinue = TRUE ;
_beginthread (Thread, 0, ¶ms) ;
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_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 ;
case WM_DESTROY:
PostQuitMessage (0) ;
return 0 ;
}
return DefWindowProc (hwnd, message, wParam, lParam) ;
}
Windows程序设计 BigJob1(源代码).rar
版权申诉
161 浏览量
2023-02-17
13:50:39
上传
评论
收藏 88KB RAR 举报
![avatar](https://profile-avatar.csdnimg.cn/a1e22b8af6174f729054a946560f6bf4_s13166803785.jpg!1)
金枝玉叶9
- 粉丝: 172
- 资源: 7638
最新资源
- 基于Python的无人载具/无人船上位机控制系统可导入坐标自动巡航,带语音反馈功能+源码解析+开发文档(毕设&课设&项目开发)
- 附件1:赣南科技学院课程设计报告撰写规范.docx
- 编程实战:基于JAVA和SQL的离散数学题库管理系统(源代码+文档+外文翻译)
- 毕设项目:离散数学题库管理系统(JAVA+SQL+源代码+文档+外文翻译)
- 基于STM32F1系列微控制器的四旋翼飞行控制器+无人机自动控制+源码(毕业设计&课程设计&项目开发)
- library_OA.zip
- DS18B20温度传感器开发教程.docx
- 基于python开发的无人机群控与协同作业网络化控制平台+源码+算法(毕业设计&课程设计&项目开发)
- cosmos.opml
- C# yolov8 模型效果验证工具(OnnxRuntime+ByteTrack推理).rar
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
![feedback](https://img-home.csdnimg.cn/images/20220527035711.png)
![feedback](https://img-home.csdnimg.cn/images/20220527035711.png)
![feedback-tip](https://img-home.csdnimg.cn/images/20220527035111.png)