📄 truetype.c
字号:
// Borland C++ - (C) Copyright 1991, 1992 by Borland International
/*******************************************************************
program - TrueType.c
purpose - a Windows program to demo True Type fonts.
This program shows off two features of Windows 3.1: True Type
fonts, and common dialogs.
True Type fonts are scalable fonts supplied by the system. This
program demonstrates resizing and rotation of True Type characters
within a window, and allows the user to select the True Type font to
be used.
The dialog used in selecting the font is a Windows 3.1 "common
dialog." By including commdlg.h, a series of common dialogs becomes
available to the program. To invoke the font dialog, a CHOOSEFONTS
structure is filled out, and ChooseFont() is called. This system
routine handles all the dialog processing needed to select a font via
a dialog box.
In contrast, the About Box dialog herein is programmed in the
normal manner. A dialog process is provided, and a thunk for it is
created explicitly; Windows provides no automated handling for this
program-specific dialog.
Change font attributes through the menu selections. Resize the
window to see the text resized; the text "fan" will always reach the
bottom and the right side of the window.
*******************************************************************/
#define STRICT
#include <windows.h>
#include <string.h>
#include <math.h>
#include <commdlg.h>
#include "TrueType.h"
// data initialized by first instance
typedef struct tagSETUPDATA
{
char szAppName[10]; // name of application
} SETUPDATA;
SETUPDATA SetUpData;
// Data that can be referenced throughout the
// program but not passed to other instances
HINSTANCE hInst; // hInstance of application
HWND hwnd; // hWnd of main window
HANDLE hdlg; // handle of dialog resource
DLGPROC lpDlgProc; // ptr to proc for dialog box
HWND hDlgBox; // handle of dialog box
LOGFONT MainFontRec; // logical font records,...
LOGFONT CornerFontRec; // ...which store font data...
LOGFONT BorlandFontRec; // ...for different fonts.
COLORREF FanColor[10]; // color array for "fan" of text
BOOL ShadowAll; // TRUE iff fan text gets shadows
BOOL ShowAlignmentMarks; // TRUE iff we show baselines of fan
#define ROUND(x) (floor(x + .5))
#define SQR(x) (pow(x,2))
#define TITLE_LENGTH 30
LPCSTR ArcText = "TrueType"; // text seen along arc of fan
const char* FanText = "Borland C++ for Windows"; // text for leaves of fan
const char* BorlandText = "Borland"; // text for lower right window corner
const int Radius = 100; // radius of fan "hub"
const float Deg2Rad = M_PI / 18; // conversion factor, degrees->radians
// function prototypes
int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpszCmdLine, int cmdShow);
void Init(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpszCmdLine, int cmdShow);
void InitFirst(HINSTANCE hInstance);
void InitAdded(HINSTANCE hPrevInstance);
void InitEvery(HINSTANCE hInstance, int cmdShow);
LRESULT CALLBACK WndProc(HWND hWnd, UINT message,
WPARAM wParam, LPARAM lParam);
BOOL CALLBACK DlgBoxProc(HWND hDlg, UINT message,
WPARAM wParam, LPARAM lParam);
void wmCreate(void);
void cmAbout(void);
void cmAlignmentMarks(void);
void cmFonts(HWND);
void cmShadows(void);
void DoPaint(void);
void cm(void);
//*******************************************************************
// WinMain - TrueType main
//
// parameters:
// hInstance - The instance of this instance of this
// application.
// hPrevInstance - The instance of the previous instance
// of this application. This will be 0
// if this is the first instance.
// lpszCmdLine - A long pointer to the command line that
// started this application.
// cmdShow - Indicates how the window is to be shown
// initially. ie. SW_SHOWNORMAL, SW_HIDE,
// SW_MIMIMIZE.
//
// returns:
// wParam from last message.
//
//*******************************************************************
int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpszCmdLine, int cmdShow)
{
MSG msg;
// Go init this application.
Init(hInstance, hPrevInstance, lpszCmdLine, cmdShow);
// Get and dispatch messages for this applicaton.
while (GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
} // while
return(msg.wParam);
} // end of WinMain()
//*******************************************************************
// Init - init the TrueType demo application
//
// parameters:
// hInstance - The instance of this instance of this
// application.
// hPrevInstance - The instance of the previous instance
// of this application. This will be 0
// if this is the first instance.
// lpszCmdLine - A long pointer to the command line that
// started this application.
// cmdShow - Indicates how the window is to be shown
// initially. ie. SW_SHOWNORMAL, SW_HIDE,
// SW_MIMIMIZE.
//
//*******************************************************************
#pragma argsused
void Init(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpszCmdLine, int cmdShow)
{
if (!hPrevInstance) // if no prev instance, this is first
InitFirst(hInstance);
else // this is not first instance
InitAdded(hPrevInstance);
InitEvery(hInstance, cmdShow); // init for all instances
} // end of Init()
//*******************************************************************
// InitFirst - done only for first instance of TrueType demo
//
// parameters:
// hInstance - The instance of this instance of this
// application.
//
//*******************************************************************
void InitFirst(HINSTANCE hInstance)
{
WNDCLASS wcTTFClass;
// Get string from resource with application name.
LoadString(hInstance, IDS_NAME, (LPSTR) SetUpData.szAppName, 10);
// Define the window class for this application.
wcTTFClass.style = CS_HREDRAW | CS_VREDRAW;
wcTTFClass.lpfnWndProc = WndProc;
wcTTFClass.cbClsExtra = 0;
wcTTFClass.cbWndExtra = 0;
wcTTFClass.hInstance = hInstance;
wcTTFClass.hIcon = LoadIcon(hInstance, SetUpData.szAppName);
wcTTFClass.hCursor = LoadCursor(NULL, IDC_ARROW);
wcTTFClass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
wcTTFClass.lpszClassName = SetUpData.szAppName;
wcTTFClass.lpszMenuName = SetUpData.szAppName;
// Register the class
RegisterClass(&wcTTFClass);
} // end of InitFirst()
//*******************************************************************
// InitAdded - done only for added instances of TrueType demo
//
// parameters:
// hPrevInstance - The instance of the previous instance
// of this application.
//
//*******************************************************************
#pragma argsused
void InitAdded(HINSTANCE hPrevInstance)
{
// get the results of the initialization of first instance
GetInstanceData(hPrevInstance, (BYTE*) &SetUpData, sizeof(SETUPDATA));
} // end of InitAdded()
//*******************************************************************
// InitEvery - done for every instance of TrueType demo program
//
// parameters:
// hInstance - The instance of this instance of this
// application.
// cmdShow - Indicates how the window is to be shown
// initially. ie. SW_SHOWNORMAL, SW_HIDE,
// SW_MIMIMIZE.
//
//*******************************************************************
#pragma argsused
void InitEvery(HINSTANCE hInstance, int cmdShow)
{
char title[TITLE_LENGTH+1];
hInst = hInstance; // save for use by window procs
// fetch in the window title from the stringtable resource
LoadString(hInstance, IDS_TITLE, (LPSTR)title, TITLE_LENGTH);
// Create applications main window.
hwnd = CreateWindow(SetUpData.szAppName, // window class name
(LPSTR)title, // window title
WS_OVERLAPPEDWINDOW, // window style
CW_USEDEFAULT, // x etc.: use defaults
CW_USEDEFAULT, // y
CW_USEDEFAULT, // cx
CW_USEDEFAULT, // cy
NULL, // no parent for this window
NULL, // use the class menu
hInstance, // who created this window
NULL // no parms to pass on
);
ShowWindow(hwnd, cmdShow);
UpdateWindow(hwnd);
} // end of InitEvery()
//*******************************************************************
// WndProc - handles messages for this application
//
// parameters:
// hWnd - The window handle for this message
// message - The message number
// wParam - The WPARAM parameter for this message
// lParam - The LPARAM parameter for this message
//
// returns:
// depends on message.
//
//*******************************************************************
LRESULT CALLBACK WndProc(HWND hWnd, UINT message,
WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_CREATE:
wmCreate();
break;
case WM_COMMAND:
switch (wParam)
{
case CM_ABOUT:
cmAbout();
break;
case CM_EXIT:
// Tell windows to destroy our window.
DestroyWindow(hWnd);
break;
case CM_ALIGNMENTMARKS:
cmAlignmentMarks();
break;
case CM_FONTS:
cmFonts(hWnd);
break;
case CM_SHADOWS:
cmShadows();
break;
default:
break;
} // switch wParam
break;
case WM_PAINT:
DoPaint();
break;
case WM_GETMINMAXINFO:
// Limit the minimum size of the window to 300x300,
// so the fonts don't get too small
((POINT far *)lParam)[3].x = 300;
((POINT far *)lParam)[3].y = 300;
break;
case WM_DESTROY:
// This is the end if we were closed by a DestroyWindow call.
PostQuitMessage(0);
break;
default:
return(DefWindowProc(hWnd, message, wParam, lParam));
} // switch message
return(0L);
} // end of WndProc()
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -