I need to tab into a text box without any text being highlighted (no problem there) but also need to be able to
place the caret in the text box to match the position it held the last time the text box lost the focus. I'm
using the GetCaretPos and SetCaretPos API calls, and the caret seems to be get positioned properly when you
re-enter the text box, but in reality it is not.
My problem is demonstrated in the following code... when you execute it, use your keyboard or mouse to position
the caret in the center of the text in the first text box and then press tab twice. Upon re-entering the first
text box, the caret looks repositioned. However, use your left arrow key to move the caret and you will see that
the caret was really at the right end of the text.
Any Ideas?
Timm
[This message has been edited by Timm Motl (edited July 24, 2001).]
place the caret in the text box to match the position it held the last time the text box lost the focus. I'm
using the GetCaretPos and SetCaretPos API calls, and the caret seems to be get positioned properly when you
re-enter the text box, but in reality it is not.
My problem is demonstrated in the following code... when you execute it, use your keyboard or mouse to position
the caret in the center of the text in the first text box and then press tab twice. Upon re-entering the first
text box, the caret looks repositioned. However, use your left arrow key to move the caret and you will see that
the caret was really at the right end of the text.
Code:
#COMPILE EXE #REGISTER NONE #INCLUDE "WIN32API.INC" CALLBACK FUNCTION DlgProc STATIC PT AS POINTAPI SELECT CASE CBMSG CASE %WM_COMMAND SELECT CASE CBCTLMSG CASE %EN_SETFOCUS ' Remove text selection highlight from text boxes CONTROL SEND CBHNDL, CBCTL, %EM_SETSEL, -1, -1 SELECT CASE CBCTL CASE 100 ' Attempt to position caret in Text Box 1 SetCaretPos PT.x, PT.y END SELECT CASE %EN_KILLFOCUS SELECT CASE CBCTL CASE 100 ' Remember caret position for Text Box 1 GetCaretPos PT END SELECT END SELECT END SELECT END FUNCTION FUNCTION PBMAIN LOCAL hDlg AS LONG DIALOG NEW 0 ,"Caret Test",,, 200, 65, %WS_MINIMIZEBOX + %WS_SYSMENU TO hDlg CONTROL ADD TEXTBOX, hDlg, 100, "Text Box 1", 10, 10, 176, 12 CONTROL ADD TEXTBOX, hDlg, 200, "Text Box 2", 10, 25, 176, 12 DIALOG SHOW MODAL hDlg CALL DlgProc END FUNCTION
Timm
[This message has been edited by Timm Motl (edited July 24, 2001).]
Comment