Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Windows API functions for edit box controls
Message
From
01/11/2001 22:13:01
 
 
To
31/10/2001 13:25:49
General information
Forum:
Visual FoxPro
Category:
Windows API functions
Miscellaneous
Thread ID:
00575476
Message ID:
00576554
Views:
34
This message has been marked as the solution to the initial question of the thread.
>Hi Ed,
>
>Thanks for your help! I follow where you're going with the POINT structure associated with a control's hWnd, however, I'm still clueless about how to get information regarding the screen position of the text cursor within a control. In order to get started, don't I need some way of finding more information about the position of the text cursor so I can in turn begin converting it to form coordinates?

You'd need to call GetCursorPos(), which returns an lpPOINT, a pointer to a POINT structure, to get the mouse cursor position:
DECLARE SHORT GetCursorPos IN WIN32API STRING @ lpPoint
cPointBuffer = REPCL(CHR(0),8)
IF GetCursorPos(@cPointBuffer) # 0
   * it worked
ELSE
  * it didn't
ENDIF
You have to split up the point structure. To get the character caret, it's a POINT rel;ative to the client window, so you need something lke:
DECLARE INTEGER GetActiveWindow IN WIN32API
DECLARE SHORT ShowCaret IN WIN32API INTEGER
DECLARE SHORT GetCaretPos IN WIN32API STRING @ lpPoint
cPointBuffer = REPL(CHR(0),8)
= ShowCaret(GetActiveWindow())
IF GetCaretPos(@cPointBuffer) # 0
  * it worked
ELSE
   * it didn't
ENDIF
You have to extract the point, and compute it relative to the current window rather than the screen.

>
>I've studied the MS RTF control and don't see any information about properties that return the screen position (vs. the .SelStart or equivalent's linear position in the text stream) of the text cursor as well.

It has an hWnd of it's own, so you can use that rather than GetActiveWindow(), and the point will be relative to the control's position. If it works, it's relative to the RTF control position, so you don't have the arduous task of computing the bounds of the native edit box in the containing form.
>
>I think(?) what I'm trying to find are control properties similar to a form's CurrentX and CurrentY properties.

AFAIK, the properties of interest aren't aren't part of the control's native interface; the API routines offered above let you get the OS offered location, allowing you to compute the value using other details presented within VFP. If you want this often, create a subclass of the EditBox implementing what you want, and work off the enhanced subclass instead of working from the base class loacking it came from.
>
>Idea: Is there a way to move the mouse to the position of a control's text cursor? If so I could grab the location of the text cursor by using the mouse's current coordinates?!

Compute the caret position, and move the mouse there, but then, you'd already have the coordinates.
>
>Thanks again for your help!
>Malcolm
>
>>>Is there a Windows API function that will return the ABSOLUTE row and column position (in pixels) of the text cursor within an edit box?
>>>
>>>Is there a Windows API function that will return the row and column position (in pixels) of the text cursor within an edit box RELATIVE to the frame of the edit control?
>>
>>In both cases, not trivially with native VFP controls; there's an API which can resolve a POINT structure relative to an hWnd (a Form has an hWnd, as do most ActiveX controls, but you'd need to compute the location of the edit box frame and convert the POINT in the Form to a POINT in the edit box frame.
>>
>>You'd probably find it easier using an instance of the RTF ActiveX control.
EMail: EdR@edrauh.com
"See, the sun is going down..."
"No, the horizon is moving up!"
- Firesign Theater


NT and Win2K FAQ .. cWashington WSH/ADSI/WMI site
MS WSH site ........... WSH FAQ Site
Wrox Press .............. Win32 Scripting Journal
eSolutions Services, LLC

The Surgeon General has determined that prolonged exposure to the Windows Script Host may be addictive to laboratory mice and codemonkeys
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform