@@ -53,7 +53,7 @@ wstring getTextFromCombo(HWND hCombo)
5353 auto str = std::make_unique<wchar_t []>(strSize);
5454 std::fill_n (str.get (), strSize, L' \0 ' );
5555
56- ::SendMessage (hCombo, WM_GETTEXT , FINDREPLACE_MAXLENGTH - 1 , reinterpret_cast <LPARAM >(str.get()));
56+ ::SendMessage (hCombo, WM_GETTEXT , FINDREPLACE_MAXLENGTH , reinterpret_cast <LPARAM >(str.get()));
5757 return wstring (str.get ());
5858}
5959
@@ -63,7 +63,7 @@ void delLeftWordInEdit(HWND hEdit)
6363 auto str = std::make_unique<wchar_t []>(strSize);
6464 std::fill_n (str.get (), strSize, L' \0 ' );
6565
66- ::SendMessage (hEdit, WM_GETTEXT , FINDREPLACE_MAXLENGTH - 1 , reinterpret_cast <LPARAM >(str.get()));
66+ ::SendMessage (hEdit, WM_GETTEXT , FINDREPLACE_MAXLENGTH , reinterpret_cast <LPARAM >(str.get()));
6767 WORD cursor = 0 ;
6868 ::SendMessage (hEdit, EM_GETSEL , (WPARAM )&cursor, 0);
6969 WORD wordstart = cursor;
@@ -4919,7 +4919,7 @@ LRESULT FAR PASCAL FindReplaceDlg::comboEditProc(HWND hwnd, UINT message, WPARAM
49194919 else if ((message == WM_KEYDOWN ) && (wParam == VK_DOWN ) && (::SendMessage (hwndCombo, CB_GETCURSEL , 0 , 0 ) == CB_ERR ))
49204920 {
49214921 // down key on unselected combobox item -> store current edit text as draft
4922- ::SendMessage (hwndCombo, WM_GETTEXT , FINDREPLACE_MAXLENGTH - 1 , reinterpret_cast <LPARAM >(draftString.get()));
4922+ ::SendMessage (hwndCombo, WM_GETTEXT , FINDREPLACE_MAXLENGTH , reinterpret_cast <LPARAM >(draftString.get()));
49234923 }
49244924 else if ((message == WM_KEYDOWN ) && (wParam == VK_UP ) && (::SendMessage (hwndCombo, CB_GETCURSEL , 0 , 0 ) == CB_ERR ))
49254925 {
@@ -4931,11 +4931,54 @@ LRESULT FAR PASCAL FindReplaceDlg::comboEditProc(HWND hwnd, UINT message, WPARAM
49314931 {
49324932 // up key on top selected combobox item -> restore draft to edit text
49334933 ::SendMessage (hwndCombo, CB_SETCURSEL , WPARAM (-1 ), 0);
4934- ::SendMessage (hwndCombo, WM_SETTEXT , FINDREPLACE_MAXLENGTH - 1 , reinterpret_cast <LPARAM >(draftString.get()));
4934+ ::SendMessage (hwndCombo, WM_SETTEXT , 0 , reinterpret_cast <LPARAM >(draftString.get()));
49354935 ::SendMessage (hwndCombo, CB_SETEDITSEL , 0 , MAKELPARAM (0 , -1 ));
49364936 return 0 ;
49374937
49384938 }
4939+ else if (message == WM_PASTE )
4940+ {
4941+ // needed to allow CR (i.e., multiline) into combobox text;
4942+ // (the default functionality terminates the paste at the first CR character)
4943+
4944+ HWND hParent = ::GetParent (hwndCombo);
4945+ HWND hFindWhatCombo = ::GetDlgItem (hParent, IDFINDWHAT );
4946+ HWND hReplaceWithCombo = ::GetDlgItem (hParent, IDREPLACEWITH );
4947+ if ((hwndCombo == hFindWhatCombo) || (hwndCombo == hReplaceWithCombo))
4948+ {
4949+ CLIPFORMAT cfColumnSelect = static_cast <CLIPFORMAT >(::RegisterClipboardFormat (L" MSDEVColumnSelect" ));
4950+ if (!::IsClipboardFormatAvailable (cfColumnSelect))
4951+ {
4952+ wstring clipboardText = strFromClipboard ();
4953+ if (!clipboardText.empty ())
4954+ {
4955+ wstring origText = getTextFromCombo (hwndCombo);
4956+
4957+ DWORD selStartIndex = 0 ;
4958+ DWORD selEndIndex = 0 ;
4959+ // In case there are selected text in combo box field
4960+ ::SendMessage (hwndCombo, CB_GETEDITSEL , (WPARAM )&selStartIndex, (LPARAM )&selEndIndex);
4961+
4962+ wstring changedText = origText.substr (0 , selStartIndex) + clipboardText + origText.substr (selEndIndex);
4963+ if (changedText.length () > FINDREPLACE_MAXLENGTH - 1 )
4964+ {
4965+ changedText = changedText.substr (0 , FINDREPLACE_MAXLENGTH - 1 );
4966+ }
4967+
4968+ if (changedText != origText)
4969+ {
4970+ ::SendMessage (hwndCombo, WM_SETTEXT , 0 , reinterpret_cast <LPARAM >(changedText.c_str()));
4971+
4972+ ::SendMessage (hParent, WM_COMMAND ,
4973+ MAKELPARAM (hwndCombo == hFindWhatCombo ? IDFINDWHAT : IDREPLACEWITH , CBN_EDITUPDATE ),
4974+ reinterpret_cast<LPARAM>(hwndCombo));
4975+ }
4976+ }
4977+ }
4978+
4979+ return 0 ;
4980+ }
4981+ }
49394982 return CallWindowProc(originalComboEditProc, hwnd, message, wParam, lParam);
49404983}
49414984
0 commit comments