Annotation of mstools/samples/ntfonts/toolbar.c, revision 1.1

1.1     ! root        1: /**************************************************************************\
        !             2: *  toolbar.c -- module for the "toolbar" on top of the main window.
        !             3: *   Includes the window procedure and an initialization routine.
        !             4: *
        !             5: \**************************************************************************/
        !             6: 
        !             7: #include <windows.h>
        !             8: #include "ntfonts.h"
        !             9: 
        !            10: 
        !            11: /* for the initial positioning of the buttons within the toolbar. */
        !            12: #define SPACEBUTTON 5
        !            13: #define CXBUTTON ((GetSystemMetrics (SM_CXFULLSCREEN)) /5 -2*SPACEBUTTON)
        !            14: #define BUTTONTOP    TOOLBARHEIGHT/8
        !            15: #define BUTTONHEIGHT TOOLBARHEIGHT*3/4
        !            16: #define BUTTONLEFT(x) ((2*x+1)*SPACEBUTTON + x*CXBUTTON)
        !            17: 
        !            18: #define BORDER     4
        !            19: 
        !            20: 
        !            21: 
        !            22: int initTB (HWND hwndMain)
        !            23: {
        !            24: WNDCLASS  wc;
        !            25: 
        !            26:   wc.style = NULL;
        !            27:   wc.lpfnWndProc = (WNDPROC)ToolBarWndProc;
        !            28:   wc.cbClsExtra = 0;
        !            29:   wc.cbWndExtra = 0;
        !            30:   wc.hInstance = hInst;
        !            31:   wc.hIcon = NULL;
        !            32:   wc.hCursor = LoadCursor(NULL, IDC_ARROW);
        !            33:   wc.hbrBackground = GetStockObject(LTGRAY_BRUSH);
        !            34:   wc.lpszMenuName = NULL;
        !            35:   wc.lpszClassName = "ToolBar";
        !            36: 
        !            37:   if (!RegisterClass(&wc)) return (FALSE);
        !            38: 
        !            39:   hwndTB = CreateWindow(
        !            40:       "ToolBar",
        !            41:       NULL,
        !            42:       WS_CHILD | WS_CLIPSIBLINGS | WS_VISIBLE,
        !            43:       0,0,
        !            44:       GetSystemMetrics (SM_CXFULLSCREEN),
        !            45:       TOOLBARHEIGHT,
        !            46:       hwndMain, NULL, hInst, NULL);
        !            47: 
        !            48:   if (!hwndTB) return (FALSE);
        !            49: 
        !            50:   return TRUE;
        !            51: }
        !            52: 
        !            53: 
        !            54: /**************************************************************************\
        !            55: *
        !            56: *  function:  ToolBarWndProc
        !            57: *
        !            58: *  input parameters:  normal window procedure parameters.
        !            59: *
        !            60: *  global variables:
        !            61: *   hwndMain - parent of the toolbar.
        !            62: *
        !            63: * When the window is created, create the various buttons.  When those
        !            64: *  buttons send WM_COMMAND messages later, send the messages back to hwndMain.
        !            65: *
        !            66: \**************************************************************************/
        !            67: LRESULT ToolBarWndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
        !            68: {
        !            69: static HWND  hwndButton;
        !            70:   switch (message) {
        !            71: 
        !            72:     /**********************************************************************\
        !            73:     *  WM_CREATE
        !            74:     *
        !            75:     * Create the various buttons which are on the toolbar.  Once the buttons
        !            76:     *  are created, set the window ID so that the WM_COMMANDS may be
        !            77:     *  distinguished.
        !            78:     \**********************************************************************/
        !            79:     case WM_CREATE: {
        !            80:       hwndButton = CreateWindow(
        !            81:         "BUTTON","&EnumFonts()",
        !            82:         WS_CHILD | WS_VISIBLE,
        !            83:         BUTTONLEFT(0),BUTTONTOP, CXBUTTON, BUTTONHEIGHT,
        !            84:         hwnd, NULL, hInst, NULL);
        !            85:       SetWindowLong (hwndButton, GWL_ID, TBID_ENUM);
        !            86: 
        !            87:       hwndButton = CreateWindow(
        !            88:         "BUTTON","&CreateFont()",
        !            89:         WS_CHILD | WS_VISIBLE,
        !            90:         BUTTONLEFT(1),BUTTONTOP, CXBUTTON, BUTTONHEIGHT,
        !            91:         hwnd, NULL, hInst, NULL);
        !            92:       SetWindowLong (hwndButton, GWL_ID, TBID_CREATE);
        !            93: 
        !            94:       hwndButton = CreateWindow(
        !            95:         "BUTTON","Get&TextMetric()",
        !            96:         WS_CHILD | WS_VISIBLE ,
        !            97:         BUTTONLEFT(2),BUTTONTOP, CXBUTTON, BUTTONHEIGHT,
        !            98:         hwnd, NULL, hInst, NULL);
        !            99:       SetWindowLong (hwndButton, GWL_ID, TBID_GETTM);
        !           100: 
        !           101: 
        !           102:       /* create the two check boxes */
        !           103:       hwndButton = CreateWindow(
        !           104:         "BUTTON","SetMapperFlags(1)",
        !           105:         WS_CHILD | WS_VISIBLE | BS_AUTOCHECKBOX,
        !           106:         BUTTONLEFT(3),BUTTONTOP, CXBUTTON, BUTTONHEIGHT/2,
        !           107:         hwnd, NULL, hInst, NULL);
        !           108:       SetWindowLong (hwndButton, GWL_ID, TBID_CHKMAPPERFLAGS);
        !           109: 
        !           110:       hwndButton = CreateWindow(
        !           111:         "BUTTON","ShowAllGlyphs",
        !           112:         WS_CHILD | WS_VISIBLE | BS_AUTOCHECKBOX,
        !           113:         BUTTONLEFT(3),BUTTONTOP +  BUTTONHEIGHT/2, CXBUTTON, BUTTONHEIGHT/2,
        !           114:         hwnd, NULL, hInst, NULL);
        !           115:       SetWindowLong (hwndButton, GWL_ID, TBID_CHKALLGLYPHS);
        !           116: 
        !           117: 
        !           118:       /* put the printer fonts button near the RIGHT edge. */
        !           119:       hwndButton = CreateWindow(
        !           120:         "BUTTON","&Printer fonts",
        !           121:         WS_CHILD | WS_VISIBLE,
        !           122:         BUTTONLEFT(4),BUTTONTOP, CXBUTTON, BUTTONHEIGHT,
        !           123:         hwnd, NULL, hInst, NULL);
        !           124:       SetWindowLong (hwndButton, GWL_ID, TBID_PRINT);
        !           125:     } break;
        !           126: 
        !           127: 
        !           128:     /**********************************************************************\
        !           129:     *  WM_CTLCOLORBTN
        !           130:     *
        !           131:     * Try to set the background of the check boxes to match the toolbar.
        !           132:     \**********************************************************************/
        !           133:     case WM_CTLCOLORBTN: {
        !           134:       HDC hdc;
        !           135:       hdc = (HDC)wParam;
        !           136:       SetBkMode (hdc, TRANSPARENT);
        !           137: 
        !           138:       return (LONG) GetStockObject (LTGRAY_BRUSH);
        !           139:     } break;
        !           140: 
        !           141: 
        !           142:     /**********************************************************************\
        !           143:     *  WM_COMMAND
        !           144:     *
        !           145:     * Send the command messages back to hwndMain.
        !           146:     \**********************************************************************/
        !           147:     case WM_COMMAND:
        !           148:       PostMessage (hwndMain,message, wParam, lParam);
        !           149:     break;
        !           150: 
        !           151: 
        !           152:     /**********************************************************************\
        !           153:     *  WM_PAINT
        !           154:     *
        !           155:     * Paint two rectangular strips, one on top, one on bottom.
        !           156:     \**********************************************************************/
        !           157:     case WM_PAINT : {
        !           158:       PAINTSTRUCT ps;
        !           159:       RECT rect;
        !           160:       HDC hdc;
        !           161: 
        !           162:       hdc = BeginPaint(hwnd, &ps);
        !           163:       GetClientRect (hwnd, &rect);
        !           164:       rect.bottom = rect.top+BORDER;
        !           165:       FillRect (hdc, &rect, GetStockObject (WHITE_BRUSH));
        !           166:       GetClientRect (hwnd, &rect);
        !           167:       rect.top = rect.bottom-BORDER;
        !           168:       FillRect (hdc, &rect, GetStockObject (GRAY_BRUSH));
        !           169: 
        !           170:       EndPaint (hwnd, &ps);
        !           171:     } break;
        !           172: 
        !           173: 
        !           174:     default:
        !           175:       return (DefWindowProc(hwnd, message, wParam, lParam));
        !           176:     }
        !           177:     return (NULL);
        !           178: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.