Difference between revisions of "Multilines"

From Team Developer SqlWindows Wiki
Jump to: navigation, search
(New page: a)
 
Line 1: Line 1:
a
+
This page covers multiline tips & tricks.
 +
 
 +
__TOC__
 +
<br>
 +
 
 +
<h2 style="margin:0;background-color:#ddcef2;font-size:120%;font-weight:bold;border:1px solid #afa3bf;text-align:left;color:#000;padding:0.2em 0.4em;">[[Image:Pointer.png]]How to place the cursor at a specific location in the text, text selection and insertion</h2>
 +
First define these WinApi constants
 +
<pre>
 +
  Number: EM_GETSEL        = 0x00B0
 +
  Number: EM_SETSEL        = 0x00B1
 +
  Number: EM_SCROLLCARET    = 0x00B7
 +
  Number: EM_REPLACESEL    = 0x00C2
 +
</pre>
 +
 
 +
To place the cursor/caret at a specific character location (nPos).<br>
 +
<sub>0 (zero) means the first location from the left</sub>
 +
 
 +
<pre>
 +
  ! 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 )
 +
</pre>
 +
 
 +
When text should be selected, use different values for nLeftPos and nRightPos
 +
 
 +
<pre>
 +
  Set nLeftPos = 200
 +
  Set nRightPos = 210
 +
  Call SalSendMsg( hWndField, EM_SETSEL, nLeftPos, nRightPos )
 +
</pre>
 +
 
 +
To deselect text use
 +
<pre>
 +
  Call SalSendMsg( hWndField, EM_SETSEL, -1, -1 )
 +
</pre>
 +
 
 +
To insert text at a specific location
 +
<pre>
 +
  ! 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" )
 +
</pre>
 +
 
 +
To replace text which is selected, like above except use the appropriate nLeftPos and nRightPos values.
 +
 
 +
Now to get the current position/selection boundaries
 +
<pre>
 +
  Set nReturn = SalSendMsg( hWndField, EM_GETSEL, 0, 0 )
 +
  !
 +
  Set nLeftPos = SalNumberLow( nReturn )
 +
  Set nRightPos = SalNumberHigh( nReturn )
 +
</pre>
 +
 
 +
<sub>If no selections are performed above, you should first set the focus to the field</sub>
 +
 
 +
<pre>
 +
  Call SalSetFocus( hWndField )
 +
</pre>
 +
 
 +
 
 +
<h2 style="margin:0;background-color:#ddcef2;font-size:120%;font-weight:bold;border:1px solid #afa3bf;text-align:left;color:#000;padding:0.2em 0.4em;">[[Image:Pointer.png]]How to make a scrollable but disabled multiline</h2>
 +
When you disable the field, the scrollbars are also disabled.<br>
 +
<br>
 +
Use this instead to have scrolling
 +
<pre>
 +
  Call VisWinSetFlags ( hWndField, WF_DisplayOnly, TRUE )
 +
</pre>

Revision as of 12:42, 12 September 2008

This page covers multiline tips & tricks.

Contents


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

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 )


Pointer.pngHow to make a scrollable but disabled multiline

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

Use this instead to have scrolling

   Call VisWinSetFlags ( hWndField, WF_DisplayOnly, TRUE )