I am interrogating the editor gadget to find the line number and column of the cursor. I can get the line number ok... but getting the column that the cursor has moved to (with the cursor keys) has stumped me. The lines are of differing lengths so that doesn't help.
Does anyone have any ideas?
Editor Gadget - which column is cursor in?
Editor Gadget - which column is cursor in?
Leopard-parallels-XP-Vista
- electrochrisso
- Addict

- Posts: 989
- Joined: Mon May 14, 2007 2:13 am
- Location: Darling River
Re: Editor Gadget - which column is cursor in?
Got these from the CodeArchive.chm a handy thing to have, you should be able to find it through the search.
I hope its what you need. 
Code: Select all
Procedure Editor_GetCursorX(Gadget)
; returns X-Pos of Cursor
REG = GadgetID(Gadget)
SendMessage_(REG,#EM_EXGETSEL,0,Range.CHARRANGE)
ProcedureReturn (Range\cpMax-(SendMessage_(REG,#EM_LINEINDEX,SendMessage_(REG,#EM_EXLINEFROMCHAR,0,Range\cpMin),0))+1)
EndProcedure
Procedure Editor_GetCursorY(Gadget)
; returns Y-Pos of Cursor
REG = GadgetID(Gadget)
SendMessage_(REG,#EM_EXGETSEL,0,Range.CHARRANGE)
ProcedureReturn SendMessage_(REG,#EM_EXLINEFROMCHAR,0,Range\cpMin)+1
EndProcedure
PureBasic! Purely the best 
Re: Editor Gadget - which column is cursor in?
Edit: duh, double 
Code: Select all
Procedure x_editorgadget_cursorcolumn(gadgetnr.i)
Protected range.CHARRANGE, id.i
;
range.CHARRANGE
id = GadgetID(gadgetnr)
SendMessage_(id,#EM_EXGETSEL,0,range.CHARRANGE)
ProcedureReturn (range\cpMax-(SendMessage_(id,#EM_LINEINDEX,SendMessage_(id,#EM_EXLINEFROMCHAR,0,range\cpMin),0)))
;
EndProcedure
Procedure x_editorgadget_cursorrow(gadgetnr)
Protected range.CHARRANGE, id.i
;
range.CHARRANGE
id = GadgetID(gadgetnr)
SendMessage_(id,#EM_EXGETSEL,0,@range)
ProcedureReturn SendMessage_(id,#EM_EXLINEFROMCHAR,0,range\cpMin)
;
EndProcedure
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB - upgrade incoming...)
( The path to enlightenment and the PureBasic Survival Guide right here... )
( The path to enlightenment and the PureBasic Survival Guide right here... )
Re: Editor Gadget - which column is cursor in?
Thanks so much. But both procedures only return the maximum number of either columns or lines, not where the cursor is in those lines. At least, that is the result I'm getting with the editor gadget after loading up an RTF and then moving around within it. Again, thank you both for your response though.
Leopard-parallels-XP-Vista
Re: Editor Gadget - which column is cursor in?
Ok... I got it working... and you were both absolutely right. I needed to use variables to hold the returned values instead of trying to convert them immediately to strings....
Thanks! Very helpful forum indeed.
John
Thanks! Very helpful forum indeed.
John
Leopard-parallels-XP-Vista

