Source code of Windows XP (NT5)
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.

184 lines
3.8 KiB

  1. //
  2. // CFindDialog.CPP
  3. //
  4. // Find Dialog Class
  5. //
  6. #include "stdafx.h"
  7. #include "resource.h"
  8. #include "CFindDialog.h"
  9. //
  10. // Ctor
  11. //
  12. CFindDialog::CFindDialog(
  13. HWND hParent
  14. )
  15. {
  16. if ( !g_hwndFind )
  17. {
  18. _hParent = hParent;
  19. _hDlg = CreateDialogParam( g_hInstance,
  20. MAKEINTRESOURCE( IDD_FIND ),
  21. _hParent,
  22. (DLGPROC) CFindDialog::DlgProc,
  23. (LPARAM) this
  24. );
  25. g_hwndFind = _hDlg;
  26. }
  27. }
  28. //
  29. // Dtor
  30. //
  31. CFindDialog::~CFindDialog( )
  32. {
  33. DestroyWindow( _hDlg );
  34. g_hwndFind = NULL;
  35. }
  36. //
  37. // _OnCommand( )
  38. //
  39. LRESULT
  40. CFindDialog::_OnCommand(
  41. WPARAM wParam,
  42. LPARAM lParam )
  43. {
  44. WORD wId = LOWORD(wParam);
  45. switch ( wId )
  46. {
  47. case IDCANCEL:
  48. ShowWindow( _hDlg, SW_HIDE );
  49. return TRUE;
  50. case IDC_B_MARK_ALL:
  51. case IDC_B_FIND_NEXT:
  52. {
  53. LPTSTR pszSearchString;
  54. DWORD dwLen;
  55. WPARAM wFlags;
  56. HWND hwnd;
  57. wFlags = 0;
  58. if ( Button_GetCheck( GetDlgItem( _hDlg, IDC_R_UP ) ) == BST_CHECKED )
  59. {
  60. wFlags |= FIND_UP;
  61. }
  62. if ( Button_GetCheck( GetDlgItem( _hDlg, IDC_C_MATCH_CASE ) ) == BST_CHECKED )
  63. {
  64. wFlags |= FIND_MATCHCASE;
  65. }
  66. if ( Button_GetCheck( GetDlgItem( _hDlg, IDC_C_MATCH_WHOLE_WORD_ONLY ) ) == BST_CHECKED )
  67. {
  68. wFlags |= FIND_WHOLE_WORD;
  69. }
  70. hwnd = GetDlgItem( _hDlg, IDC_CB_FIND_WHAT );
  71. dwLen = Edit_GetTextLength( hwnd ) + 1;
  72. if ( dwLen )
  73. {
  74. pszSearchString = (LPTSTR) LocalAlloc( LMEM_FIXED, dwLen * sizeof(TCHAR) );
  75. if ( pszSearchString )
  76. {
  77. Edit_GetText( hwnd, pszSearchString, dwLen );
  78. if ( wId == IDC_B_MARK_ALL )
  79. {
  80. PostMessage( _hParent, WM_MARK_ALL, wFlags, (LPARAM) pszSearchString );
  81. }
  82. else
  83. {
  84. PostMessage( _hParent, WM_FIND_NEXT, wFlags, (LPARAM) pszSearchString );
  85. }
  86. hwnd = GetDlgItem( _hDlg, IDC_CB_FIND_WHAT );
  87. if ( ComboBox_FindString( hwnd, -1, pszSearchString ) == CB_ERR )
  88. {
  89. ComboBox_InsertString( hwnd, -1, pszSearchString );
  90. }
  91. }
  92. }
  93. }
  94. return TRUE;
  95. }
  96. return 0;
  97. }
  98. //
  99. // _OnInitDialog( )
  100. //
  101. LRESULT
  102. CFindDialog::_OnInitDialog(
  103. HWND hDlg
  104. )
  105. {
  106. _hDlg = hDlg;
  107. SetWindowLongPtr( _hDlg, GWLP_USERDATA, (LONG_PTR) this );
  108. Button_SetCheck( GetDlgItem( _hDlg, IDC_R_DOWN ), BST_CHECKED );
  109. return 0;
  110. }
  111. //
  112. // _OnDestroyWindow( )
  113. //
  114. LRESULT
  115. CFindDialog::_OnDestroyWindow( )
  116. {
  117. return 0;
  118. }
  119. //
  120. // DlgProc( )
  121. //
  122. LRESULT
  123. CALLBACK
  124. CFindDialog::DlgProc(
  125. HWND hDlg,
  126. UINT uMsg,
  127. WPARAM wParam,
  128. LPARAM lParam )
  129. {
  130. CFindDialog * pfd = (CFindDialog *) GetWindowLongPtr( hDlg, GWLP_USERDATA );
  131. if ( pfd != NULL )
  132. {
  133. switch( uMsg )
  134. {
  135. case WM_COMMAND:
  136. return pfd->_OnCommand( wParam, lParam );
  137. case WM_DESTROY:
  138. SetWindowLongPtr( hDlg, GWLP_USERDATA, (LONG_PTR)NULL );
  139. return pfd->_OnDestroyWindow( );
  140. case WM_SHOWWINDOW:
  141. if ( wParam )
  142. {
  143. SetFocus( GetDlgItem( hDlg, IDC_CB_FIND_WHAT ) );
  144. }
  145. break;
  146. default:
  147. break; // fall thru
  148. }
  149. }
  150. if ( uMsg == WM_INITDIALOG )
  151. {
  152. pfd = (CFindDialog *) lParam;
  153. return pfd->_OnInitDialog( hDlg );
  154. }
  155. return 0;
  156. };