home *** CD-ROM | disk | FTP | other *** search
/ Windows Graphics Programming / Feng_Yuan_Win32_GDI_DirectX.iso / Samples / Chapt_17 / CodePrint / progview.h < prev    next >
Encoding:
C/C++ Source or Header  |  2000-05-24  |  2.6 KB  |  93 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   : progview.h                                                             //
  10. //  Description: KProgrampageCanvas window class                                     //
  11. //  Version    : 1.00.000, May 31, 2000                                              //
  12. //-----------------------------------------------------------------------------------//
  13.  
  14. int   CountLine(const char * text, int size);
  15.  
  16. class KProgramPageCanvas : public KPageCanvas
  17. {
  18.     char * m_pBuffer;
  19.     int    m_nSize;
  20.  
  21.     HFONT          m_hFont;
  22.     int              m_nLineCount;
  23.     int              m_nLinePerPage;
  24.     KTextFormator m_formator;
  25.     
  26.     void SyntaxHighlight(HDC hDC, int x, int y, const TCHAR * mess);
  27.  
  28.     void GetWndClassEx(WNDCLASSEX & wc)
  29.     {
  30.         KPageCanvas::GetWndClassEx(wc);
  31.  
  32.         wc.hIcon = LoadIcon(m_hInst, MAKEINTRESOURCE(IDI_PRINT));
  33.     }
  34.  
  35. public:
  36.     
  37.     virtual void OnCreate(void);
  38.     virtual void RefreshPaper(void);
  39.  
  40.     virtual int GetColumnCount(void)
  41.     {
  42.         RECT rect;
  43.  
  44.         GetClientRect(m_hWnd, & rect);
  45.  
  46.         int clientwidth = rect.right - rect.left - MARGIN_X;
  47.         int pagewidth   = m_Paper.cx * m_nScale / BASE_DPI + MARGIN_X;
  48.  
  49.         return max(1, clientwidth / pagewidth);
  50.     }
  51.  
  52.     virtual int GetPageCount(void)
  53.     {
  54.         if ( m_hFont==NULL )
  55.             return 1;
  56.         else
  57.         {
  58.             m_nLinePerPage = (int) (GetDrawableHeight() / m_formator.GetLinespace());
  59.  
  60.             if ( m_nLinePerPage<=0 )
  61.                 return 1;
  62.  
  63.             return ( m_nLineCount + m_nLinePerPage-1 ) / m_nLinePerPage;
  64.         }
  65.     }
  66.  
  67.     virtual void UponDrawPage(HDC hDC, const RECT * rcPaint, int width, int height, int pageno);
  68.     
  69.     virtual int OnCommand(int cmd, HWND hWnd);
  70.     
  71.     KProgramPageCanvas(char * pBuffer, int size, HBRUSH hBackground) : KPageCanvas(hBackground)
  72.     {
  73.         m_pBuffer     = pBuffer;
  74.         m_nSize         = size;
  75.         m_nLineCount = CountLine(pBuffer, size);
  76.  
  77.         m_hFont          = NULL;
  78.     }
  79.  
  80.     ~KProgramPageCanvas()
  81.     {
  82.         if ( m_pBuffer )
  83.         {
  84.             delete [] m_pBuffer;
  85.             m_pBuffer = NULL;
  86.         }
  87.  
  88.         if ( m_hFont )
  89.             DeleteObject(m_hFont);
  90.     }
  91. };
  92.  
  93.