popfond.c

来自「C#一个实例源代码」· C语言 代码 · 共 49 行

C
49
字号
#include <windows.h>
#include <commdlg.h>
  
static LOGFONT logfont;
static HFONT   hFont;

void PopFontInitialize(HWND hwndEdit)
{
	GetObject(GetStockObject(SYSTEM_FONT),sizeof(LOGFONT),(PTSTR)&logfont);

	hFont=CreateFontIndirect(&logfont);
	SendMessage(hwndEdit,WM_SETFONT,(WPARAM)hFont,0);
}

void PopFontChooseFont(HWND hwnd)
{
	CHOOSEFONT cf;
	cf.lStructSize=sizeof(CHOOSEFONT);
	cf.hwndOwner=hwnd;
	cf.hDC=NULL;
	cf.lpLogFont=&logfont;
	cf.iPointSize=0;
	cf.Flags=CF_INITTOLOGFONTSTRUCT|CF_SCREENFONTS|CF_EFFECTS;
	cf.rgbColors=0;
	cf.lCustData=0;
	cf.lpfnHook=0;
	cf.lpTemplateName=0;
	cf.hInstance=0;
	cf.lpszStyle=0;
	cf.nFontType=0;
	cf.nSizeMax=0;
	cf.nSizeMin=0;
	return ChooseFont(&cf);
}

void PopFontSetFont(HWND hwndEdit)
{
	HFONT hFontNew;
	RECT  rect;

	hFontNew=CreateFontIndirect(&logfont);
	SendMessage(hwndEdit,WM_SETFONT,(WPARAM)hFontNew,0);
	DeleteObject(hFont);
	GetClientRect(hwndEdit,&rect);
	InvalidateRect(hwndEdit,&rect,1);
}


⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?