Multilines

From Team Developer SqlWindows Wiki
Revision as of 20:48, 24 September 2008 by DaveRabelink (Talk | contribs)

Jump to: navigation, search

This page covers Multiline tips & tricks.

Contents


Pointer2.png How to place the cursor at a specific location in the text, text selection and insertion Pointer.png

First define these WinApi constants

   Number: EM_GETSEL         = 0x00B0
   Number: EM_SETSEL         = 0x00B1
   Number: EM_SCROLLCARET    = 0x00B7
   Number: EM_REPLACESEL     = 0x00C2

To place the cursor/caret at a specific character location (nPos).
0 (zero) means the first location from the left

   ! Place the cursor at position 200 in the text. Set left and right position at the same value
   Set nLeftPos = 200
   Set nRightPos = 200
   Call SalSendMsg( hWndField, EM_SETSEL, nLeftPos, nRightPos )
   !
   ! When the cursor is out of view, the field does not scroll automatically, so you should scroll it by using :
   Call SalSendMsg( hWndField, EM_SCROLLCARET, 0, 0 )

When text should be selected, use different values for nLeftPos and nRightPos

   Set nLeftPos = 200
   Set nRightPos = 210
   Call SalSendMsg( hWndField, EM_SETSEL, nLeftPos, nRightPos )

To deselect text use

   Call SalSendMsg( hWndField, EM_SETSEL, -1, -1 )

To insert text at a specific location

   ! Place the cursor at position 200 in the text. Set left and right position at the same value
   Set nLeftPos = 200
   Set nRightPos = 200
   Call SalSendMsg( hWndField, EM_SETSEL, nLeftPos, nRightPos )
   !
   ! Now insert some text at the current caret position
   Call VisSendMsgString( hWndField, EM_REPLACESEL, TRUE, "This will be inserted" )

To replace text which is selected, like above except use the appropriate nLeftPos and nRightPos values.

Now to get the current position/selection boundaries

   Set nReturn = SalSendMsg( hWndField, EM_GETSEL, 0, 0 )
   !
   Set nLeftPos = SalNumberLow( nReturn ) 
   Set nRightPos = SalNumberHigh( nReturn ) 

If no selections are performed above, you should first set the focus to the field

   Call SalSetFocus( hWndField )


Pointer2.png How to make a scrollable but disabled multiline Pointer.png

When you disable the field, the scrollbars are also disabled.

Use this instead to have scrolling

   Call VisWinSetFlags ( hWndField, WF_DisplayOnly, TRUE )