Jump to content

ControlGetText


Recommended Posts

I want to get text from current control, but control is not in my GUI and I don't know what should I use for controlID in this case.

I use this but not work:

ControlGetText("[ACTIVE]","",_WinAPI_GetDlgCtrlID(_WinAPI_GetFocus()))
Whats the window your trying to get?

For those who are asking questions, look in the help file first. I'm tired of people asking stupid questions about how to do things when 10 seconds in the help file could solve their problem.[quote name='JRowe' date='24 January 2010 - 05:58 PM' timestamp='1264381100' post='766337'][quote name='beerman' date='24 January 2010 - 03:28 PM' timestamp='1264372082' post='766300']They already have a punishment system for abuse.[/quote]... and his his name is Valik.[/quote]www.minikori.com

Link to comment
Share on other sites

  • Moderators

Someone know what should I use for controlID or how I can get controlID?

:P

Try:

WinGetText(_WinAPI_GetFocus())

Edit:

Interesting enough:

WinGetTitle(_WinAPI_GetFocus())

Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

  • Moderators

Is not work. Return 0. :P

Read my edit.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

  • Moderators

Is not work. Return 0. :P

Read my edit.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

  • Moderators

Return 0. Is another way to get text from a control? :P

The method with WinGetTitle worked fine for me.
#include <WinAPI.au3>
#include <GUIConstantsEx.au3>

Opt('MustDeclareVars', 1)

_Main()

Func _Main()
    Local $gui, $msg, $btnFocus, $win, $text
    $gui = GUICreate("__WinAPI_GetFocus Example", 200, 200)
    Local $hlabel = GUICtrlCreateEdit("I am an edit", 10, 10, 150, 50)
    $btnFocus = GUICtrlCreateButton("Get Focus", 50, 85, 100, 30)
    GUISetState(@SW_SHOW)
    While 1
        $msg = GUIGetMsg()
        Select
            Case $msg = $GUI_EVENT_CLOSE
                Exit
            Case $msg = $btnFocus
                ControlFocus($gui, "", $hlabel) ;;;;;;; Put focus on edit
                $win = _WinAPI_GetFocus()
                $text = "Full Title: " & WinGetTitle($win) & @LF
                $text &= "Full Text: " & WinGetText($win) & @LF
                $text &= "Handle: " & WinGetHandle($win) & @LF
                $text &= "Process: " & WinGetProcess($win) & @LF
                MsgBox(0, "", $text)
        EndSelect
    WEnd
EndFunc   ;==>_Main
That clearly demonstrating it working. Are you even sure it's a standard control and not owner drawn. Did you try using AutoInfo tool to see what the results are? Maybe what you think has focus doesn't?

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

use autoit info to get the control id

I can't use autoit info to get control id

Just tested and _WinAPI_GetFocus() return 0x000000, but the edit control is selected.

@SmOke_N

Your example is good but I can't focus edit control because I don't know controlID.

ControlFocus($gui, "", $hlabel)
Edited by Andreik
Link to comment
Share on other sites

  • Moderators

I can't use autoit info to get control id

Just tested and _WinAPI_GetFocus() return 0x000000, but the edit control is selected.

@SmOke_N

Your example is good but I can't focus edit control because I don't know controlID.

ControlFocus($gui, "", $hlabel)
Doesn't mean it has focus... doesn't mean it isn't owner drawn.

Is this a public/free download?

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

  • Moderators

Look post#4. Is free download (oDC 5.31)

That's a picture... you don't expect me to go out of my way to find a link to it do you?

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

  • Moderators
Local $hWnd = WinGetHandle("oDC 5.31 - The following untitled edition - [Public Hubs]")

While WinExists($hWnd)
    If WinActive($hWnd) Then ConsoleWrite( ControlGetText($hWnd, "", "[CLASSNN:" & ControlGetFocus($hWnd) & "]") & @CRLF)
    Sleep(10)
WEnd

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

  • 6 months later...

Having this same problem. Is there a bug with _WinAPI_GetFocus() ? I can't even get focus on calc.exe or notepad.exe. Keeps returning 0x0000000. The final solution here does me no good as my script will be used on many diff windows, not one with a static name

sleep (5000) ;give time to focus a window after start
$win =_WinAPI_GetFocus()
MsgBox(0, "handle", $win) -----> 0x0000000
$wintitle = WinGetTitle($win)
MsgBox(0, "title", $wintitle) ------> 0
Edited by DssTrainer
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...