|
|
1.1 ! root 1: /**************************************************************************\ ! 2: * demownd.c -- module for the window with the test font. ! 3: * Includes the window procedure and an initialization routine. ! 4: * ! 5: * store the handle to the test font in the extra bytes of this window. ! 6: * ! 7: \**************************************************************************/ ! 8: ! 9: #include <windows.h> ! 10: #include <string.h> ! 11: #include "ntfonts.h" ! 12: ! 13: #define GRIDCOLOR PALETTEINDEX (3) ! 14: #define TICKSPACE 10 ! 15: ! 16: ! 17: ! 18: int initDemo(HWND hwndMain) ! 19: { ! 20: WNDCLASS wc; ! 21: ! 22: wc.style = CS_VREDRAW | CS_HREDRAW; ! 23: wc.lpfnWndProc = (WNDPROC)DemoWndProc; ! 24: wc.cbClsExtra = 0; ! 25: wc.cbWndExtra = 0; ! 26: wc.hInstance = hInst; ! 27: wc.hIcon = LoadIcon(hInst, "ntfontsIcon"); ! 28: wc.hCursor = LoadCursor(NULL, IDC_ARROW); ! 29: wc.hbrBackground = NULL; ! 30: wc.lpszMenuName = NULL; ! 31: wc.lpszClassName = "Demo"; ! 32: ! 33: if (!RegisterClass(&wc)) return (FALSE); ! 34: ! 35: hwndDemo = CreateWindow( ! 36: "Demo", ! 37: "TextOut()", ! 38: WS_CHILD | WS_CLIPSIBLINGS | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_VISIBLE | ! 39: WS_CAPTION | WS_SYSMENU | WS_THICKFRAME, ! 40: CHILDLEFT(2), ! 41: CHILDTOP, ! 42: GetSystemMetrics (SM_CXFULLSCREEN)/3 - 10, ! 43: GetSystemMetrics (SM_CYFULLSCREEN)/3, ! 44: hwndMain, NULL, hInst, NULL); ! 45: ! 46: if (!hwndDemo) return (FALSE); ! 47: ! 48: ! 49: return TRUE; ! 50: } ! 51: ! 52: ! 53: ! 54: ! 55: /**************************************************************************\ ! 56: * ! 57: * function: DemoWndProc() ! 58: * ! 59: * input parameters: normal window procedure parameters. ! 60: * ! 61: * global variables: ! 62: * allglyphsGlobal - TRUE, then paint all of the glyphs. ! 63: * mapperflagsGlobal - input to SetMapperFlags(). ! 64: \**************************************************************************/ ! 65: LRESULT DemoWndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) ! 66: { ! 67: static HANDLE hPenGrid; ! 68: static LPLOGFONT lplf; ! 69: static LPTEXTMETRIC lptm; ! 70: static HFONT hfont; ! 71: ! 72: switch (message) { ! 73: ! 74: ! 75: /**********************************************************************\ ! 76: * WMU_DEMOTOLF ! 77: * ! 78: * lParam - pointer to LOGFONT structure. ! 79: * ! 80: * User message. Fill up the demo LOGFONT from the HFONT ! 81: * in the extra bytes. ! 82: \**********************************************************************/ ! 83: case WMU_DEMOTOLF: { ! 84: lplf = (LPLOGFONT) lParam; ! 85: ! 86: hfont = (HFONT) GetWindowLong (hwnd, GWL_USERDATA); ! 87: GetObject (hfont, sizeof(LOGFONT), lplf); ! 88: } return 0; ! 89: ! 90: ! 91: ! 92: ! 93: /**********************************************************************\ ! 94: * WMU_LFTODEMO ! 95: * ! 96: * lParam - pointer to LOGFONT structure. ! 97: * ! 98: * User message. Use the input LOGFONT structure to create a new ! 99: * font for this window. Store the new font in the HFONT extra bytes. ! 100: \**********************************************************************/ ! 101: case WMU_LFTODEMO: { ! 102: lplf = (LPLOGFONT) lParam; ! 103: ! 104: /* Get and delete the last font placed in this window. */ ! 105: hfont = (HFONT) GetWindowLong (hwnd, GWL_USERDATA); ! 106: DeleteObject (hfont); ! 107: ! 108: /* Create a new logical font and set it into the windows extra bytes. */ ! 109: hfont = CreateFontIndirect (lplf); ! 110: SetWindowLong (hwnd, GWL_USERDATA, (LONG) hfont); ! 111: InvalidateRect (hwnd, NULL, TRUE); ! 112: } return 0; ! 113: ! 114: /**********************************************************************\ ! 115: * WMU_DEMOTOTM ! 116: * ! 117: * lParam - pointer to TEXTMETRIC structure. ! 118: * ! 119: * User message. Fill up the TEXTMETRIC from the HFONT ! 120: * in the extra bytes. ! 121: \**********************************************************************/ ! 122: case WMU_DEMOTOTM: { ! 123: HDC hdc; ! 124: ! 125: lptm = (LPTEXTMETRIC) lParam; ! 126: ! 127: hfont = (HFONT) GetWindowLong (hwnd, GWL_USERDATA); ! 128: ! 129: ! 130: hdc = GetDC (hwnd); ! 131: SelectObject (hdc,hfont); ! 132: GetTextMetrics (hdc, lptm); ! 133: ReleaseDC (hwnd, hdc); ! 134: } return 0; ! 135: ! 136: ! 137: ! 138: ! 139: ! 140: ! 141: ! 142: /**********************************************************************\ ! 143: * WM_CREATE ! 144: * ! 145: * Create pens for drawing with later. ! 146: \**********************************************************************/ ! 147: case WM_CREATE: ! 148: hPenGrid = CreatePen (PS_SOLID, 1, GRIDCOLOR); ! 149: SetWindowLong (hwnd, GWL_USERDATA, (LONG) GetStockObject (SYSTEM_FONT)); ! 150: ! 151: allglyphsGlobal = ! 152: mapperflagsGlobal = FALSE; ! 153: ! 154: break; ! 155: ! 156: ! 157: /**********************************************************************\ ! 158: * WM_DESTROY ! 159: * ! 160: * Complement of the WM_CREATE message. Delete the pens that were ! 161: * created and then call postquitmessage. ! 162: \**********************************************************************/ ! 163: case WM_DESTROY: ! 164: DeleteObject (hPenGrid); ! 165: ! 166: break; ! 167: ! 168: ! 169: ! 170: /**********************************************************************\ ! 171: * WM_ERASEBKGND ! 172: * ! 173: * Offset the origin conditional on allglyphsGlobal. Grid the window. ! 174: \**********************************************************************/ ! 175: case WM_ERASEBKGND: { ! 176: HDC hdc; ! 177: RECT rect; ! 178: int i; ! 179: ! 180: hdc = (HDC)wParam; ! 181: ! 182: GetClientRect (hwnd, &rect); ! 183: FillRect (hdc, &rect, GetStockObject (LTGRAY_BRUSH)); ! 184: ! 185: if (!allglyphsGlobal) { ! 186: SetViewportOrgEx (hdc, rect.right /2, rect.bottom/2, NULL); ! 187: OffsetRect (&rect, -rect.right/2, -rect.bottom/2); ! 188: } ! 189: ! 190: SelectObject(hdc, hPenGrid); ! 191: /* Draw vertical lines. */ ! 192: for (i = 0; i<= rect.right; i+=TICKSPACE){ ! 193: MoveToEx (hdc, i, rect.top, NULL); ! 194: LineTo (hdc, i, rect.bottom); ! 195: MoveToEx (hdc, -i, rect.top, NULL); ! 196: LineTo (hdc, -i, rect.bottom); ! 197: } ! 198: MoveToEx (hdc, 1, rect.top, NULL); ! 199: LineTo (hdc, 1, rect.bottom); ! 200: ! 201: /* Draw horizontal lines. */ ! 202: for (i = 0; i<= rect.bottom; i+=TICKSPACE){ ! 203: MoveToEx (hdc, rect.left,i, NULL); ! 204: LineTo (hdc, rect.right,i); ! 205: MoveToEx (hdc, rect.left,-i, NULL); ! 206: LineTo (hdc, rect.right,-i); ! 207: } ! 208: MoveToEx (hdc, rect.left, 1, NULL); ! 209: LineTo (hdc, rect.right,1); ! 210: } return TRUE; ! 211: ! 212: ! 213: ! 214: /**********************************************************************\ ! 215: * WM_PAINT ! 216: * ! 217: * Offset the origin conditional on allglyphsGlobal. Write the "Hello" ! 218: * string if allglyphsGlobal is FALSE, otherwise step though all of ! 219: * the glyphs (from TEXTMETRIC.tmFirstChar to TEXTMETRIC.tmLastChar) ! 220: * and write them in the window. ! 221: \**********************************************************************/ ! 222: case WM_PAINT: { ! 223: HDC hdc; ! 224: PAINTSTRUCT ps; ! 225: RECT rect; ! 226: POINT point; ! 227: BYTE outByte; ! 228: LOGFONT lf; ! 229: TEXTMETRIC tm; ! 230: ! 231: hdc = BeginPaint(hwnd, &ps); ! 232: SetMapperFlags (hdc, mapperflagsGlobal); ! 233: ! 234: GetClientRect (hwnd, &rect); ! 235: hfont = (HFONT) GetWindowLong (hwnd, GWL_USERDATA); ! 236: SelectObject (hdc,hfont); ! 237: SetBkMode (hdc, TRANSPARENT); ! 238: ! 239: ! 240: if (!allglyphsGlobal) { ! 241: SetViewportOrgEx (hdc, rect.right /2, rect.bottom/2, NULL); ! 242: TextOut (hdc, 0, 0, "Hello", 5); ! 243: } else { ! 244: SetTextAlign (hdc, TA_LEFT | TA_TOP | TA_UPDATECP); ! 245: GetObject (hfont, sizeof(LOGFONT), &lf); ! 246: GetTextMetrics (hdc, &tm); ! 247: ! 248: MoveToEx (hdc, 0,0, NULL); ! 249: ! 250: for (outByte = tm.tmFirstChar; outByte <= tm.tmLastChar; outByte++) { ! 251: ! 252: GetCurrentPositionEx (hdc, &point); ! 253: if (point.x > (rect.right - lf.lfWidth)) { ! 254: point.x = 0; ! 255: point.y += lf.lfHeight; ! 256: MoveToEx (hdc, point.x, point.y, NULL); ! 257: } ! 258: if (point.y > rect.bottom) break; ! 259: if (outByte == MAXBYTE) break; // tm.tmLastChar is often 0xff ! 260: ! 261: TextOut (hdc, 0,0, &outByte, 1); ! 262: ! 263: ! 264: } ! 265: } ! 266: ! 267: ! 268: EndPaint (hwnd, &ps); ! 269: ! 270: } return FALSE; ! 271: ! 272: ! 273: default: ! 274: return (DefWindowProc(hwnd, message, wParam, lParam)); ! 275: } ! 276: return (NULL); ! 277: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.