473,386 Members | 1,958 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Getting the position of the caret

Hi,

I need to know the position (X, Y cohordinates) of the caret. I'm
using the function:

[DllImport("user32.dll")]
private static extern int GetCaretPos(ref POINT lpPoint);

I'm actually getting a result but I think that refers to the
cohordinates of the Textbox the caret is in and not the screen
cohordinates.

I need a global cohordinate since I want to show a window at that
position.

Moreover, I'd need to find the position of the caret not for my
application window but for the current active application.

Thanks.
Nov 16 '05 #1
6 7994
On 26/12/2004 kurotsuke wrote:
Hi,

I need to know the position (X, Y cohordinates) of the caret. I'm
using the function:

[DllImport("user32.dll")]
private static extern int GetCaretPos(ref POINT lpPoint);

I'm actually getting a result but I think that refers to the
cohordinates of the Textbox the caret is in and not the screen
cohordinates.

I need a global cohordinate since I want to show a window at that
position.

Moreover, I'd need to find the position of the caret not for my
application window but for the current active application.

Thanks.


Have a look in the help for PointToClient and PointToScreen.
I won't try and tell you which one to use as I always get them confused!

--
Jeff Gaines
Posted with XanaNews 1.17.1.2 http://www.wilsonc.demon.co.uk/delphi.htm
Nov 16 '05 #2
On Sun, 26 Dec 2004 07:46:01 -0800, "Jeff Gaines"
<wh*********@newsgroup.nospam> wrote:
On 26/12/2004 kurotsuke wrote:
Hi,

I need to know the position (X, Y cohordinates) of the caret. I'm
using the function:

[DllImport("user32.dll")]
private static extern int GetCaretPos(ref POINT lpPoint);

I'm actually getting a result but I think that refers to the
cohordinates of the Textbox the caret is in and not the screen
cohordinates.

I need a global cohordinate since I want to show a window at that
position.

Moreover, I'd need to find the position of the caret not for my
application window but for the current active application.

Thanks.


Have a look in the help for PointToClient and PointToScreen.
I won't try and tell you which one to use as I always get them confused!


Thanks.
I've tried and come up with the following code. It works OK when my
application has the focus but I would like to display the window near
the caret also when other applications has the focus. How can I do it?
Thanks a lot.

Point mypoint=Point.Empty;
GetCaretPos(ref mypoint);
IntPtr hWnd = GetFocus ();
ClientToScreen (hWnd, ref mypoint);
this.SetDesktopLocation (mypoint.X, mypoint.Y);
ShowWindow(this.Handle, 4);
Nov 16 '05 #3
On 26/12/2004 kurotsuke wrote:
On Sun, 26 Dec 2004 07:46:01 -0800, "Jeff Gaines"
<wh*********@newsgroup.nospam> wrote:
On 26/12/2004 kurotsuke wrote:
Hi,

I need to know the position (X, Y cohordinates) of the caret. I'm
using the function:

[snipped]

Have a look in the help for PointToClient and PointToScreen.
I won't try and tell you which one to use as I always get them
confused!


Thanks.
I've tried and come up with the following code. It works OK when my
application has the focus but I would like to display the window near
the caret also when other applications has the focus. How can I do it?
Thanks a lot.

Point mypoint=Point.Empty;
GetCaretPos(ref mypoint);
IntPtr hWnd = GetFocus ();
ClientToScreen (hWnd, ref mypoint);
this.SetDesktopLocation (mypoint.X, mypoint.Y);
ShowWindow(this.Handle, 4);


That's starting to get complex.

If the user is using another app, i.e. you app does not have focus,
what do you plan to use to trigger your ShowWindow routine?

--
Jeff Gaines
Posted with XanaNews 1.17.1.2 http://www.wilsonc.demon.co.uk/delphi.htm
Nov 16 '05 #4
On Sun, 26 Dec 2004 11:40:15 -0800, "Jeff Gaines"
<wh*********@newsgroup.nospam> wrote:

That's starting to get complex.

If the user is using another app, i.e. you app does not have focus,
what do you plan to use to trigger your ShowWindow routine?


The code I posted is just sample code. I was testing it using a timer
that fires every few seconds. In my real application I'm going to use
hooks to detect when certain keys are pressed and plan to show a
window where the user is typing.
Thanks.
Nov 16 '05 #5
On 26/12/2004 kurotsuke wrote:
On Sun, 26 Dec 2004 11:40:15 -0800, "Jeff Gaines"
<wh*********@newsgroup.nospam> wrote:

That's starting to get complex.

If the user is using another app, i.e. you app does not have focus,
what do you plan to use to trigger your ShowWindow routine?


The code I posted is just sample code. I was testing it using a timer
that fires every few seconds. In my real application I'm going to use
hooks to detect when certain keys are pressed and plan to show a
window where the user is typing.
Thanks.


Sorry, that's a bit beyond me. I did set up a system wide keyboard hook
once but had to use C++, I believe you can't do it with .NET.

I'll have to leave it for the gurus.

--
Jeff Gaines
Posted with XanaNews 1.17.1.2 http://www.wilsonc.demon.co.uk/delphi.htm
Nov 16 '05 #6
On Sun, 26 Dec 2004 13:06:56 -0800, "Jeff Gaines"
<wh*********@newsgroup.nospam> wrote:
On 26/12/2004 kurotsuke wrote:
On Sun, 26 Dec 2004 11:40:15 -0800, "Jeff Gaines"
<wh*********@newsgroup.nospam> wrote:
>
> That's starting to get complex.
>
> If the user is using another app, i.e. you app does not have focus,
> what do you plan to use to trigger your ShowWindow routine?


The code I posted is just sample code. I was testing it using a timer
that fires every few seconds. In my real application I'm going to use
hooks to detect when certain keys are pressed and plan to show a
window where the user is typing.
Thanks.


Sorry, that's a bit beyond me. I did set up a system wide keyboard hook
once but had to use C++, I believe you can't do it with .NET.

I'll have to leave it for the gurus.


For those who may be interested I managed to solve the problem with
this code:

IntPtr hFocus = GetFocus();
IntPtr hFore;
uint id=0;

if (hFocus == IntPtr.Zero) {
hFore= GetForegroundWindow ();
AttachThreadInput(GetWindowThreadProcessId(hFore, out id),
GetCurrentThreadId(), true);
hFocus = GetFocus();
GetCaretPos(ref mypoint);
ClientToScreen (hFocus, ref mypoint);
}
Nov 16 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: - ions | last post by:
hi, i am in the procces of writing a chat program for a main Assigment, the problem im stuck on is one of the Carets position in a JTextArea, when i hit the enter key, it appends the msg to the...
1
by: Barry | last post by:
Retoring Caret Position after text field correction -------------------------------------------------------------------------------- Hi, my code has the following form - function...
4
by: torch | last post by:
I have trawled the internet for a solution to this one . All I need is the caret position as a number. I have seen quite a few text insertion functions that do something like this : ...
4
by: cc | last post by:
Hi, Is possible set and get the caret position of cursor in a text field ? Thanks, Carlo
1
by: ryanmhuc | last post by:
Is there a way to get the caret position of a text input using FireFox. I am aware of ways to such with IE but have been unable to accomplish in FireFox and have not found a solution in the groups...
2
by: DaveR | last post by:
Can anybody help me to a)get the user's cursor insertion point (caret) from a multiline textbox, using client-side script I suppose, and then b)return the position to VB code behind? I have...
0
by: Oenone | last post by:
I would like to set the caret position in a (single-line) textbox to a position based on the number of pixels from the left of the control. For example, I want the caret to be positioned 50...
3
by: ReGenesis0 | last post by:
Is it possible to determine the caret position, in terms of x/y pixels, within a textarea? (I want to have a suggestion box pop up under where you're typing... so i need to determine where you are...
0
Jezternz
by: Jezternz | last post by:
Okay, so a while back I managed to retrieve it correctly. In this thread: http://bytes.com/topic/javascript/answers/786211-retrieving-caret-start-end-values#post3127765 However I have found...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.