Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

169 lines
4.0 KiB

  1. /****************************************************************************\
  2. *
  3. * basedlg.h
  4. *
  5. * Created: William Taylor (wtaylor) 01/22/01
  6. *
  7. * MS Ratings Base Property Page
  8. *
  9. \****************************************************************************/
  10. #ifndef BASE_DIALOG_H
  11. #define BASE_DIALOG_H
  12. #include "apithk.h"
  13. class CCommonDialogRoutines
  14. {
  15. public:
  16. void ShowHideWindow( HWND hwndDlg, int iCtrl, BOOL fEnable )
  17. {
  18. HWND hCtrl = ::GetDlgItem( hwndDlg, iCtrl );
  19. ASSERT( hCtrl );
  20. if ( hCtrl )
  21. {
  22. ::EnableWindow( hCtrl, fEnable );
  23. ::ShowWindow( hCtrl, fEnable ? SW_SHOW : SW_HIDE );
  24. }
  25. }
  26. void SetErrorFocus( HWND hwndDlg, int iCtrl )
  27. {
  28. HWND hCtrl = ::GetDlgItem( hwndDlg, iCtrl );
  29. ASSERT( hCtrl );
  30. if ( hCtrl )
  31. {
  32. ::SetFocus( hCtrl );
  33. ::SendMessage( hCtrl, EM_SETSEL, 0, -1 );
  34. }
  35. }
  36. };
  37. template <WORD t_wDlgTemplateID>
  38. class CBasePropertyPage : public CPropertyPage<t_wDlgTemplateID>
  39. {
  40. private:
  41. PROPSHEETPAGE * m_ppsPage;
  42. public:
  43. typedef CBasePropertyPage<t_wDlgTemplateID> thisClass;
  44. typedef CPropertyPage<t_wDlgTemplateID> baseClass;
  45. BEGIN_MSG_MAP(thisClass)
  46. CHAIN_MSG_MAP_ALT(baseClass, 0)
  47. END_MSG_MAP()
  48. CBasePropertyPage(_U_STRINGorID title = (LPCTSTR)NULL) : CPropertyPage<t_wDlgTemplateID>(title)
  49. {
  50. m_ppsPage = NULL;
  51. }
  52. ~CBasePropertyPage()
  53. {
  54. if ( m_ppsPage )
  55. {
  56. LocalFree( m_ppsPage );
  57. m_ppsPage = NULL;
  58. }
  59. }
  60. operator PROPSHEETPAGE*() { return m_ppsPage; }
  61. // Override to insure Luna works!
  62. HPROPSHEETPAGE Create()
  63. {
  64. HINSTANCE hinst = _Module.GetResourceInstance();
  65. ASSERT( hinst );
  66. ASSERT( ! m_ppsPage );
  67. m_ppsPage = Whistler_CreatePropSheetPageStruct( hinst );
  68. if ( ! m_ppsPage )
  69. {
  70. TraceMsg( TF_ERROR, "CBasePropertyPage::Create() - m_ppsPage could not be created!" );
  71. return 0;
  72. }
  73. m_ppsPage->dwFlags = PSP_USECALLBACK;
  74. m_ppsPage->hInstance = hinst;
  75. baseClass * pT = static_cast<baseClass *>(this);
  76. pT; // avoid level 4 warning
  77. m_ppsPage->pszTemplate = MAKEINTRESOURCE(pT->IDD);
  78. m_ppsPage->pfnDlgProc = baseClass::StartDialogProc;
  79. m_ppsPage->pfnCallback = baseClass::PropPageCallback;
  80. m_ppsPage->lParam = (LPARAM)this;
  81. return ::CreatePropertySheetPage( m_ppsPage );
  82. }
  83. protected:
  84. void MarkChanged()
  85. {
  86. SendMessage( GetParent(), PSM_CHANGED, (WPARAM) m_hWnd, 0 );
  87. }
  88. void ShowHideControl( int iCtrl, BOOL fEnable )
  89. {
  90. CCommonDialogRoutines cdr;
  91. cdr.ShowHideWindow( m_hWnd, iCtrl, fEnable );
  92. }
  93. };
  94. template <class TDerived>
  95. class CBaseDialog : public CDialogImpl<TDerived>
  96. {
  97. public:
  98. typedef CBaseDialog<TDerived> thisClass;
  99. typedef CDialogImpl<TDerived> baseClass;
  100. BEGIN_MSG_MAP(thisClass)
  101. // CHAIN_MSG_MAP_ALT(baseClass, 0)
  102. END_MSG_MAP()
  103. protected:
  104. void ShowHideControl( int iCtrl, BOOL fEnable )
  105. {
  106. CCommonDialogRoutines cdr;
  107. cdr.ShowHideWindow( m_hWnd, iCtrl, fEnable );
  108. }
  109. void SetErrorControl( int iCtrl )
  110. {
  111. CCommonDialogRoutines cdr;
  112. cdr.SetErrorFocus( m_hWnd, iCtrl );
  113. }
  114. void ReduceDialogHeight( int iCtrl )
  115. {
  116. RECT rectControlBox;
  117. ASSERT( GetDlgItem( iCtrl ) );
  118. ::GetWindowRect( GetDlgItem( iCtrl ), &rectControlBox );
  119. RECT rectWindow;
  120. GetWindowRect( &rectWindow );
  121. int nNewHeight = ( rectControlBox.bottom - rectWindow.top ) + 8;
  122. RECT rectSize;
  123. GetClientRect( &rectSize );
  124. rectSize.bottom = nNewHeight;
  125. SetWindowPos( NULL, &rectSize, SWP_NOMOVE | SWP_NOZORDER );
  126. }
  127. };
  128. #endif