//ËïöÎMFCÉîÈëÏê½â MFC¿ò¼Ü·â×°ÑÝʾ
#include <windows.h>
#include <windowsx.h>
#include <stdio.h>
LRESULT CALLBACK WindowProc(
HWND hwnd, // handle to window
UINT uMsg, // message identifier
WPARAM wParam, // first message parameter
LPARAM lParam); // second message parameter
class CWnd
{
public:
BOOL CreateEx(
DWORD dwExStyle, // extended window style
LPCTSTR lpClassName, // registered class name
LPCTSTR lpWindowName, // 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, // menu handle or child identifier
HINSTANCE hInstance, // handle to application instance
LPVOID lpParam); // window-creation data
BOOL ShowWindow(int nCmdShow); // show state
BOOL UpdateWindow();
public:
HWND m_hWnd;
};
BOOL CWnd::CreateEx(
DWORD dwExStyle, // extended window style
LPCTSTR lpClassName, // registered class name
LPCTSTR lpWindowName, // 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, // menu handle or child identifier
HINSTANCE hInstance, // handle to application instance
LPVOID lpParam) // window-creation data
{
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, // command line
int nCmdShow) // show state
{
WNDCLASS wndclass; //ÏÈÉè¼Æ´°¿ÚÀà
wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = 0;
wndclass.hbrBackground = (HBRUSH)GetStockObject(DKGRAY_BRUSH);
wndclass.hCursor = LoadCursor(NULL,IDC_ARROW);
wndclass.hIcon = LoadIcon(NULL,IDI_APPLICATION);
wndclass.hInstance = hInstance;
wndclass.lpfnWndProc = WindowProc;
wndclass.lpszClassName = "RPG";
wndclass.lpszMenuName = 0;
wndclass.style = CS_VREDRAW | CS_HREDRAW;
RegisterClass(&wndclass); ///×¢ÒâÏȽ¨Á¢ÔÙ×¢²á°º
CWnd wnd;
wnd.CreateEx(NULL,"RPG","RPG",WS_OVERLAPPEDWINDOW,0,0,800,600,NULL,NULL,hInstance,NULL);
wnd.ShowWindow(SW_SHOWNORMAL);
wnd.UpdateWindow();
MSG msg; //ÏûϢѭ»·
while(GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;
}
LRESULT CALLBACK WindowProc(
HWND hwnd, // handle to window
UINT uMsg, // message identifier
WPARAM wParam, // first message parameter
LPARAM lParam) // second message parameter
{
HDC hdc;
switch(uMsg)
{
case WM_LBUTTONDOWN:
MessageBox(hwnd,"Äú°´ÏÂÁËÊó±ê×ó¼ü°º","×¢Òâ",MB_OK);
hdc = GetDC(hwnd);
TextOut(hdc,0,0,"¸ÐлÄú¶ÔVC++ÉîÈëÏê½âµÄÖ§³Ö°º",strlen("¸ÐлÄú¶ÔVC++ÉîÈëÏê½âµÄÖ§³Ö°º"));
ReleaseDC(hwnd,hdc);
break;
case WM_CHAR:
char szChar[20];
sprintf(szChar,"Char is %d",wParam);
MessageBox(hwnd,szChar,"×¢Òâ",MB_OK);
break;
case WM_PAINT:
PAINTSTRUCT ps;
hdc = BeginPaint(hwnd,&ps);
TextOut(hdc,0,0,"Õâ¸öÊÇÖØ»æµÎŶ",strlen("Õâ¸öÊÇÖØ»æµÎŶ"));
EndPaint(hwnd,&ps);
break;
case WM_CLOSE: //Õâ¸öcaseÓëϱߵÄdestroyÕâ¸öcase²»ÒªÅª´íÁË£¬·ñÔò´°¿Ú²»³öÏÖ£¬µ«ÔÚÈÎÎñ¹ÜÀíÆ÷ÖÐÔËÐÐ
if(IDYES == MessageBox(hwnd,"ÄúÕæµÄÒªÍ˳öô?","×¢Òâ",MB_YESNO))
{
DestroyWindow(hwnd);
}
break;
case WM_DESTROY:
PostQuitMessage(0);
//////////////////////////////////////////?????????????????????
break;
default:
return DefWindowProc(hwnd,uMsg,wParam,lParam); // ±ðÍü¼ÇÁËreturn
}
return 0;
}
|