Jump to content

  • Log In with Google      Sign In   
  • Create Account

Windows Text Cursor Hotspot offset


Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.


  • You cannot reply to this topic
5 replies to this topic

#1   Members   -  Reputation: 381

Like
0Likes
Like

Posted 29 March 2014 - 03:07 AM

Hi all

 

While implementing selection using the mouse for my textbox i have realized, that the windows text cursor seems to have some offset from its center bar to the hotspot, its actually exactly 2px to the left. I can show you the problem with images:

 

Image 1: The cursor is at the position WM_MOUSEMOVE gives 0 and moving the mouse one pixel to the left makes it show the sizing cursor (so its out of the client area)

53368ca7b25c3_Cursor_Crop.png

 

As you can see the center bar of the cursor is clearly not at this point.

 

Image 2: The cursor is again at position 0, but this time its the default cursor

53368ce2e4dd8_Cursor2_Crop.png

 

This cursor correctly points to the beginning of the client area.

 

Is there a way to determine this offset? Is it the same for xp, vista, win7, win8? This seems to be a bit annoying in my opinion...

 

Greetings

Plerion



#2   GDNet+   -  Reputation: 10739

Like
2Likes
Like

Posted 29 March 2014 - 07:19 AM


Is there a way to determine this offset?

Yep. GetIconInfo.

 

The ICONINFO structure pointed to on return from that function provides the (relative) coordinates of the hotspot for a cursor.

 

FYI, this info easily found by googling for (of all things): "windows cursor hotspot" wink.png

 

Also just FYI: The onscreen cursor follows the mouse, whatever that cursor may be (IDC_ARROW, IDC_IBEAM, etc.). It can differ from the Windows caret position, which, for text input is commonly displayed as a blinking underscore or vertical line to let the user know where keyboard character input will be placed. You can see the difference by clicking in the Reply box on this page - a blinking vertical line caret appears in the edit box, but the cursor still follows the mouse.


Edited by Buckeye, 29 March 2014 - 07:32 AM.

Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly.

You don't forget how to play when you grow old; you grow old when you forget how to play.


#3   Members   -  Reputation: 381

Like
0Likes
Like

Posted 29 March 2014 - 08:54 AM

Hey Buckeye

 

I forgot to mention that: the hotspot is given with an x-value of 8, the center bar is in the monochrome bitmap at a pixel offset of 10, so its actually already wrong there. Considering that a particular user might have overriden the default text cursor in his system i cannot just look for the center bar in the bitmap as maybe someone has a different default text cursor.

 

Greetings

Plerion



#4   GDNet+   -  Reputation: 10739

Like
0Likes
Like

Posted 29 March 2014 - 11:28 AM

Hey Buckeye

 

I forgot to mention that: the hotspot is given with an x-value of 8, the center bar is in the monochrome bitmap at a pixel offset of 10, so its actually already wrong there. Considering that a particular user might have overriden the default text cursor in his system i cannot just look for the center bar in the bitmap as maybe someone has a different default text cursor.

 

Greetings

Plerion

 

I'm not at all sure what you mean by "its actually wrong there." If you mean it's not where you would like it to be, create your own cursor with a hotspot where you'd like it.

 

Can you describe what your concern is, what problem you're trying to solve?


Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly.

You don't forget how to play when you grow old; you grow old when you forget how to play.


#5   Members   -  Reputation: 381

Like
1Likes
Like

Posted 29 March 2014 - 12:08 PM

Hello Buckeye

 

For me as a normal user i would suspect that the hotspot of the cursor is exactly where the vertical bar of the text cursor is. Everything else does not make any sense to me as thats the location you are clicking. Yet however if you take the 8 pixel offset you get from the icon info for the x-hotspot and go to that position in the cursors bitmap you land 2 pixels left of the vertical bar. That means on windows 7 if you want to get the effective location the user intended to click youd have to add 2 pixel to the value you get in WM_MOUSEMOVE or similar messages. If you dont do so youll drive the user nuts as he would have to click 2 pixels more left than he wants to click.

 

The use case i had problem implementing was:
The user clicks into the textbox and the caret of the textbox should move to the closest letter at the click position. Due to this 2 pixel offset to the left visually you had to click into the next letter to get the caret to the one you actually wanted.

 

So, yes, i say its not where i want it and i stay by my opinion: Its just plain wrong how it is right now.

 

Greetings

Plerion



#6   GDNet+   -  Reputation: 10739

Like
0Likes
Like

Posted 29 March 2014 - 01:29 PM


That means on windows 7 if you want to get the effective location the user intended to click youd have to add 2 pixel to the value you get in WM_MOUSEMOVE or similar messages.

Perhaps that's what applications must do. I haven't tried to write my own edit control as it's too easy to let Windows controls do that work.


Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly.

You don't forget how to play when you grow old; you grow old when you forget how to play.





Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.




PARTNERS