Defines the selected text in the edit control portion.
C
int WINAPI SftBox_GetSelText(HWND hwndCtl, LPTSTR lpszBuffer); BOOL WINAPI SftBox_SetSelText(HWND hwndCtl, LPCTSTR lpszText);
C++
int CSftBox::GetSelText(LPTSTR lpszBuffer) const; BOOL CSftBox::SetSelText(LPCTSTR lpszText);
hwndCtl
The window handle of the combo box control.
lpszBuffer
A pointer to a buffer where the selected text is returned. The buffer must be large enough to hold the selected text, including a terminating '\0' character. Use GetSelTextLength to retrieve the length of the selected text.
lpszText
A pointer to the text which replaces the selected text.
GetSelText returns the length of the selected text (in characters), not including the terminating '\0' character. -1 is returned if an error occurred or if the combo box is a dropdown list combo box, which does not have an edit control portion. In this case, an empty string is returned in lpszBuffer.
SetSelText returns TRUE if the function was successful. FALSE is returned if the combo box is a dropdown list combo box.
The GetSelText and SetSelText functions define the selected text in the edit control portion of a simple or dropdown combo box.
GetSelText retrieves the currently selected text. If no text is selected, an empty string is returned and the return value is 0.
SetSelText replaces the currently selected text with the text specified. The new text is then selected. If no text is selected when SetSelText is called, the new text is inserted at the position of the caret (insertion point) and is not selected.
SetSelText modifies the text in the edit control portion in the same way as if the user had typed the text. The SFTBOXN_EDITUPDATE and SFTBOXN_EDITCHANGE notifications are sent to the parent window and the combo box searches for a matching item (see SetEditSearchMode).
The selected text range can be retrieved and defined using GetEditSel and SetEditSel.
SftBox_SetDropHighlight(hwndTarget, -1, FALSE);
if (!IsOver(hwndTarget, lpInfo->hwnd))
return; // dropped somewhere else
szText[0] = 0;
if (lpInfo->area == SFTBOX_AREA_EDIT) {
// The selected text of the edit portion is copied
if (SftBox_GetSelTextLength(hwndSource) < sizeof(szText) / sizeof(szText[0]))
SftBox_GetSelText(hwndSource, szText);
} else {
// An item of the list is moved
LONG from = (LONG) lpInfo->UserData;
if (SftBox_GetTextLength(hwndSource, from, 0) < sizeof(szText) / sizeof(szText[0])) {
SftBox_GetText(hwndSource, from, 0, szText);
SftBox_DeleteString(hwndSource, from);
if (SftBox_GetCount(hwndSource) > 0)
target.SetDropHighlight(-1, FALSE);
if (!IsOver(target, lpInfo->hwnd))
return; // dropped somewhere else
szText[0] = 0;
if (lpInfo->area == SFTBOX_AREA_EDIT) {
// The selected text of the edit portion is copied
if (source.GetSelTextLength() < sizeof(szText) / sizeof(szText[0]))
source.GetSelText(szText);
} else {
// An item of the list is moved
LONG from = (LONG) lpInfo->UserData;
if (source.GetTextLength(from, 0) < sizeof(szText) / sizeof(szText[0])) {
source.GetText(from, 0, szText);
source.DeleteString(from);
if (source.GetCount() > 0)See Also C/C++ API | Categories | Notifications