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