Sign in to follow this  
Subotron

Highlight edit box selection (SOLVED)

Recommended Posts

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]

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Sounds like you're doing non modal dialogs, and is forgetting to call IsDialogMessage in your main message loop.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this