StoneColdCrazy
Programmer
In TMemo or TRichEdit, when u write a text editor, for example u want to display the caret position in your status bar, the way I currently doing it is like this:<br><br>// in my RichEdit->OnKeyDown event handler<br>//-----------------------------------------------<br>/*some params r missing*/<br>void __fastcall TMainForm::OnRichEditKeyDown(WORD& Key)<br> {<br> SendMessage(RichEdit->Handle, WM_KEYUP, Key, 0);<br> }<br><br>// in my RichEdit->OnKeyUp event handler<br>//------------------------------------------------<br>/*some params r missing*/<br>void __fastcall TMainForm::OnRichEditKeyUp(/**/)<br> {<br> StatusBar->Panels->Items[0]->Text =<br> String(++RichEdit->CaretPos.y) +<br> ":" +<br> String(++RichEdit->CaretPos.x);<br> }<br><br>WM_KEYDOWN occurs when the key is held down, even when for a while. WM_KEYUP occurs only when the key is released, so if u held down a key for a while many WM_KEYDOWN events will occur, but only one WM_KEYUP (at the end) when u released the key. TRichEdit and TMemo update CaretPos after WM_KEYDOWN, but before WM_KEYUP. So WM_KEYUP is the place to query CaretPos, and in onKeyDown event handler we send a message WM_KEYUP, so that TRichEdit update the carret and call OnkeyUp event handler. This way we can track CaretPos event when the user holds down the key for a while...<br><br>Is there any better way to do this? ~~StonE~~