home *** CD-ROM | disk | FTP | other *** search
/ Windows Graphics Programming / Feng_Yuan_Win32_GDI_DirectX.iso / Samples / Chapt_01 / Hello2 / Hello2.cpp next >
Encoding:
C/C++ Source or Header  |  2000-07-27  |  2.2 KB  |  58 lines

  1. //-----------------------------------------------------------------------------------//
  2. //              Windows Graphics Programming: Win32 GDI and DirectDraw               //
  3. //                             ISBN  0-13-086985-6                                   //
  4. //                                                                                   //
  5. //  Written            by  Yuan, Feng                             www.fengyuan.com   //
  6. //  Copyright (c) 2000 by  Hewlett-Packard Company                www.hp.com         //
  7. //  Published          by  Prentice Hall PTR, Prentice-Hall, Inc. www.phptr.com      //
  8. //                                                                                   //
  9. //  FileName   : hello2.cpp                                                             //
  10. //  Description: Hellow World Demo 2, full screen display, Chapter 1                 //
  11. //  Version    : 1.00.001, July 26, 2000                                             //
  12. //-----------------------------------------------------------------------------------//
  13.  
  14. #define STRICT
  15. #define WIN32_LEAN_AND_MEAN
  16.  
  17. #include <windows.h>
  18. #include <tchar.h>
  19. #include <assert.h>
  20.  
  21. void CenterText(HDC hDC, int x, int y, LPCTSTR szFace, LPCTSTR szMessage, int point)
  22. {
  23.     HFONT hFont = CreateFont(- point * GetDeviceCaps(hDC, LOGPIXELSY) / 72,
  24.                              0, 0, 0, FW_BOLD, TRUE, FALSE, FALSE, 
  25.                              ANSI_CHARSET, OUT_TT_PRECIS, CLIP_DEFAULT_PRECIS, 
  26.                              PROOF_QUALITY, VARIABLE_PITCH, szFace);
  27. //  assert(hFont);
  28.  
  29.     HGDIOBJ hOld = SelectObject(hDC, hFont);
  30.  
  31.     SetTextAlign(hDC, TA_CENTER | TA_BASELINE);
  32.  
  33.     SetBkMode(hDC, TRANSPARENT);
  34.     SetTextColor(hDC, RGB(0, 0, 0xFF));
  35.     TextOut(hDC, x, y, szMessage, _tcslen(szMessage));
  36.  
  37.     SelectObject(hDC, hOld);
  38.     DeleteObject(hFont);
  39. }
  40.  
  41. const TCHAR szMessage[] = _T("Hello, World");
  42. const TCHAR szFace[]    = _T("Times New Roman");
  43.  
  44. #pragma comment(linker, "-merge:.rdata=.text")
  45. #pragma comment(linker, "-align:512")
  46.  
  47. extern "C" void WinMainCRTStartup()
  48. {
  49.     HDC hDC = GetDC(NULL);
  50. //  assert(hDC);
  51.  
  52.     CenterText(hDC, GetSystemMetrics(SM_CXSCREEN) / 2,
  53.             GetSystemMetrics(SM_CYSCREEN) / 2,
  54.             szFace, szMessage, 72);
  55.     
  56.     ReleaseDC(NULL, hDC);
  57.     ExitProcess(0);
  58. }