Jump to content

Read Data From A Windows Control, Is It Possible ?


ptrex
 Share

Recommended Posts

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

Link to comment
Share on other sites

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.

 

Link to comment
Share on other sites

@gafrost

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

Link to comment
Share on other sites

Read data from Any Windows Edit Control

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 :think: !!

; 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
Link to comment
Share on other sites

  • 1 year later...

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.

 

Link to comment
Share on other sites

  • 1 year later...

This works:

; 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.

[left][sub]We're trapped in the belly of this horrible machine.[/sub][sup]And the machine is bleeding to death...[/sup][sup][/sup][/left]

Link to comment
Share on other sites

  • 8 months later...

Hi 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?

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
Link to comment
Share on other sites

Hi 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

Steven

You might not have any text in Notepad that can be read to put into $Ret[4].

Malkey.

Link to comment
Share on other sites

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

Edited by Stevo
Link to comment
Share on other sites

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

I was messing around with this one until I realized your script worked.

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
Link to comment
Share on other sites

Hi Malkey,

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
Link to comment
Share on other sites

Using 3.3.0.0 on Vista 32b the following script runs. Don't have a 64b to try on at this time.

#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.

 

Link to comment
Share on other sites

Hi GaryFrost,

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.

#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
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...