?? mfcexp1_2.cpp
字號:
//設計Windows程序必須包含的頭文件-------------------------------------------------
#include<windows.h>
//定義全局變量--------------------------------------------------------------------------------
HINSTANCE hInst;
HWND hWnd;
MSG msg;
char lpszClassName[]="窗口";
char*ShowText;
//定義函數--------------------------------------------------------------------------------------
ATOM MyRegisterClass(HINSTANCE hInstance);//注冊窗口類函數
BOOL Create(HINSTANCE, int); //程序實例初始化函數
int Run(); //消息循環函數
LRESULT CALLBACK WndProc(HWND, UINT,
WPARAM, LPARAM); //窗口函數
//主函數-----------------------------------------------------------------------------------------
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
MyRegisterClass(hInstance); //定義和注冊窗口類
Create(hInstance, nCmdShow); //創建窗口
ShowWindow(hWnd, nCmdShow); //顯示窗口
UpdateWindow(hWnd); //更新屏幕顯示
return Run(); //消息循環
}
//注冊窗口類的函數--------------------------------------------------------------------------
ATOM MyRegisterClass(HINSTANCE hInstance)
{
WNDCLASS wc;
wc.style=0;
wc.lpfnWndProc=WndProc;
wc.cbClsExtra=0;
wc.cbWndExtra=0;
wc.hInstance=hInstance;
wc.hIcon=LoadIcon(NULL,IDI_APPLICATION);
wc.hCursor=LoadCursor(NULL,IDC_ARROW);
wc.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);
wc.lpszMenuName=NULL;
wc.lpszClassName=lpszClassName;
return RegisterClass(&wc);
}
//創建窗口的函數-----------------------------------------------------------------------------
BOOL Create(HINSTANCE hInstance, int nCmdShow)
{
hWnd=CreateWindow( lpszClassName,
"Windows",
WS_OVERLAPPEDWINDOW,
120,50,800,600,
NULL,
NULL,
hInstance,
NULL);
return TRUE;
}
//消息循環的函數-----------------------------------------------------------------------------
int Run( )
{
while (GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
//窗口函數--------------------------------------------------------------------------------------
LRESULT CALLBACK WndProc(HWND hWnd, UINT message,
WPARAM wParam, LPARAM lParam)
{
PAINTSTRUCT ps;
HDC hdc;
switch (message)
{
case WM_LBUTTONDOWN:
ShowText="Hello!";
InvalidateRect(hWnd,NULL,1);
break;
case WM_PAINT:
hdc = BeginPaint(hWnd, &ps);
TextOut(hdc,50,50,ShowText,6);
EndPaint(hWnd, &ps);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}
//--------------------------------------------------------------------------------------------------
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -