我想了很久不知那里了错,窗口不能正常显示出来~
我看了很久的教程跟我的代码差不多,就是不能显示出来,我是刚学VC++的,请大虾指点一下!
我用的编译软件C-FREE 系统XP
#include <windows.h>
#include <stdio.h>
LRESULT CALLBACK WinSunProc(
HWND hwnd, // handle to window
UINT uMsg, // message identifier
WPARAM wParam, // first message parameter
LPARAM lParam // second message parameter
);
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPorcInstance,LPSTR lpcmdLine,
int nShowCmd)
{
//*******************设计窗口***********************
WNDCLASS wndclass;
wndclass.cbClsExtra=0;
wndclass.cbWndExtra=0;
wndclass.hbrBackground=(HBRUSH)GetStockObject(DKGRAY_BRUSH);
wndclass.hCursor=LoadCursor(NULL,IDC_IBEAM);
wndclass.hIcon=LoadIcon(NULL,IDI_ERROR);
wndclass.style=CS_HREDRAW|CS_VREDRAW;
wndclass.hInstance=hInstance;
wndclass.lpfnWndProc=WinSunProc;
wndclass.lpszMenuName=NULL;
wndclass.lpszClassName="TC";
//************注册窗口和创造窗口*********************
RegisterClass(&wndclass);
HWND hwnd;
hwnd=CreateWindow("TC","现在正在学习VC++,制作窗口",WS_OVERLAPPEDWINDOW,
0,0,600,400,NULL,NULL,hInstance,NULL);
ShowWindow(hwnd,SW_MAXIMIZE);
//*******************从键盘或鼠标得到消息*********
MSG msg;
while(GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;
}
//*************输入设备的消息和响应**************
LRESULT CALLBACK WinSunProc(HWND hwnd,UINT uMsg,WPARAM wParam,LPARAM lparam)
{
switch(uMsg)
{
case WM_CHAR:
char szChar[20];
sprintf(szChar,"char is %d",wParam);
MessageBox(hwnd,szChar,"刚学不久vc++",MB_YESNO);
break;
case WM_LBUTTONDOWN:
MessageBox(hwnd,"mouse clicked","weixinOK",0);
HDC hdc;
hdc=GetDC(hwnd);
TextOut(hdc,0,50,"文字",strlen("看行不行"));
ReleaseDC(hwnd,hdc);
break;
case WM_PAINT:
HDC hDC;
PAINTSTRUCT ps;
hDC=BeginPaint(hwnd,&ps);
TextOut(hDC,0,0,"又一个",strlen("呵呵"));
EndPaint(hwnd,&ps);
break;
case WM_CLOSE:
if(IDYES==MessageBox(hwnd,"是否真的结束?","weixin",MB_YESNO))
{
DestroyWindow(hwnd);
}
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd,uMsg,0,0);
}
return 0;
}