Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
GetCaretPos() ignores cursor keys and mouse click
Message
De
07/04/2005 11:07:27
Cetin Basoz
Engineerica Inc.
Izmir, Turquie
 
 
À
07/04/2005 10:30:54
Information générale
Forum:
Visual FoxPro
Catégorie:
Fonctions Windows API
Divers
Thread ID:
01002065
Message ID:
01002308
Vues:
19
This message has been marked as the solution to the initial question of the thread.
Not exactly:) You mean you need to get position with something that invokes KeyPress event? If so why not check there. You say it's for popup. Popup even could do the calculation itself.
*Form.Keypress
LPARAMETERS nKeyCode, nShiftAltCtrl
If nKeyCode = 93 and nShiftAltCtrl=1 && Shift+F10 or Menu Key near right Ctrl
* GetCaretPos to lnX,lnY
this.ActiveControl.RightClick(m.lnx,m.lny)
endif

*RightClick of control
Lparameters tnX,tnY
Local lnRow,lnCol
lnRow = Iif(Empty(tnY),Mrow(),m.tnY/Fontmetric(1))
lnCol = Iif(Empty(tnX),Mcol(),m.tnX/Fontmetric(6))
DO myShortcut.mpr with m.lnRow,m.lnCol, this

* ShortCut uses passed lnRow,lnCol instead of mrow,mcol
Parameter tnRow, tnCol, oRef
Define POPUP myContextMenu shortcut RELATIVE from m.tnRow, m.tnCol
*...
PS: Your method has also another side effect like lostfocus, next control gotfocus etc if it's at the end of a textbox.
Cetin

>Cetin,
>
>> I don't understand quite well though where do you call that code (on key interception?)
>
>As usual, thank you very much for your help! You're probably confused because my description of this topic may not have been as well written as I would have liked. (Truth be told, even I'm confused!)
>
>My goal was to be able to display a shortcut menu at the current cursor (caret) position in a textbox or editbox control. Non-mouse users would invoke the popup via the Shift+F10 keystroke consistent with other Windows apps that provide a keystroke shortcut alternative to rightmouse click for invoking context menus.
>
>So, my challenge became how to figure out where the cursor (caret) was relative to the current form. Your GetCaretPos() code from 2001 and, surprisingly, row()/col() could be used to determine the exact position of the caret. In this situation I found row()/col() better because these functions return foxel based values that the define popup command requires for specifying a popup location.
>
>So far, so good :) ... then I realized that when a user repositions the cursor (caret) via the keyboard or mouse that GetCaretPos() and row()/col() values are NOT updated. This meant that my shortcut menus would often popup in the wrong location. I googled this behavior (cursor keys and mouse not updating GetCaretPos) but could not find anyone else complaining about this so my guess is that this behavior is specific to VFP.
>
>In my research and experiments I could find no way for GetCaretPos() or row()/col() to update their coordinates unless I entered a visibly displayed char. So my "solution", er hack :) was to give these functions their little visible char - for just just a split second - to force their coordinates to resynch with the physical location of the caret - and then to take away that temp char and restore the control's value to its original state. All this under the cover of LockScreen = True.
>
>Conclusion: An ugly solution that appears to work in all my test cases. Worse side effect is when cursor is in bottom right of an editbox and the temp space key forces the scollbar to advance forward. The effect is visually disconcerting (the user sees a mysterious scroll), but the GetCaretPos() and row()/col() coordinates are synched properly and a popup menu will appear in the expected position.
>
>Does this answer your question?
>
>Best regards,
>Malcolm
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform