home *** CD-ROM | disk | FTP | other *** search
/ Windows Graphics Programming / Feng_Yuan_Win32_GDI_DirectX.iso / Samples / Chapt_01 / Hello3 / Hello3.h < prev    next >
Encoding:
C/C++ Source or Header  |  2000-05-16  |  2.9 KB  |  91 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   : hello3.h                                                             //
  10. //  Description: Hello World Demo 3, C++ window, Chapter 1                           //
  11. //  Version    : 1.00.000, May 31, 2000                                              //
  12. //-----------------------------------------------------------------------------------//
  13.  
  14. #define STRICT
  15. #define WIN32_LEAN_AND_MEAN
  16.  
  17. #include <windows.h>
  18. #include <assert.h>
  19. #include <tchar.h>
  20.  
  21. #include "..\..\include\win.h"
  22.  
  23. const TCHAR szMessage[] = _T("Hello, World !");
  24. const TCHAR szFace[]    = _T("Times New Roman");
  25. const TCHAR szHint[]    = _T("Press ESC to quit.");
  26. const TCHAR szProgram[] = _T("HelloWorld3");
  27.  
  28. void CenterText(HDC hDC, int x, int y, LPCTSTR szFace, 
  29.                 LPCTSTR szMessage, int point)
  30. {
  31.     HFONT hFont = CreateFont(
  32.         - point * GetDeviceCaps(hDC, LOGPIXELSY) / 72,
  33.         0, 0, 0, FW_BOLD, TRUE, FALSE, FALSE, 
  34.         ANSI_CHARSET, OUT_TT_PRECIS, CLIP_DEFAULT_PRECIS, 
  35.         PROOF_QUALITY, VARIABLE_PITCH, szFace);
  36.     assert(hFont);
  37.  
  38.     HGDIOBJ hOld = SelectObject(hDC, hFont);
  39.  
  40.     SetTextAlign(hDC, TA_CENTER | TA_BASELINE);
  41.  
  42.     SetBkMode(hDC, TRANSPARENT);
  43.     SetTextColor(hDC, RGB(0, 0, 0xFF));
  44.     TextOut(hDC, x, y, szMessage, _tcslen(szMessage));
  45.  
  46.     SelectObject(hDC, hOld);
  47.     DeleteObject(hFont);
  48. }
  49.  
  50.  
  51. class KHelloWindow : public KWindow
  52. {
  53.     void OnKeyDown(WPARAM wParam, LPARAM lParam)
  54.     {
  55.         if ( wParam==VK_ESCAPE )
  56.             PostMessage(m_hWnd, WM_CLOSE, 0, 0);
  57.     }
  58.  
  59.     void OnDraw(HDC hDC)
  60.     {
  61.         TextOut(hDC, 0, 0, szHint, lstrlen(szHint));
  62.         CenterText(hDC, GetDeviceCaps(hDC, HORZRES)/2,
  63.                  GetDeviceCaps(hDC, VERTRES)/2,
  64.                  szFace, szMessage, 72);
  65.     }
  66.  
  67. public:
  68.     
  69. };
  70.  
  71.  
  72. int WINAPI WinMain(HINSTANCE hInst, HINSTANCE, 
  73.                    LPSTR lpCmd, int nShow)
  74. {
  75.     KHelloWindow win;
  76.     
  77.     win.CreateEx(0, szProgram, szProgram,
  78.                  WS_POPUP,
  79.                  0, 0,
  80.                  GetSystemMetrics( SM_CXSCREEN ),
  81.                  GetSystemMetrics( SM_CYSCREEN ),
  82.                  NULL, NULL, hInst);
  83.         
  84.     win.ShowWindow(nShow);
  85.  
  86.     BOOL rslt = IsZoomed(win.m_hWnd);
  87.  
  88.     win.UpdateWindow();
  89.   
  90.     return win.MessageLoop();
  91. }