TestDlg1.cpp 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. // TestDlg1.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "ylgl.h"
  5. #include "TestDlg1.h"
  6. #ifdef _DEBUG
  7. #define new DEBUG_NEW
  8. #undef THIS_FILE
  9. static char THIS_FILE[] = __FILE__;
  10. #endif
  11. /////////////////////////////////////////////////////////////////////////////
  12. // TestDlg dialog
  13. TestDlg::TestDlg(CWnd* pParent /*=NULL*/)
  14. : CDialog(TestDlg::IDD, pParent)
  15. {
  16. //{{AFX_DATA_INIT(TestDlg)
  17. // NOTE: the ClassWizard will add member initialization here
  18. //}}AFX_DATA_INIT
  19. }
  20. void TestDlg::DoDataExchange(CDataExchange* pDX)
  21. {
  22. CDialog::DoDataExchange(pDX);
  23. //{{AFX_DATA_MAP(TestDlg)
  24. // NOTE: the ClassWizard will add DDX and DDV calls here
  25. //}}AFX_DATA_MAP
  26. }
  27. BEGIN_MESSAGE_MAP(TestDlg, CDialog)
  28. //{{AFX_MSG_MAP(TestDlg)
  29. ON_WM_CTLCOLOR()
  30. //}}AFX_MSG_MAP
  31. END_MESSAGE_MAP()
  32. /////////////////////////////////////////////////////////////////////////////
  33. // TestDlg message handlers
  34. BOOL TestDlg::OnInitDialog()
  35. {
  36. CDialog::OnInitDialog();
  37. // TODO: Add extra initialization here
  38. CRect rc;
  39. GetDlgItem(IDC_STATIC5)->GetWindowRect(rc);
  40. ScreenToClient(rc);
  41. m_propertySheet.m_Rect = rc;
  42. m_propertySheet.m_nPages = -1; // init this membervariable
  43. m_propertySheet.m_nActPage = 0; // init this membervariable
  44. m_propertySheet.m_nCtrlID = 2000; // control-id in the dialog
  45. // and create it on the screen
  46. m_propertySheet.Create (WS_VISIBLE | WS_CHILD | WS_TABSTOP,
  47. m_propertySheet.m_Rect, this, m_propertySheet.m_nCtrlID);
  48. // Now add the dialogs page per page
  49. TC_ITEM Item;
  50. Item.mask = TCIF_TEXT;
  51. CMyPropertyPage *pPropPage;
  52. int nN;
  53. int nPages = 2; // in my example I have two pages
  54. for (nN = 0; nN < nPages; nN++)
  55. {
  56. pPropPage = new (CMyPropertyPage); // new it
  57. // Create the tab and the dialog
  58. switch (nN)
  59. {
  60. case 0: // page number 1 - a small example
  61. Item.pszText = _T("¹«Ë¾¼ò½é");
  62. pPropPage->m_strTitle = _T("&Page1"); // or get the title of m_fontPage - whatwever you want
  63. pPropPage->m_pDialogPage = (CMyPropDialog *) &m_propPage1;
  64. pPropPage->m_pDialogPage->Create (IDD_PROPPAGE1, &m_propertySheet);
  65. break;
  66. case 1: // page number 1 - a small example
  67. Item.pszText = _T("¹«Ë¾ww");
  68. pPropPage->m_strTitle = _T("&Page2"); // or get the title of m_fontPage - whatwever you want
  69. pPropPage->m_pDialogPage = (CMyPropDialog *) &m_propPage2;
  70. pPropPage->m_pDialogPage->Create (IDD_PROPPAGE2, &m_propertySheet);
  71. break;
  72. }
  73. m_propertySheet.InsertItem (nN, &Item); // this is fot CTabWnd
  74. pPropPage->m_hLocal = NULL; // nothing is created on the fly
  75. // important information on delete!
  76. // add it to the array
  77. m_propertySheet.m_Dialogs.Add (pPropPage);
  78. m_propertySheet.m_nPages++; // one more page
  79. // the size of CTabWnd is m_rect
  80. // the size of the dialog is smaller
  81. pPropPage->m_Rect.top = 30; // above there must be enough place for the tab-control
  82. pPropPage->m_Rect.left = 10; // border of 10 units is good
  83. pPropPage->m_Rect.bottom = m_propertySheet.m_Rect.bottom - m_propertySheet.m_Rect.top - 10;
  84. pPropPage->m_Rect.right = m_propertySheet.m_Rect.right - m_propertySheet.m_Rect.left - 10;
  85. // Only the 1. page should be active at startup
  86. if (nN > 0)
  87. {
  88. pPropPage->m_pDialogPage->SetWindowPos(NULL, pPropPage->m_Rect.left,
  89. pPropPage->m_Rect.top, 0, 0,
  90. SWP_HIDEWINDOW | SWP_NOSIZE);
  91. }
  92. else
  93. {
  94. pPropPage->m_pDialogPage->SetWindowPos(NULL, pPropPage->m_Rect.left,
  95. pPropPage->m_Rect.top, 0, 0,
  96. SWP_SHOWWINDOW | SWP_NOSIZE);
  97. }
  98. }
  99. return TRUE; // return TRUE unless you set the focus to a control
  100. // EXCEPTION: OCX Property Pages should return FALSE
  101. }
  102. extern CBrush g_editbkbrush;
  103. HBRUSH TestDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
  104. {
  105. HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
  106. if(nCtlColor==CTLCOLOR_STATIC)
  107. {
  108. char szTemp[MAX_PATH];
  109. GetClassName(pWnd->GetSafeHwnd (), szTemp, sizeof(szTemp));
  110. if(lstrcmpi(szTemp, "Edit") == 0)
  111. {
  112. pDC->SetBkColor( g_bkcol );
  113. return g_editbkbrush;
  114. }
  115. else
  116. {
  117. pDC->SetBkColor( g_bkcol );
  118. pDC->SetBkMode (TRANSPARENT);
  119. }
  120. return g_editbkbrush;
  121. }
  122. else if(nCtlColor==COLOR_BACKGROUND)
  123. {
  124. pDC->SetBkColor( g_bkcol );
  125. pDC->SetBkMode (TRANSPARENT);
  126. return g_editbkbrush;
  127. }
  128. // TODO: Return a different brush if the default is not desired
  129. return g_editbkbrush;
  130. }