VS2010求助
我刚开始学MFC,写了一个简单的MFC,程序编译没有错误,可是为什么看不到显示界面呢?应该怎样设置,才能看到运行结果?#include"windows.h"
#include"stdafx.h"
#include<cstdlib>
LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);
int WINAPI WinMain(HINSTANCE,HINSTANCE,LPSTR,int);
int WINAPI WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdline,
int nCmdShow)
{
WNDCLASS wcApp;
MSG msg;
HWND ghWnd=NULL;
char *szAppName="Windows Api Application";
char * szAppTitle="Windows API 窗口程序";
wcApp.style=CS_HREDRAW;
wcApp.lpfnWndProc=WndProc;
wcApp.cbClsExtra=0;
wcApp.hInstance=hInstance;
wcApp.hIcon=LoadIcon(NULL,IDI_WINLOGO);
wcApp.hCursor=LoadCursor(NULL,IDC_ARROW);
wcApp.hbrBackground=(HBRUSH)COLOR_ACTIVEBORDER;
wcApp.lpszMenuName=NULL;
wcApp.lpszClassName=szAppName;
RegisterClass(&wcApp);
ghWnd=CreateWindow(szAppName,
szAppTitle,
WS_OVERLAPPEDWINDOW,
100,
100,
350,
300,
NULL,
NULL,
hInstance,
NULL);
if(NULL==ghWnd)
return 0;
ShowWindow(ghWnd,nCmdShow);
UpdateWindow(ghWnd);
while(GetMessage(&msg,NULL,0,0));
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
LRESULT CALLBACK WndProc(HWND hwnd,
UINT message,
WPARAM wParam,
LPARAM lParam)
{
char* msgCreate="收到WM_CREATE消息,建立窗口";
char* msgDestroy="收到WM_DESTROUY消息,窗口关闭";
char* msgCaption="收到消息";
char*msgLBTN="鼠标左键按下,收到WM_LBUTTONDOWN消息";
switch(message)
{
case WM_CREATE:
MessageBox(GetFocus(),msgCreate,msgCaption,MB_OK|MB_ICONEXCLAMATION);
break;
case WM_LBUTTONDOWN:
MessageBox(GetFocus(),msgLBTN,msgCaption,MB_OK|MB_ICONINFORMATION);
break;
case WM_DESTROY:
MessageBox(GetFocus(),msgDestroy,msgCaption,MB_OK|MB_ICONHAND);
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd,message,wParam,lParam);
}
system("pause");
return FALSE;
} WNDCLASS wcApp = { 0 };
or
WNDCLASS wcApp;
memset(&wcApp, 0, sizeof(wcApp));
还有你实在太强大了,往WndProc里放阻塞的system()... 还有MessageBox()...,尤其是你那个system(),放得位置太销魂了,程序收到WM_CREATE之后就会阻塞在那里了。。。
用好调试功能。。。 不用调试也可以用 OutputDebugString() 谢谢,受益匪浅
页:
[1]