📄 winmain.cpp
字号:
#include <windows.h>
#include <stdlib.h>
#include <string.h>
#define FLASE 0
#define TRUE 1
LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);
BOOL InitWindowsClass(HINSTANCE hInstance);
BOOL InitWindowsClass(HINSTANCE hInstance,int nCmdShow);
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow)
{
MSG Message;
if(!InitWindowsClass(hInstance))
return FLASE;
if(!InitWindowsClass(hInstance,nCmdShow))
return FLASE;
while(GetMessage(&Message,0,0,0))
{
TranslateMessage(&Message);
DispatchMessage(&Message);
}
return Message.wParam;
}
LRESULT CALLBACK WndProc(HWND hWnd,UINT iMessage,UINT wParam,LONG lParam)
{
static long nXChar,nYChar,nCaps;
HDC hDC;
TEXTMETRIC tm;
HFONT hF_black,hF_big;
short LnCount = 6;
char lpsz_1[] = "只要青春还在";
char lpsz_2[] = "我就不会悲哀";
char lpsz_3[] = "纵使黑夜吞噬了一切";
char lpsz_4[] = "太阳还可以重新回来";
char lpsz_5[] = "只要生命还在";
char lpsz_6[] = "我就不会悲哀";
//char lpsz_7[] = "纵使陷身茫茫沙漠里";
int X = 0,Y = 0;
SIZE size;
PAINTSTRUCT PtStr;
switch(iMessage)
{
case WM_PAINT:
hDC = BeginPaint(hWnd,&PtStr);
SetTextColor(hDC,RGB(255,0,0));
GetTextMetrics(hDC,&tm);
TextOut(hDC,X,Y,lpsz_1,strlen(lpsz_1));
Y = Y + tm.tmHeight + tm.tmExternalLeading;
hF_black = CreateFont
(
18,
0,
0,
0,
FW_SEMIBOLD,
0,
0,
0,
GB2312_CHARSET,
OUT_DEFAULT_PRECIS,
CLIP_DEFAULT_PRECIS,
DEFAULT_QUALITY,
DEFAULT_PITCH|FF_DONTCARE,
"中体字"
);
SetTextColor(hDC,RGB(0,255,0));
SelectObject(hDC,hF_black);
GetTextMetrics(hDC,&tm);
TextOut(hDC,X,Y,lpsz_2,strlen(lpsz_2));
Y = Y + tm.tmHeight + tm.tmExternalLeading;
GetTextExtentPoint32(hDC,lpsz_2,strlen(lpsz_2),&size);
SetTextColor(hDC,RGB(0,0,255));
TextOut(hDC,X,Y,lpsz_3,strlen(lpsz_3));
Y = Y + tm.tmHeight + tm.tmExternalLeading;
hF_big = CreateFont
(
30,
0,
0,
0,
FW_SEMIBOLD,
1,
1,
0,
GB2312_CHARSET,
OUT_DEFAULT_PRECIS,
CLIP_DEFAULT_PRECIS,
DEFAULT_QUALITY,
DEFAULT_PITCH|FF_DONTCARE,
"大号字"
);
SetTextColor(hDC,RGB(200,255,200));
SelectObject(hDC,hF_big);
Y = Y + tm.tmHeight + tm.tmExternalLeading;
TextOut(hDC,X,Y,lpsz_4,strlen(lpsz_4));
Y = Y + tm.tmHeight +10* tm.tmExternalLeading;
SetTextColor(hDC,RGB(100,100,100));
TextOut(hDC,X,Y,lpsz_5,strlen(lpsz_5));
GetTextExtentPoint32(hDC,lpsz_5,strlen(lpsz_5),&size);
X = X + size.cx;
TextOut(hDC,X+5,Y,lpsz_6,strlen(lpsz_6));
EndPaint(hWnd,&PtStr);
DeleteObject(hF_black);
DeleteObject(hF_big);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return(DefWindowProc(hWnd,iMessage,wParam,lParam));
}
return 0;
}
BOOL InitWindowsClass(HINSTANCE hInstance,int nCmdShow)
{
HWND hWnd;
hWnd = CreateWindow("Example the Text output",
"文本输出",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
0,
CW_USEDEFAULT,
0,
NULL,
NULL,
hInstance,
NULL);
if(!hWnd)
return FALSE;
ShowWindow(hWnd,nCmdShow);
UpdateWindow(hWnd);
return TRUE;
}
BOOL InitWindowsClass(HINSTANCE hInstance)
{
WNDCLASS WndClass;
WndClass.cbClsExtra = 0;
WndClass.cbWndExtra = 0;
WndClass.hbrBackground = (HBRUSH)(GetStockObject(WHITE_BRUSH));
WndClass.hCursor = LoadCursor(NULL,IDC_ARROW);
WndClass.hIcon = LoadIcon(NULL,"END");
WndClass.hInstance = hInstance;
WndClass.lpfnWndProc = WndProc;
WndClass.lpszClassName = "Example the Text output";
WndClass.lpszMenuName = NULL;
WndClass.style = CS_HREDRAW|CS_VREDRAW;
return RegisterClass(&WndClass);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -