|
|
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: *
1.1.1.2 ! root 5: * Steve Firebaugh
! 6: * Microsoft Developer Support
! 7: * Copyright (c) 1992 Microsoft Corporation
! 8: *
1.1 root 9: \**************************************************************************/
1.1.1.2 ! root 10: #define UNICODE
1.1 root 11:
12: #include <windows.h>
13: #include "ntfonts.h"
14:
15:
16: /* for the initial positioning of the buttons within the toolbar. */
1.1.1.2 ! root 17: #define SPACEBUTTON 8
1.1 root 18: #define CXBUTTON ((GetSystemMetrics (SM_CXFULLSCREEN)) /5 -2*SPACEBUTTON)
19: #define BUTTONTOP TOOLBARHEIGHT/8
20: #define BUTTONHEIGHT TOOLBARHEIGHT*3/4
21: #define BUTTONLEFT(x) ((2*x+1)*SPACEBUTTON + x*CXBUTTON)
22:
1.1.1.2 ! root 23: #define BORDER 2
1.1 root 24:
25:
26:
1.1.1.2 ! root 27: int initTB (HWND hwndParent)
1.1 root 28: {
29: WNDCLASS wc;
30:
31: wc.style = NULL;
32: wc.lpfnWndProc = (WNDPROC)ToolBarWndProc;
33: wc.cbClsExtra = 0;
34: wc.cbWndExtra = 0;
35: wc.hInstance = hInst;
36: wc.hIcon = NULL;
37: wc.hCursor = LoadCursor(NULL, IDC_ARROW);
38: wc.hbrBackground = GetStockObject(LTGRAY_BRUSH);
39: wc.lpszMenuName = NULL;
1.1.1.2 ! root 40: wc.lpszClassName = TEXT("ToolBar");
1.1 root 41:
42: if (!RegisterClass(&wc)) return (FALSE);
43:
44: hwndTB = CreateWindow(
1.1.1.2 ! root 45: TEXT("ToolBar"),
1.1 root 46: NULL,
47: WS_CHILD | WS_CLIPSIBLINGS | WS_VISIBLE,
48: 0,0,
49: GetSystemMetrics (SM_CXFULLSCREEN),
50: TOOLBARHEIGHT,
1.1.1.2 ! root 51: hwndParent, NULL, hInst, NULL);
1.1 root 52:
53: if (!hwndTB) return (FALSE);
54:
55: return TRUE;
56: }
57:
58:
59: /**************************************************************************\
60: *
61: * function: ToolBarWndProc
62: *
63: * input parameters: normal window procedure parameters.
64: *
65: * global variables:
66: * hwndMain - parent of the toolbar.
67: *
68: * When the window is created, create the various buttons. When those
69: * buttons send WM_COMMAND messages later, send the messages back to hwndMain.
70: *
71: \**************************************************************************/
1.1.1.2 ! root 72: LRESULT CALLBACK ToolBarWndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
1.1 root 73: {
74: static HWND hwndButton;
75: switch (message) {
76:
77: /**********************************************************************\
78: * WM_CREATE
79: *
80: * Create the various buttons which are on the toolbar. Once the buttons
81: * are created, set the window ID so that the WM_COMMANDS may be
82: * distinguished.
83: \**********************************************************************/
84: case WM_CREATE: {
85: hwndButton = CreateWindow(
1.1.1.2 ! root 86: TEXT("BUTTON"),TEXT("EnumFonts"),
1.1 root 87: WS_CHILD | WS_VISIBLE,
88: BUTTONLEFT(0),BUTTONTOP, CXBUTTON, BUTTONHEIGHT,
89: hwnd, NULL, hInst, NULL);
90: SetWindowLong (hwndButton, GWL_ID, TBID_ENUM);
91:
92: hwndButton = CreateWindow(
1.1.1.2 ! root 93: TEXT("BUTTON"),TEXT("CreateFont"),
1.1 root 94: WS_CHILD | WS_VISIBLE,
95: BUTTONLEFT(1),BUTTONTOP, CXBUTTON, BUTTONHEIGHT,
96: hwnd, NULL, hInst, NULL);
97: SetWindowLong (hwndButton, GWL_ID, TBID_CREATE);
98:
99: hwndButton = CreateWindow(
1.1.1.2 ! root 100: TEXT("BUTTON"),TEXT("GetMetrics"),
1.1 root 101: WS_CHILD | WS_VISIBLE ,
102: BUTTONLEFT(2),BUTTONTOP, CXBUTTON, BUTTONHEIGHT,
103: hwnd, NULL, hInst, NULL);
104: SetWindowLong (hwndButton, GWL_ID, TBID_GETTM);
105:
106: hwndButton = CreateWindow(
1.1.1.2 ! root 107: TEXT("BUTTON"),TEXT("GetFontData"),
! 108: WS_CHILD | WS_VISIBLE ,
! 109: BUTTONLEFT(3),BUTTONTOP, CXBUTTON, BUTTONHEIGHT,
1.1 root 110: hwnd, NULL, hInst, NULL);
1.1.1.2 ! root 111: SetWindowLong (hwndButton, GWL_ID, TBID_GETFONTDATA);
1.1 root 112:
113: hwndButton = CreateWindow(
1.1.1.2 ! root 114: TEXT("BUTTON"),TEXT("Enum(Printer)"),
1.1 root 115: WS_CHILD | WS_VISIBLE,
116: BUTTONLEFT(4),BUTTONTOP, CXBUTTON, BUTTONHEIGHT,
117: hwnd, NULL, hInst, NULL);
118: SetWindowLong (hwndButton, GWL_ID, TBID_PRINT);
119:
120: } break;
121:
122:
123: /**********************************************************************\
124: * WM_COMMAND
125: *
126: * Send the command messages back to hwndMain.
127: \**********************************************************************/
128: case WM_COMMAND:
129: PostMessage (hwndMain,message, wParam, lParam);
130: break;
131:
132:
133: /**********************************************************************\
134: * WM_PAINT
135: *
136: * Paint two rectangular strips, one on top, one on bottom.
137: \**********************************************************************/
138: case WM_PAINT : {
139: PAINTSTRUCT ps;
140: RECT rect;
141: HDC hdc;
142:
143: hdc = BeginPaint(hwnd, &ps);
144: GetClientRect (hwnd, &rect);
1.1.1.2 ! root 145: rect.right --;
! 146: rect.bottom --;
! 147:
! 148: SelectObject (hdc, GetStockObject (BLACK_PEN));
! 149: MoveToEx (hdc, rect.right, rect.top, NULL);
! 150: LineTo (hdc, rect.right, rect.bottom);
! 151: LineTo (hdc, rect.left, rect.bottom);
! 152: SelectObject (hdc, GetStockObject (WHITE_PEN));
! 153: LineTo (hdc, rect.left, rect.top);
! 154: LineTo (hdc, rect.right, rect.top);
1.1 root 155:
156: EndPaint (hwnd, &ps);
157: } break;
158:
159:
160: default:
161: return (DefWindowProc(hwnd, message, wParam, lParam));
162: }
163: return (NULL);
164: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.