Gyannea
October 15th, 2004, 04:37 PM
There must be 100s of messages to control and get information from an edit box, but I could not find out how to get the last character typed by the user. I suppose one could do it by responding to the EN_CHANGE message and emptying the entire contents and looking at the end of the buffer. That is pretty lousy.
Is there something simple I am missing here? I am surprised I could find nothing about that in any of the FAQs. Maybe it is so simple I am missing something obvious.
What I need to do is to take the character typed by the user and transmit it immediatley over the radio. Once it is gone, it is gone! I was hoping to use the edit control to save me all the scrolling logic and all the other junk. But it does not look too promising. It looks like I will have to manage text input in my own window. Don't like that idea much, either! There is a lot of nitty gritty work in that effort!
Actually, I would like to prevent the user from doing anything except typing in text and the backspace delete to erase the last text entry (that delete character can also be transmitted over the radio). But nothing else. However, it would be nice to have a scrolling window of what has been typed and all the buffer logic done!
Any ideas on how to use the edit control to do that?
Thanks,
Brian
MrViggy
October 15th, 2004, 04:42 PM
If you need every single character typed, it sounds like you need to handle the EN_CHANGE message anyhow.
How about getting the text; dumping it into a std::string, then doing something like "myText[myText.size()-1]"
Viggy
kawasaki056
October 16th, 2004, 04:00 AM
the reason you feel lousy about EN_SELCHANGE is that the EN_SELCHANGE is sent whenever the sel is changed , even if character is not input ?
there is another way you can take to achieve your purpose.
search anywhere with key word "subclass" .
it goes like ,
LRESULT CALLBACK EditSubclassProc( HWND , UINT , WPARAM, LPARAM ) ;
WNDPROC orgProc ; // these 2 declarations are necessary .
....
hEdit = CreateWindow( ...) ; // you create edit control
orgProc = SubclassWindow( hEdit , EditSubclassProc ) ; // necessary .
// <= this is MACRO in "windowsx.h" ,
/* if you want basic knowledge of this MACRO, the below functions the same .
orgProc = (WNDPROC) SetWindowLong( hEdit , GWL_WNDPROC , (LONG)EditSubclassProc ) ; */
/*
// and in , perhaps most other samples of these subclassification(?), operation like ,
orgProc = (WNDPROC)GetWindowLong(hEdit , GWL_WNDPROC ) ;" is add , which is more careful way .(but you can pass the operation of this one line , writing like above of this.using SubclassWindow() or SetWindowLong )
so what I want to say here is that you can search yourself with keywords,
"SubclassWindow , SetWindowLong , GetWindowLong "
*/
this is preparation .
the below is the main dish.
LRESULT CALLBACK EditSubclassProc( HWND hWnd , UINT msg, WPARAM wp,LPARAM lp )
{ // here HWND is always the window handle of edit , "hEdit".
Switch( msg )
{ case WM_CHAR :
// YOUR OWN OPERATION !
switch( wp ) { case VK_UP : case VK_RETURN : break ; }
// if you would like , you can even write like it .
break ;
case WM_KEYDOWN :
// YOUR OWN OPERATION !
break ;
case WM_KEYUP :
// YOUR OWN OPERATION !
break ;
}
return CallWindowProc( orgProc , hWnd , msg , wp , lp ) ;
} // these 3 of WM_CHAR , WM_KEYDOWN , WM_KEYUP differs a little from each other ,so examine and select which you like.
then , do not forget on the end of application,
SetWindowLong( hEdit , GWL_WNDPROC , orgProc ) ;
// this would be best written just "BEFORE" the "hEdit" is DESTROYED.
// in my memory , child windows are destoryed after the parent's
// WM_DESTROY operated ,so,as long as you dont DestroyWindow(hEdit)
// yourself , best written on "WM_DESTROY" event.
// Wrong timing of SetWindowLong( .. , orgProc ) ; causes exception error so take care.
there are many samples of subclassing window, refer to those.
and , you were talking you feel lousy , but these matches you favor ?
if I write codes you are taliking about ,I choose subclassing way , because it is easy to figure out or grasp construction of codes.
I am afraid no other way is found ... or ,, You Already Know These Technique ???hahaha.
------------------------------------------------------------------------------------------------------
I am sorry I am mistaking EM_SELCHANGE and EM_CHANGE , but that makes not so much difference to my discussion.
NoHero
October 16th, 2004, 06:28 AM
Please use code tags when posting code, this makes the entire thing more interesting for others to read ...
WM_COMMAND with LOWORD(wParam) == ID of the edit box, is send when user types something in the edit box ....
kawasaki056
October 16th, 2004, 09:28 AM
may be I am tired .
sorry for incorrect post.
NoHero
October 16th, 2004, 11:35 AM
But why not use EN_CHANGE?! ...
MSDN:
The EN_CHANGE notification message is sent when the user has taken an action that may have altered text in an edit control. Unlike the EN_UPDATE notification message, this notification message is sent after the system updates the screen. The parent window of the edit control receives this notification message through a WM_COMMAND message.