myspacee Posted September 14, 2011 Share Posted September 14, 2011 Hello to all,building a tool that allow to my user to 'map' some value in a text file. Need to return line and column cursor as SciTE does:http://static.repubblica.it/laprovinciapavese/Appoggio/coord.JPGthank you for any info,m. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted September 14, 2011 Moderators Share Posted September 14, 2011 myspacee, This should give you the idea: expandcollapse popup#include <GUIConstantsEx.au3> #include <EditConstants.au3> #Include <GuiEdit.au3> Global $aLocation[2] = [0, 0] $sText = "This is a long piece of text which should require wrapping in the edit control - " & _ "which is provided by the combination of $ES_WANTRETURN and $ES_MULTILINE styles" $hGUI = GUICreate("Test", 500, 500) $hEdit = GUICtrlCreateEdit($sText, 10, 10, 200, 200, BitOr($ES_WANTRETURN, $ES_MULTILINE)) $hButton_Locate = GUICtrlCreateButton("Locate", 10, 300, 80, 30) $hButton_Reset = GUICtrlCreateButton("Reset", 10, 350, 80, 30) $hButton_Relocate = GUICtrlCreateButton("Relocate", 10, 400, 80, 30) $hLabel_Line = GUICtrlCreateLabel("Line: ", 100, 300, 100, 20) $hLabel_Col = GUICtrlCreateLabel("Col: ", 200, 300, 100, 20) GUISetState() ; Set cursor to start _GUICtrlEdit_SetSel($hEdit, 0, 0) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $hButton_Locate ; Show and save current position GUICtrlSetData($hLabel_Line, "Line: " & ControlCommand($hGUI, "", $hEdit, "GetCurrentLine", "")) GUICtrlSetData($hLabel_Col, "Col: " & ControlCommand($hGUI, "", $hEdit, "GetCurrentCol", "")) ; Get current position in usable form $aLocation = _GUICtrlEdit_GetSel($hEdit) GUICtrlSetState($hEdit, $GUI_FOCUS) Case $hButton_Reset ; Reset cursor to start GUICtrlSetState($hEdit, $GUI_FOCUS) _GUICtrlEdit_SetSel($hEdit, 0, 0) Case $hButton_Relocate ; Relocate cursor to stored position GUICtrlSetState($hEdit, $GUI_FOCUS) _GUICtrlEdit_SetSel($hEdit, $aLocation[0], $aLocation[1]) EndSwitch WEnd All clear? M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
taietel Posted September 14, 2011 Share Posted September 14, 2011 Here is another solution: expandcollapse popup#include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <GuiStatusBar.au3> _Test() Func _Test() Local $sTxt For $i = 1 To 20 $sTxt &= "This is a sample text " & @CRLF Next Local $hGUI = GUICreate("Test - Get current Line/Column", 600, 400) Local $hEdit = GUICtrlCreateEdit("", 5, 5, 590, 365, BitOR($ES_NOHIDESEL, $ES_WANTRETURN, $WS_VSCROLL)) Local $StatusBar1 = _GUICtrlStatusBar_Create($hGUI) Local $StatusBar1_PartsWidth[2] = [100, -1] _GUICtrlStatusBar_SetParts($StatusBar1, $StatusBar1_PartsWidth) _GUICtrlStatusBar_SetText($StatusBar1, "Line: ", 0) _GUICtrlStatusBar_SetText($StatusBar1, "Column: ", 1) _GUICtrlStatusBar_SetMinHeight($StatusBar1, 25) GUISetState() GUICtrlSetData($hEdit, $sTxt) While 1 Sleep(10) $pos = _GetLineColumn($hEdit) _GUICtrlStatusBar_SetText($StatusBar1, "Line: " & $pos[0], 0) _GUICtrlStatusBar_SetText($StatusBar1, "Column: " & $pos[1], 1) $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd EndFunc ;==>_Test Func _GetLineColumn($hWnd) $hWnd = GUICtrlGetHandle($hWnd) Local $aRet[2] Local $iLine = _SendMessage($hWnd, 0xc9, -1, 0) Local $iSel = _SendMessage($hWnd, 0xb0, 0, 0) Local $iLineIndex = _SendMessage($hWnd, 0xbb, -1, 0) Local $iColumn = BitAND($iSel, 0xffff) - $iLineIndex $aRet[0] = $iLine + 1 $aRet[1] = $iColumn + 1 Return $aRet EndFunc ;==>_GetLineColumn Things you should know first...In the beginning there was only ONE! And zero... Progs: Create PDF(TXT2PDF,IMG2PDF) 3D Bar Graph DeskGadget Menu INI Photo Mosaic 3D Text Link to comment Share on other sites More sharing options...
myspacee Posted September 15, 2011 Author Share Posted September 15, 2011 nice! thank you both, m. Link to comment Share on other sites More sharing options...
JailDoctor Posted December 8, 2011 Share Posted December 8, 2011 (edited) A window from a program I automated with an Autoit script gives me feedback at the top of the screen. I copy the feedback and compare it to some potential messages that guide how the script will continue. I am sending a MouseClickDrag to select the top portion of window. I then Ctrl C to copy the selection. The mouse movement is annoying and I imagine all the copying may use the CPU resources (slow things down). This is what I have: WinActivate("MyWindow") WinMove("MyWindow", "", 10, 200, 800, 500) ; move and size the window to ensure the mouse goes where it needs to go. MouseClickDrag("left", 19, 288,736, 298) ControlSend("MyWindow", "", "", "{CTRLDOWN}c{CTRLUP}") ; copy the selection. ;etc. I tried $hEdit = WinGetHandle("MyWindow","") ; Set Selection _GUICtrlEdit_SetSel($hEdit, 19, 298) ; got the xy coordinates from the window info tool. It didn't seem _GUICtrlEdit_SetSel actually selected the text in the window because Ctrl + C and then V would not paste what is on supposedly selected. I expected to have the area selected and then use something like _GUICtrlEdit_GetSel to "copy" the text or assign it to some variable like $MyMessage, but _GUICtrlEdit_GetSel only gives me the coordinates of the first and last character of the selection, not the actual text in the selection. Any suggestions about selecting a portion of a window without having the mouse move all over the place, copy the text or maybe assign it to a variable? Your help is appreciated. Edited December 8, 2011 by JailDoctor Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted December 9, 2011 Moderators Share Posted December 9, 2011 JailDoctor,Firstly I very much doubt that the value you have in $hEdit is the handle of the edit control you are looking for - so it is little wonder that _GUICtrlEdit_SetSel failed. WinGetHandle will get you the handle of the main GUI - I suspect that the edit control is only one of the controls within it. When you use the AutoIt Window Info tool, what do you see in the "Control" tab when you place the Finder over the edit? You should be able to get Class and Instance values to identify it. Next, did you look at the Help file to see what _GUICtrlEdit_GetSel returns? You say you "expected" the selected text to be placed in a variable - a cursory glance at the first line of the relevant page in the Help file shows that the function "Retrieves the starting and ending character positions of the current selection" - which is exactly what it does. You need to read all the text in the edit and then use StringMid to get the selected text like this: #include <GUIConstantsEx.au3> #include <GuiEdit.au3> $sData = "A few characters to put in the edit" $hGUI = GUICreate("Test", 500, 500) $hEdit = GUICtrlCreateEdit($sData, 10, 10, 480, 300) $hButton = GUICtrlCreateButton("Read", 10, 400, 80, 30) $hLabel = GUICtrlCreateLabel("", 100, 400, 380, 30) GUICtrlSetFont(-1, 16) GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $hButton $sText = GUICtrlRead($hEdit) $aSel = _GUICtrlEdit_GetSel($hEdit) $sSel = StringMid($sText, $aSel[0] + 1, $aSel[1] - $aSel[0]) ; The | are just to show you have the correct selection GUICtrlSetData($hLabel, "|" & $sSel & "|") EndSwitch WEndSo try to get the handle of the edit control within the GUI and then do what I did above. If you run into problems, post the data in the "Control" tab of the Info Tool and perhaps a screen shot of the GUI itself. Good luck. M23P.S. Your question has very little to do with the earlier posts. Rather than hijack an existing thread, just start your own next time. Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
JailDoctor Posted December 12, 2011 Share Posted December 12, 2011 I apologize Melba, it wasn’t my intention to hijack a thread. I assumed it was related to my issue because the GUICtrlRead($hEdit) command does not return anything from my program’s window. I need to select the top line of the window and copy whatever is in that area. Myspace started the thread with “tool that allow to my user to 'map' some value in a text file” so I assumed the thread referred to finding some text in a specific area of a window. I am sorry I used the word “expected” when what I meant was “what I want is.” Since GUICtrlRead($hEdit) does not produce anything, how can I copy the top of the window to emulate the MouseClickDrag without the mouse moving to that area. MouseClickDrag("left", 19, 288,736, 298) I move and size the window each time before the command, so I know the coordinates to copy are the same. Autoit widow info follows: >>>> Window <<<< Title: BASE - EXTRA! Office Client Class: SDIMainFrame Position: 10, 200 Size: 732, 484 Style: 0x14CFC000 ExStyle: 0x00000110 Handle: 0x00050048 >>>> Control <<<< Class: Instance: ClassnameNN: Advanced (Class): ID: Text: Position: Size: ControlClick Coords: Style: ExStyle: Handle: >>>> Mouse <<<< Position: 541, 218 Cursor ID: 2 Color: 0x87A9D5 >>>> StatusBar <<<< 1: Connected to host county_base [10.10.2.244] 2: 3: 4: 5: NUM 6: 7: 12:02 PM >>>> Visible Text <<<< Connected to host county_base [10.10.2.244] Default Toolbar Default Toolbar >>>> Hidden Text <<<< Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted December 12, 2011 Moderators Share Posted December 12, 2011 JailDoctor,Is the text you are trying to copy listed in the >>>> Visible Text <<<< section? M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
JailDoctor Posted December 12, 2011 Share Posted December 12, 2011 (edited) No, the text I need is not listed in the >>>> Visible Text <<<<Connected to host county_base [10.10.2.244] - This is in the left lower corner of the window, exactly like the first image of the thread posted by myspacee.Default Toolbar - I do not see this anywhere in the window.The top of the black screen shows a line " ---> ENTER DESIRED ACTION"The message changes based on the results of the queries.I can select that text draging the mouse.GUICtrlRead($hEdit) returns:Connected to host county_base [10.10.2.244]Default ToolbarDefault Toolbar And I described as "nothing" because I thought these stings are pretty much meaningless. It is not the text I need from the very first line of the window.GUICtrlRead($hEdit) does not return " ---> ENTER DESIRED ACTION" and this is what I need. Edited December 12, 2011 by JailDoctor Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted December 13, 2011 Moderators Share Posted December 13, 2011 JailDoctor, I am clutching at straws here, but try this: $sText = WinGetText("BASE - EXTRA! Office Client") MsgBox(0, "Text", $sText) If there is no control in the GUI to hold the text, but you can select it with the mouse, I am at a loss if this does not work. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
JailDoctor Posted December 13, 2011 Share Posted December 13, 2011 (edited) Thanks, but $sText = WinGetText("BASE - EXTRA! Office Client") MsgBox(0, "Text", $sText) Gives me the same result as GUICtrlRead($hEdit): Connected to host county_base [10.10.2.244] Default Toolbar Default Toolbar Is there a way to select an area of the window without highlighting it as the MouseClickDrag command does? MouseClickDrag works because it selects the specific area I want, then I copy the selection and use the clipboard functions to get the content. When one looks at the screen, the mouse moves to that area, selects the area and then continues to another area to click and enter a variable. I want to do all that without the mouse moving, just copying whatever is in the specific area of the window. Edited December 13, 2011 by JailDoctor Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now