|
|
1.1 ! root 1: /**************************************************************************** ! 2: ! 3: PROGRAM: ShowUni.c ! 4: ! 5: PURPOSE: Adds, deletes, creates and displays fonts ! 6: ! 7: FUNCTIONS: ! 8: ! 9: WinMain() - calls initialization function, processes message loop ! 10: EditfileInit() - initializes window data and registers window ! 11: EditfileWndProc() - processes messages ! 12: About() - processes messages for "About" dialog box ! 13: SelectFont() - select a font ! 14: ! 15: ****************************************************************************/ ! 16: ! 17: #include <windows.h> ! 18: #include <string.h> ! 19: #include "showuni.h" ! 20: #include <commdlg.h> ! 21: ! 22: struct __range { ! 23: int low; ! 24: int high; ! 25: } range[] = { ! 26: {0x20, 0x7f}, //ASCII ! 27: {0xa0, 0xff}, //Latin ! 28: {0x100, 0x17f}, //European Latin ! 29: {0x180, 0x1f0}, //Extended Latin ! 30: {0x250, 0x2a8}, //Standard Phonetic ! 31: {0x2b0, 0x2e9}, //Modifier Letters ! 32: {0x300, 0x341}, //Generic Diacritical ! 33: {0x370, 0x3f5}, //Greek ! 34: {0x400, 0x486}, //Cyrillic ! 35: {0x490, 0x4cc}, //Extended Cyrillic ! 36: {0x5b0, 0x5f5}, //Hebrew ! 37: {0x20a0,0x20aa}, //Currency Symbols ! 38: {0x2100,0x2138}, //Letterlike Symbols ! 39: {0x2190,0x21ea}, //Arrows ! 40: {0x2200,0x22f1} }; //Math Operators ! 41: ! 42: HANDLE hInst; ! 43: ! 44: HFONT hFont; ! 45: TCHAR FontNameList[32][128]; /* list of added fonts */ ! 46: INT nFontIndex = 0; /* position in FontList */ ! 47: INT nLineSpace; ! 48: ! 49: TEXTMETRIC TextMetric; ! 50: LOGFONT LogFont; ! 51: POINT ptCurrent = {0, 0}; ! 52: TCHAR FontList[MAXFONT][32]; ! 53: INT FontIndex = 0; ! 54: INT CurrentFont = 0; ! 55: DLGPROC lpDlg; ! 56: FONTENUMPROC lpEnumFunc; ! 57: TCHAR AppName[] = TEXT("ShowUnicode Sample Application"); ! 58: TCHAR WindowTitle[80]; ! 59: TCHAR OutBuffer[257]; ! 60: int low=0x20, high=0x7f; ! 61: int CurrentButton=ID_ASCII; ! 62: ! 63: ! 64: /**************************************************************************** ! 65: ! 66: FUNCTION: WinMain(HANDLE, HANDLE, LPTSTR, int) ! 67: ! 68: PURPOSE: calls initialization function, processes message loop ! 69: ! 70: ****************************************************************************/ ! 71: ! 72: int WINAPI WinMain(HANDLE hInstance, HANDLE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) ! 73: { ! 74: HWND hWnd; ! 75: MSG msg; ! 76: ! 77: ! 78: if (!hPrevInstance) ! 79: if (!ShowUniInit(hInstance)) ! 80: return (FALSE); ! 81: ! 82: hInst = hInstance; ! 83: ! 84: lstrcpy(WindowTitle, AppName); ! 85: lstrcat(WindowTitle, TEXT(" : Lucida Sans Unicode")); ! 86: ! 87: hWnd = CreateWindow(TEXT("ShowUni"), ! 88: WindowTitle, ! 89: WS_OVERLAPPEDWINDOW, ! 90: CW_USEDEFAULT, ! 91: CW_USEDEFAULT, ! 92: CW_USEDEFAULT, ! 93: CW_USEDEFAULT, ! 94: NULL, ! 95: NULL, ! 96: hInstance, ! 97: NULL); ! 98: ! 99: if (!hWnd) ! 100: return (FALSE); ! 101: ! 102: ShowWindow(hWnd, nCmdShow); ! 103: UpdateWindow(hWnd); ! 104: ! 105: while (GetMessage(&msg, NULL, NULL, NULL)) { ! 106: TranslateMessage(&msg); ! 107: DispatchMessage(&msg); ! 108: } ! 109: return (msg.wParam); ! 110: } ! 111: ! 112: /**************************************************************************** ! 113: ! 114: FUNCTION: ShowUniInit(HANDLE) ! 115: ! 116: PURPOSE: Initializes window data and registers window class ! 117: ! 118: ****************************************************************************/ ! 119: ! 120: INT ShowUniInit(HANDLE hInstance) ! 121: { ! 122: HANDLE hMemory; ! 123: PWNDCLASS pWndClass; ! 124: BOOL bSuccess; ! 125: ! 126: hMemory = LocalAlloc(LPTR, sizeof(WNDCLASS)); ! 127: if(!hMemory){ ! 128: MessageBox(NULL, TEXT("<ShowUniInit> Not enough memory."), NULL, MB_OK | MB_ICONHAND); ! 129: return(FALSE); ! 130: } ! 131: ! 132: pWndClass = (PWNDCLASS) LocalLock(hMemory); ! 133: pWndClass->hCursor = LoadCursor(NULL, IDC_ARROW); ! 134: pWndClass->hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDC_SHOWUNI)); ! 135: pWndClass->lpszMenuName = MAKEINTRESOURCE(IDM_SHOWUNI); ! 136: pWndClass->lpszClassName = (LPTSTR) TEXT("ShowUni"); ! 137: pWndClass->hbrBackground = GetStockObject(WHITE_BRUSH); ! 138: pWndClass->hInstance = hInstance; ! 139: pWndClass->style = NULL; ! 140: pWndClass->lpfnWndProc = ShowUniWndProc; ! 141: ! 142: bSuccess = RegisterClass((LPWNDCLASS) pWndClass); ! 143: ! 144: LocalUnlock(hMemory); ! 145: LocalFree(hMemory); ! 146: return (bSuccess); ! 147: } ! 148: ! 149: ! 150: /**************************************************************************** ! 151: ! 152: FUNCTION: ShowCharacters(HDC, INT, INT) ! 153: ! 154: PURPOSE: display character set using current font ! 155: ! 156: ****************************************************************************/ ! 157: ! 158: VOID ShowCharacters( ! 159: HDC hDC, ! 160: int low, ! 161: int high ! 162: ) ! 163: { ! 164: HFONT hOldFont; ! 165: TEXTMETRIC TextMetric; ! 166: UINT X; ! 167: UINT Y; ! 168: int i; ! 169: LPTSTR p; ! 170: ! 171: GetTextMetrics(hDC, &TextMetric); ! 172: hFont = CreateFont( TextMetric.tmHeight, TextMetric.tmAveCharWidth, 0, 0, ! 173: FW_NORMAL, FALSE, FALSE, FALSE, ! 174: UNICODE_CHARSET, ! 175: OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, ! 176: DEFAULT_QUALITY, DEFAULT_PITCH, ! 177: FontList[CurrentFont]); ! 178: ! 179: for (i=low ; i<=high ; i++) { ! 180: OutBuffer[i-low] = (TCHAR)i; ! 181: } ! 182: ! 183: if (!(hOldFont = SelectObject(hDC, hFont))) ! 184: return; ! 185: GetTextMetrics(hDC, &TextMetric); ! 186: nLineSpace = TextMetric.tmHeight + TextMetric.tmExternalLeading + 1; ! 187: X = ptCurrent.x; ! 188: Y = ptCurrent.y; ! 189: ! 190: for (p=OutBuffer,i=high-low+1 ; i>64 ; i-=64,p+=64,Y+=nLineSpace) { ! 191: TextOut(hDC, X, Y, p, 64); ! 192: } ! 193: TextOut(hDC, X, Y, p, i); ! 194: SelectObject(hDC, hOldFont); ! 195: } ! 196: ! 197: ! 198: /**************************************************************************** ! 199: ! 200: FUNCTION: EnumFunc(LPLOGFONT, LPTEXTMETRIC, DWORD, LPARAM) ! 201: ! 202: PURPOSE: Finds unicode fonts ! 203: ! 204: ****************************************************************************/ ! 205: ! 206: INT APIENTRY EnumFunc( ! 207: LPLOGFONT lpLogFont, ! 208: LPTEXTMETRIC lpTextMetric, ! 209: DWORD FontType, ! 210: LPARAM lpData) ! 211: { ! 212: if ((int)lpData == 0) { ! 213: if (lpLogFont->lfCharSet != UNICODE_CHARSET) ! 214: return 1; ! 215: lstrcpy((LPTSTR)FontList[FontIndex], ! 216: (LPTSTR)(lpLogFont->lfFaceName)); ! 217: return (++FontIndex); ! 218: } ! 219: else ! 220: return 0; ! 221: } ! 222: ! 223: /**************************************************************************** ! 224: ! 225: FUNCTION: GetFonts(HWND) ! 226: ! 227: PURPOSE: Get available fonts ! 228: ! 229: ****************************************************************************/ ! 230: ! 231: VOID GetFonts(HWND hWnd) ! 232: { ! 233: #if 0 ! 234: HDC hDC; ! 235: ! 236: FontIndex = 0; ! 237: hDC = GetDC(hWnd); ! 238: lpEnumFunc = (FONTENUMPROC)MakeProcInstance((FARPROC)EnumFunc, hInst); ! 239: EnumFonts(hDC, (LPTSTR)NULL, lpEnumFunc, (LPARAM)NULL); ! 240: FreeProcInstance((FARPROC)lpEnumFunc); ! 241: ReleaseDC(hWnd, hDC); ! 242: #else ! 243: FontIndex = 1; ! 244: lstrcpy(FontList[0], TEXT("Lucida Sans Unicode")); ! 245: #endif ! 246: } ! 247: ! 248: /**************************************************************************** ! 249: ! 250: FUNCTION: SelectFont(HWND, unsigned, WORD, LONG) ! 251: ! 252: PURPOSE: Initializes window data and registers window class ! 253: ! 254: ****************************************************************************/ ! 255: ! 256: BOOL APIENTRY SelectFont( ! 257: HWND hDlg, ! 258: UINT message, ! 259: WPARAM wParam, ! 260: LONG lParam) ! 261: { ! 262: ! 263: INT i; ! 264: INT index; ! 265: ! 266: switch (message) { ! 267: case WM_INITDIALOG: ! 268: for (i=0; i<FontIndex; i++) { /* displays available fonts */ ! 269: SendDlgItemMessage(hDlg, ID_TYPEFACE, LB_ADDSTRING, ! 270: NULL, (LONG) (LPTSTR) FontList[i]); ! 271: SendDlgItemMessage(hDlg, ID_TYPEFACE, LB_SETCURSEL, ! 272: 0, 0L); ! 273: } ! 274: return (TRUE); ! 275: break; ! 276: ! 277: case WM_COMMAND: ! 278: switch (LOWORD(wParam)) { ! 279: case IDOK: ! 280: okay: ! 281: index=SendDlgItemMessage(hDlg, ID_TYPEFACE, ! 282: LB_GETCURSEL, 0, 0L); ! 283: if (index == LB_ERR) { ! 284: MessageBox(hDlg, TEXT("No font selected"), ! 285: TEXT("Select Font"), MB_OK | MB_ICONEXCLAMATION); ! 286: break; ! 287: } ! 288: CurrentFont = index; ! 289: EndDialog(hDlg, 1); ! 290: break; ! 291: ! 292: case IDCANCEL: ! 293: EndDialog(hDlg, 0); ! 294: break; ! 295: ! 296: case ID_TYPEFACE: ! 297: switch (HIWORD(wParam)) { ! 298: case LBN_SELCHANGE: ! 299: index = SendDlgItemMessage(hDlg, ID_TYPEFACE, ! 300: LB_GETCURSEL, 0, 0L); ! 301: if (index == LB_ERR) ! 302: break; ! 303: break; ! 304: ! 305: case LBN_DBLCLK: ! 306: goto okay; ! 307: break; ! 308: } ! 309: break; ! 310: ! 311: default: ! 312: break; ! 313: } ! 314: break; ! 315: ! 316: default: ! 317: break; ! 318: } ! 319: return (FALSE); ! 320: } ! 321: ! 322: /**************************************************************************** ! 323: ! 324: FUNCTION: Range(HWND, unsigned, WORD, LONG) ! 325: ! 326: PURPOSE: Selects a range of characters to display ! 327: ! 328: ****************************************************************************/ ! 329: ! 330: BOOL APIENTRY Range( ! 331: HWND hDlg, ! 332: UINT message, ! 333: WPARAM wParam, ! 334: LONG lParam) ! 335: { ! 336: BOOL f; ! 337: int i; ! 338: static int CurrentButtonTmp; ! 339: ! 340: switch (message) { ! 341: case WM_INITDIALOG: ! 342: f = SetDlgItemInt(hDlg, ID_LOW, low, FALSE); ! 343: f = SetDlgItemInt(hDlg, ID_HIGH, high, FALSE); ! 344: CheckRadioButton(hDlg, ID_ASCII, ID_MATH, CurrentButton); ! 345: CurrentButtonTmp = CurrentButton; ! 346: return (TRUE); ! 347: break; ! 348: ! 349: case WM_COMMAND: ! 350: switch (LOWORD(wParam)) { ! 351: case IDOK: ! 352: low = GetDlgItemInt(hDlg, ID_LOW, &f, FALSE); ! 353: high = GetDlgItemInt(hDlg, ID_HIGH, &f, FALSE); ! 354: if (high-low > 256) { ! 355: MessageBox(NULL, TEXT("Range too large - 256 max"), ! 356: NULL, MB_OK | MB_ICONHAND); ! 357: } ! 358: else { ! 359: CurrentButton = CurrentButtonTmp; ! 360: EndDialog(hDlg, TRUE); ! 361: } ! 362: break; ! 363: ! 364: case IDCANCEL: ! 365: EndDialog(hDlg, FALSE); ! 366: break; ! 367: ! 368: case ID_ASCII: ! 369: case ID_LATIN: ! 370: case ID_LATIN_E: ! 371: case ID_LATIN_X: ! 372: case ID_MODIFIER: ! 373: case ID_DIACRITICAL: ! 374: case ID_PHONETIC: ! 375: case ID_GREEK: ! 376: case ID_CYRILLIC: ! 377: case ID_CYRILLIC_X: ! 378: case ID_HEBREW: ! 379: case ID_CURRENCY: ! 380: case ID_LETTERS: ! 381: case ID_ARROWS: ! 382: case ID_MATH: ! 383: for (i=ID_ASCII ; i<=ID_MATH ; i++) { ! 384: if (IsDlgButtonChecked(hDlg, i)) { ! 385: f = SetDlgItemInt(hDlg, ID_LOW, ! 386: range[i-ID_ASCII].low, FALSE); ! 387: f = SetDlgItemInt(hDlg, ID_HIGH, ! 388: range[i-ID_ASCII].high, FALSE); ! 389: CurrentButtonTmp = i; ! 390: break; ! 391: } ! 392: } ! 393: break; ! 394: ! 395: default: ! 396: break; ! 397: } ! 398: break; ! 399: ! 400: default: ! 401: break; ! 402: } ! 403: return (FALSE); ! 404: } ! 405: ! 406: ! 407: /**************************************************************************** ! 408: ! 409: FUNCTION: ShowUniWndProc(HWND, unsigned, WORD, LONG) ! 410: ! 411: PURPOSE: Processes messages ! 412: ! 413: ****************************************************************************/ ! 414: ! 415: LONG APIENTRY ShowUniWndProc( ! 416: HWND hWnd, ! 417: UINT message, ! 418: WPARAM wParam, ! 419: LONG lParam) ! 420: { ! 421: HDC hDC; ! 422: PAINTSTRUCT ps; ! 423: ! 424: ! 425: switch(message) { ! 426: case WM_CREATE: ! 427: GetFonts(hWnd); ! 428: break; ! 429: ! 430: case WM_PAINT: ! 431: hDC = BeginPaint(hWnd, &ps); ! 432: ShowCharacters(hDC, low, high); ! 433: EndPaint(hWnd, &ps); ! 434: break; ! 435: ! 436: case WM_COMMAND: ! 437: switch (LOWORD(wParam)) { ! 438: ! 439: /* File Menu */ ! 440: ! 441: case IDM_EXIT: ! 442: DestroyWindow(hWnd); ! 443: break; ! 444: ! 445: case IDM_ABOUT: ! 446: lpDlg = MakeProcInstance((DLGPROC)About, hInst); ! 447: DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUT), hWnd, lpDlg); ! 448: FreeProcInstance(lpDlg); ! 449: break; ! 450: ! 451: /* Show menu */ ! 452: ! 453: case IDM_CLEAR: ! 454: InvalidateRect(hWnd, (LPRECT)NULL, TRUE); ! 455: break; ! 456: ! 457: case IDM_SHOWCHARS: ! 458: InvalidateRect(hWnd, (LPRECT)NULL, TRUE); ! 459: break; ! 460: ! 461: case IDM_SHOWRANGE: ! 462: lpDlg = MakeProcInstance((DLGPROC)Range, hInst); ! 463: if (DialogBox(hInst, MAKEINTRESOURCE(IDD_RANGE), hWnd, lpDlg)) { ! 464: } ! 465: FreeProcInstance(lpDlg); ! 466: break; ! 467: ! 468: /* Font menu */ ! 469: ! 470: case IDM_SELECTFONT: ! 471: lpDlg = MakeProcInstance((DLGPROC)SelectFont, hInst); ! 472: if (DialogBox(hInst, MAKEINTRESOURCE(IDD_SELECT), hWnd, lpDlg)) { ! 473: hFont = CreateFont( 10, 10, 0, 0, ! 474: FW_NORMAL, FALSE, FALSE, FALSE, ! 475: UNICODE_CHARSET, ! 476: OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, ! 477: DEFAULT_QUALITY, DEFAULT_PITCH, ! 478: FontList[CurrentFont]); ! 479: SetFaceName(hWnd); ! 480: } ! 481: FreeProcInstance(lpDlg); ! 482: break; ! 483: ! 484: } ! 485: break; ! 486: ! 487: case WM_LBUTTONUP: ! 488: ptCurrent.x = LOWORD(lParam); ! 489: ptCurrent.y = HIWORD(lParam); ! 490: hDC = GetDC(hWnd); ! 491: ShowCharacters(hDC, low, high); ! 492: ReleaseDC(hWnd, hDC); ! 493: break; ! 494: ! 495: case WM_FONTCHANGE: ! 496: GetFonts(hWnd); ! 497: break; ! 498: ! 499: case WM_DESTROY: ! 500: PostQuitMessage(0); ! 501: break; ! 502: ! 503: default: ! 504: return (DefWindowProc(hWnd, message, wParam, lParam)); ! 505: } ! 506: return (0L); ! 507: } ! 508: ! 509: /**************************************************************************** ! 510: ! 511: FUNCTION: SetFaceName(HWND) ! 512: ! 513: PURPOSE: Retrieves current font's face name, places it in WindowTitle ! 514: ! 515: ****************************************************************************/ ! 516: ! 517: VOID SetFaceName(HWND hWnd) ! 518: { ! 519: TCHAR buf[80]; ! 520: HDC hDC; ! 521: ! 522: hDC = GetDC(hWnd); ! 523: SelectObject(hDC, hFont); ! 524: lstrcpy(WindowTitle, AppName); ! 525: lstrcat(WindowTitle, TEXT(" : ")); ! 526: GetTextFace(hDC, 80, buf); ! 527: lstrcat(WindowTitle, buf); ! 528: SetWindowText(hWnd, (LPTSTR) WindowTitle); ! 529: ! 530: ReleaseDC(hWnd, hDC); ! 531: } ! 532: ! 533: /**************************************************************************** ! 534: ! 535: FUNCTION: About(HWND, unsigned, WORD, LONG) ! 536: ! 537: PURPOSE: Processes messages for "About" dialog box ! 538: ! 539: MESSAGES: ! 540: ! 541: WM_INITDIALOG - initialize dialog box ! 542: WM_COMMAND - Input received ! 543: ! 544: ****************************************************************************/ ! 545: ! 546: BOOL APIENTRY About( ! 547: HWND hDlg, ! 548: UINT message, ! 549: WPARAM wParam, ! 550: LONG lParam) ! 551: { ! 552: switch (message) { ! 553: case WM_INITDIALOG: ! 554: return (TRUE); ! 555: ! 556: case WM_COMMAND: ! 557: if (LOWORD(wParam) == IDOK) { ! 558: EndDialog(hDlg, TRUE); ! 559: return (TRUE); ! 560: } ! 561: return (TRUE); ! 562: } ! 563: return (FALSE); ! 564: UNREFERENCED_PARAMETER(lParam); ! 565: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.