多线程win32API程序改错?

cwhe_10 cwhe_10 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区


/*---------------------------------------
MULTI1.C -- Multitasking Demo
(c) Charles Petzold, 1998
---------------------------------------*/

#include <windows.h>
#include <math.h>

LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ;

int cyChar ;

int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
PSTR szCmdLine, int iCmdShow)
{
static TCHAR szAppName[] = TEXT ("Multi1") ;
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 ("Multitasking 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 ;
}

int CheckBottom (HWND hwnd, int cyClient, int iLine)
{
if (iLine * cyChar + cyChar > cyClient)
{
InvalidateRect (hwnd, NULL, TRUE) ;
UpdateWindow (hwnd) ;
iLine = 0 ;
}
return iLine ;
}

// ------------------------------------------------
// Window 1: Display increasing sequence of numbers
// ------------------------------------------------

LRESULT APIENTRY WndProc1 (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
static int iNum, iLine, cyClient ;
HDC hdc ;
TCHAR szBuffer[16] ;

switch (message)
{
case WM_SIZE:
cyClient = HIWORD (lParam) ;
return 0 ;
case WM_TIMER:
if (iNum < 0)
iNum = 0 ;

iLine = CheckBottom (hwnd, cyClient, iLine) ;
hdc = GetDC (hwnd) ;

TextOut (hdc, 0, iLine * cyChar, szBuffer,
wsprintf (szBuffer, TEXT ("%d"), iNum++)) ;

ReleaseDC (hwnd, hdc) ;
iLine++ ;
return 0 ;
}
return DefWindowProc (hwnd, message, wParam, lParam) ;
}

// ------------------------------------------------------
// Window 2: Display increasing sequence of prime numbers
// ------------------------------------------------------

LRESULT APIENTRY WndProc2 (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
static int iNum = 1, iLine, cyClient ;
HDC hdc ;
int i, iSqrt ;
TCHAR szBuffer[16] ;

switch (message)
{
case WM_SIZE:
cyClient = HIWORD (lParam) ;
return 0 ;

case WM_TIMER:
do {
if (++iNum < 0)
iNum = 0 ;

iSqrt = (int) sqrt (iNum) ;
for (i = 2 ; i <= iSqrt ; i++)
if (iNum % i == 0)
break ;
}
while (i <= iSqrt) ;

iLine = CheckBottom (hwnd, cyClient, iLine) ;
hdc = GetDC (hwnd) ;

TextOut (hdc, 0, iLine * cyChar, szBuffer,
wsprintf (szBuffer, TEXT ("%d"), iNum)) ;
ReleaseDC (hwnd, hdc) ;
iLine++ ;
return 0 ;
}
return DefWindowProc (hwnd, message, wParam, lParam) ;
}

// ----------------------------------------------------------
// Window 3: Display increasing sequence of Fibonacci numbers
// ----------------------------------------------------------

LRESULT APIENTRY WndProc3 (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
static int iNum = 0, iNext = 1, iLine, cyClient ;
HDC hdc ;
int iTemp ;
TCHAR szBuffer[16] ;

switch (message)
{
case WM_SIZE:
cyClient = HIWORD (lParam) ;
return 0 ;

case WM_TIMER:
if (iNum < 0)
{
iNum = 0 ;
iNext = 1 ;
}

iLine = CheckBottom (hwnd, cyClient, iLine) ;
hdc = GetDC (hwnd) ;
TextOut (hdc, 0, iLine * cyChar, szBuffer,
(LPCWSTR) wsprintf (szBuffer, "%d", iNum)) ;

ReleaseDC (hwnd, hdc) ;
iTemp = iNum ;
iNum = iNext ;
iNext += iTemp ;
iLine++ ;
return 0 ;
}
return DefWindowProc (hwnd, message, wParam, lParam) ;
}

// -----------------------------------------
// Window 4: Display circles of random radii
// -----------------------------------------

LRESULT APIENTRY WndProc4 (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
static int cxClient, cyClient ;
HDC hdc ;
int iDiameter ;

switch (message)
{
case WM_SIZE:
cxClient = LOWORD (lParam) ;
cyClient = HIWORD (lParam) ;
return 0 ;

case WM_TIMER:
InvalidateRect (hwnd, NULL, TRUE) ;
UpdateWindow (hwnd) ;

iDiameter = rand() % (max (1, min (cxClient, cyClient))) ;
hdc = GetDC (hwnd) ;

Ellipse (hdc, (cxClient - iDiameter) / 2,
(cyClient - iDiameter) / 2,
(cxClient + iDiameter) / 2,
(cyClient + iDiameter) / 2) ;

ReleaseDC (hwnd, hdc) ;
return 0 ;
}
return DefWindowProc (hwnd, message, wParam, lParam) ;
}

// -----------------------------------
// Main window to create child windows
// -----------------------------------

LRESULT APIENTRY WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
static HWND hwndChild[4] ;
static TCHAR * szChildClass[] = { TEXT ("Child1"), TEXT ("Child2"),
TEXT ("Child3"), TEXT ("Child4") } ;
static WNDPROC ChildProc[] = { WndProc1, WndProc2, WndProc3, WndProc4 } ;
HINSTANCE hInstance ;
int i, cxClient, cyClient ;
WNDCLASS wndclass ;

switch (message)
{
case WM_CREATE:
hInstance = (HINSTANCE) GetWindowLong (hwnd, GWL_HINSTANCE) ;

wndclass.style = CS_HREDRAW | CS_VREDRAW ;
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 ;

for (i = 0 ; i < 4 ; i++)
{
wndclass.lpfnWndProc = ChildProc[i] ;
wndclass.lpszClassName = szChildClass[i] ;

RegisterClass (&wndclass) ;

hwndChild[i] = CreateWindow (szChildClass[i], NULL,
WS_CHILDWINDOW | WS_BORDER | WS_VISIBLE,
0, 0, 0, 0,
hwnd, (HMENU) i, hInstance, NULL) ;
}

cyChar = HIWORD (GetDialogBaseUnits ()) ;
SetTimer (hwnd, 1, 10, NULL) ;
return 0 ;

case WM_SIZE:
cxClient = LOWORD (lParam) ;
cyClient = HIWORD (lParam) ;

for (i = 0 ; i < 4 ; i++)
MoveWindow (hwndChild[i], (i % 2) * cxClient / 2,
(i > 1) * cyClient / 2,
cxClient / 2, cyClient / 2, TRUE) ;
return 0 ;

case WM_TIMER:
for (i = 0 ; i < 4 ; i++)
SendMessage (hwndChild[i], WM_TIMER, wParam, lParam) ;

return 0 ;

case WM_CHAR:
if (wParam == '\x1B')
DestroyWindow (hwnd) ;

return 0 ;

case WM_DESTROY:
KillTimer (hwnd, 1) ;
PostQuitMessage (0) ;
return 0 ;
}
return DefWindowProc (hwnd, message, wParam, lParam) ;
}


报错提示:

1>f:\code\mfc\20-编程竞赛问题四个窗口\20-编程竞赛问题四个窗口\4个窗口编程竞赛.cpp(120): error C2668: “sqrt”: 对重载函数的调用不明确
1> d:\program files\microsoft visual studio 10.0\vc\include\math.h(589): 可能是“long double sqrt(long double)”
1> d:\program files\microsoft visual studio 10.0\vc\include\math.h(541): 或 “float sqrt(float)”
1> d:\program files\microsoft visual studio 10.0\vc\include\math.h(127): 或 “double sqrt(double)”
1> 尝试匹配参数列表“(int)”时
1>f:\code\mfc\20-编程竞赛问题四个窗口\20-编程竞赛问题四个窗口\4个窗口编程竞赛.cpp(166): error C2664: “wsprintfW”: 不能将参数 2 从“const char [3]”转换为“LPCWSTR”
1> 与指向的类型无关;转换要求 reinterpret_cast、C 样式转换或函数样式转换
1>
1>生成失败。

问怎么改啊,还有->这个符号是干嘛的啊
...全文

相关推荐

Win32纯API实现的简单画图程序

【Win32纯API实现的简单画图程序】是一个基于Windows操作系统编程的项目,它利用了Windows API(应用程序接口)来构建一个基本的图形编辑器。

Claude16888

Win32/MFC皮肤化实战:从.skin资源到稳定UI改造

Windows桌面应用UI美化本质是窗口绘制机制的底层干预,其核心在于GDI+绘图重定向、窗口消息钩子(如WM_DRAWITEM/WM_NCPAINT)拦截与控件子类化技术。这类方案不依赖.NET或Qt,以纯C++实现跨Windows XP至Win11 LTSC兼容,具备低侵入、零业务逻辑修改的技术优势,广泛应用于工业软件、医疗设备及军工系统的遗留系统现代化升级。尤其适合需快速提升UI质感但受限于重构预算与运行环境约束的场景。本文聚焦.skin资源集成、Skin++/BCG引擎适配、MFC控件皮肤启用时机及

东予薏米

OpenSSL 1.1.1 32位静态库编译与集成实战指南

TLS 加密通信是互联网应用的基础保障,而 OpenSSL 作为最广泛使用的密码库,其版本与架构选择直接影响程序的安全性和兼容性。在 Windows 平台下,针对 32 位(x86)环境的旧系统或工业软件,开发者常需要将 OpenSSL 编译为静态库以简化部署、避免 DLL 冲突。静态链接将加密逻辑直接嵌入可执行文件,既规避了运行库依赖,也保证了版本隔离,特别适合工控上位机、银行辅助工具等存量项目。然而,静态库的编译并非一键完成,需要正确配置 Perl、NASM、VS 工具链,并处理 CRT 运行时库不一致

weixin_33981932

Win32 API多线程编程例程

【Win32 API多线程编程】是一种在Windows操作系统中实现并发执行任务的技术。通过创建多个线程,程序可以同时处理多个任务,提高系统效率。

singleman9691

Win32 多线程程序设计(pdf)

Win32 API提供了丰富的接口支持多线程编程,使得开发者能够充分利用多核处理器的潜力,提高程序的执行效率。

迷你苑
评论 2
收藏 已收藏
分享
返回顶部
cwhe_10
进程/线程/DLL 15,466 成员 49,169 内容