新学MFC,按照书上程序敲的,vs2010编译成功,exe文件在后台运行,但不显示窗口
#include<windows.h>
LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);
int WINAPI WinMain(HINSTANCE hInstance,
HINSTANCE preInstance,
LPSTR ipCmdShow,
int nCmdShow)
{
HWND hwnd1;
HWND hwnd2;
HWND hwnd3;
MSG msg;
/*窗口1*/
char lpszClassName1[]="窗口1";//窗口类名
//char lpszTitle[]="My_Windows"
//窗口标题
WNDCLASS wc1;
wc1.style=0;//窗口类型为缺省类型
wc1.lpfnWndProc=WndProc;//定义窗口处理函数
wc1.cbClsExtra=0;//窗口类无扩展
wc1.cbWndExtra=0;//窗口实例无扩展
wc1.hInstance=hInstance;//当前实例句柄
wc1.hIcon=LoadIcon(NULL,IDI_APPLICATION);//窗口的最小化图标为缺省图标
wc1.hCursor=LoadCursor(NULL,IDC_ARROW);//窗口采用箭头光标
wc1.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);//窗口背景为白色
wc1.lpszMenuName=NULL;//窗口无菜单
wc1.lpszClassName=lpszClassName1;//窗口类名为窗口
RegisterClass(&wc1);
/*窗口2*/
char lpszClassName2[]="窗口2";//窗口类名
//char lpszTitle[]="My_Windows"
//窗口标题
WNDCLASS wc2;
wc2.style=0;//窗口类型为缺省类型
wc2.lpfnWndProc=WndProc;//定义窗口处理函数
wc2.cbClsExtra=0;//窗口类无扩展
wc2.cbWndExtra=0;//窗口实例无扩展
wc2.hInstance=hInstance;//当前实例句柄
wc2.hIcon=LoadIcon(NULL,IDI_APPLICATION);//窗口的最小化图标为缺省图标
wc2.hCursor=LoadCursor(NULL,IDC_ARROW);//窗口采用箭头光标
wc2.hbrBackground=(HBRUSH)GetStockObject(GRAY_BRUSH);//窗口背景为白色
wc2.lpszMenuName=NULL;//窗口无菜单
wc2.lpszClassName=lpszClassName2;//窗口类名为窗口
RegisterClass(&wc2);
hwnd1=CreateWindow(lpszClassName1,
"Windows1",
WS_OVERLAPPEDWINDOW,
120,50,700,500,
NULL,
NULL,
hInstance,
NULL);
hwnd2=CreateWindow(lpszClassName2,
"Windows2",
WS_OVERLAPPEDWINDOW,
150,80,800,600,
NULL,
NULL,
hInstance,
NULL);
hwnd3=CreateWindow(lpszClassName1,
"Windows3",
WS_OVERLAPPEDWINDOW,
200,130,500,300,
NULL,
NULL,
hInstance,
NULL);
ShowWindow(hwnd1,nCmdShow);//显示窗口
UpdateWindow(hwnd1);//绘制用户区
ShowWindow(hwnd2,nCmdShow);//显示窗口
UpdateWindow(hwnd2);//绘制用户区
ShowWindow(hwnd3,nCmdShow);//显示窗口
UpdateWindow(hwnd3);//绘制用户区
while(GetMessage(&msg,NULL,0,0))
/*--------------消息循环------------*/
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
/*------------窗口函数-----------*/
LRESULT CALLBACK WndProc(HWND hwnd,//哪一个窗口发过来的消息
UINT message,//什么消息
WPARAM wParam,//字参数
LPARAM lParam)//长字参数
{
switch(message)
{
case WM_LBUTTONDOWN:{MessageBeep(0);}break;
case WM_DESTROY:PostQuitMessage(0);break;
default:DefWindowProc(hwnd,message,wParam,lParam);//缺省时采用系统消息缺省处理函数
}
return 0;
}