Highlight edit box selection (SOLVED)

Started by
6 comments, last by Subotron 17 years, 10 months ago
I'm currently exploring the resource editor in Visual C++. I added some edit boxes to my window, but they give me some headaches because of 2 things I can't accomplish: 1: (more general, not only edit boxes) using the tab button doesn't switch to another control, although I set the tab stops for some items. 2: when I set the focus on an edit box, I want to 'highlight' the text (number) inside (i.o.w. it should become blue, the same as when you double-click on it) If you people can tell me how to archieve the two things above, I'm a very happy man (for about 5 seconds until I find a new problem, but nevertheless...) [Edited by - Subotron on June 6, 2006 12:18:48 PM]
Advertisement
SetSel() SetFocus()

other one look ctrl+d set tabstop

Kuphryn
thanks, but I should've mentioned I'm not using MFC or stdafx.h

I tried this:
case EN_SETFOCUS:if (LOWORD(wparam) == IDC_EDIT_BOX){	HWND temp = GetDlgItem(window.get_wnd(0), IDC_EDIT_BOX); // handler to the edit box (=correct)	DWORD text_length = GetWindowTextLength(temp);	SetFocus(temp);	#ifdef WIN32		// This happens, because I can replace the text afterwards, but		// just EM_SETSEL doesn't make it blue		SendMessage(temp, EM_SETSEL, 0, text_length);	#else		SendMessage(temp, EM_SETSEL, 0, MAKELONG (text_length, text_length));	#endif}break;

As said in the comment, the text is selected (as EM_REPLACESEL works) but doesn't turn blue... (I associate being blue with meaning "if you press a key now this will replace the currently selected text in the edit box" which comes in handy in combination with tabs)

[Edited by - Subotron on June 5, 2006 10:19:54 PM]
SetFocus() after SendMessage()

Now?

Kuphryn
nope, that doesn't work either :(
Sounds like you're doing non modal dialogs, and is forgetting to call IsDialogMessage in your main message loop.
edit: I looked up that function, and put it in my message handler function like this:

if (!IsDialogMessage(wnd[0], &msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}

where wnd[0] is the window handle and translate/dispatch functions where already there but without an if-check.

This fixes the no-tab problem, but not the selection problem
hmmm it is fixed now, by throwing out the code I put in at all! Don't know why this failed when I tried before, probably forgot something, but it works now! I never understood that a dialog window CAN do all these things for you, by just one function :)

Thanks a lot guys!

This topic is closed to new replies.

Advertisement