c77216b11b810f9880434630ae0cacf74d73fb69
2 // ------------------------------------------------------------------
3 // Windows 2000 Graphics API Black Book
4 // Chapter 8 - Listing 8.1 (Scaled Text Demo)
6 // Created by Damon Chandler <dmc27@ee.cornell.edu>
7 // Updates can be downloaded at: <www.coriolis.com>
9 // Please do not hesistate to e-mail me at dmc27@ee.cornell.edu
10 // if you have any questions about this code.
11 // ------------------------------------------------------------------
14 //>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
19 // for the MakeFont() function...
21 //<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
25 const char* WndClassName
= "GMainWnd";
26 LRESULT CALLBACK
MainWndProc(HWND HWnd
, UINT Msg
, WPARAM WParam
,
30 int APIENTRY
WinMain(HINSTANCE hInstance
, HINSTANCE
, LPTSTR
,
36 memset(&wc
, 0, sizeof(WNDCLASS
));
38 wc
.style
= CS_HREDRAW
| CS_VREDRAW
;
39 wc
.lpszClassName
= WndClassName
;
40 wc
.lpfnWndProc
= MainWndProc
;
42 wc
.hCursor
= LoadCursor(NULL
, IDC_ARROW
);
43 wc
.hbrBackground
= reinterpret_cast<HBRUSH
>(
47 if (RegisterClass(&wc
))
51 WndClassName
, TEXT("Scaled Text Demo"),
52 WS_OVERLAPPEDWINDOW
| WS_CAPTION
|
53 WS_VISIBLE
| WS_CLIPCHILDREN
,
54 CW_USEDEFAULT
, CW_USEDEFAULT
, 800, 300,
55 NULL
, NULL
, hInst
, NULL
60 ShowWindow(hWnd
, nCmdShow
);
64 while (GetMessage(&msg
, NULL
, 0, 0))
66 TranslateMessage(&msg
);
67 DispatchMessage(&msg
);
73 //-------------------------------------------------------------------------
76 HWND hTrackBar
= NULL
;
79 LPCSTR pText
= TEXT("The Scaled Text!");
81 LRESULT CALLBACK
MainWndProc(HWND hWnd
, UINT msg
, WPARAM wParam
,
88 INITCOMMONCONTROLSEX icx
;
89 icx
.dwSize
= sizeof(INITCOMMONCONTROLSEX
);
90 icx
.dwICC
= ICC_BAR_CLASSES
;
92 InitCommonControlsEx(&icx
);
97 TBS_HORZ
| TBS_BOTH
| TBS_AUTOTICKS
|
98 TBS_FIXEDLENGTH
| TBS_ENABLESELRANGE
|
99 WS_CHILD
| WS_VISIBLE
,
101 hWnd
, NULL
, hInst
, NULL
104 assert(hTrackBar
!= NULL
);
105 SNDMSG(hTrackBar
, TBM_SETTHUMBLENGTH
, 20, 0);
106 SNDMSG(hTrackBar
, TBM_SETRANGEMAX
, TRUE
, 100);
108 // create the TrueType (scalable) font
109 HDC hDC
= GetDC(hWnd
);
112 // see Chapter 4 for the definition of MakeFont
113 hTTFont
= font::MakeFont(hDC
, "Impact", 72);
118 ReleaseDC(hWnd
, hDC
);
120 ReleaseDC(hWnd
, hDC
);
125 if (reinterpret_cast<HWND
>(lParam
) == hTrackBar
)
128 // adjust the scaling factor according to
129 // the position of the trackbar's slider
131 scale
= static_cast<double>(
132 (SNDMSG(hTrackBar
, TBM_GETPOS
, 0, 0) + 1) / 50.0
134 InvalidateRect(hWnd
, NULL
, true);
140 LRESULT res
= DefWindowProc(hWnd
, msg
, wParam
, lParam
);
142 HDC hDC
= reinterpret_cast<HDC
>(wParam
);
143 HFONT hOldFont
= static_cast<HFONT
>(
144 SelectObject(hDC
, hTTFont
)
148 SetBkMode(hDC
, TRANSPARENT
);
150 // open a path bracket
151 if (!BeginPath(hDC
)) throw;
153 // record the text to the path
154 TextOut(hDC
, 10, 10, pText
, lstrlen(pText
));
156 // close the path bracket and
157 // select the path into hDC
160 // determine the number of endpoints in the path
161 const int num_points
= GetPath(hDC
, NULL
, NULL
, 0);
164 // make room for the POINTs and vertex types
165 POINT
* pPEnds
= new POINT
[num_points
];
166 unsigned char* pTypes
= new unsigned char[num_points
];
169 // get the path's description
170 int num_got
= GetPath(hDC
, pPEnds
, pTypes
, num_points
);
173 // start a new path bracket
174 if (!BeginPath(hDC
)) throw;
176 // scale each point in the description
178 for (iPoint
= 0; iPoint
< num_got
; ++iPoint
)
180 pPEnds
[iPoint
].x
= static_cast<LONG
>(
181 scale
* pPEnds
[iPoint
].x
+ 0.5
183 pPEnds
[iPoint
].y
= static_cast<LONG
>(
184 scale
* pPEnds
[iPoint
].y
+ 0.5
188 for (iPoint
= 0; iPoint
< num_points
; ++iPoint
)
190 // handle the MoveToEx case
191 if (pTypes
[iPoint
] == PT_MOVETO
)
194 hDC
, pPEnds
[iPoint
].x
, pPEnds
[iPoint
].y
, NULL
197 // handle the LineTo case
199 pTypes
[iPoint
] == PT_LINETO
||
200 pTypes
[iPoint
] == (PT_LINETO
| PT_CLOSEFIGURE
)
203 LineTo(hDC
, pPEnds
[iPoint
].x
, pPEnds
[iPoint
].y
);
205 // handle the PolyBezierTo case
207 pTypes
[iPoint
] == PT_BEZIERTO
||
208 pTypes
[iPoint
] == (PT_BEZIERTO
| PT_CLOSEFIGURE
)
211 PolyBezierTo(hDC
, pPEnds
+ iPoint
, 3);
216 // close the new path bracket
219 // stroke and fill the new path
220 StrokeAndFillPath(hDC
);
238 SelectObject(hDC
, hOldFont
);
240 SelectObject(hDC
, hOldFont
);
247 0, HIWORD(lParam
) - 40, LOWORD(lParam
), 40,
255 DeleteObject(hTTFont
);
260 return DefWindowProc(hWnd
, msg
, wParam
, lParam
);
262 //-------------------------------------------------------------------------