|
|
Microsoft Windows NT Build 297 06-28-1992
/**************************************************************************\
* demownd.c -- module for the window with the test font.
* Includes the window procedure and an initialization routine.
*
* store the handle to the test font in the extra bytes of this window.
*
\**************************************************************************/
#include <windows.h>
#include <string.h>
#include "ntfonts.h"
#define GRIDCOLOR PALETTEINDEX (3)
#define TICKSPACE 10
int initDemo(HWND hwndMain)
{
WNDCLASS wc;
wc.style = CS_VREDRAW | CS_HREDRAW;
wc.lpfnWndProc = (WNDPROC)DemoWndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInst;
wc.hIcon = LoadIcon(hInst, "ntfontsIcon");
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = NULL;
wc.lpszMenuName = NULL;
wc.lpszClassName = "Demo";
if (!RegisterClass(&wc)) return (FALSE);
hwndDemo = CreateWindow(
"Demo",
"TextOut()",
WS_CHILD | WS_CLIPSIBLINGS | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_VISIBLE |
WS_CAPTION | WS_SYSMENU | WS_THICKFRAME,
CHILDLEFT(2),
CHILDTOP,
GetSystemMetrics (SM_CXFULLSCREEN)/3 - 10,
GetSystemMetrics (SM_CYFULLSCREEN)/3,
hwndMain, NULL, hInst, NULL);
if (!hwndDemo) return (FALSE);
return TRUE;
}
/**************************************************************************\
*
* function: DemoWndProc()
*
* input parameters: normal window procedure parameters.
*
* global variables:
* allglyphsGlobal - TRUE, then paint all of the glyphs.
* mapperflagsGlobal - input to SetMapperFlags().
\**************************************************************************/
LRESULT DemoWndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
static HANDLE hPenGrid;
static LPLOGFONT lplf;
static LPTEXTMETRIC lptm;
static HFONT hfont;
switch (message) {
/**********************************************************************\
* WMU_DEMOTOLF
*
* lParam - pointer to LOGFONT structure.
*
* User message. Fill up the demo LOGFONT from the HFONT
* in the extra bytes.
\**********************************************************************/
case WMU_DEMOTOLF: {
lplf = (LPLOGFONT) lParam;
hfont = (HFONT) GetWindowLong (hwnd, GWL_USERDATA);
GetObject (hfont, sizeof(LOGFONT), lplf);
} return 0;
/**********************************************************************\
* WMU_LFTODEMO
*
* lParam - pointer to LOGFONT structure.
*
* User message. Use the input LOGFONT structure to create a new
* font for this window. Store the new font in the HFONT extra bytes.
\**********************************************************************/
case WMU_LFTODEMO: {
lplf = (LPLOGFONT) lParam;
/* Get and delete the last font placed in this window. */
hfont = (HFONT) GetWindowLong (hwnd, GWL_USERDATA);
DeleteObject (hfont);
/* Create a new logical font and set it into the windows extra bytes. */
hfont = CreateFontIndirect (lplf);
SetWindowLong (hwnd, GWL_USERDATA, (LONG) hfont);
InvalidateRect (hwnd, NULL, TRUE);
} return 0;
/**********************************************************************\
* WMU_DEMOTOTM
*
* lParam - pointer to TEXTMETRIC structure.
*
* User message. Fill up the TEXTMETRIC from the HFONT
* in the extra bytes.
\**********************************************************************/
case WMU_DEMOTOTM: {
HDC hdc;
lptm = (LPTEXTMETRIC) lParam;
hfont = (HFONT) GetWindowLong (hwnd, GWL_USERDATA);
hdc = GetDC (hwnd);
SelectObject (hdc,hfont);
GetTextMetrics (hdc, lptm);
ReleaseDC (hwnd, hdc);
} return 0;
/**********************************************************************\
* WM_CREATE
*
* Create pens for drawing with later.
\**********************************************************************/
case WM_CREATE:
hPenGrid = CreatePen (PS_SOLID, 1, GRIDCOLOR);
SetWindowLong (hwnd, GWL_USERDATA, (LONG) GetStockObject (SYSTEM_FONT));
allglyphsGlobal =
mapperflagsGlobal = FALSE;
break;
/**********************************************************************\
* WM_DESTROY
*
* Complement of the WM_CREATE message. Delete the pens that were
* created and then call postquitmessage.
\**********************************************************************/
case WM_DESTROY:
DeleteObject (hPenGrid);
break;
/**********************************************************************\
* WM_ERASEBKGND
*
* Offset the origin conditional on allglyphsGlobal. Grid the window.
\**********************************************************************/
case WM_ERASEBKGND: {
HDC hdc;
RECT rect;
int i;
hdc = (HDC)wParam;
GetClientRect (hwnd, &rect);
FillRect (hdc, &rect, GetStockObject (LTGRAY_BRUSH));
if (!allglyphsGlobal) {
SetViewportOrgEx (hdc, rect.right /2, rect.bottom/2, NULL);
OffsetRect (&rect, -rect.right/2, -rect.bottom/2);
}
SelectObject(hdc, hPenGrid);
/* Draw vertical lines. */
for (i = 0; i<= rect.right; i+=TICKSPACE){
MoveToEx (hdc, i, rect.top, NULL);
LineTo (hdc, i, rect.bottom);
MoveToEx (hdc, -i, rect.top, NULL);
LineTo (hdc, -i, rect.bottom);
}
MoveToEx (hdc, 1, rect.top, NULL);
LineTo (hdc, 1, rect.bottom);
/* Draw horizontal lines. */
for (i = 0; i<= rect.bottom; i+=TICKSPACE){
MoveToEx (hdc, rect.left,i, NULL);
LineTo (hdc, rect.right,i);
MoveToEx (hdc, rect.left,-i, NULL);
LineTo (hdc, rect.right,-i);
}
MoveToEx (hdc, rect.left, 1, NULL);
LineTo (hdc, rect.right,1);
} return TRUE;
/**********************************************************************\
* WM_PAINT
*
* Offset the origin conditional on allglyphsGlobal. Write the "Hello"
* string if allglyphsGlobal is FALSE, otherwise step though all of
* the glyphs (from TEXTMETRIC.tmFirstChar to TEXTMETRIC.tmLastChar)
* and write them in the window.
\**********************************************************************/
case WM_PAINT: {
HDC hdc;
PAINTSTRUCT ps;
RECT rect;
POINT point;
BYTE outByte;
LOGFONT lf;
TEXTMETRIC tm;
hdc = BeginPaint(hwnd, &ps);
SetMapperFlags (hdc, mapperflagsGlobal);
GetClientRect (hwnd, &rect);
hfont = (HFONT) GetWindowLong (hwnd, GWL_USERDATA);
SelectObject (hdc,hfont);
SetBkMode (hdc, TRANSPARENT);
if (!allglyphsGlobal) {
SetViewportOrgEx (hdc, rect.right /2, rect.bottom/2, NULL);
TextOut (hdc, 0, 0, "Hello", 5);
} else {
SetTextAlign (hdc, TA_LEFT | TA_TOP | TA_UPDATECP);
GetObject (hfont, sizeof(LOGFONT), &lf);
GetTextMetrics (hdc, &tm);
MoveToEx (hdc, 0,0, NULL);
for (outByte = tm.tmFirstChar; outByte <= tm.tmLastChar; outByte++) {
GetCurrentPositionEx (hdc, &point);
if (point.x > (rect.right - lf.lfWidth)) {
point.x = 0;
point.y += lf.lfHeight;
MoveToEx (hdc, point.x, point.y, NULL);
}
if (point.y > rect.bottom) break;
if (outByte == MAXBYTE) break; // tm.tmLastChar is often 0xff
TextOut (hdc, 0,0, &outByte, 1);
}
}
EndPaint (hwnd, &ps);
} return FALSE;
default:
return (DefWindowProc(hwnd, message, wParam, lParam));
}
return (NULL);
}
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.