Jump to content

Recommended Posts

Posted

This is code to click the menu items "View | Status bar" and "Organize | Layout | Navigation pane". Note that the menu item names are localized. You have to change the names in the code to your own language.

 

#include "CUIAutomation2.au3"

Opt( "MustDeclareVars", 1 )

Global $oUIAutomation

MainFunc()


Func MainFunc()

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

  ; 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

  ; --- Click View | "Status bar" ---

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

  ; Find menubar
  Local $pMenubar, $oMenubar
  $oWindow.FindFirst( $TreeScope_Descendants, $pCondition, $pMenubar )
  $oMenubar = ObjCreateInterface( $pMenubar, $sIID_IUIAutomationElement, $dtagIUIAutomationElement )
  If Not IsObj( $oMenubar ) Then Return

  ; Condition to find View menu item
  Local $pCondition1, $pCondition2
  $oUIAutomation.CreatePropertyCondition( $UIA_ControlTypePropertyId, $UIA_MenuItemControlTypeId, $pCondition1 )
  $oUIAutomation.CreatePropertyCondition( $UIA_NamePropertyId, "View", $pCondition2 )
  $oUIAutomation.CreateAndCondition( $pCondition1, $pCondition2, $pCondition )
  If Not $pCondition Then Return

  ; Find View menu item
  Local $pMenuItem, $oMenuItem
  $oMenubar.FindFirst( $TreeScope_Descendants, $pCondition, $pMenuItem )
  $oMenuItem = ObjCreateInterface( $pMenuItem, $sIID_IUIAutomationElement, $dtagIUIAutomationElement )
  If Not IsObj( $oMenuItem ) Then Return

  ; Click (DoDefaultAction) View menu item
  Local $pLegacyMenu, $oLegacyMenu
  $oMenuItem.GetCurrentPattern( $UIA_LegacyIAccessiblePatternId, $pLegacyMenu )
  $oLegacyMenu = ObjCreateInterface( $pLegacyMenu, $sIID_IUIAutomationLegacyIAccessiblePattern, $dtagIUIAutomationLegacyIAccessiblePattern )
  If Not IsObj( $oLegacyMenu ) Then Return
  $oLegacyMenu.DoDefaultAction()
  Sleep(150)

  ; Get UI Automation element for Desktop
  Local $pWindow2, $oWindow2
  $oUIAutomation.GetRootElement( $pWindow2 ) ; Desktop
  Local $oWindow2 = ObjCreateInterface( $pWindow2, $sIID_IUIAutomationElement, $dtagIUIAutomationElement )
  If Not IsObj( $oWindow2 ) Then Return

  ; Find popup (Context) menu
  Local $pContext, $oContext
  $oUIAutomation.CreatePropertyCondition( $UIA_ClassNamePropertyId, "#32768", $pCondition )
  $oWindow2.FindFirst( $TreeScope_Descendants, $pCondition, $pContext )
  $oContext = ObjCreateInterface( $pContext, $sIID_IUIAutomationElement, $dtagIUIAutomationElement )
  If Not IsObj( $oContext ) Then Return

  ; Condition to find "Status bar" menu item
  $oUIAutomation.CreatePropertyCondition( $UIA_ControlTypePropertyId, $UIA_MenuItemControlTypeId, $pCondition1 )
  $oUIAutomation.CreatePropertyCondition( $UIA_NamePropertyId, "Status bar", $pCondition2 )
  $oUIAutomation.CreateAndCondition( $pCondition1, $pCondition2, $pCondition )
  If Not $pCondition Then Return

  ; Find "Status bar" menu item
  $oContext.FindFirst( $TreeScope_Descendants, $pCondition, $pMenuItem )
  $oMenuItem = ObjCreateInterface( $pMenuItem, $sIID_IUIAutomationElement, $dtagIUIAutomationElement )
  If Not IsObj( $oMenuItem ) Then Return

  ; Click (Invoke) "Status bar" menu item
  Local $pInvoke, $oInvoke
  $oMenuItem.GetCurrentPattern( $UIA_InvokePatternId, $pInvoke )
  $oInvoke = ObjCreateInterface( $pInvoke, $sIID_IUIAutomationInvokePattern, $dtagIUIAutomationInvokePattern )
  If Not IsObj( $oInvoke ) Then Return
  $oInvoke.Invoke()

  ; --- Click Organize | Layout | "Navigation pane" ---

  ; Condition to find Organize button
  $oUIAutomation.CreatePropertyCondition( $UIA_ControlTypePropertyId, $UIA_ButtonControlTypeId, $pCondition1 )
  $oUIAutomation.CreatePropertyCondition( $UIA_NamePropertyId, "Organize", $pCondition2 )
  $oUIAutomation.CreateAndCondition( $pCondition1, $pCondition2, $pCondition )
  If Not $pCondition Then Return

  ; Find Organize button
  Local $pButton, $oButton
  $oWindow.FindFirst( $TreeScope_Descendants, $pCondition, $pButton )
  $oButton = ObjCreateInterface( $pButton, $sIID_IUIAutomationElement, $dtagIUIAutomationElement )
  If Not IsObj( $oButton ) Then Return

  ; Click (Invoke) Organize button
  $oButton.GetCurrentPattern( $UIA_InvokePatternId, $pInvoke )
  $oInvoke = ObjCreateInterface( $pInvoke, $sIID_IUIAutomationInvokePattern, $dtagIUIAutomationInvokePattern )
  If Not IsObj( $oInvoke ) Then Return
  $oInvoke.Invoke()
  Sleep(150)

  ; Get UI Automation element for Desktop
  Local $pWindow2, $oWindow2
  $oUIAutomation.GetRootElement( $pWindow2 ) ; Desktop
  Local $oWindow2 = ObjCreateInterface( $pWindow2, $sIID_IUIAutomationElement, $dtagIUIAutomationElement )
  If Not IsObj( $oWindow2 ) Then Return

  ; Find popup (Context) menu
  $oUIAutomation.CreatePropertyCondition( $UIA_ClassNamePropertyId, "#32768", $pCondition )
  $oWindow2.FindFirst( $TreeScope_Descendants, $pCondition, $pContext )
  $oContext = ObjCreateInterface( $pContext, $sIID_IUIAutomationElement, $dtagIUIAutomationElement )
  If Not IsObj( $oContext ) Then Return

  ; Condition to find Layout menu item
  $oUIAutomation.CreatePropertyCondition( $UIA_ControlTypePropertyId, $UIA_MenuItemControlTypeId, $pCondition1 )
  $oUIAutomation.CreatePropertyCondition( $UIA_NamePropertyId, "Layout", $pCondition2 )
  $oUIAutomation.CreateAndCondition( $pCondition1, $pCondition2, $pCondition )
  If Not $pCondition Then Return

  ; Find Layout menu item
  $oContext.FindFirst( $TreeScope_Descendants, $pCondition, $pMenuItem )
  $oMenuItem = ObjCreateInterface( $pMenuItem, $sIID_IUIAutomationElement, $dtagIUIAutomationElement )
  If Not IsObj( $oMenuItem ) Then Return

  ; Expand Layout menu
  Local $pExpand, $oExpand
  $oMenuItem.GetCurrentPattern( $UIA_ExpandCollapsePatternId, $pExpand )
  $oExpand = ObjCreateInterface( $pExpand, $sIID_IUIAutomationExpandCollapsePattern, $dtagIUIAutomationExpandCollapsePattern )
  If Not IsObj( $oExpand ) Then Return
  $oExpand.Expand()
  Sleep(150)

  ; Get UI Automation element for Desktop
  Local $pWindow2, $oWindow2
  $oUIAutomation.GetRootElement( $pWindow2 ) ; Desktop
  Local $oWindow2 = ObjCreateInterface( $pWindow2, $sIID_IUIAutomationElement, $dtagIUIAutomationElement )
  If Not IsObj( $oWindow2 ) Then Return

  ; Condition to find Layout menu
  $oUIAutomation.CreatePropertyCondition( $UIA_ClassNamePropertyId, "#32768", $pCondition1 )
  $oUIAutomation.CreatePropertyCondition( $UIA_NamePropertyId, "Layout", $pCondition2 )
  $oUIAutomation.CreateAndCondition( $pCondition1, $pCondition2, $pCondition )
  If Not $pCondition Then Return

  ; Find Layout menu
  $oWindow2.FindFirst( $TreeScope_Descendants, $pCondition, $pContext )
  $oContext = ObjCreateInterface( $pContext, $sIID_IUIAutomationElement, $dtagIUIAutomationElement )
  If Not IsObj( $oContext ) Then Return

  ; Condition to find "Navigation pane" menu item
  $oUIAutomation.CreatePropertyCondition( $UIA_ControlTypePropertyId, $UIA_MenuItemControlTypeId, $pCondition1 )
  $oUIAutomation.CreatePropertyCondition( $UIA_NamePropertyId, "Navigation pane", $pCondition2 )
  $oUIAutomation.CreateAndCondition( $pCondition1, $pCondition2, $pCondition )
  If Not $pCondition Then Return

  ; Find "Navigation pane" menu item
  $oContext.FindFirst( $TreeScope_Descendants, $pCondition, $pMenuItem )
  $oMenuItem = ObjCreateInterface( $pMenuItem, $sIID_IUIAutomationElement, $dtagIUIAutomationElement )
  If Not IsObj( $oMenuItem ) Then Return

  ; Click (Invoke) "Navigation pane" menu item
  $oMenuItem.GetCurrentPattern( $UIA_InvokePatternId, $pInvoke )
  $oInvoke = ObjCreateInterface( $pInvoke, $sIID_IUIAutomationInvokePattern, $dtagIUIAutomationInvokePattern )
  If Not IsObj( $oInvoke ) Then Return
  $oInvoke.Invoke()

EndFunc

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

Posted (edited)

Thanks LarsJ for your code, i see only now your reply in 2nd page.
I have immediately proved your code, changing into my language: i have into CommandBar:

"Organizza"  (Organize)
    - Riquadro di spostamento (NavPane)
    - Layout
        - Barra dei menu (MenuBar)
        - Riquadro dettagli (Details Pane)
        - Riquadro di spostamento (NavPane)

        
but i'm sorry, i don't know how use it, don't run.


 
For now i have always used mouse shortcut that access to CommandBar -> LayOut -> NavPane -> On/Off
but for me is not a good idea.
I want remove Panel and StatusBar without opens their menu if is realizable.

For this reason I have removed COMMAND BAR that is not immediately to use its functions,
hacking "shellstyle.dll" and putting value height to = -32 and i have replace it adding
customizable toolbars as:  stExBar - ClassicShell - QTTabBar.
Now I need a script that i can insert its compiled EXE in my explorer toolbar and permit me to automatically
HIDE Navigation Pane and an other EXE that also disable/Enable StatusBar and for other use putting code into

more big project

Reading different forums i have discovered that changing bit value in windows registry i can obtain
StatusBar On/OFF  &  Navigation Pane On/OFF.
Unfortunately need "reboot" or "logon" or close/reOpen new session of Explorer to take effect.

http://www.sevenforums.com/tutorials/61502-navigation-pane-turn-off.html

http://www.tipsnext.com/windows-8/steps-to-show-hide-navigation-pane-in-windows-8-file-explorer/



For now i have created new Registry Key that have permit me to inserted Navigation Pane ON/OFF
into Mouse Right Click when cursor is on left side Panel and using it i can hide/show navPane
without close any session because it take immediately effect on active session.

[HKEY_CLASSES_ROOTFoldershellNavPanel]
"PaneVisibleProperty"="PageSpaceControlSizer_Visible"
"PaneID"="{cb316b22-25f7-42b8-8a09-540d23a43c2f}"
"Position"="Bottom"
@="Show/Hide Navigation Panel"


....But is not what i'm looking for and i don't find other explanations/informations
on web to realize that i want and statusBar i don't know to disable without shortcut

 

Thanks a lot for your time.

Edited by mercadantelaura
Posted (edited)

Now your script runs.

MenuView was hided from program QTTabBar and script don't obtain  its presence, for this reason don't run before

Unfortunately your code to run uses always access to menu and it is more slow than Mouse shortcut

using function "Send"

If you have some other idea to realize it i thanks to you.

If though menu is possible, and i have added NavPane in other position into mouse context, will be possible also

find a solution to access to sub-commands Windows.Navpane without using pop menu, what do you think ?

This spoke how Hide/Show Status bar through KeyReg (but Need always open new session)

http://www.sevenforums.com/tutorials/61523-status-bar-turn-off.html

 

Thanks again

Edited by mercadantelaura
Posted

Nobody can code and compile to EXE  using any script that know (AutoIT, AutoHotkey, C++...) that permit me to have direct access to Navigation Pane ON/OFF

without using menu as default windows button located into commadbar-Layout Menu ??

 

Thanks to all, and sorry for insistance.

Posted (edited)

Mr.  LarsJ  I need again your help if you can.
I have saw, using your script that "Organize Menu" and its subcommands can be invoked from your script also if i have

full hided command bar. (also if MenuBar need to be visible)

Searching on WEB i found program "Custom Explorer Toolbar" that has permit me to add function

that i want (NavPane) directly in command bar on right side of Organize Menu

in order to not open --> organize...Layout...NavPane to access it but using it without open menu that now

is not necessary Infact it is a direct buttom execute.


In your script i have replaced Name "Organize" with "NavPane" and runs immediately as i want, but unfortunately

i would a script only for this function, but your code includes also other functions.

I have proved to delete from script, access to MenuBar - ViewMode included for previously my request
on StatusBar that you gently have coded for me, but i don't know how do.

I need script that invoke only EXECUTE of this Button that i have added to command bar,
without access StatusBar/MenuBar/ViewMode and without open Organize-Layout now not necessary

Please can you remove all parts unnecessary to realize this i don't have sufficient knowledge to do this,

also if i read guide, infact i have removed wrong parts and causes always errors with variable don't declared

If you can i thanks so much

Edited by mercadantelaura
Posted

Try this:

#include "CUIAutomation2.au3"

Opt( "MustDeclareVars", 1 )

Global $oUIAutomation

MainFunc()


Func MainFunc()

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

  ; 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

  ; --- Click "Navigation pane" ---

  ; Condition to find "Navigation pane" button
  Local $pCondition1, $pCondition2, $pCondition
  $oUIAutomation.CreatePropertyCondition( $UIA_ControlTypePropertyId, $UIA_ButtonControlTypeId, $pCondition1 )
  $oUIAutomation.CreatePropertyCondition( $UIA_NamePropertyId, "Navigation pane", $pCondition2 )
  $oUIAutomation.CreateAndCondition( $pCondition1, $pCondition2, $pCondition )
  If Not $pCondition Then Return

  ; Find "Navigation pane" button
  Local $pButton, $oButton
  $oWindow.FindFirst( $TreeScope_Descendants, $pCondition, $pButton )
  $oButton = ObjCreateInterface( $pButton, $sIID_IUIAutomationElement, $dtagIUIAutomationElement )
  If Not IsObj( $oButton ) Then Return

  ; Click (Invoke) "Navigation pane" button
  Local $pInvoke, $oInvoke
  $oButton.GetCurrentPattern( $UIA_InvokePatternId, $pInvoke )
  $oInvoke = ObjCreateInterface( $pInvoke, $sIID_IUIAutomationInvokePattern, $dtagIUIAutomationInvokePattern )
  If Not IsObj( $oInvoke ) Then Return
  $oInvoke.Invoke()

EndFunc

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
  • Recently Browsing   0 members

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