From 08c8690cf0ea7b961373ecaddecc28bd40403e30 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Fri, 21 Jan 2005 15:02:58 +0000 Subject: [PATCH] check for error in GetSelection(long *, long *); clean up SetSelect(long, long) git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@31542 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/msw/combobox.cpp | 42 ++++++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/src/msw/combobox.cpp b/src/msw/combobox.cpp index 4bb8998363..642e48329a 100644 --- a/src/msw/combobox.cpp +++ b/src/msw/combobox.cpp @@ -650,12 +650,11 @@ void wxComboBox::SetInsertionPointEnd() long wxComboBox::GetInsertionPoint() const { -#ifdef __WIN32__ - DWORD Pos=(DWORD)SendMessage(GetHwnd(), CB_GETEDITSEL, 0, 0L); - return Pos&0xFFFF; -#else - return 0; -#endif + // CB_GETEDITSEL returns the index of the last character after selection in + // its high-order word + DWORD pos= (DWORD)::SendMessage(GetHwnd(), CB_GETEDITSEL, 0, 0L); + + return HIWORD(pos); } wxTextPos wxComboBox::GetLastPosition() const @@ -691,19 +690,15 @@ void wxComboBox::Remove(long from, long to) void wxComboBox::SetSelection(long from, long to) { - HWND hWnd = GetHwnd(); - long fromChar = from; - long toChar = to; - // if from and to are both -1, it means - // (in wxWidgets) that all text should be selected. - // This translates into Windows convention - if ((from == -1) && (to == -1)) + // if from and to are both -1, it means (in wxWidgets) that all text should + // be selected, translate this into Windows convention + if ( (from == -1) && (to == -1) ) { - fromChar = 0; - toChar = -1; + from = 0; } - if ( SendMessage(hWnd, CB_SETEDITSEL, (WPARAM)0, (LPARAM)MAKELONG(fromChar, toChar)) == CB_ERR ) + if ( SendMessage(GetHwnd(), CB_SETEDITSEL, + 0, (LPARAM)MAKELONG(from, to)) == CB_ERR ) { wxLogDebug(_T("CB_SETEDITSEL failed")); } @@ -712,10 +707,17 @@ void wxComboBox::SetSelection(long from, long to) void wxComboBox::GetSelection(long* from, long* to) const { DWORD dwStart, dwEnd; - ::SendMessage(GetHwnd(), CB_GETEDITSEL, (WPARAM)&dwStart, (LPARAM)&dwEnd); - - *from = dwStart; - *to = dwEnd; + if ( ::SendMessage(GetHwnd(), CB_GETEDITSEL, + (WPARAM)&dwStart, (LPARAM)&dwEnd) == CB_ERR ) + { + *from = + *to = 0; + } + else + { + *from = dwStart; + *to = dwEnd; + } } int wxComboBox::GetSelection() const -- 2.45.2