Jump to content

get window handle


manit
 Share

Recommended Posts

  • Moderators

manit,

This will be exciting

I am sure it will be! ;)

what function can I use to create table taking line by line input from file

I would suggest starting with _FileReadToArray to split the file into separate lines. Then perhaps parse the line (split out the separate elements) with StringSplit. Finally recombine the elements and use GUICtrlCreateListViewItem to put them into the ListView.

how can I set an action to be executed if a check box is toggled

You will probably need to keep an array of the state of the checkboxes and use _GUICtrlListView_GetItemChecked in a loop to check whether they have been altered.

I hope that helps. Just post your code (and a sample of the file you are using to get the data) if you run into trouble getting it to work. :graduated:

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • Replies 57
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Posted Images

this is a start where I am trying to display the table.

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <ButtonConstants.au3>
#include <ListviewConstants.au3>
 GUICreate("My GUI", 800, 600)    
$listview = GUICtrlCreateListView("check|handle|level|PID|restore,maximize,minimize|active,inactive|enable,disable|visible,hidden|application", 10, 10, 800, 600, -1, $LVS_EX_CHECKBOXES)
$file = FileOpen("log.txt", 0)
    $line = FileReadLine($file)
    $item1 = GUICtrlCreateListViewItem($line, $listview)
    GUISetState()
    GUICtrlSetData($item1,"")
    
    While 1
        $msg = GUIGetMsg()
       
        If $msg = $GUI_EVENT_CLOSE Then ExitLoop
    WEnd
    ;MsgBox(0, "Line read:", $line)

Here I have processed cmdow-log to log.txt which contains '|' at places wherever new column begins.

haven't tried to monitor checkbox change yet.

Currently , I find that first column window handles don't appear . Instead checkboxes replace them .

Edited by manit
Link to comment
Share on other sites

now I am able to read whole file

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <ButtonConstants.au3>
#include <ListviewConstants.au3>
GUICreate("My GUI", 800, 600)   
$listview = GUICtrlCreateListView("handle|level|PID|restore,maximize,minimize|active,inactive|enable,disable|visible,hidden|application", 10, 10, 800, 600, -1, $LVS_EX_CHECKBOXES)
$file = FileOpen("log.txt", 0)
While 1
    $line = FileReadLine($file)
    If @error = -1 Then ExitLoop
    $item1 = GUICtrlCreateListViewItem($line, $listview)
    GUICtrlSetData($item1,"")
    Wend
    GUISetState()
    While 1
        $msg = GUIGetMsg()
      
        If $msg = $GUI_EVENT_CLOSE Then ExitLoop
    WEnd
    ;MsgBox(0, "Line read:", $line)

Question that remain is

(1)checkbox overwrite first column content . How to prevent ?

(2)scroll bar is too thin .

(3)I was also looking at stringsplit function .

How can I express delimiter as ' \+' . In regex that meant to treat one or more consecutive spaces as single space.

Edited by manit
Link to comment
Share on other sites

Just a point that might help, there's no reason to use an external program to get any of the information that you can get from cmdow, it's all available from commands in AutoIt. This might make your programming a little more streamlined if you don't have to rely on running another program to get that info.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

I changed width & height argument in guicreate to get satisfactory vertical scrollbar & proper height so that last rows aren't chopped.

The question that remains is

(1)checkbox overwrite first column content in most lines. How to prevent ?

(2)I created this batch file

which , when run in command prompt with cmdow & sed binaries present in same folder , works fine.

If I try 'Run(getlog.bat)' in my au3 script.

I get

error:missing separator character after keyword

Edited by manit
Link to comment
Share on other sites

  • Moderators

manit,

If you got your ListView to display any data I would be very surprised as the syntax of the lines in the file does not match that required by GUICtrlCreateListViewItem. You need to replace the spaces in the file with "|" separators - StringRegExpReplace is the tool for this. :graduated:

As to your 2 points:

- 1. Increase the width of the first column by using _GUICtrlListView_SetColumnWidth.

- 2. Decrease the size of the ListView so it fits within the GUI - at the moment the scrollbar is nearly outside the right hand edge. ;)

This works using the data file you posted above - look for the <<<<<<<<<<<<<<<<<< lines: ;)

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <ButtonConstants.au3>
#include <GUIListview.au3> ; <<<<<<<<<<<<<<<<<<<
 
GUICreate("My GUI", 800, 600)
$listview = GUICtrlCreateListView("handle|level|PID|restore,maximize,minimize|active,inactive|enable,disable|visible,hidden|application", 10, 10, 780, 580, -1, $LVS_EX_CHECKBOXES)
_GUICtrlListView_SetColumnWidth($listview, 0, 100) ; <<<<<<<<<<<<<<<<<<<
$file = FileOpen("log.txt", 0)
While 1
    $line = FileReadLine($file)
    If @error = -1 Then ExitLoop
    $sItem = StringregExpReplace($line, "(\s+)", "|") ; <<<<<<<<<<<<<<<<<<<
    ConsoleWrite($sItem & @CRLF)
    $item1 = GUICtrlCreateListViewItem($sItem, $listview)
    GUICtrlSetData($item1, "")
WEnd
GUISetState()
 
While 1
    $msg = GUIGetMsg()
    If $msg = $GUI_EVENT_CLOSE Then ExitLoop
WEnd

All clear? :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

so now my code stands as

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <ButtonConstants.au3>
#include <ListviewConstants.au3>
 Run("getlog.bat")
 GUICreate("My GUI", 1000, 650, -1, -1)  
;$button = GUICtrlCreateButton("Value?", 675, 470)
$listview = GUICtrlCreateListView("handle                 |level|PID|restore,maximize,minimize|active,inactive|enable,disable|visible,hidden|application|TITLE", 10, 10, 900, 600, -1, $LVS_EX_CHECKBOXES)
$file = FileOpen("log.txt", 0)
While 1
    $line = FileReadLine($file)
    If @error = -1 Then ExitLoop
    $item1 = GUICtrlCreateListViewItem($line, $listview)
    GUICtrlSetData($item1,"")
    Wend
    GUISetState()
    While 1
        $msg = GUIGetMsg()
       
        If $msg = $GUI_EVENT_CLOSE Then ExitLoop
        ;Select
        ;Case $msg = $button
         ;     MsgBox(0, "listview item", GUICtrlRead(GUICtrlRead($listview)))
        ;EndSelect
    WEnd
    ;MsgBox(0, "Line read:", $line)

The scrollbar problem is solved.

here is a screenshot.

Problem remains of window handle being eaten by checkboxes.

post-67503-0-86904600-1317899635_thumb.j

Link to comment
Share on other sites

Melba23 , you have used functions of autoit to derive log.txt from cmdow-log.txt

I used getlog.bat which is using binaries of cmdow & sed . See attached 'log.txt' being used by GUICtrlCreateListViewItem.

Problem remains of missing window handle in first column of table

log.txt

Link to comment
Share on other sites

  • Moderators

manit,

I see the handles - both with your new code and my posted script above. Do you see the handles when you use my code with _GUICtrlListView_SetColumnWidth? :graduated:

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

I sorted that by creating useless first column

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <ButtonConstants.au3>
#include <ListviewConstants.au3>
 Run("getlog.bat")
 GUICreate("My GUI", 1000, 650, -1, -1)  
;$button = GUICtrlCreateButton("Value?", 675, 470)
$listview = GUICtrlCreateListView("select|handle|level|PID|restore,maximize,minimize|active,inactive|enable,disable|visible,hidden|application|TITLE", 10, 10, 900, 600, -1, $LVS_EX_CHECKBOXES)
$file = FileOpen("log.txt", 0)
While 1
    $line = FileReadLine($file)
    If @error = -1 Then ExitLoop
    $item1 = GUICtrlCreateListViewItem($line, $listview)
    GUICtrlSetData($item1,"")
    Wend
    GUISetState()
    While 1
        $msg = GUIGetMsg()
       
        If $msg = $GUI_EVENT_CLOSE Then ExitLoop
        ;Select
        ;Case $msg = $button
         ;     MsgBox(0, "listview item", GUICtrlRead(GUICtrlRead($listview)))
        ;EndSelect
    WEnd
    ;MsgBox(0, "Line read:", $line)

My batchfile is

great-cmdow > cmdow-log.txt
great-sed -e "s/^/0|/g"  -e "1 d" -e "s/ \+/|/g" -e "s/|/ /10g" cmdow-log.txt > log.txt
exit
Link to comment
Share on other sites

actually _GUICtrlListView_SetColumnWidth was widening the first column but not showing handle . Though I had

Included GuiListView.au3. There were no errors .

Now my task is to grab the checkbox status & associated window handle which is content of second column in corresponding row.

Link to comment
Share on other sites

  • Moderators

manit,

As you seem to have ignored pretty much every suggestion I have made so far I was wondering whether to suggest anything more at all. ;)

However, I am in a good mood, so here is how you do it: :graduated:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GuiListView.au3>

; Set flag to indicate click in ListView checkbox
Global $fClick = False

; Create array to hold checkbox state
Global $aCheck[4]

$Gui = GUICreate("Test", 400, 250)

$hListView = GUICtrlCreateListView("Items", 2, 2, 220, 196)
$hWndListView = GUICtrlGetHandle($hListView)
_GUICtrlListView_SetExtendedListViewStyle($hWndListView, BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT, $LVS_EX_CHECKBOXES))
_GUICtrlListView_SetColumnWidth($hWndListView, 0, $LVSCW_AUTOSIZE_USEHEADER)
GUICtrlCreateListViewItem("Item 1", $hListView)
GUICtrlCreateListViewItem("Item 2", $hListView)
GUICtrlCreateListViewItem("Item 3", $hListView)
GUICtrlCreateListViewItem("Item 4", $hListView)

GUISetState()

GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            ExitLoop
    EndSwitch

    ; If an item was double clicked
    If $fClick Then
        $fClick = False
        For $i = 0 To 3
            $fCheck = _GUICtrlListView_GetItemChecked($hWndListView, $i)
            If $fCheck <> $aCheck[$i] Then
                $aCheck[$i] = $fCheck
                Switch $fCheck
                    Case True
                        ConsoleWrite("You checked the CheckBox in Row " & $i & @CRLF)
                    Case False
                        ConsoleWrite("You unchecked the CheckBox in Row " & $i & @CRLF)
                EndSwitch
                ExitLoop
            EndIf
        Next
    EndIf

WEnd

Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)

    #forceref $hWnd, $iMsg, $iwParam

    Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR

    $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iCode = DllStructGetData($tNMHDR, "Code")

    Switch $hWndFrom
        Case $hWndListView
            Switch $iCode
                Case $NM_CLICK
                    $fClick = True
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

i don't want to digress.

Here is one of the logs (which has 926 lines) generated by cmdow which displays its prowess.

Can autoit give me such handles of all windows.

I'd say at least 80% of that list aren't windows handles and are not needed for the project you described on the first page. Most of those handles appear to be control handles for various controls inside the actual windows you want to hide/show. So, to answer your question, yes AutoIt can get the same Windows handles you require, without a lot of extra handles you have no intention of using or needing.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

to Melba23.

sorry . This time I will read this code thoroughly , then reply.

actually _GUICtrlListView_SetColumnWidth was widening the first column but not showing handle . Though I had

Included GuiListView.au3. There were no errors .

You see , once I read then replied. :graduated:

to BrewManNH

I think level 1 windows are meant to be displayed on desktop. So my aim was to get handles of all those . There are more than 250 of those. No doubt many are control related to application . But if I or somebody has hidden a window then there is no way I can unhide it easily as it won't be on a taskbar.

Link to comment
Share on other sites

to BrewManNH

I think level 1 windows are meant to be displayed on desktop. So my aim was to get handles of all those . There are more than 250 of those. No doubt many are control related to application . But if I or somebody has hidden a window then there is no way I can unhide it easily as it won't be on a taskbar.

That would be incorrect, WinSetState doesn't require the window to be visible, only that it exists and you can identify it. Here's a simple script to show what I mean. Open a Notepad window whether a blank document or not it doesn't matter. Then run this script and it will hide the Notepad window(s) and then 10 seconds later, show it (them) again.

$Array = WinList()
For $I = 1 To $Array[0][0]
 If StringInStr($Array[$I][0], "Notepad") Then
  $Variable = $Array[$I][1]
  ConsoleWrite('! Hiding Notepad' & @lf)
  WinSetState($Variable, "", @SW_HIDE)
 EndIf
Next
Sleep(10000)
For $I = 1 To $Array[0][0]
 If StringInStr($Array[$I][0], "Notepad") Then
  $Variable = $Array[$I][1]
  ConsoleWrite('! Showing Notepad' & @lf)
  WinSetState($Variable, "", @SW_SHOW)
 EndIf
Next

This is not the most elegant approach to doing this, but it shows that AutoIt can act upon the windows regardless of whether it's on the Taskbar or not.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

Lev Level of the window. The desktop window at level 0 is the area on which all other windows are painted. Top level windows are level 1 (and may be shown on the taskbar), all windows of level 2+ are child windows.

from http://www.commandline.co.uk/cmdow/

If I hide window on taskbar then I wanted to create a program which digs out this hidden window regardless I know the title or process of that window.

Atleast , I can guess from a list the window i am seeking for looking at caption.

If autoit can give me list of hidden level1 windows then it is okay.

Edited by manit
Link to comment
Share on other sites

to

Melba23

I read the test code you sent.

I replaced consolewrite command by msgbox & got notification on selecting or unselecting any row.

Now I have to get content of second column of that row which contains handle.

I will try .

You can advise me day after tomorrow if I am unable to accomplish that.

In any case , I will report what I did.

Thank You.

Link to comment
Share on other sites

  • Moderators

manit,

I will not be aroound much for the next week so I will leave you a hint to use if you get stuck: ;)

_GUICtrlListView_GetItemTextArray or _GUICtrlListView_GetItemTextString might be good places to start looking. :graduated:

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

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