Something went wrong. Try again.
Reactos
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
// ------------------------------------------------------------------// Windows 2000 Graphics API Black Book// Chapter 8 - Listing 8.1 (Scaled Text Demo)//// Created by Damon Chandler <dmc27@ee.cornell.edu>// Updates can be downloaded at: <www.coriolis.com>//// Please do not hesistate to e-mail me at dmc27@ee.cornell.edu// if you have any questions about this code.// ------------------------------------------------------------------
//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>#include <windows.h>#include <commctrl.h>#include <cassert>
// for the MakeFont() function...#include "mk_font.h"//<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
HINSTANCE hInst;const char* WndClassName = "GMainWnd";LRESULT CALLBACK MainWndProc(HWND HWnd, UINT Msg, WPARAM WParam, LPARAM LParam);
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE, LPTSTR, int nCmdShow){ hInst = hInstance;
WNDCLASS wc; memset(&wc, 0, sizeof(WNDCLASS));
wc.style = CS_HREDRAW | CS_VREDRAW; wc.lpszClassName = WndClassName; wc.lpfnWndProc = MainWndProc; wc.hInstance = hInst; wc.hCursor = LoadCursor(NULL, IDC_ARROW); wc.hbrBackground = reinterpret_cast<HBRUSH>( COLOR_BTNFACE + 1 );
if (RegisterClass(&wc)) { HWND hWnd = CreateWindow( WndClassName, TEXT("Scaled Text Demo"), WS_OVERLAPPEDWINDOW | WS_CAPTION | WS_VISIBLE | WS_CLIPCHILDREN, CW_USEDEFAULT, CW_USEDEFAULT, 800, 300, NULL, NULL, hInst, NULL );
if (hWnd) { ShowWindow(hWnd, nCmdShow); UpdateWindow(hWnd);
MSG msg; while (GetMessage(&msg, NULL, 0, 0)) { TranslateMessage(&msg); DispatchMessage(&msg); } } } return 0;}//-------------------------------------------------------------------------
HWND hTrackBar = NULL;HFONT hTTFont = NULL;double scale = 0.0;LPCSTR pText = TEXT("The Scaled Text!");
LRESULT CALLBACK MainWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam){ switch (msg) { case WM_CREATE: { INITCOMMONCONTROLSEX icx; icx.dwSize = sizeof(INITCOMMONCONTROLSEX); icx.dwICC = ICC_BAR_CLASSES;
InitCommonControlsEx(&icx);
hTrackBar = CreateWindow( TRACKBAR_CLASS, "", TBS_HORZ | TBS_BOTH | TBS_AUTOTICKS | TBS_FIXEDLENGTH | TBS_ENABLESELRANGE | WS_CHILD | WS_VISIBLE, 10, 260, 375, 40, hWnd, NULL, hInst, NULL );
assert(hTrackBar != NULL); SNDMSG(hTrackBar, TBM_SETTHUMBLENGTH, 20, 0); SNDMSG(hTrackBar, TBM_SETRANGEMAX, TRUE, 100);
// create the TrueType (scalable) font HDC hDC = GetDC(hWnd); try { // see Chapter 4 for the definition of MakeFont hTTFont = font::MakeFont(hDC, "Impact", 72); if (!hTTFont) throw; } catch (...) { ReleaseDC(hWnd, hDC); } ReleaseDC(hWnd, hDC); break; } case WM_HSCROLL: { if (reinterpret_cast<HWND>(lParam) == hTrackBar) { // // adjust the scaling factor according to // the position of the trackbar's slider // scale = static_cast<double>( (SNDMSG(hTrackBar, TBM_GETPOS, 0, 0) + 1) / 50.0 ); InvalidateRect(hWnd, NULL, true); } break; } case WM_ERASEBKGND: { LRESULT res = DefWindowProc(hWnd, msg, wParam, lParam);
HDC hDC = reinterpret_cast<HDC>(wParam); HFONT hOldFont = static_cast<HFONT>( SelectObject(hDC, hTTFont) ); try { SetBkMode(hDC, TRANSPARENT);
// open a path bracket if (!BeginPath(hDC)) throw;
// record the text to the path TextOut(hDC, 10, 10, pText, lstrlen(pText));
// close the path bracket and // select the path into hDC EndPath(hDC);
// determine the number of endpoints in the path const int num_points = GetPath(hDC, NULL, NULL, 0); if (num_points > 0) { // make room for the POINTs and vertex types POINT* pPEnds = new POINT[num_points]; unsigned char* pTypes = new unsigned char[num_points]; try { // get the path's description int num_got = GetPath(hDC, pPEnds, pTypes, num_points); if (num_got > 0) { // start a new path bracket if (!BeginPath(hDC)) throw;
// scale each point in the description int iPoint; for (iPoint = 0; iPoint < num_got; ++iPoint) { pPEnds[iPoint].x = static_cast<LONG>( scale * pPEnds[iPoint].x + 0.5 ); pPEnds[iPoint].y = static_cast<LONG>( scale * pPEnds[iPoint].y + 0.5 ); }
for (iPoint = 0; iPoint < num_points; ++iPoint) { // handle the MoveToEx case if (pTypes[iPoint] == PT_MOVETO) { MoveToEx( hDC, pPEnds[iPoint].x, pPEnds[iPoint].y, NULL ); } // handle the LineTo case else if ( pTypes[iPoint] == PT_LINETO || pTypes[iPoint] == (PT_LINETO | PT_CLOSEFIGURE) ) { LineTo(hDC, pPEnds[iPoint].x, pPEnds[iPoint].y); } // handle the PolyBezierTo case else if ( pTypes[iPoint] == PT_BEZIERTO || pTypes[iPoint] == (PT_BEZIERTO | PT_CLOSEFIGURE) ) { PolyBezierTo(hDC, pPEnds + iPoint, 3); iPoint += 2; } }
// close the new path bracket EndPath(hDC);
// stroke and fill the new path StrokeAndFillPath(hDC); } } catch (...) { // clean up delete [] pTypes; delete [] pPEnds; throw; } // clean up delete [] pTypes; delete [] pPEnds; } // ... } catch (...) { SelectObject(hDC, hOldFont); } SelectObject(hDC, hOldFont); return res; } case WM_SIZE: { MoveWindow( hTrackBar, 0, HIWORD(lParam) - 40, LOWORD(lParam), 40, false ); break; } case WM_DESTROY: { // clean up DeleteObject(hTTFont); PostQuitMessage(0); break; } } return DefWindowProc(hWnd, msg, wParam, lParam);}//-------------------------------------------------------------------------