473,499 Members | 1,593 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 8008
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
6277
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
3243
by: Barry | last post by:
Retoring Caret Position after text field correction -------------------------------------------------------------------------------- Hi, my code has the following form - function...
4
5662
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
9328
by: cc | last post by:
Hi, Is possible set and get the caret position of cursor in a text field ? Thanks, Carlo
1
7184
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
6758
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
1799
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
8371
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
2544
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
7009
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...
1
6899
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7390
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5475
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4602
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3103
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3094
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
665
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
302
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.