|
Why does the program run in the background? I can't figure it out. I hope my predecessors can enlighten me. Don't think the problem is simple. I just started learning 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, "Do you really want to exit?", "Warning", MB_YESNO))
{
:: DestroyWindow (hwnd);
}
Ranch
break;
case WM_DESTROY:
:: PostQuitMessage (0);
break;
default:
return :: DefWindowProc (hwnd, uMsg, wParam, lParam);
Ranch
}
return 0;
} |
|