创建具有窗口的线程出现错误,哪位帮看下?
//创建具有窗口的线程
#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.