Read Data From A Windows Control, Is It Possible ?
#1
Posted 18 April 2006 - 09:22 AM
But is there anyone who can show me how to read data from a NORMAL WINDOWS control.
I can hide, move, read the control text, ... anything you want, but not the data ?
Is it that difficult to do ?
If it is not possible can someone tell me why ?
Thanks
#2
Posted 19 April 2006 - 11:12 AM
I have been struggling to read data for a non-windows control.
But is there anyone who can show me how to read data from a NORMAL WINDOWS control.
I can hide, move, read the control text, ... anything you want, but not the data ?
Is it that difficult to do ?
If it is not possible can someone tell me why ?
Thanks
using controlgethandle most can be done.
Take a look at the include files for the beta, GuiCombo, GuiList, GuiListView to name a few
You'll see if statements to check if it is a handle or control id being passed in.
Also if you want to find out more about the messages being used look at Individual Control Information
Gary
SciTE for AutoItDirections for Submitting Standard UDFs
Don't argue with an idiot; people watching may not be able to tell the difference.
#3
Posted 19 April 2006 - 11:58 AM
Thanks for the tips.
I' ll have a look.
The plan of attack is that I will try to get to read data from a windows control.
Than I will try to transpose that to a non windows control.
If I find the solution I post it back to share.
ptrex
#4
Posted 21 April 2006 - 01:01 PM
This is an example of how to read data from an Edit control, like notepad.
This was realized due to the tips and help of gafrost
; My first DLLCall ; ptrex #include <GUIConstants.au3> #include <GUIedit.au3> Opt("WinTitleMatchMode", 4); Allow ClassName lookup Global Const $EM_GETLINE = 0xC4 Dim $LineCount Dim $LineNum Dim $Ret Dim $LineLen Dim $FirstCharPos Dim $Buffer Const $Applhandle = WinGetHandle("classname=Notepad") Const $Ctrlhandle = ControlGetHandle("","",15) WinWaitActive($Applhandle) sleep(500) WinHandle() ;CtrlReadLineNum($Ctrlhandle) ;LineIndex($Ctrlhandle) ;LineLenght($Ctrlhandle) CtrlRead($Ctrlhandle) Func WinHandle(); tested = OK $result = DllCall("user32.dll", "int", "MessageBox", "hwnd", 0, "str", "Window Active " & $Ctrlhandle, "str", "Handle Test" , "int", 0) EndFunc Func CtrlReadLineNum($Ctrlhandle); tested = OK $Ctrlread = _GUICtrlEditGetLineCount($Ctrlhandle) MsgBox(0,"Test","Line #" & " "& $Ctrlread) EndFunc Func LineIndex($Ctrlhandle); tested = OK $Ctrlread =_GUICtrlEditLineIndex($Ctrlhandle) MsgBox(0,"Test","Line Index" & " "& $Ctrlread) EndFunc Func LineLenght($Ctrlhandle); tested = OK $Ctrlread =_GUICtrlEditLineLength($Ctrlhandle) MsgBox(0,"Test","Line Lenght" & " "& $Ctrlread) EndFunc Func CtrlRead($Ctrlhandle); tested = OK $LineCount = _GUICtrlEditGetLineCount($Ctrlhandle) MsgBox(0, "Test", "Line #" & " " & $LineCount) For $LineNum = 0 To $LineCount - 1 $FirstCharPos = _GUICtrlEditLineIndex($Ctrlhandle, $LineNum) MsgBox(0, "Test", "First Char Pos on Line IDX: " & $FirstCharPos) $LineLen = _GUICtrlEditLineLength($Ctrlhandle, $FirstCharPos) MsgBox(0, "Test", "Length: " & $LineLen) $Buffer = $LineLen $Ret = DllCall("user32.dll", "int", "SendMessage", "hwnd", $Ctrlhandle, "int", $EM_GETLINE, "int", $LineNum, "str", "") MsgBox(0, "Test", "Text is =" & " " & $Ret[4]) Next EndFunc ;==>CtrlRead
Open notepad type a few lines of text and run the code.
Edited by ptrex, 14 September 2012 - 09:25 AM.
#5
Posted 30 July 2007 - 12:20 PM
hmm ?? Line 8 --> Global Const $EM_GETLINE = 0xC4
#6
Posted 01 August 2007 - 06:13 PM
ERROR: $EM_GETLINE previously declared as a 'Const'
hmm ?? Line 8 --> Global Const $EM_GETLINE = 0xC4
This topic is from a year ago, includes have changed since then.
SciTE for AutoItDirections for Submitting Standard UDFs
Don't argue with an idiot; people watching may not be able to tell the difference.
#7
Posted 01 September 2008 - 03:17 AM
; My first DLLCall ; ptrex #include <GUIConstants.au3> #include <GuiConstantsEx.au3> #include <GUIedit.au3> Opt("WinTitleMatchMode", 4); Allow ClassName lookup ;~ Global Const $EM_GETLINE = 0xC4 Dim $LineCount Dim $LineNum Dim $Ret Dim $LineLen Dim $FirstCharPos Dim $Buffer Const $Applhandle = WinGetHandle("classname=Notepad") Const $Ctrlhandle = ControlGetHandle("","",15) WinWaitActive($Applhandle) sleep(500) WinHandle() ;CtrlReadLineNum($Ctrlhandle) ;LineIndex($Ctrlhandle) ;LineLenght($Ctrlhandle) CtrlRead($Ctrlhandle) Func WinHandle(); tested = OK $result = DllCall("user32.dll", "int", "MessageBox", "hwnd", 0, "str", "Window Active " & $Ctrlhandle, "str", "Handle Test" , "int", 0) EndFunc Func CtrlReadLineNum($Ctrlhandle); tested = OK $Ctrlread = _GUICtrlEdit_GetLineCount($Ctrlhandle) MsgBox(0,"Test","Line #" & " "& $Ctrlread) EndFunc Func LineIndex($Ctrlhandle); tested = OK $Ctrlread =_GUICtrlEdit_LineIndex($Ctrlhandle) MsgBox(0,"Test","Line Index" & " "& $Ctrlread) EndFunc Func LineLenght($Ctrlhandle); tested = OK $Ctrlread =_GUICtrlEdit_LineLength($Ctrlhandle) MsgBox(0,"Test","Line Lenght" & " "& $Ctrlread) EndFunc Func CtrlRead($Ctrlhandle); tested = OK $LineCount = _GUICtrlEdit_GetLineCount($Ctrlhandle) MsgBox(0, "Test", "Line #" & " " & $LineCount) For $LineNum = 0 To $LineCount - 1 $FirstCharPos = _GUICtrlEdit_LineIndex($Ctrlhandle, $LineNum) MsgBox(0, "Test", "First Char Pos on Line IDX: " & $FirstCharPos) $LineLen = _GUICtrlEdit_LineLength($Ctrlhandle, $FirstCharPos) MsgBox(0, "Test", "Length: " & $LineLen) $Buffer = $LineLen $Ret = DllCall("user32.dll", "int", "SendMessage", "hwnd", $Ctrlhandle, "int", $EM_GETLINE, "int", $LineNum, "str", "") MsgBox(0, "Test", "Text is =" & " " & $Ret[4]) Next EndFunc;==>CtrlRead
I was trying to get it to work from an input with $ES_PASSWORD, seems to lockup and do nothing.
We're trapped in the belly of this horrible machine.And the machine is bleeding to death...
#8
Posted 02 May 2009 - 10:57 AM
I have mad minor changes -Its basicaly similar to Firestorm version above- to compile and run on v3.2.12.1.
Now for text= I get empty string. That is reading $Ret[4].
What I might be doing wrong?
Here is my script:
#Region;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_outfile=readData.exe #EndRegion;**** Directives created by AutoIt3Wrapper_GUI **** ; My first DLLCall ; ptrex #include <GUIConstants.au3> #include <GuiConstantsEx.au3> #include <GUIedit.au3> Opt("WinTitleMatchMode", 4); Allow ClassName lookup ; Global Const $EM_GETLINE = 0xC4 Dim $LineCount Dim $LineNum Dim $Ret Dim $LineLen Dim $FirstCharPos Dim $Buffer Const $Applhandle = WinGetHandle("classname=Notepad") Const $Ctrlhandle = ControlGetHandle("","",15) WinWaitActive($Applhandle) sleep(500) WinHandle() ;CtrlReadLineNum($Ctrlhandle) ;LineIndex($Ctrlhandle) ;LineLenght($Ctrlhandle) CtrlRead($Ctrlhandle) Func WinHandle(); tested = OK $result = DllCall("user32.dll", "int", "MessageBox", "hwnd", 0, "str", "Window Active " & $Ctrlhandle, "str", "Handle Test" , "int", 0) EndFunc Func CtrlReadLineNum($Ctrlhandle); tested = OK $Ctrlread = _GUICtrlEdit_GetLineCount($Ctrlhandle) MsgBox(0,"Test","Line #" & " "& $Ctrlread) EndFunc Func LineIndex($Ctrlhandle); tested = OK $Ctrlread =_GUICtrlEdit_LineIndex($Ctrlhandle) MsgBox(0,"Test","Line Index" & " "& $Ctrlread) EndFunc Func LineLenght($Ctrlhandle); tested = OK $Ctrlread =_GUICtrlEdit_LineLength($Ctrlhandle) MsgBox(0,"Test","Line Lenght" & " "& $Ctrlread) EndFunc Func CtrlRead($Ctrlhandle); tested = OK $LineCount = _GUICtrlEdit_GetLineCount($Ctrlhandle) MsgBox(0, "Test", "Line #" & " " & $LineCount) For $LineNum = 0 To $LineCount - 1 $FirstCharPos = _GUICtrlEdit_LineIndex($Ctrlhandle, $LineNum) MsgBox(0, "Test", "First Char Pos on Line IDX: " & $FirstCharPos) $LineLen = _GUICtrlEdit_LineLength($Ctrlhandle, $FirstCharPos) MsgBox(0, "Test", "Length: " & $LineLen) $Buffer = $LineLen $Ret = DllCall("user32.dll", "int", "SendMessage", "hwnd", $Ctrlhandle, "int", $EM_GETLINE, "int", $LineNum, "str", "") MsgBox(0, "Test", "Text is =" & " " & $Ret[4]) Next EndFunc;==>CtrlRead
Many thanks.
Steven
Edited by Stevo, 02 May 2009 - 11:17 AM.
#9
Posted 02 May 2009 - 12:36 PM
StevenHi Ptrex,
I have mad minor changes -Its basicaly similar to Firestorm version above- to compile and run on v3.2.12.1.
Now for text= I get empty string. That is reading $Ret[4].
What I might be doing wrong?
Many thanks.
Steven
You might not have any text in Notepad that can be read to put into $Ret[4].
Malkey.
#10
Posted 02 May 2009 - 01:35 PM
Many thanks for your quick reply.
I do have text in notepad. I tested this again a minute ago.
I typed in a simple word -my name- on notepad and then ran the script. I get everything right except the text is empty again.
Would you by any chance have another working script you can post here please?
Basically I need to read data from 3rd party application richtext editcontrols such as notepad, etc. This is not possible using ControlGetText() because of being richtext...
Regards, Steven
Regards,
Steven
Edited by Stevo, 02 May 2009 - 01:36 PM.
#11
Posted 02 May 2009 - 02:10 PM
I was messing around with this one until I realized your script worked.Hi Malkey,
Many thanks for your quick reply.
I do have text in notepad. I tested this again a minute ago.
I typed in a simple word -my name- on notepad and then ran the script. I get everything right except the text is empty again.
Would you by any chance have another working script you can post here please?
Basically I need to read data from 3rd party application richtext editcontrols such as notepad, etc. This is not possible using ControlGetText() because of being richtext...
Regards, Steven
Regards,
Steven
This one also works on my XP.
#Region;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Outfile=readData.exe #EndRegion;**** Directives created by AutoIt3Wrapper_GUI **** ; My first DLLCall ; ptrex #include <GUIConstants.au3> #include <GuiConstantsEx.au3> #include <GUIedit.au3> ;Opt("WinTitleMatchMode", 4); Allow ClassName lookup ; Global Const $EM_GETLINE = 0xC4 Dim $LineCount Dim $LineNum Dim $Ret Dim $LineLen Dim $FirstCharPos Dim $Buffer WinActivate("[class:Notepad]", "") WinWaitActive("[class:Notepad]", "") Local $Applhandle = WinGetHandle(""); [class:Notepad]") Local $Ctrlhandle = ControlGetHandle("", "", "Edit1") ConsoleWrite("$Ctrlhandle " & $Ctrlhandle & @CRLF) WinHandle() ;CtrlReadLineNum($Ctrlhandle) ;LineIndex($Ctrlhandle) ;LineLenght($Ctrlhandle) CtrlRead($Ctrlhandle) $str = ControlGetText("", "", "[Class:Edit]") ;MsgBox(0,"Test",$str) Func WinHandle(); tested = OK $result = DllCall("user32.dll", "int", "MessageBox", "hwnd", $Applhandle, "str", "Control Window Active " & $Ctrlhandle, "str", "Handle Test", "int", 0) EndFunc ;==>WinHandle Func CtrlReadLineNum($Ctrlhandle); tested = OK $Ctrlread = _GUICtrlEdit_GetLineCount($Ctrlhandle) MsgBox(0, "Test", "Line #" & " " & $Ctrlread) EndFunc ;==>CtrlReadLineNum Func LineIndex($Ctrlhandle); tested = OK $Ctrlread = _GUICtrlEdit_LineIndex($Ctrlhandle) MsgBox(0, "Test", "Line Index" & " " & $Ctrlread) EndFunc ;==>LineIndex Func LineLenght($Ctrlhandle); tested = OK $Ctrlread = _GUICtrlEdit_LineLength($Ctrlhandle) MsgBox(0, "Test", "Line Lenght" & " " & $Ctrlread) EndFunc ;==>LineLenght Func CtrlRead($Ctrlhandle); tested = OK $LineCount = _GUICtrlEdit_GetLineCount($Ctrlhandle) MsgBox(0, "Test", "Line #" & " " & $LineCount) For $LineNum = 0 To $LineCount - 1 $FirstCharPos = _GUICtrlEdit_LineIndex($Ctrlhandle, $LineNum) MsgBox(0, "Test", "First Char Pos on Line IDX: " & $FirstCharPos) $LineLen = _GUICtrlEdit_LineLength($Ctrlhandle, $FirstCharPos) MsgBox(0, "Test", "Length: " & $LineLen) $Buffer = $LineLen $Ret = DllCall("user32.dll", "int", "SendMessage", "hwnd", $Ctrlhandle, "int", $EM_GETLINE, "int", $LineNum, "str", "") MsgBox(0, "Test", "Text is =" & " " & $Ret[4]) Next EndFunc ;==>CtrlRead
#12
Posted 02 May 2009 - 02:44 PM
Many thanks for sending you script.
This one still didn't work. I run Vista SP1. So what I did I copied it to XP Desktop. Then it runs OK.
I think this method needs to be changed for it to work on Vista.
Kind of running ideas here.
Many thanks again.
Steven
Edited by Stevo, 02 May 2009 - 02:45 PM.
#13
Posted 03 May 2009 - 04:20 PM
#Region;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Outfile=readData.exe #EndRegion;**** Directives created by AutoIt3Wrapper_GUI **** ; My first DLLCall ; ptrex #include <GUIConstants.au3> #include <GuiConstantsEx.au3> #include <GUIedit.au3> ;Opt("WinTitleMatchMode", 4); Allow ClassName lookup ; Global Const $EM_GETLINE = 0xC4 Dim $LineCount Dim $LineNum Dim $Ret Dim $LineLen Dim $FirstCharPos Dim $Buffer Run("notepad") WinActivate("[class:Notepad]", "") WinWaitActive("[class:Notepad]", "") Local $Applhandle = WinGetHandle(""); [class:Notepad]") Local $Ctrlhandle = ControlGetHandle("", "", "Edit1") ConsoleWrite("$Ctrlhandle " & $Ctrlhandle & @CRLF) WinHandle() Local $sFile = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\AutoIt v3\AutoIt", "InstallDir") & "\include\changelog.txt" ; Create GUI _GUICtrlEdit_SetText($Ctrlhandle, FileRead($sFile)) CtrlRead($Ctrlhandle) $str = ControlGetText("", "", "[Class:Edit]") ;MsgBox(0,"Test",$str) Func WinHandle(); tested = OK $result = DllCall("user32.dll", "int", "MessageBox", "hwnd", $Applhandle, "str", "Control Window Active " & $Ctrlhandle, "str", "Handle Test", "int", 0) EndFunc ;==>WinHandle Func CtrlReadLineNum($Ctrlhandle); tested = OK $Ctrlread = _GUICtrlEdit_GetLineCount($Ctrlhandle) MsgBox(0, "Test", "Line #" & " " & $Ctrlread) EndFunc ;==>CtrlReadLineNum Func LineIndex($Ctrlhandle); tested = OK $Ctrlread = _GUICtrlEdit_LineIndex($Ctrlhandle) MsgBox(0, "Test", "Line Index" & " " & $Ctrlread) EndFunc ;==>LineIndex Func LineLenght($Ctrlhandle); tested = OK $Ctrlread = _GUICtrlEdit_LineLength($Ctrlhandle) MsgBox(0, "Test", "Line Lenght" & " " & $Ctrlread) EndFunc ;==>LineLenght Func CtrlRead($Ctrlhandle); tested = OK $LineCount = _GUICtrlEdit_GetLineCount($Ctrlhandle) MsgBox(0, "Test", "Line #" & " " & $LineCount) For $LineNum = 0 To $LineCount - 1 $return = MsgBox(1, "Test", "Text is =" & " " & _GUICtrlEdit_GetLine($Ctrlhandle, $LineNum)) If $return = 2 Then ExitLoop Next EndFunc ;==>CtrlRead
SciTE for AutoItDirections for Submitting Standard UDFs
Don't argue with an idiot; people watching may not be able to tell the difference.
#14
Posted 04 May 2009 - 03:04 AM
Thank you very much. That worked OK on Notepad.
However when I try to read the text from RichText controls I get "Text is = ?". So just a question mark as the value.
My next question is how to read the value of Richtext Control Edits?
Many thanks for your kind help.
Cheers, Steven
Using 3.3.0.0 on Vista 32b the following script runs. Don't have a 64b to try on at this time.
AutoIt#Region;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Outfile=readData.exe #EndRegion;**** Directives created by AutoIt3Wrapper_GUI **** ; My first DLLCall ; ptrex #include <GUIConstants.au3> #include <GuiConstantsEx.au3> #include <GUIedit.au3> ;Opt("WinTitleMatchMode", 4); Allow ClassName lookup ; Global Const $EM_GETLINE = 0xC4 Dim $LineCount Dim $LineNum Dim $Ret Dim $LineLen Dim $FirstCharPos Dim $Buffer Run("notepad") WinActivate("[class:Notepad]", "") WinWaitActive("[class:Notepad]", "") Local $Applhandle = WinGetHandle(""); [class:Notepad]") Local $Ctrlhandle = ControlGetHandle("", "", "Edit1") ConsoleWrite("$Ctrlhandle " & $Ctrlhandle & @CRLF) WinHandle() Local $sFile = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\AutoIt v3\AutoIt", "InstallDir") & "\include\changelog.txt" ; Create GUI _GUICtrlEdit_SetText($Ctrlhandle, FileRead($sFile)) CtrlRead($Ctrlhandle) $str = ControlGetText("", "", "[Class:Edit]") ;MsgBox(0,"Test",$str) Func WinHandle(); tested = OK $result = DllCall("user32.dll", "int", "MessageBox", "hwnd", $Applhandle, "str", "Control Window Active " & $Ctrlhandle, "str", "Handle Test", "int", 0) EndFunc ;==>WinHandle Func CtrlReadLineNum($Ctrlhandle); tested = OK $Ctrlread = _GUICtrlEdit_GetLineCount($Ctrlhandle) MsgBox(0, "Test", "Line #" & " " & $Ctrlread) EndFunc ;==>CtrlReadLineNum Func LineIndex($Ctrlhandle); tested = OK $Ctrlread = _GUICtrlEdit_LineIndex($Ctrlhandle) MsgBox(0, "Test", "Line Index" & " " & $Ctrlread) EndFunc ;==>LineIndex Func LineLenght($Ctrlhandle); tested = OK $Ctrlread = _GUICtrlEdit_LineLength($Ctrlhandle) MsgBox(0, "Test", "Line Lenght" & " " & $Ctrlread) EndFunc ;==>LineLenght Func CtrlRead($Ctrlhandle); tested = OK $LineCount = _GUICtrlEdit_GetLineCount($Ctrlhandle) MsgBox(0, "Test", "Line #" & " " & $LineCount) For $LineNum = 0 To $LineCount - 1 $return = MsgBox(1, "Test", "Text is =" & " " & _GUICtrlEdit_GetLine($Ctrlhandle, $LineNum)) If $return = 2 Then ExitLoop Next EndFunc ;==>CtrlRead
Edited by Stevo, 04 May 2009 - 03:06 AM.
#15
Posted 04 May 2009 - 10:05 AM
SciTE for AutoItDirections for Submitting Standard UDFs
Don't argue with an idiot; people watching may not be able to tell the difference.
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users




