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

visual4825 2005-08-19 09:45:31

//创建具有窗口的线程

#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.
...全文
90 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
DentistryDoctor 2005-08-19
  • 打赏
  • 举报
回复
这与源代码没关系。
可能是进行尚在运行或是被其它什么占用,所以造成链接器无法写文件。
flyelf 2005-08-19
  • 打赏
  • 举报
回复
打开任务管理器,把thread1.ex的进程结束,然后编译

15,471

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 进程/线程/DLL
社区管理员
  • 进程/线程/DLL社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧