一个VC程序,我也调不出错误在哪,希望高手指点!!!
#include <windows.h>LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);
DWORD WINAPI MyThread(LPVOID lpParameter);
int APIENTRY WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow)
{
WNDCLASSEX wndclass;
static char szAppName[] = "Hello Everyone";
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,IDC_ARROW);
wndclass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
wndclass.lpszMenuName = NULL;
wndclass.hIconSm = LoadIcon(NULL,IDI_APPLICATION);
RegisterClassEx(&wndclass);
DWORD dw;
HANDLE handle;
handle = CreateThread(NULL,0,MyThread,(LPVOID)&wndclass,0,&dw);
CloseHandle(handle);
::MyThread(&wndclass);
return 0;
}
DWORD WINAPI MyThread(LPVOID lpParameter)
{
HWND hWnd;
MSG msg;
WNDCLASSEX * pw = (WNDCLASSEX *) lpParameter;
hWnd = CreateWindow(pw->lpszClassName,"My Hello Program",WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,NULL,NULL,pw->hInstance,NULL);
ShowWindow(hWnd,SW_SHOWNORMAL);
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,Everyone",-1,&rect,DT_SINGLELINE|DT_CENTER|DT_VCENTER);
EndPaint(hWnd,&ps);
return 0;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd,iMessage,wParam,lParam);
}
return (0);
}
求指点。