Jump to content

Get window handle through list


EpicMonkey
 Share

Recommended Posts

Here is my code so far , found it lying around some where :

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <GUIListBox.au3>
#include <WindowsConstants.au3>
$Form1_1 = GUICreate("Form1", 256, 240, 242, 150)
$Group4 = GUICtrlCreateGroup("Window", 8, 0, 241, 233)
$List1 = GUICtrlCreateList("", 16, 16, 225, 175)
$Button1 = GUICtrlCreateButton("Get Handle", 16, 200, 105, 25)
$Button2 = GUICtrlCreateButton("Refresh", 136, 200, 105, 25)
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUISetState(@SW_SHOW)
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Button1
Local $handle1 = GUICtrlGetHandle($List1)
ControlSend($handle1, "", "Edit1", "This is a text")
Case $Button2
GUICtrlSetData($List1, '')
$aPL = WinList("Untitled")
For $iCC = 1 To UBound($aPL) - 1
$sLoadList =$aPL[$iCC][0] & ' :: Handle: ' & $aPL[$iCC][1]
GUICtrlSetData($List1, $sLoadList)
Next
EndSwitch
WEnd
[/PHP]

What this script does is , gets all the open notepads and puts them in the list , what i want to do next is ... when i click the GetHandle button,

I want it to get handle of the notepad i selected from the list , Any hints or replies will be appreciated

Edited by EpicMonkey
Link to comment
Share on other sites

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <GUIListBox.au3>
#include <WindowsConstants.au3>
#Include <GuiListBox.au3>
#include <ListboxConstants.au3>
$Form1_1 = GUICreate("Form1", 256, 240, 242, 150)
$Group4 = GUICtrlCreateGroup("Window", 8, 0, 241, 233)
$List1 = GUICtrlCreateList("", 16, 16, 225, 175,$GUI_SS_DEFAULT_LIST-$LBS_SORT)
$Button1 = GUICtrlCreateButton("Get Handle", 16, 200, 105, 25)
$Button2 = GUICtrlCreateButton("Refresh", 136, 200, 105, 25)
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUISetState(@SW_SHOW)
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
            $temp = _GUICtrlListBox_GetCurSel($List1)
            If $temp <> -1 Then ControlSend($aPL[$temp+1][1], "", "Edit1", "This is a text")
        Case $Button2
            GUICtrlSetData($List1, '')
            $aPL = WinList("[CLASS:Notepad]")
            For $iCC = 1 To UBound($aPL) - 1
                $sLoadList = $aPL[$iCC][0] & ' :: Handle: ' & $aPL[$iCC][1]
                GUICtrlSetData($List1, $sLoadList)
            Next
    EndSwitch
WEnd

Edited by bogQ

TCP server and client - Learning about TCP servers and clients connection
Au3 oIrrlicht - Irrlicht project
Au3impact - Another 3D DLL game engine for autoit. (3impact 3Drad related)



460px-Thief-4-temp-banner.jpg
There are those that believe that the perfect heist lies in the preparation.
Some say that it’s all in the timing, seizing the right opportunity. Others even say it’s the ability to leave no trace behind, be a ghost.

 
Link to comment
Share on other sites

no problem

i did a litle mess from there and instead

_ArrayAdd($final,$aPL[$iCC][1])

and after that calling it with $final[$temp+1]

i shud done only with no _ArrayAdd and only with $aPL[$temp+1][1], and some other things so i corrected the code from upper post and now its working correctly

$GUI_SS_DEFAULT_LIST-$LBS_SORT it will change default stule not to sort GUICtrlCreateList alphabetically so that array can match the index correctly

so hwnd is storred in array variable under some index number, we do know that first element of array (element 0) that is returned from WinList command hold Number of windows returned so we dont need that 0 element and we do know that we need to start from 1 instead 0

now look in help file for _GUICtrlListBox_GetCurSel and youl notice that the command will return -1 if nothing is sellected, so if return something diffrent that -1 wer on the correct path " If $temp <> -1 Then"

now we look at its return valye if its success

Success: Zero based index of the currently selected item

this starts with zero meaning that if we sellect first line it will return it as index 0, if we sellect second line it will return it as 1 and so on

now if we see that array starts from 1 and _GUICtrlListBox_GetCurSel starts from zero we do know that we must increas it +1 to aline the results "$temp+1"

so _GUICtrlListBox_GetCurSel return 0 on first sellected line, we elevate it with +1 and pull data from that array variable as $aPL[$temp+1][1]

as for

WinList("[CLASS:Notepad]")

i get class form autoit window info tool (you can locate it in start meny), and look in help file for "Window Titles and Text (Advanced)" under "Advanced Window Descriptions" for more explanation about CLASS: title parametar or other parametars that can be there instead.

Edited by bogQ

TCP server and client - Learning about TCP servers and clients connection
Au3 oIrrlicht - Irrlicht project
Au3impact - Another 3D DLL game engine for autoit. (3impact 3Drad related)



460px-Thief-4-temp-banner.jpg
There are those that believe that the perfect heist lies in the preparation.
Some say that it’s all in the timing, seizing the right opportunity. Others even say it’s the ability to leave no trace behind, be a ghost.

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