PropertyGridItemFont.h 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. #pragma once
  2. //////////////////////////////////////////////////////////////////////
  3. // CPropertyGridItemFont is a CPropertyGridItem derived class.
  4. // It is used to create Font-value item in a Property Grid control.
  5. //
  6. class CPropertyGridItemFont : public CPropertyGridItem
  7. {
  8. public:
  9. // Constructs a CPropertyGridItemFont object.
  10. //
  11. CPropertyGridItemFont(
  12. // Caption of the item.
  13. CString strCaption,
  14. // Initial value
  15. LOGFONT& font);
  16. // Constructs a CPropertyGridItemFont object.
  17. //
  18. CPropertyGridItemFont(
  19. // Identifier of the item.
  20. UINT nID,
  21. // Initial value
  22. LOGFONT& font);
  23. // Destroys a CPropertyGridItemFont object.
  24. //
  25. virtual ~CPropertyGridItemFont(void);
  26. private:
  27. LOGFONT m_lfValue;
  28. LOGFONT* m_pBindFont; // 绑定到属性项的字体对象
  29. public:
  30. // Call this method to change item's value
  31. //
  32. void SetFont(
  33. // The new value of the item.
  34. LOGFONT& font);
  35. // Call this method to get the LOGFONT value of the item.
  36. //
  37. void GetFont(
  38. //Pointer to the LOGFONT structure to receive the font information.
  39. LOGFONT* lf);
  40. // 把一个字体对象绑定到属性项
  41. void BindToFont(LOGFONT* pBindFont)
  42. {
  43. m_pBindFont = pBindFont;
  44. if (m_pBindFont)
  45. SetFont(*m_pBindFont);
  46. }
  47. // 把字体对象转换成类似“宋体; 9pt”这样的字符串
  48. static CString FontToString(LOGFONT& font);
  49. protected:
  50. virtual void OnInplaceButtonDown();
  51. // 字体对话框的回调函数
  52. static UINT CALLBACK FontDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam);
  53. };
  54. //////////////////////////////////////////////////////////////////////
  55. AFX_INLINE void CPropertyGridItemFont::GetFont(LOGFONT* lf) {
  56. ASSERT(lf != NULL); memcpy(lf, &m_lfValue, sizeof(LOGFONT));
  57. }