Jump to content

CONTROLLIST problems on my Windows 7 x64


Recommended Posts

I need for my different purposes to get how many items there are in window folder active right ponel
and how many items are selected in that active window list and change the default details view
to EXTRA LARGE ICONS for Windows Seven or Large Icons under XP.

If @OSVersion = "WIN_7" Then
    $sControl = "DirectUIHWND3"
Else
    $sControl = "SysListView321"
Endif

$ItemNumber = ControlListView("[Active]", "", $sControl,"GetItemCount")
$SelectNumber = ControlListView("[Active]", "", $sControl, "GetSelectedCount")

If $SelectNumber < $ItemNumber Then
    ControlListView("[Active]", "", $sControl, "SelectAll")
    ControlListView("[Active]", "", $sControl, "ViewChange", "largeicons")
Endif

Unfortunately my script runs only under Windows XP 32 bits but NOT under Windows7 64 Bits
AutoIT Guide reports:

<< Some commands may fail when using a 32-bit AutoIt process to read from a 64-bit process.
<< Likewise commands may fail when using a 64-bit AutoIt process to read from a 32-bit process.

...therefore i have launched my script in both method using AutoIT 32Bit and 64 bit without effect.

"GetItemCount"  and  "GetSelectedCount"  return always ZERO value

and "Large icons" is not setted.

(I would want "EXTRA Large Icons" but i don't know how set EXTRA Large)

Using this function:     $sControl = ControlGetFocus(WinGetTitle("[Active]"))

- Under Windows XP:    "SysListView321" is the "Right Panel Control" obtained
- Under Windows Seven Sp1 64 Bit the control used is:    "DirectUIHWND3"

and i have inserted this value in my script.

Where i'm wronging ??
Can you help me with some suggestion ?
Thank you

Link to comment
Share on other sites

In AutoIT folder there is: AutoIt3.exe   and  AutoIt3_x64.exe  i have proved using 1st and second exe to run my Au3 file but under Win7 x64 my script don't run, under XP run correctly

Under Win7 script is launched and finished without errors, but script don't make that i want.

Script do nothing under Win7.

Edited by mercadantelaura
Link to comment
Share on other sites

Thank you for reply JohnOne, but    NOTHING  TO  DO,    don't run on my system.

I have readed directives and i have inserted into my script your suggestion and compile ir using Wrapper.

I have added Msgbox that shows me value of variable "$ItemNumber" and "$SelectNumber "

and when i select some files and i run script the answr is:

$ItemNumber = 0
$SelectNumber = 0

Always zero ??
I have 20 files and 3 folders into right panel and i have selected 10 files !!


How can i write a script that run under win7 x64 and do that i want ??

Link to comment
Share on other sites

Counting the number of items (files/folders) and especially selected items in Windows Explorer on Win 7 is not easy to do with built-in commands. The real challenge is that the listview on Win 7 is a virtual listview.

This means that the listview contains only the items that you can see. The rest of the items are stored in a table probably in the form of PIDLs. When you scroll up/down the virtual items get realized and shown in the listview. The items that scrolls out of sight will be stored in the tabel as virtual items. You can find more info here.

A solution to that problem is to use the UI Automation framework which is a COM based framework.

If you are not used to COM programming this can also be a challenge. I'll try to figure out how to get these numbers and if I succeed I'll add the code to this thread. But I need a few days and may be also the weekend. If I don't succeed I'll let you know.

Link to comment
Share on other sites

Thank you very much LarsJ i will wait your reply in next week.

My 1st purpose into my script was:

Count items selected in explorer session list and if is not selected all files then select all files

and change view into "EXTRA LARGE ICONS"   if possible    (large icons is too small for my purpose)

Only when i press:   ("+{ESC}")  using HotKeySet, script come back to "DETAILS" and deselect all files

 

I hope that there is solution under my Win7 x64

Link to comment
Share on other sites

Try this for a start. You need the CUIAutomation2.au3 UDF in the bottom of first post here.

 

#include "CUIAutomation2.au3"

Opt( "MustDeclareVars", 1 )

MainFunc()


Func MainFunc()

  ; Get window handle
  ; Be sure to use the right class if you are on Vista or Windows 8
  Local $hWindow = WinGetHandle( "[CLASS:CabinetWClass]", "" )  ; Windows Explorer, Windows 7
  ;Local $hWindow = WinGetHandle( "[CLASS:ExploreWClass]", "" ) ; Windows Explorer, Windows XP
  If Not $hWindow Then Return

  ; Create UI Automation object
  Local $oUIAutomation
  $oUIAutomation = ObjCreateInterface( $sCLSID_CUIAutomation, $sIID_IUIAutomation, $dtagIUIAutomation )
  If Not IsObj( $oUIAutomation ) Then Return

  ; Get UI Automation element from window handle
  Local $pWindow, $oWindow
  $oUIAutomation.ElementFromHandle( $hWindow, $pWindow )
  $oWindow = ObjCreateInterface( $pWindow, $sIID_IUIAutomationElement, $dtagIUIAutomationElement )
  If Not IsObj( $oWindow ) Then Return

  ; Condition to find listview
  Local $pCondition
  $oUIAutomation.CreatePropertyCondition( $UIA_ControlTypePropertyId, $UIA_ListControlTypeId, $pCondition )
  If Not $pCondition Then Return

  ; Find listview
  Local $pUIList, $oUIList
  $oWindow.FindFirst( $TreeScope_Descendants, $pCondition, $pUIList )
  $oUIList = ObjCreateInterface( $pUIList, $sIID_IUIAutomationElement, $dtagIUIAutomationElement )
  If Not IsObj( $oUIList ) Then Return

  ; Get number of items and selected items
  Local $sStatus
  $oUIList.GetCurrentPropertyValue( $UIA_ItemStatusPropertyId, $sStatus )
  MsgBox( 0, "", $sStatus )

EndFunc

Returns empty string on XP. OK on Win 7. Not tested on Vista or Win 8.

If you are running a 64 bit windows you must run the script as a 64 bit program.

Wasn't that just easy?

Link to comment
Share on other sites

This is code to set the view type (details, extra large icons, ...) of the listview.

 

#include "CUIAutomation2.au3"

Opt( "MustDeclareVars", 1 )

MainFunc()


Func MainFunc()

  ; Get window handle for Windows Explorer
  Local $hWindow = WinGetHandle( "[CLASS:CabinetWClass]", "" )  ; Vista, 7, 8
  ;Local $hWindow = WinGetHandle( "[CLASS:ExploreWClass]", "" ) ; Windows XP
  If Not $hWindow Then Return

  ; Create UI Automation object
  Local $oUIAutomation
  $oUIAutomation = ObjCreateInterface( $sCLSID_CUIAutomation, $sIID_IUIAutomation, $dtagIUIAutomation )
  If Not IsObj( $oUIAutomation ) Then Return

  ; Get UI Automation element from window handle
  Local $pWindow, $oWindow
  $oUIAutomation.ElementFromHandle( $hWindow, $pWindow )
  $oWindow = ObjCreateInterface( $pWindow, $sIID_IUIAutomationElement, $dtagIUIAutomationElement )
  If Not IsObj( $oWindow ) Then Return

  ; Condition to find listview
  Local $pCondition
  $oUIAutomation.CreatePropertyCondition( $UIA_ControlTypePropertyId, $UIA_ListControlTypeId, $pCondition )
  If Not $pCondition Then Return

  ; Find listview
  Local $pUIList, $oUIList
  $oWindow.FindFirst( $TreeScope_Descendants, $pCondition, $pUIList )
  $oUIList = ObjCreateInterface( $pUIList, $sIID_IUIAutomationElement, $dtagIUIAutomationElement )
  If Not IsObj( $oUIList ) Then Return

  ; Create multiple view pattern object
  Local $pView, $oView
  $oUIList.GetCurrentPattern( $UIA_MultipleViewPatternId, $pView )
  $oView = ObjCreateInterface( $pView, $sIID_IUIAutomationMultipleViewPattern, $dtagIUIAutomationMultipleViewPattern )
  If Not IsObj( $oView ) Then Return

  ; Set view
  Local $sView
  $oView.SetCurrentView( 0 ) ; Values 0 - 7 on Win 7: 0 = Extra Large Icons, 5 = Details, 7 = Content
  $oView.GetViewName( 0, $sView )
  MsgBox( 0, "", $sView )

EndFunc

Doesn't work on XP. If you are running a 64 bit windows you must run the script as a 64 bit program.

Link to comment
Share on other sites

Thank you very much LarsJ for your time .

I have proved on my Win7 x64 your "EXTRA LARGE ICON" function and it runs very well.  :-)
I'm very satisfied, thanks again.
In the script i also added this mouse shortcuts in order to maximize effect of my design.

Send("!vb") ; --> Status Bar  ON / OFF     ( MenuBar -> View )
Send("!d+{TAB 4}{ENTER}LN") ; -->  Navigation pane  ON / OFF     ( Organize -> Layout )
Send("{F11}")  ; Maximize Windows to all screen dimension available

There is possibility to disable "status bar" and "Navigation pane" without use
mouse shortcut that for few moment using this method, shows on screen opened pop menu ?
When i have finished my design i will press +ESC and all files SELECTED i need that will be
unselected and StatusBar and Navigation Pane will be showed again.

Do you think that is realizable this ?

Edited by mercadantelaura
Link to comment
Share on other sites

Also your function to know number of selected files on active folder runs very well.
Thanks for help and congratualtions for good job.
Sorry, but unfortunately i'm beginner and Msgbox shows [ selected / number files value ]
but i don't know how test the variable.

; Get number of items and selected items
  Local $sStatus
  $oUIList.GetCurrentPropertyValue( $UIA_ItemStatusPropertyId, $sStatus )
  MsgBox( 0, "", $sStatus )

.....I need to do test:

If $SelectNumber < $ItemNumber Then
    Send("^a")  ; only way that i know to "SELECT ALL"
Else
    Send("{F5}")    ; only way that i know to "DESELECT ALL"  Refreshing Window
Endif

...but how can i get   < $SelectNumber >  and   < $ItemNumber >  value from   < $sStatus >  variable ?
It is not an array [0] .. [1]

Can you explain me please.
 

Link to comment
Share on other sites

To have two separate varibles with my little know-how of AutoIT i have done in this mode:

Local $FileNumber = StringSplit ( $sStatus, " "  )
Local $FileSelect = StringSplit ( StringRight($sStatus, StringLen ($sStatus) - (StringInStr ($sStatus, ",") + 1)), " "  )

If $FileNumber[1] = $FileSelect[1] Then
    Send("{F5}")
Else
    Send("^a")
Endif

If in future somebody can modify my script replacing mouse shortcuts to disable StatusBar and NavigationPane

with script that do same thing without open pop menu is the perfection and maximum that i need for my purpose.

Thanks again to  LarsJ for scripts

Edited by mercadantelaura
Link to comment
Share on other sites

Link to comment
Share on other sites

This is code to select all items in the listview.

 

#include "CUIAutomation2.au3"

Opt( "MustDeclareVars", 1 )

Global $oUIAutomation

MainFunc()


Func MainFunc()

  ; Get window handle for Windows Explorer
  Local $hWindow = WinGetHandle( "[CLASS:CabinetWClass]", "" ) ; Vista, 7, 8
  If Not $hWindow Then Return

  ; Create UI Automation object
  $oUIAutomation = ObjCreateInterface( $sCLSID_CUIAutomation, $sIID_IUIAutomation, $dtagIUIAutomation )
  If Not IsObj( $oUIAutomation ) Then Return

  ; Get UI Automation element from window handle
  Local $pWindow, $oWindow
  $oUIAutomation.ElementFromHandle( $hWindow, $pWindow )
  $oWindow = ObjCreateInterface( $pWindow, $sIID_IUIAutomationElement, $dtagIUIAutomationElement )
  If Not IsObj( $oWindow ) Then Return

  ; Condition to find listview
  Local $pCondition
  $oUIAutomation.CreatePropertyCondition( $UIA_ControlTypePropertyId, $UIA_ListControlTypeId, $pCondition )
  If Not $pCondition Then Return

  ; Find listview
  Local $pList, $oList
  $oWindow.FindFirst( $TreeScope_Descendants, $pCondition, $pList )
  $oList = ObjCreateInterface( $pList, $sIID_IUIAutomationElement, $dtagIUIAutomationElement )
  If Not IsObj( $oList ) Then Return

  ; Select or deselect all items
  SelectAllItems( $oList, True )

EndFunc


Func SelectAllItems( $oList, $bSelect )

  ; ItemContainer object
  ; A virtual listview must support the ItemContainer object
  Local $pItemContainer, $oItemContainer
  $oList.GetCurrentPattern( $UIA_ItemContainerPatternId, $pItemContainer )
  $oItemContainer = ObjCreateInterface( $pItemContainer, $sIID_IUIAutomationItemContainerPattern, $dtagIUIAutomationItemContainerPattern )
  If Not IsObj( $oItemContainer ) Then Return

  ; Find first item
  Local $pItem, $oItem
  ; The following command works for both real and virtual items
  $oItemContainer.FindItemByProperty( 0, $UIA_NamePropertyId, 0, $pItem )
  $oItem = ObjCreateInterface( $pItem, $sIID_IUIAutomationElement, $dtagIUIAutomationElement )
  If Not IsObj( $oItem ) Then Return ; Empty folder

  ; Is first item a virtual item?
  Local $pVirtualItem, $oVirtualItem
  $oItem.GetCurrentPattern( $UIA_VirtualizedItemPatternId, $pVirtualItem )
  If $pVirtualItem Then ; First item is a virtual item, realize it
    $oVirtualItem = ObjCreateInterface( $pVirtualItem, $sIID_IUIAutomationVirtualizedItemPattern, $dtagIUIAutomationVirtualizedItemPattern )
    $oVirtualItem.Realize() ; $oItem is now a real item
  EndIf

  Local $pSelection, $oSelection

  While $pItem
    ; Add to or remove from selection
    $oItem.GetCurrentPattern( $UIA_SelectionItemPatternId, $pSelection )
    $oSelection = ObjCreateInterface( $pSelection, $sIID_IUIAutomationSelectionItemPattern, $dtagIUIAutomationSelectionItemPattern )
    If $bSelect Then
      $oSelection.AddToSelection()
    Else
      $oSelection.RemoveFromSelection()
    EndIf

    ; Find next item
    $oItemContainer.FindItemByProperty( $pItem, $UIA_NamePropertyId, 0, $pItem )
    $oItem = ObjCreateInterface( $pItem, $sIID_IUIAutomationElement, $dtagIUIAutomationElement )
    If Not IsObj( $oItem ) Then ExitLoop ; No more items

    ; Virtual item?
    $oItem.GetCurrentPattern( $UIA_VirtualizedItemPatternId, $pVirtualItem )
    If $pVirtualItem Then ; The item is a virtual item, realize it
      $oVirtualItem = ObjCreateInterface( $pVirtualItem, $sIID_IUIAutomationVirtualizedItemPattern, $dtagIUIAutomationVirtualizedItemPattern )
      $oVirtualItem.Realize() ; $oItem is now a real item
    EndIf
  WEnd

EndFunc

Doesn't work on XP. If you are running a 64 bit windows you must run the script as a 64 bit program.

For questions about menus and toolbars see those sections in the help file.

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