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.

113 lines
2.5 KiB

  1. #ifndef __TEXTDLG_H_INCLUDED
  2. #define __TEXTDLG_H_INCLUDED
  3. #include <windows.h>
  4. #include <simstr.h>
  5. class CTextDialog
  6. {
  7. public:
  8. class CData
  9. {
  10. private:
  11. CSimpleString m_strText;
  12. bool m_bReadOnly;
  13. private:
  14. CData( const CData & );
  15. CData &operator=( const CData & );
  16. public:
  17. CData( LPCTSTR pszText=NULL, bool bReadOnly=true )
  18. : m_strText(pszText),
  19. m_bReadOnly(bReadOnly)
  20. {
  21. }
  22. ~CData(void)
  23. {
  24. }
  25. void ReadOnly( bool bReadOnly )
  26. {
  27. m_bReadOnly = bReadOnly;
  28. }
  29. bool ReadOnly(void) const
  30. {
  31. return m_bReadOnly;
  32. }
  33. void Text( LPCTSTR pszText )
  34. {
  35. m_strText = pszText;
  36. }
  37. CSimpleString Text(void)
  38. {
  39. return m_strText;
  40. }
  41. const CSimpleString &Text(void) const
  42. {
  43. return m_strText;
  44. }
  45. };
  46. private:
  47. HWND m_hWnd;
  48. CData *m_pData;
  49. private:
  50. CTextDialog(void);
  51. CTextDialog( const CTextDialog & );
  52. CTextDialog &operator=( const CTextDialog & );
  53. private:
  54. CTextDialog( HWND hWnd )
  55. : m_hWnd(hWnd),
  56. m_pData(NULL)
  57. {
  58. }
  59. ~CTextDialog(void)
  60. {
  61. }
  62. void OnOK( WPARAM, LPARAM )
  63. {
  64. EndDialog( m_hWnd, IDOK );
  65. }
  66. void OnCancel( WPARAM, LPARAM )
  67. {
  68. EndDialog( m_hWnd, IDCANCEL );
  69. }
  70. LRESULT OnInitDialog( WPARAM wParam, LPARAM lParam )
  71. {
  72. m_pData = reinterpret_cast<CData*>(lParam);
  73. if (m_pData)
  74. {
  75. SetDlgItemText( m_hWnd, IDC_TEXT_TEXT, m_pData->Text() );
  76. if (m_pData->ReadOnly())
  77. {
  78. SendDlgItemMessage( m_hWnd, IDC_TEXT_TEXT, EM_SETREADONLY, TRUE, 0 );
  79. }
  80. }
  81. return 0;
  82. }
  83. LRESULT OnCommand( WPARAM wParam, LPARAM lParam )
  84. {
  85. SC_BEGIN_COMMAND_HANDLERS()
  86. {
  87. SC_HANDLE_COMMAND(IDOK,OnOK);
  88. SC_HANDLE_COMMAND(IDCANCEL,OnCancel);
  89. }
  90. SC_END_COMMAND_HANDLERS();
  91. }
  92. public:
  93. static INT_PTR CALLBACK DialogProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
  94. {
  95. SC_BEGIN_DIALOG_MESSAGE_HANDLERS(CTextDialog)
  96. {
  97. SC_HANDLE_DIALOG_MESSAGE( WM_INITDIALOG, OnInitDialog );
  98. SC_HANDLE_DIALOG_MESSAGE( WM_COMMAND, OnCommand );
  99. }
  100. SC_END_DIALOG_MESSAGE_HANDLERS();
  101. }
  102. };
  103. #endif