Core Function WinGetCaretPos

From Sputnik Wiki
(Difference between revisions)
Jump to: navigation, search
(Example)
(Example)
Line 41: Line 41:
 
{
 
{
 
     my List ( $x_adjust =  5, $y_adjust = 40 );
 
     my List ( $x_adjust =  5, $y_adjust = 40 );
my $t = array();
+
    my $t = array();
  
 
     Opt("CaretCoordMode", 0);          //relative mode
 
     Opt("CaretCoordMode", 0);          //relative mode

Revision as of 10:36, 27 November 2011

WinGetCaretPos ( )

Contents

Description

Returns the coordinates of the caret in the foreground window.

Parameters

None

Return Value

Success: Returns a 2-element array containing the following information:

$array[0] = X coordinate 
$array[1] = Y coordinate 

Failure: Returns 0.

Remarks

WinGetCaretPos might not return accurate values for Multiple Document Interface (MDI) applications if absolute CaretCoordMode is used.

See example for a workaround. Note: Some applications report static coordinates regardless of caret position!

Example

$a = WinGetCaretPos();
if($a)	
{
	println("First Method Pos $a[0], $a[1]");
}
 
// More reliable method to get caret coords in MDI text editors.
Function _CaretPos()
{
    my List ( $x_adjust =  5, $y_adjust = 40 );
    my $t = array();
 
    Opt("CaretCoordMode", 0);           //relative mode
    my $c = WinGetCaretPos();           //relative caret coords
    my $w = WinGetPos("");              //window's coords
    my $f = ControlGetFocus("","");     //text region "handle"
    my $e = ControlGetPos("", "", $f);  //text region coords
 
    If ( isVarArray($c) && isVarArray($w) && isVarArray($e) )
	{
        	$t[0] = $c[0] + $w[0] + $e[0] + $x_adjust;
        	$t[1] = $c[1] + $w[1] + $e[1] + $y_adjust;
       		Return $t;     //absolute screen coords of caret cursor    
	}
	else
        	return 0;
}
Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox