|  | 
 
| 为什么程序会在后台运行啊,实在是想不通,望前辈能赐教,不能嫌问题简单啊,本人刚开始学VC,源码如下: 
 
 #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
 );
 
 
 
 class CWnd
 {
 public:
 CWnd();
 BOOL CreateEx(
 DWORD dwExStyle,      // extended window style
 LPCTSTR lpClassName,  // pointer to registered class name
 LPCTSTR lpWindowName, // pointer to window name
 DWORD dwStyle,        // window style
 int x,                // horizontal position of window
 int y,                // vertical position of window
 int nWidth,           // window width
 int nHeight,          // window height
 HWND hWndParent,      // handle to parent or owner window
 HMENU hMenu,          // handle to menu, or child-window identifier
 HINSTANCE hInstance,  // handle to application instance
 LPVOID lpParam);      // pointer to window-creation data
 
 BOOL  ShowWindow(int nCmdShow); // show state of window
 BOOL  UpdateWindow();
 
 public:
 HWND m_hWnd;
 
 };
 
 CWnd::CWnd()
 {
 m_hWnd=NULL;
 }
 
 BOOL CWnd::CreateEx(
 DWORD dwExStyle,      // extended window style
 LPCTSTR lpClassName,  // pointer to registered class name
 LPCTSTR lpWindowName, // pointer to window name
 DWORD dwStyle,        // window style
 int x,                // horizontal position of window
 int y,                // vertical position of window
 int nWidth,           // window width
 int nHeight,          // window height
 HWND hWndParent,      // handle to parent or owner window
 HMENU hMenu,          // handle to menu, or child-window identifier
 HINSTANCE hInstance,  // handle to application instance
 LPVOID lpParam)
 {
 m_hWnd=::CreateWindowEx(dwExStyle,lpClassName,lpWindowName,dwStyle,x,y,
 nWidth,nHeight,hWndParent,hMenu,hInstance,lpParam);
 if(m_hWnd!=NULL)
 return TRUE;
 else
 return FALSE;
 
 }
 
 BOOL CWnd::ShowWindow(int nCmdShow)
 {
 return ::ShowWindow(m_hWnd,nCmdShow);
 
 }
 
 BOOL CWnd::UpdateWindow()
 {
 return ::UpdateWindow(m_hWnd);
 }
 
 int WINAPI WinMain(
 HINSTANCE hInstance,  // handle to current instance
 HINSTANCE hPrevInstance,  // handle to previous instance
 LPSTR lpCmdLine,      // pointer to command line
 int nCmdShow          // show state of window
 )
 {
 WNDCLASS   wndcls;
 wndcls.cbClsExtra=0;
 wndcls.cbWndExtra=0;
 wndcls.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);
 wndcls.hCursor=LoadCursor(NULL,IDC_CROSS);
 wndcls.hIcon=LoadIcon(NULL,IDI_ERROR);
 wndcls.lpfnWndProc=WinSunProc;
 wndcls.lpszClassName="sun2006";
 wndcls.lpszMenuName=NULL;
 wndcls.style=CS_VREDRAW | CS_HREDRAW;
 RegisterClass(&wndcls);
 CWnd cwnd;
 cwnd.CreateEx(NULL,"sun2006","weixin",WS_OVERLAPPEDWINDOW,0,0,
 800,600,NULL,NULL,hInstance,NULL);
 
 cwnd.ShowWindow(SW_SHOWNORMAL);
 
 cwnd.UpdateWindow();
 
 MSG msg;
 while(GetMessage(&msg,NULL,0,0))
 {
 TranslateMessage(&msg);
 DispatchMessage(&msg);
 }
 
 return 0;
 }
 
 LRESULT CALLBACK WinSunProc(
 HWND hwnd,      // handle to window
 UINT uMsg,      // message identifier
 WPARAM wParam,  // first message parameter
 LPARAM lParam   // second message parameter
 )
 {
 switch(uMsg)
 {
 case WM_CLOSE:
 if(IDYES==::MessageBox(hwnd,"真的要退出吗?","警告",MB_YESNO))
 {
 ::DestroyWindow(hwnd);
 }
 
 break;
 case WM_DESTROY:
 ::PostQuitMessage(0);
 break;
 default:
 return ::DefWindowProc(hwnd,uMsg,wParam,lParam);
 
 
 }
 return 0;
 }
 | 
 |