--- mstools/samples/ntfonts/allfont.c 2018/08/09 18:20:59 1.1.1.1 +++ mstools/samples/ntfonts/allfont.c 2018/08/09 18:22:14 1.1.1.2 @@ -2,6 +2,10 @@ * allfont.c -- module to display the result of enumerating all fonts. * Includes the window procedure and an initialization routine. * +* Steve Firebaugh +* Microsoft Developer Support +* Copyright (c) 1992 Microsoft Corporation +* * There are actually two windows serviced by this module. One for the * display fonts, one for the printer fonts. * @@ -57,6 +61,7 @@ * for each window is stored in the GWLU_NFACES extra bytes. * \**************************************************************************/ +#define UNICODE #include #include @@ -78,14 +83,10 @@ typedef struct tagArFonts{ #define BMSIZE 14 -/* user defined create messsage, sent to window once CreateWindow() returns */ -#define WMU_CREATE WM_USER + 10 - #define GWLU_PARFONTS 0 #define GWLU_NFACES 4 /* forward declare function prototypes. */ -HDC GetPrinterDC (VOID); VOID DrawBitmapXY (HDC, HBITMAP, int, int); PARFONTS BuildFontList(HDC, LPINT); @@ -97,7 +98,7 @@ int APIENTRY MyEnumCount(LPLOGFONT, LPTE -int initAllFont(HWND hwndMain) +int initAllFont(HWND hwndParent) { WNDCLASS wc; HDC hdc; @@ -111,7 +112,7 @@ HDC hdc; wc.hCursor = LoadCursor(NULL, IDC_CROSS); wc.hbrBackground = GetStockObject(WHITE_BRUSH); wc.lpszMenuName = NULL; - wc.lpszClassName = "AllFonts"; + wc.lpszClassName = TEXT("AllFonts"); if (!RegisterClass(&wc)) return (FALSE); @@ -119,18 +120,21 @@ HDC hdc; /* create a window to show all of the display fonts, and send it * the proper WMU_CREATE message with an HDC for the display. */ - hwndDisplayFonts = CreateWindow( - "AllFonts", - NULL, - WS_CHILD | WS_CLIPSIBLINGS | WS_HSCROLL, + hwndDisplayFonts = CreateMDIWindow( + TEXT("AllFonts"), + TEXT("EnumFonts (display)"), + WS_CHILD | WS_CLIPSIBLINGS | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | + WS_CAPTION | WS_SYSMENU | WS_THICKFRAME | WS_HSCROLL, 0,0, GetSystemMetrics (SM_CXFULLSCREEN), - GetSystemMetrics (SM_CYFULLSCREEN), - hwndMain, NULL, hInst, NULL); + GetSystemMetrics (SM_CYFULLSCREEN) - GetSystemMetrics (SM_CYMENU), + hwndParent, hInst, 0); + ShowWindow (hwndDisplayFonts, SW_HIDE); hdc = GetDC (hwndDisplayFonts); SendMessage (hwndDisplayFonts, WMU_CREATE, (DWORD)hdc, 0); ReleaseDC (hwndDisplayFonts, hdc); + ShowWindow (hwndDisplayFonts, SW_SHOWMINIMIZED); if (!hwndDisplayFonts) return (FALSE); @@ -138,21 +142,30 @@ HDC hdc; /* create a window to show all of the printer fonts, and send it * the proper WMU_CREATE message with an HDC for the printer. */ - hwndPrinterFonts = CreateWindow( - "AllFonts", - NULL, - WS_CHILD | WS_CLIPSIBLINGS | WS_HSCROLL, + + hwndPrinterFonts = CreateMDIWindow( + TEXT("AllFonts"), + TEXT("EnumFonts (printer)"), + WS_CHILD | WS_CLIPSIBLINGS | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | + WS_CAPTION | WS_SYSMENU | WS_THICKFRAME | WS_HSCROLL, 0,0, GetSystemMetrics (SM_CXFULLSCREEN), - GetSystemMetrics (SM_CYFULLSCREEN), - hwndMain, NULL, hInst, NULL); + GetSystemMetrics (SM_CYFULLSCREEN) - GetSystemMetrics (SM_CYMENU), + hwndParent, hInst, 0); + ShowWindow (hwndPrinterFonts, SW_HIDE); hdc = GetPrinterDC (); - SendMessage (hwndPrinterFonts, WMU_CREATE, (DWORD)hdc, 0); - DeleteDC (hdc); + if (hdc == NULL) { + SetWindowLong (hwndPrinterFonts, GWLU_PARFONTS, (LONG) NULL); + } else { + SendMessage (hwndPrinterFonts, WMU_CREATE, (DWORD)hdc, 0); + DeleteDC (hdc); + } + ShowWindow (hwndPrinterFonts, SW_SHOWMINIMIZED); if (!hwndPrinterFonts) return (FALSE); + return TRUE; } @@ -167,26 +180,38 @@ HDC hdc; * * Simply return an HDC for the default printer as specified in win.ini. * Note that this HDC should be deleted later (DeleteDC). +* +* + // UNICODE NOTICE + // this function held as ANSI rather than UNICODE because + // I have yet to find a decent way to parse wide character + // strings analogous to using the strtok() function. +* +* \**************************************************************************/ #define NCHAR MAX_PATH HDC GetPrinterDC () { -char szPrinter[NCHAR]; +CHAR szPrinter[NCHAR]; + +static CHAR szDevice[NCHAR]; // CreateDCA has problems +static CHAR szDriver[NCHAR]; // if these variables are in the +static CHAR szOutput[NCHAR]; // address space local to this function. +static DEVMODEA DevMode; // However, declaring them 'static' works. -char szDevice[NCHAR]; -char szDriver[NCHAR]; -char szOutput[NCHAR]; +DWORD dwResult; -DEVMODE DevMode; + dwResult = GetProfileStringA ("windows", "device", "", szPrinter, NCHAR) ; + if (dwResult == NULL) return NULL; - GetProfileString ("windows", "device", "", szPrinter, NCHAR) ; + /* note, input strings are not unicode. */ strcpy (szDevice,strtok (szPrinter, "," )); strcpy (szDriver,strtok (NULL, ", ")); strcpy (szOutput,strtok (NULL, ", ")); - return CreateDC (szDriver, szDevice, szOutput, &DevMode); + return CreateDCA (szDriver, szDevice, szOutput, (LPDEVMODEA)&DevMode); } @@ -206,7 +231,7 @@ DEVMODE DevMode; * scrolled back and forth as well as selected with the mouse. * \**************************************************************************/ -LRESULT AllFontsWndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) +LRESULT CALLBACK AllFontsWndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { RECT rectClient; int i,j; @@ -215,10 +240,13 @@ int nStrips; PARFONTS parFonts; int nFaces; + /* Get the pointer out of the userdata extra bytes. */ parFonts = (PARFONTS) GetWindowLong (hwnd, GWLU_PARFONTS); nFaces = GetWindowLong (hwnd, GWLU_NFACES); + if ((parFonts == NULL) && (message != WMU_CREATE)) + return (DefMDIChildProc(hwnd, message, wParam, lParam)); switch (message) { @@ -275,15 +303,15 @@ int nFaces; \**********************************************************************/ case WM_DESTROY: for (i= 0; i= parFonts[i].nFonts) j = (parFonts[i].nFonts-1); - ShowWindow(hwnd, SW_HIDE); + ShowWindow(hwnd, SW_MINIMIZE); UpdateWindow(hwndMain); flyWinWin(hwndMain, hwnd, hwndDlgLF, 40); SendMessage (hwndDlgLF, WMU_DEMOTOLF, 0,(LONG) &(parFonts[i].lf[j])); @@ -383,7 +411,7 @@ int nFaces; \**********************************************************************/ case WM_RBUTTONDOWN: case WM_CHAR : - ShowWindow(hwnd, SW_HIDE); + ShowWindow(hwnd, SW_MINIMIZE); SetFocus (hwndMain); break; @@ -399,10 +427,11 @@ int nFaces; HDC hdc; int iStrip; + if (parFonts == NULL) break; + GetClientRect (hwnd, &rectClient); hdc = BeginPaint(hwnd, &ps); - thumbpos = GetScrollPos (hwnd, SB_HORZ); nStrips = (rectClient.right - rectClient.left) /CXDEF + 1; @@ -418,10 +447,10 @@ int nFaces; } break; - default: - return (DefWindowProc(hwnd, message, wParam, lParam)); - } - return (NULL); + default: break; + } /* end switch */ + + return (DefMDIChildProc(hwnd, message, wParam, lParam)); } @@ -484,8 +513,8 @@ int height; int rightshift; /* load 2 bitmaps used to "tag" true type and printer fonts. */ - hbmtt = LoadBitmap (hInst, "bmtt"); - hbmdevice = LoadBitmap (hInst, "bmdevice"); + hbmtt = LoadBitmap (hInst, TEXT("bmtt")); + hbmdevice = LoadBitmap (hInst, TEXT("bmdevice")); /* establish bounds of vertical strip that all fonts are drawn into. */ hdc = GetDC (hwnd); @@ -527,7 +556,7 @@ int rightshift; /* for true type fonts, add special bitmap on left, top */ - if (!(parFonts[i].Type[j] & RASTER_FONTTYPE)) { + if (parFonts[i].Type[j] & TRUETYPE_FONTTYPE) { DrawBitmapXY (parFonts[i].hdc, hbmtt,rectClip.left,rectClip.top); rightshift = BMSIZE; } @@ -553,7 +582,7 @@ int rightshift; rectClip.left, rectClip.top, ETO_CLIPPED, &rectClip, parFonts[i].lf[j].lfFaceName, - strlen(parFonts[i].lf[j].lfFaceName), + CharStrLen(parFonts[i].lf[j].lfFaceName), NULL ); @@ -678,7 +707,7 @@ int nFonts; if ((parFontsGlobal[iFace].lf == NULL) || (parFontsGlobal[iFace].tm == NULL) || (parFontsGlobal[iFace].Type == NULL)) { - MessageBox (hwndMain, "alloc failed", "HEY!", MB_ICONSTOP | MB_OK); + MessageBox (hwndMain, TEXT("alloc failed"), MBERROR,MBERRORFLAGS); return FALSE; }