home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 21 / IOPROG_21.ISO / SOFT / FONTC.ZIP / TEMP / FontTest / TipWnd.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1998-09-25  |  4.0 KB  |  180 lines

  1. // TipWnd.cpp : implementation file
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "TipWnd.h"
  6.  
  7. #ifdef _DEBUG
  8. #define new DEBUG_NEW
  9. #undef THIS_FILE
  10. static char THIS_FILE[] = __FILE__;
  11. #endif
  12.  
  13. #define FONT_HEIGHT -18
  14.  
  15. //////////////////////////////////////////////////////////////////////////
  16. // ⌐ Paramax Technology Limited                                         // 
  17. // ----------------------------                                         //
  18. //                                                                      //
  19. // The author accepts no liablility for injury or loss of profits       // 
  20. // if this software is used. You willingness to use this software       //
  21. // indicates you accept total liability                                 //
  22. //                                                                      // 
  23. //////////////////////////////////////////////////////////////////////////
  24.  
  25.  
  26. /////////////////////////////////////////////////////////////////////////////
  27. // CTipWnd
  28.  
  29. CTipWnd::CTipWnd()
  30. {
  31. }
  32.  
  33. CTipWnd::~CTipWnd()
  34. {
  35. }
  36.  
  37. ////////////////////////////////////////////////////////////////////////////////
  38. //
  39. // FUNCTION:    CTipWnd::Create
  40. //
  41. // DESCRIPTION:    Creates tip window based on Parent window
  42. //
  43. // INPUTS:        
  44. //
  45. // RETURNS:     
  46. //
  47. // NOTES:       
  48. //
  49. // MODIFICATIONS:
  50. //
  51. // Name            Date      Version    Comments
  52. // N T ALMOND   25/09/98  1.0        Origin
  53. //
  54. ////////////////////////////////////////////////////////////////////////////////
  55. BOOL CTipWnd::Create(CWnd* pParent)
  56. {
  57.  
  58.     return     CWnd::CreateEx(0,
  59.         AfxRegisterWndClass(0),
  60.         NULL,
  61.         WS_BORDER|WS_POPUP,
  62.         0,
  63.         0,0,0,
  64.         NULL,
  65.         (HMENU)0);
  66.  
  67. }
  68.  
  69.  
  70. BEGIN_MESSAGE_MAP(CTipWnd, CWnd)
  71.     //{{AFX_MSG_MAP(CTipWnd)
  72.     ON_WM_ERASEBKGND()
  73.     ON_WM_PAINT()
  74.     //}}AFX_MSG_MAP
  75. END_MESSAGE_MAP()
  76.  
  77.  
  78. /////////////////////////////////////////////////////////////////////////////
  79. // CTipWnd message handlers
  80.  
  81. ////////////////////////////////////////////////////////////////////////////////
  82. //
  83. // FUNCTION:    CTipWnd::OnEraseBkgnd
  84. //
  85. // DESCRIPTION:    Called to paint background in infowindow color
  86. //
  87. // INPUTS:        
  88. //
  89. // RETURNS:     
  90. //
  91. // NOTES:       
  92. //
  93. // MODIFICATIONS:
  94. //
  95. // Name            Date      Version    Comments
  96. // N T ALMOND   25/09/98  1.0        Origin
  97. //
  98. ////////////////////////////////////////////////////////////////////////////////
  99. BOOL CTipWnd::OnEraseBkgnd(CDC* pDC) 
  100. {
  101.     CBrush br(GetSysColor(COLOR_INFOBK));
  102.     CRect rc;
  103.     pDC->GetClipBox(rc);
  104.     CBrush* pOldBrush = pDC->SelectObject(&br);
  105.     pDC->PatBlt(rc.left,rc.top,rc.Width(),rc.Height(),PATCOPY);
  106.  
  107.     pDC->SelectObject(pOldBrush);
  108.  
  109.     return TRUE;
  110. }
  111.  
  112. ////////////////////////////////////////////////////////////////////////////////
  113. //
  114. // FUNCTION:    CTipWnd::ShowTips
  115. //
  116. // DESCRIPTION:    Shows tip window 
  117. //
  118. // INPUTS:        
  119. //
  120. // RETURNS:     
  121. //
  122. // NOTES:       
  123. //
  124. // MODIFICATIONS:
  125. //
  126. // Name            Date      Version    Comments
  127. // N T ALMOND   25/09/98  1.0        Origin
  128. //
  129. ////////////////////////////////////////////////////////////////////////////////
  130. void CTipWnd::ShowTips(CPoint pt,const CString& str)
  131. {
  132.     CSize sz;
  133.     CDC* pDC = GetDC();
  134.  
  135.     // Create new font if the selection has changed
  136.     if (m_strFont != str)
  137.     {
  138.         m_strFont = str;
  139.  
  140.         LOGFONT lf;
  141.         ZeroMemory(&lf,sizeof(lf));
  142.  
  143.         lf.lfHeight = FONT_HEIGHT;
  144.         strcpy(lf.lfFaceName,m_strFont);
  145.         
  146.         // Delete old font
  147.         m_font.DeleteObject();
  148.         m_font.CreateFontIndirect(&lf);
  149.         
  150.  
  151.         CFont* pFont = pDC->SelectObject(&m_font);
  152.  
  153.         // String demensions of font on screen 
  154.         sz = pDC->GetTextExtent(m_strFont);
  155.  
  156.         // Give some space round the font
  157.         sz.cx += 8;
  158.         sz.cy += 8;
  159.  
  160.         pDC->SelectObject(pFont);
  161.         ReleaseDC(pDC);
  162.  
  163.         SetWindowPos(0,pt.x,pt.y,sz.cx,sz.cy,SWP_SHOWWINDOW|SWP_NOACTIVATE);
  164.         RedrawWindow(); // Force immediate redraw
  165.     }
  166. }
  167.  
  168.  
  169.  
  170. void CTipWnd::OnPaint() 
  171. {
  172.     CPaintDC dc(this); // device context for painting
  173.     
  174.     dc.SelectObject(&m_font);
  175.     CRect rc;
  176.     GetClientRect(rc);
  177.     dc.DrawText(m_strFont,rc,DT_SINGLELINE|DT_VCENTER|DT_CENTER);
  178.     // Do not call CWnd::OnPaint() for painting messages
  179. }
  180.