创建具有窗口的线程出现错误,哪位帮看下?

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

//创建具有窗口的线程

#include <windows.h>
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
DWORD WINAPI ThreadFunc(LPVOID lpParameter);

int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
// TODO: Place code here.
    WNDCLASSEX wndclass;
static char szAppName[] = "hello, vc!";

//////////////////////////////////////////////////
wndclass.cbSize = sizeof (wndclass);
wndclass.style = CS_HREDRAW | CS_VREDRAW;
wndclass.lpfnWndProc = WndProc;
wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = 0;
wndclass.hInstance = hInstance;
wndclass.hIcon = LoadIcon(hInstance, IDI_APPLICATION);
wndclass.hCursor = LoadCursor(NULL, IDI_APPLICATION);
wndclass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
wndclass.lpszMenuName = NULL;
wndclass.lpszClassName = szAppName;
wndclass.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
////////////////////////////////////////////////////

RegisterClassEx(&wndclass);

DWORD dw;
HANDLE handle;
handle = CreateThread(NULL, 0, ThreadFunc, (LPVOID)&wndclass, 0, &dw);
Sleep(3000);

CloseHandle(handle);

return 0;
}

DWORD WINAPI ThreadFunc(void *p)
{
HWND hWnd;
MSG msg;
WNDCLASS *pw = (WNDCLASS*)p;

hWnd = CreateWindow(pw->lpszClassName,
"my lover program",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
NULL,
NULL,
pw->hInstance,
NULL);

ShowWindow(hWnd, SW_SHOWNORMAL);
UpdateWindow(hWnd);

while (GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}

return msg.wParam;
}

LRESULT CALLBACK WndProc(HWND hWnd,
UINT iMessage,
WPARAM wParam,
LPARAM lParam)
{
HDC dc;
PAINTSTRUCT ps;
RECT rect;

switch(iMessage)
{
case WM_PAINT:
dc = BeginPaint(hWnd, &ps);
GetClientRect(hWnd, &rect);
DrawText(dc, "hello, every day!", -1, &rect, DT_SINGLELINE|DT_CENTER|DT_VCENTER);
EndPaint(hWnd, &ps);
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd, iMessage, wParam, lParam);
}

return (0L);
}
哪位帮我看下,哪里出了问题?谢谢了.
错误:cannot open Debug/thread1.exe for writing
Error executing link.exe.
...全文

相关推荐

评论 2
收藏 已收藏
分享
返回顶部
visual4825
进程/线程/DLL 15,465 成员 49,169 内容