--- mstools/samples/ntfonts/ntfonts.c 2018/08/09 18:20:59 1.1.1.1 +++ mstools/samples/ntfonts/ntfonts.c 2018/08/09 18:22:13 1.1.1.2 @@ -1,7 +1,11 @@ /**************************************************************************\ * ntfonts.c -- Font enumeration and manipulation program for Win32/NT. * -* version 1.0 +* +* Steve Firebaugh +* Microsoft Developer Support +* Copyright (c) 1992 Microsoft Corporation +* * * design: There is a main frame window (hwndMain) with a child toolbar, * two child dialogs, and a child demonstration window. All window handles @@ -15,10 +19,11 @@ * Communication between windows is via message passing. The toolbar passes * all of its command messages back to the main window. Other windows pass * information back and forth with the following USER defined messages: -* WMU_LFTODEMO, WMU_DEMOTOLF, & WMU_DEMOTOTM. Rectangles fly on the screen +* WMU_LFTODEMO, WMU_DEMOTOLF, WMU_DEMOTOTM... Rectangles fly on the screen * (c.f. flyWinWin) to mirror message trafic, i.e. data flow. * \**************************************************************************/ +#define UNICODE #include #include "ntfonts.h" @@ -31,7 +36,9 @@ -char initString[] = "Please wait. Initializing data structures."; +TCHAR initString[] = TEXT("Please wait. Initializing data structures."); +TCHAR szHelpPathName[] = TEXT("NTFONTS.HLP"); + /**************************************************************************\ @@ -45,8 +52,8 @@ int APIENTRY WinMain(HINSTANCE hInstance LPSTR lpCmdLine, int nCmdShow) { MSG msg; - HANDLE haccel; HWND hwndInfo; + CLIENTCREATESTRUCT clientcreate; UNREFERENCED_PARAMETER( lpCmdLine ); @@ -64,11 +71,11 @@ int APIENTRY WinMain(HINSTANCE hInstance wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hInstance = hInstance; - wc.hIcon = LoadIcon(hInstance, "ntfontsIcon"); + wc.hIcon = LoadIcon(hInstance, TEXT("ntfontsIcon")); wc.hCursor = LoadCursor(NULL, IDC_ARROW); wc.hbrBackground = NULL; - wc.lpszMenuName = NULL; - wc.lpszClassName = "ntfonts"; + wc.lpszMenuName = TEXT("ntfontsMenu"); + wc.lpszClassName = TEXT("ntfonts"); if (!RegisterClass(&wc)) return (FALSE); @@ -77,8 +84,8 @@ int APIENTRY WinMain(HINSTANCE hInstance /* Create the main window. Return false if CreateWindow() fails */ hwndMain = CreateWindow( - "ntfonts", - "NT Fonts", + TEXT("ntfonts"), + TEXT("NT Fonts"), WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, @@ -89,9 +96,21 @@ int APIENTRY WinMain(HINSTANCE hInstance if (!hwndMain) return (FALSE); + /* create the MDI "client" window. */ + clientcreate.hWindowMenu = NULL; /* don't add window names to menu */ + clientcreate.idFirstChild = 1; + hwndClient = CreateWindow( + TEXT("MDICLIENT"), + NULL, + WS_CHILD | WS_CLIPCHILDREN | WS_VISIBLE | MDIS_ALLCHILDSTYLES, + 0,0,0,0, + hwndMain, NULL, hInst, (LPVOID)&clientcreate); + if (!hwndClient) return (FALSE); + + /* create temporary window to display while initialization completes */ hwndInfo = CreateWindow( - "EDIT", + TEXT("EDIT"), initString, WS_CHILD | WS_VISIBLE | ES_READONLY | ES_MULTILINE | ES_CENTER, 0,0, @@ -99,29 +118,31 @@ int APIENTRY WinMain(HINSTANCE hInstance GetSystemMetrics (SM_CYFULLSCREEN), hwndMain, NULL, hInst, NULL); - /* make the main window visible to show the "please wait..." screen. */ - ShowWindow(hwndMain, SW_SHOWMAXIMIZED); - UpdateWindow (hwndMain); - + SetWindowPos (hwndInfo, HWND_TOP, 0,0,0,0, SWP_NOSIZE); + UpdateWindow(hwndInfo); /* perform initialization for other windows...allfont is SLOW */ - if (!initTB(hwndMain)) return FALSE; - if (!initDemo(hwndMain)) return FALSE; - if (!initDlg(hwndMain)) return FALSE; - if (!initAllFont(hwndMain)) return FALSE; + if (!initTB(hwndMain)) return FALSE; + if (!initDisplay(hwndClient)) return FALSE; + if (!initDlg(hwndClient)) return FALSE; + if (!initAllFont(hwndClient)) return FALSE; - haccel = LoadAccelerators (hInst, "TBAccel"); - /* get rid of the temporary "please wait..." window. */ DestroyWindow (hwndInfo); + ShowWindow(hwndMain, SW_SHOWMAXIMIZED); + + + ShowWindow(hwndMain, SW_SHOWMAXIMIZED); + SendMessage (hwndMain, WM_COMMAND, IDM_ARRANGE,0); /* Loop getting messages and dispatching them. */ while (GetMessage(&msg,NULL, NULL, NULL)) { - if (!TranslateAccelerator(hwndMain, haccel, &msg)) if (!IsDialogMessage (hwndDlgTM, &msg)) - if (!IsDialogMessage (hwndDlgLF, &msg)){ + if (!IsDialogMessage (hwndDlgOLTM, &msg)) + if (!IsDialogMessage (hwndDlgLF, &msg)) + if (!IsDialogMessage (hwndDlgFD, &msg)){ TranslateMessage(&msg); DispatchMessage(&msg); } @@ -139,7 +160,7 @@ int APIENTRY WinMain(HINSTANCE hInstance * input parameters: normal window procedure parameters. * \**************************************************************************/ -LRESULT MainWndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) +LRESULT CALLBACK MainWndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { static HANDLE hPenGrid; static LOGFONT lf; @@ -159,46 +180,157 @@ static TEXTMETRIC tm; case WM_COMMAND: { switch (LOWORD(wParam)) { - HWND hwndButton; + HDC hdcDemo; case TBID_ENUM: - SetWindowPos (hwndDisplayFonts, NULL, 0,0,0,0, - SWP_SHOWWINDOW | SWP_NOMOVE | SWP_NOSIZE); - SetFocus (hwndDisplayFonts); + ShowWindow(hwndDisplayFonts, SW_SHOWMAXIMIZED); break; case TBID_PRINT: - SetWindowPos (hwndPrinterFonts, NULL, 0,0,0,0, - SWP_SHOWWINDOW | SWP_NOMOVE | SWP_NOSIZE); - SetFocus (hwndPrinterFonts); + ShowWindow(hwndPrinterFonts, SW_SHOWMAXIMIZED); break; + /* Send the LOGFONT dialog a message to fill in a LOGFONT structure, + * then pass that structure along to the DEMO window. + */ case TBID_CREATE: SendMessage (hwndDlgLF, WMU_LFTODEMO, 0, (LONG) &lf); - flyWinWin (hwndMain, hwndDlgLF, hwndDemo, FWW_STEPS); - SendMessage (hwndDemo , WMU_LFTODEMO, 0, (LONG) &lf); + flyWinWin (hwndMain, hwndDlgLF, hwndDisplay, FWW_STEPS); + SendMessage (hwndDisplay , WMU_NEWFONT, 0, (LONG) &lf); break; + + /* Same exchange as LOGFONT for the TEXTMETRIC structure. + * However, for the OUTLINETEXTMETRIC stucture, + * send the DEMO window a message asking for an HDC with the + * current font selected into it. Pass that HDC along to the + * OUTLINETEXTMETRIC dialog so that it can query the structure, + * and display the values. + */ case TBID_GETTM: - SendMessage (hwndDemo , WMU_DEMOTOTM, 0, (LONG) &tm); - flyWinWin (hwndMain, hwndDemo, hwndDlgTM, FWW_STEPS); + + SendMessage (hwndDisplay , WMU_DEMOTOTM, 0, (LONG) &tm); + flyWinWin (hwndMain, hwndDisplay, hwndDlgTM, FWW_STEPS); SendMessage (hwndDlgTM, WMU_DEMOTOTM, 0, (LONG) &tm); + + hdcDemo = (HDC) SendMessage (hwndDisplay , WMU_DEMOGETDC, 0, 0); + flyWinWin (hwndMain, hwndDisplay, hwndDlgOLTM, FWW_STEPS); + SendMessage (hwndDlgOLTM, WMU_DEMOTOOLTM, 0, (LPARAM) hdcDemo); + SendMessage (hwndDisplay , WMU_DEMORELEASEDC, 0, (LPARAM) hdcDemo); + break; - /* two checkboxes. get new state and force repaint of demo window */ - case TBID_CHKALLGLYPHS: - hwndButton = GetDlgItem(hwndTB, (int) LOWORD(wParam)); - allglyphsGlobal = (BOOL) SendMessage (hwndButton, BM_GETCHECK, 0,0); - InvalidateRect (hwndDemo, NULL, TRUE); + /* Send message down to hwndDlgFD w/ HDC from hwndDisplay. + * hwndDlgFD will parse its params, and call GetFontData(). + */ + case TBID_GETFONTDATA: + + hdcDemo = (HDC) SendMessage (hwndDisplay , WMU_DEMOGETDC, 0, 0); + flyWinWin (hwndMain, hwndDisplay, hwndDlgFD, FWW_STEPS); + SendMessage (hwndDlgFD, WMU_GETFONTDATA, 0, (LPARAM) hdcDemo); + SendMessage (hwndDisplay , WMU_DEMORELEASEDC, 0, (LPARAM) hdcDemo); + break; - case TBID_CHKMAPPERFLAGS: - hwndButton = GetDlgItem(hwndTB, (int) LOWORD(wParam)); - mapperflagsGlobal = (BOOL) SendMessage (hwndButton, BM_GETCHECK, 0,0); - InvalidateRect (hwndDemo, NULL, TRUE); + + /* Simply send message to display window, and it does all work. */ + case IDM_PRINT: + SendMessage (hwndDisplay , WMU_PRINT, 0, 0); + break; + + + case IDM_HELP: + WinHelp( hwnd, szHelpPathName, HELP_INDEX, (DWORD) NULL ); break; + + case IDM_ABOUT: + DialogBox (hInst, TEXT("aboutBox"), hwnd, (DLGPROC) About); + break; + + + + /******************************************************************\ + * WM_COMMAND, IDM_FLYWINWIN + * + * Check menu on and off. Query state in FlyWinWin() function. + \******************************************************************/ + case IDM_FLYWINWIN: + if (GetMenuState (GetMenu (hwnd),IDM_FLYWINWIN, MF_BYCOMMAND) + == MF_CHECKED) { + CheckMenuItem(GetMenu (hwnd), LOWORD(wParam) , MF_UNCHECKED); + } else { + CheckMenuItem(GetMenu (hwnd), LOWORD(wParam) , MF_CHECKED); + } + break; + + + /******************************************************************\ + * WM_COMMAND, IDM_MODE* + * + * manage mutually exclusive menu. + * inform the window that it has a new mode. + * invalidate window to force repaint. + * Special case MODEALL to check that it is o.k. first. + \******************************************************************/ + case IDM_MODEALL : + if (!SendMessage (hwndDisplay, WMU_NEWMODEALL, 0,0)) { + return 0; + } + CheckMenuItem(GetMenu (hwnd), IDM_MODEHELLO , MF_UNCHECKED); + CheckMenuItem(GetMenu (hwnd), IDM_MODETMRANGE, MF_UNCHECKED); + CheckMenuItem(GetMenu (hwnd), IDM_MODEALL , MF_CHECKED); + InvalidateRect (hwndDisplay, NULL, TRUE); + return 0; + + case IDM_MODEHELLO : + CheckMenuItem(GetMenu (hwnd), IDM_MODEHELLO , MF_CHECKED); + CheckMenuItem(GetMenu (hwnd), IDM_MODETMRANGE, MF_UNCHECKED); + CheckMenuItem(GetMenu (hwnd), IDM_MODEALL , MF_UNCHECKED); + SendMessage (hwndDisplay, WMU_NEWMODEHELLO, 0,0); + InvalidateRect (hwndDisplay, NULL, TRUE); + return 0; + + case IDM_MODETMRANGE: + CheckMenuItem(GetMenu (hwnd), IDM_MODEHELLO , MF_UNCHECKED); + CheckMenuItem(GetMenu (hwnd), IDM_MODETMRANGE, MF_CHECKED); + CheckMenuItem(GetMenu (hwnd), IDM_MODEALL , MF_UNCHECKED); + SendMessage (hwndDisplay, WMU_NEWMODETMRANGE, 0,0); + InvalidateRect (hwndDisplay, NULL, TRUE); + return 0; + + + + /******************************************************************\ + * WM_COMMAND, IDM_* + * + * misc. MDI responsibilities. hwndClient does real work. + \******************************************************************/ + case IDM_CASCADE: SendMessage (hwndClient, WM_MDICASCADE, 0,0); break; + case IDM_TILE: SendMessage (hwndClient, WM_MDITILE, 0,0); break; + case IDM_ARRANGE: + ShowWindow(hwndDisplayFonts, SW_SHOWMINIMIZED); + ShowWindow(hwndPrinterFonts, SW_SHOWMINIMIZED); + ShowWindow(hwndDlgOLTM, SW_SHOWMINIMIZED); + ShowWindow(hwndDlgFD, SW_SHOWMINIMIZED); + ShowWindow(hwndDlgTM, SW_RESTORE); + SetWindowPos (hwndDlgTM, HWND_TOP, + CHILDLEFT(0), CHILDTOP, 0,0, SWP_NOSIZE); + ShowWindow(hwndDlgLF, SW_RESTORE); + SetWindowPos (hwndDlgLF, HWND_TOP, + CHILDLEFT(1), CHILDTOP, 0,0, SWP_NOSIZE); + ShowWindow(hwndDisplay, SW_RESTORE); + SetWindowPos (hwndDisplay, HWND_TOP, + CHILDLEFT(2), CHILDTOP, + GetSystemMetrics (SM_CXFULLSCREEN)/3 - 10, + GetSystemMetrics (SM_CYFULLSCREEN)/3, 0); + SendMessage (hwndClient, WM_MDIICONARRANGE, 0,0); + break; + + + + } /* end switch */ } break; /* end WM_COMMAND */ @@ -212,7 +344,10 @@ static TEXTMETRIC tm; * Create pens for drawing with later. \**********************************************************************/ case WM_CREATE: - hPenGrid = CreatePen (PS_SOLID, 1, GRIDCOLOR); + hPenGrid = CreatePen (PS_SOLID, 1, GRIDCOLOR); + CheckMenuItem (GetMenu (hwnd), IDM_FLYWINWIN, MF_BYCOMMAND | MF_CHECKED); + CheckMenuItem (GetMenu (hwnd), IDM_MODEHELLO, MF_BYCOMMAND | MF_CHECKED); + gDisplaymode = IDM_MODEHELLO; break; @@ -224,12 +359,33 @@ static TEXTMETRIC tm; \**********************************************************************/ case WM_DESTROY: DeleteObject (hPenGrid); + WinHelp( hwnd, szHelpPathName, (UINT) HELP_QUIT, (DWORD) NULL ); PostQuitMessage(0); break; /**********************************************************************\ + * WM_SIZE + * + * When the frame is sized, then change the size of the MDI client. + \**********************************************************************/ + case WM_SIZE: { + + RECT r; + GetClientRect (hwnd, &r); + r.top += TOOLBARHEIGHT; + r.bottom -= TOOLBARHEIGHT; + SetWindowPos (hwndClient, HWND_BOTTOM, + r.left, r.top, r.right, r.bottom, 0); + return TRUE; + + } break; + + + //HACK. This code not used because of new MDI. + // move to subclassed client window. + /**********************************************************************\ * WM_ERASEBKGND * \**********************************************************************/ @@ -259,14 +415,31 @@ static TEXTMETRIC tm; } return TRUE; - default: - return (DefWindowProc(hwnd, message, wParam, lParam)); - } - return (NULL); + default: break; + } /* end switch */ + + return (DefFrameProc(hwnd, hwndClient, message, wParam, lParam)); } +/***************************************************************************\ +* FUNCTION: About +\***************************************************************************/ +LRESULT CALLBACK About(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) +{ + if ((message == WM_COMMAND) && (LOWORD(wParam) == IDOK)) { + EndDialog (hwnd, TRUE); + return TRUE; + } + if ((message == WM_SYSCOMMAND) && (wParam == SC_CLOSE)) { + EndDialog (hwnd, TRUE); + return TRUE; + } + return FALSE; +} + + @@ -276,34 +449,43 @@ static TEXTMETRIC tm; * Send rectangles flying on the screen to indicate data flow. * * input parameters: -* hwndMain - parent window in which other two exist (grandchildren o.k.) +* handParent - parent window in which other two exist (grandchildren o.k.) * hwndFrom - rectangles originate here. * hwndTo - and travel here. * steps - number of steps to take. Fewer is faster. * \**************************************************************************/ -VOID flyWinWin(HWND hwndMain, HWND hwndFrom, HWND hwndTo, int steps) +VOID flyWinWin(HWND handParent, HWND hwndFrom, HWND hwndTo, int steps) { RECT rectFrom, rectTo; RECT rectI; HDC hdc; int i, iLeft, iTop, iRight, iBottom; + /* The menu bar contains a checked/unchecked item which stores the + * state of the user's preference on whether this "information flow" + * should be done or not. If unchecked, then return before doing + * anything. + */ + if (GetMenuState (GetMenu (hwndMain),IDM_FLYWINWIN, MF_BYCOMMAND) + != MF_CHECKED) return; + + /* retrieve the window rects in screen coordinates. */ GetWindowRect (hwndFrom, &rectFrom); GetWindowRect (hwndTo, &rectTo); /* convert them to be relative to the parent window. */ - ScreenToClient (hwndMain,(LPPOINT)&rectFrom.left); - ScreenToClient (hwndMain,(LPPOINT)&rectFrom.right); - ScreenToClient (hwndMain,(LPPOINT)&rectTo.left); - ScreenToClient (hwndMain,(LPPOINT)&rectTo.right); + ScreenToClient (handParent,(LPPOINT)&rectFrom.left); + ScreenToClient (handParent,(LPPOINT)&rectFrom.right); + ScreenToClient (handParent,(LPPOINT)&rectTo.left); + ScreenToClient (handParent,(LPPOINT)&rectTo.right); /* Get an HDC, set the ROP so that painting twice will restore to the * same state. Then select in the NULL brush so that the Rectangle() * call will not fill in the interior. */ - hdc = GetDC (hwndMain); + hdc = GetDC (handParent); SetROP2(hdc, R2_NOT); SelectObject (hdc, GetStockObject (NULL_BRUSH)); @@ -339,5 +521,5 @@ int i, iLeft, iTop, iRight, iBottom; Rectangle (hdc, rectI.left, rectI.top , rectI.right, rectI.bottom); } - ReleaseDC (hwndMain,hdc); + ReleaseDC (handParent,hdc); }