Sign in to follow this  
Followers 0
step887

richtext and cursor position

3 posts in this topic

So when I click on something in the rich text edit, I would like to be able to get the line number. I could not find a function that got xy from cursor in relationship to the control

So my thinking was get the y pos of the ctri and then add scroll postion to get the other all y position and then get char pos from xy and then get line from char pos. that only works until you scroll down...

so if there is an way to do this, I would appreciate it.

example code:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Guirichedit.au3>
;set random crap and fonts
$fdata = "academy engraved let,algerian,amaze,arial,arial black,balthazar,bankgothic lt bt,bart,bimini,comic sans ms,book antiqua,bookman old style,braggadocio,britannic bold,brush script mt,century gothic," & _
"century schoolbook,chasm,chicago,colonna mt,comic sans ms,commercialscript bt,coolsville,courier,courier new,cursive,dayton,desdemona,fantasy,flat brush,footlight mt light,futurablack bt,futuralight bt," & _
"garamond,gaze,geneva,georgia,geotype tt,helterskelter,helvetica,herman,highlight let,impact,jester,joan,john handy let,jokerman let,kelt,kids,kino mt,la bamba let,lithograph,lucida console,map symbols," & _
"marlett,matteroffact,matisse itc,matura mt script capitals,mekanik let,monaco,monospace,monotype sorts,ms linedraw,new york,olddreadfulno7 bt,orange let,palatino,playbill,pump demi bold let,puppylike,roland," & _
"sans-serif,scripts,scruff let,serif,short hand,signs normal,simplex,simpson,stylus bt,superfrench,surfer,swis721 bt,swis721 blkoul bt,symap,symbol,tahoma,technic,tempus sans itc,terk,times,times new roman," & _
"trebuchet ms,trendy,txt,verdana,victorian let,vineta bt,vivian,webdings,wingdings,western,westminster,westwood let,wide latin,zapfellipt bt "
$fonts = StringSplit($fdata,",")
$rdata = "Adult|Aeroplane|Air|Aircraft Carrier|Airforce|Airport|Album|Alphabet|Apple|Arm|Army|Baby|Baby|Backpack|Balloon|Banana|Bank|Barbecue|Bathroom|Bathtub|Bed|Bed|Bee|Bible|Bible|Bird|Bomb|Book|Boss|Bottle|Bowl|Box|Boy|Brain|Bridge|Butterfly|Button|Cappuccino|Car|Car-race|Carpet|Carrot|Cave|Chair|Chess Board|Chief|Child|Chisel|Chocolates|Church|Church|Circle|Circus|Circus|Clock|Clown|Coffee|Coffee-shop|Comet|Compact Disc|Compass|Computer|Crystal|Cup|Cycle|Data Base|Desk|Diamond|Dress|Drill|Drink|Drum|Dung|Ears|Earth|Egg|Electricity|Elephant|Eraser|Explosive|Eyes|Family|Fan|Feather|Festival|Film|Finger|Fire|Floodlight|Flower|Foot|Fork|Freeway|Fruit|Fungus|Game|Garden|Gas|Gate|Gemstone|Girl|Gloves|God|Grapes|Guitar|Hammer|Hat|Hieroglyph|Highway|Horoscope|Horse|Hose|Ice|Ice-cream|Insect|Jet fighter|Junk|Kaleidoscope|Kitchen|Knife|Leather jacket|Leg|Library|Liquid|Magnet|Man|Map|Maze|Meat|Meteor|Microscope|Milk|Milkshake|Mist|Money $$$$|Monster|Mosquito|Mouth|Nail|Navy|Necklace|Needle|Onion|PaintBrush|Pants|Parachute|Passport|Pebble|Pendulum|Pepper|Perfume|Pillow|Plane|Planet|Pocket|Post-office|Potato|Printer|Prison|Pyramid|Radar|Rainbow|Record|Restaurant|Rifle|Ring|Robot|Rock|Rocket|Roof|Room|Rope|Saddle|Salt|Sandpaper|Sandwich|Satellite|School|Sex|Ship|Shoes|Shop|Shower|Signature|Skeleton|Slave|Snail|Software|Solid|Space Shuttle|Spectrum|Sphere|Spice|Spiral|Spoon|Sports-car|Spot Light|Square|Staircase|Star|Stomach|Sun|Sunglasses|Surveyor|Swimming Pool|Sword|Table|Tapestry|Teeth|Telescope|Television|Tennis racquet|Thermometer|Tiger|Toilet|Tongue|Torch|Torpedo|Train|Treadmill|Triangle|Tunnel|Typewriter|Umbrella|Vacuum|Vampire|Videotape|Vulture|Water|Weapon|Web|Wheelchair|Window|Woman|Worm|X-ray"
$random = StringSplit($rdata,"|")
global $hRichEdit
6
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
$hGUI = GUICreate("My GUI")
$hRichEdit = _GUICtrlRichEdit_Create($hgui,"", 5,5,350,150,BitOR($ES_MULTILINE, $WS_VSCROLL, $ES_AUTOVSCROLL))
for $i = 1 to random(50,200,1)
$len = StringLen(_GUICtrlRichEdit_GetText($hrichedit));find current length of rich text
$data =  $i & ". " &$random[Random(1,$random[0],1)]; set counter and random word
_GUICtrlRichEdit_AppendText($hrichedit,$data & @CRLF); add to control
_GUICtrlRichEdit_SetSel($hrichedit, $len , $len + StringLen( $data)+1);select what was added
_GUICtrlRichEdit_SetFont($hrichedit,"12",$fonts[Random(1,$fonts[0],1)]);set random font
_GUICtrlRichEdit_Deselect($hrichedit); deselect
next
_GUICtrlRichEdit_SetScrollPos($hRichEdit, 0, 0); put cursor at the top when all done
_GUICtrlRichEdit_SetEventMask($hRichEdit, $ENM_MOUSEEVENTS); set up wmnotify
GUISetState()
While 1
If GUIGetMsg() =-3 Then ExitLoop
WEnd

Func WM_NOTIFY($hWnd, $iMsg, $iWparam, $iLparam)
#forceref $iMsg, $iWparam
Local $hWndFrom, $iCode, $tNMHDR, $tMsgFilter, $hMenu, $arr
$tNMHDR = DllStructCreate($tagNMHDR, $iLparam)
$hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
$iCode = DllStructGetData($tNMHDR, "Code")
Switch $hWndFrom
  Case $hRichEdit
   Select
    Case $iCode = $EN_MSGFILTER
     $tMsgFilter = DllStructCreate($tagMSGFILTER, $iLparam)
     If DllStructGetData($tMsgFilter, "msg") = $WM_LBUTTONUP Then;when left mouse click
      $y = _WinAPI_GetMousePosY(True, $hrichedit); get position of y in control
      $arr = _GUICtrlRichEdit_GetScrollPos($hrichedit); get scroll position
      $char = _GUICtrlRichEdit_GetCharPosFromXY($hrichedit, 10,$arr[1] +$y);put 10 for x because it should not matter
      ;scroll pos + y pos should equal y of the control
      ConsoleWrite ("y: " & $y & " s: " & $arr[1] & " line:  " &_GUICtrlRichEdit_GetLineNumberFromCharPos($hrichedit,$char) & @crlf); output to console
      EndIf
   EndSelect
EndSwitch

Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY

Share this post


Link to post
Share on other sites



step887,

I would use ControlCommand with the "GetCurrentLine" command. If you fire on mouse primary button down you can do it like this: ;)

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Guirichedit.au3>
;set random crap and fonts
$fdata = "academy engraved let,algerian,amaze,arial,arial black,balthazar,bankgothic lt bt,bart,bimini,comic sans ms,book antiqua,bookman old style,braggadocio,britannic bold,brush script mt,century gothic," & _
        "century schoolbook,chasm,chicago,colonna mt,comic sans ms,commercialscript bt,coolsville,courier,courier new,cursive,dayton,desdemona,fantasy,flat brush,footlight mt light,futurablack bt,futuralight bt," & _
        "garamond,gaze,geneva,georgia,geotype tt,helterskelter,helvetica,herman,highlight let,impact,jester,joan,john handy let,jokerman let,kelt,kids,kino mt,la bamba let,lithograph,lucida console,map symbols," & _
        "marlett,matteroffact,matisse itc,matura mt script capitals,mekanik let,monaco,monospace,monotype sorts,ms linedraw,new york,olddreadfulno7 bt,orange let,palatino,playbill,pump demi bold let,puppylike,roland," & _
        "sans-serif,scripts,scruff let,serif,short hand,signs normal,simplex,simpson,stylus bt,superfrench,surfer,swis721 bt,swis721 blkoul bt,symap,symbol,tahoma,technic,tempus sans itc,terk,times,times new roman," & _
        "trebuchet ms,trendy,txt,verdana,victorian let,vineta bt,vivian,webdings,wingdings,western,westminster,westwood let,wide latin,zapfellipt bt "
$fonts = StringSplit($fdata, ",")
$rdata = "Adult|Aeroplane|Air|Aircraft Carrier|Airforce|Airport|Album|Alphabet|Apple|Arm|Army|Baby|Baby|Backpack|Balloon|Banana|Bank|Barbecue|Bathroom|Bathtub|Bed|Bed|Bee|Bible|Bible|Bird|Bomb|Book|Boss|Bottle|Bowl|Box|Boy|Brain|Bridge|Butterfly|Button|Cappuccino|Car|Car-race|Carpet|Carrot|Cave|Chair|Chess Board|Chief|Child|Chisel|Chocolates|Church|Church|Circle|Circus|Circus|Clock|Clown|Coffee|Coffee-shop|Comet|Compact Disc|Compass|Computer|Crystal|Cup|Cycle|Data Base|Desk|Diamond|Dress|Drill|Drink|Drum|Dung|Ears|Earth|Egg|Electricity|Elephant|Eraser|Explosive|Eyes|Family|Fan|Feather|Festival|Film|Finger|Fire|Floodlight|Flower|Foot|Fork|Freeway|Fruit|Fungus|Game|Garden|Gas|Gate|Gemstone|Girl|Gloves|God|Grapes|Guitar|Hammer|Hat|Hieroglyph|Highway|Horoscope|Horse|Hose|Ice|Ice-cream|Insect|Jet fighter|Junk|Kaleidoscope|Kitchen|Knife|Leather jacket|Leg|Library|Liquid|Magnet|Man|Map|Maze|Meat|Meteor|Microscope|Milk|Milkshake|Mist|Money $$$$|Monster|Mosquito|Mouth|Nail|Navy|Necklace|Needle|Onion|PaintBrush|Pants|Parachute|Passport|Pebble|Pendulum|Pepper|Perfume|Pillow|Plane|Planet|Pocket|Post-office|Potato|Printer|Prison|Pyramid|Radar|Rainbow|Record|Restaurant|Rifle|Ring|Robot|Rock|Rocket|Roof|Room|Rope|Saddle|Salt|Sandpaper|Sandwich|Satellite|School|Sex|Ship|Shoes|Shop|Shower|Signature|Skeleton|Slave|Snail|Software|Solid|Space Shuttle|Spectrum|Sphere|Spice|Spiral|Spoon|Sports-car|Spot Light|Square|Staircase|Star|Stomach|Sun|Sunglasses|Surveyor|Swimming Pool|Sword|Table|Tapestry|Teeth|Telescope|Television|Tennis racquet|Thermometer|Tiger|Toilet|Tongue|Torch|Torpedo|Train|Treadmill|Triangle|Tunnel|Typewriter|Umbrella|Vacuum|Vampire|Videotape|Vulture|Water|Weapon|Web|Wheelchair|Window|Woman|Worm|X-ray"
$random = StringSplit($rdata, "|")


$hGUI = GUICreate("My GUI")
$hRichEdit = _GUICtrlRichEdit_Create($hGUI, "", 5, 5, 350, 150, BitOR($ES_MULTILINE, $WS_VSCROLL, $ES_AUTOVSCROLL))
For $i = 1 To Random(50, 200, 1)
    $len = StringLen(_GUICtrlRichEdit_GetText($hRichEdit));find current length of rich text
    $data = $i & ". " & $random[Random(1, $random[0], 1)]; set counter and random word
    _GUICtrlRichEdit_AppendText($hRichEdit, $data & @CRLF); add to control
    _GUICtrlRichEdit_SetSel($hRichEdit, $len, $len + StringLen($data) + 1);select what was added
    _GUICtrlRichEdit_SetFont($hRichEdit, "12", $fonts[Random(1, $fonts[0], 1)]);set random font
    _GUICtrlRichEdit_Deselect($hRichEdit); deselect
Next
_GUICtrlRichEdit_SetScrollPos($hRichEdit, 0, 0); put cursor at the top when all done

GUISetState()

$iCurr_Line = -1

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            ExitLoop
        Case $GUI_EVENT_PRIMARYDOWN
            $iLine = ControlCommand($hGUI, "", $hRichEdit, "GetCurrentLine", "")
            If $iLine <> $iCurr_Line Then
                $iCurr_Line = $iLine
                ConsoleWrite($iLine & @CRLF)
            EndIf
    EndSwitch
WEnd

I hope that helps. :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

thanks again Melba, guess it shows how little I know, I pouring over the _guictrlrich functions trying to figure it out

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0