Jump to content

Recommended Posts

Posted (edited)

Basically, I want to replace the default action of a shutdown button in win 10 so I can show alert and ask user to confirm.

Is that even possible?

@junkew

Having the following values for all properties: 
Title is: <Shut down>   Class   := <TextBlock>  controltype:= <UIA_TextControlTypeId>   ,<50020>    , (0000C364)    13;923;232;16
*** Parent Information top down ***
3: Title is: <Start>    Class   := <Windows.UI.Core.CoreWindow> controltype:= <UIA_WindowControlTypeId> ,<50032>    , (0000C370)    0;0;1920;1040
"Title:=Start;controltype:=UIA_WindowControlTypeId;class:=Windows.UI.Core.CoreWindow""  
2: Title is: <Popup>    Class   := <Popup>  controltype:= <UIA_WindowControlTypeId> ,<50032>    , (0000C370)    0;874;258;114
"Title:=Popup;controltype:=UIA_WindowControlTypeId;class:=Popup""   
1: Title is: <Power options>    Class   := <MenuFlyout> controltype:= <UIA_MenuControlTypeId>   ,<50009>    , (0000C359)    0;874;258;114
"Title:=Power options;controltype:=UIA_MenuControlTypeId;class:=MenuFlyout""    
0: Title is: <Shut down>    Class   := <MenuFlyoutItem> controltype:= <UIA_MenuItemControlTypeId>   ,<50011>    , (0000C35B)    1;915;256;32
"Title:=Shut down;controltype:=UIA_MenuItemControlTypeId;class:=MenuFlyoutItem""    


;~ *** Standard code maintainable ***
#include "UIAWrappers.au3"
AutoItSetOption("MustDeclareVars", 1)

_UIA_setVar("oP1","Title:=Start;controltype:=UIA_WindowControlTypeId;class:=Windows.UI.Core.CoreWindow")    ;Start
_UIA_setVar("oP2","Title:=Popup;controltype:=UIA_WindowControlTypeId;class:=Popup") ;Popup
_UIA_setVar("oP3","Title:=Power options;controltype:=UIA_MenuControlTypeId;class:=MenuFlyout")  ;Power options
_UIA_setVar("oP4","Title:=Shut down;controltype:=UIA_MenuItemControlTypeId;class:=MenuFlyoutItem")  ;Shut down

;~ $oUIElement=_UIA_getObjectByFindAll("Shutdown.mainwindow", "title:=Shut down;ControlType:=UIA_TextControlTypeId", $treescope_subtree)
_UIA_setVar("oUIElement","Title:=Shut down;controltype:=UIA_TextControlTypeId;class:=TextBlock") ;ControlType:=UIA_TextControlTypeId;classname:=TextBlock")

;~ Actions split away from logical/technical definition above can come from configfiles 

;~_UIA_Action("oP1","highlight")
_UIA_Action("oP1","setfocus")
;~_UIA_Action("oP2","highlight")
_UIA_Action("oP2","setfocus")
;~_UIA_Action("oP3","highlight")
_UIA_Action("oP3","setfocus")
;~_UIA_Action("oP4","highlight")
_UIA_Action("oP4","setfocus")

_UIA_action("oUIElement","highlight")
;~_UIA_action("oUIElement","click")


;~ *** Standard code Flexible***
#include "UIAWrappers.au3"
AutoItSetOption("MustDeclareVars", 1)

Local $oP3=_UIA_getObjectByFindAll($UIA_oDesktop, "Title:=Start;controltype:=UIA_WindowControlTypeId;class:=Windows.UI.Core.CoreWindow", $treescope_children)   
_UIA_Action($oP3,"setfocus")
Local $oP2=_UIA_getObjectByFindAll($oP3, "Title:=Popup;controltype:=UIA_WindowControlTypeId;class:=Popup", $treescope_children) 
Local $oP1=_UIA_getObjectByFindAll($oP2, "Title:=Power options;controltype:=UIA_MenuControlTypeId;class:=MenuFlyout", $treescope_children)  
Local $oP0=_UIA_getObjectByFindAll($oP1, "Title:=Shut down;controltype:=UIA_MenuItemControlTypeId;class:=MenuFlyoutItem", $treescope_children)  
;~ First find the object in the parent before you can do something
;~$oUIElement=_UIA_getObjectByFindAll("Shutdown.mainwindow", "title:=Shut down;ControlType:=UIA_TextControlTypeId", $treescope_subtree)
Local $oUIElement=_UIA_getObjectByFindAll($oP0, "title:=Shut down;ControlType:=UIA_TextControlTypeId", $treescope_subtree)
;~_UIA_action($oUIElement,"highlight")
_UIA_action($oUIElement,"click")


*** Detailed properties of the highlighted element ***
UIA_title:= <Shut down>
UIA_text:= <Shut down>
UIA_regexptitle:= <Shut down>
UIA_class:= <TextBlock>
UIA_regexpclass:= <TextBlock>
UIA_iaccessiblechildId:= <0>
UIA_id:= <TextBlock>
UIA_handle:= <0>
UIA_RuntimeId:= <42;65966;3;4>
UIA_BoundingRectangle:= <13;923;232;16>
UIA_ProcessId:= <6944>
UIA_ControlType:= <50020>
UIA_LocalizedControlType:= <text>
UIA_Name:= <Shut down>
UIA_HasKeyboardFocus:= <False>
UIA_IsKeyboardFocusable:= <False>
UIA_IsEnabled:= <True>
UIA_AutomationId:= <TextBlock>
UIA_ClassName:= <TextBlock>
UIA_ClickablePoint:= <129;931>
UIA_Culture:= <1033>
UIA_IsControlElement:= <True>
UIA_IsContentElement:= <True>
UIA_IsPassword:= <False>
UIA_NativeWindowHandle:= <0>
UIA_IsOffscreen:= <False>
UIA_Orientation:= <0>
UIA_FrameworkId:= <XAML>
UIA_IsRequiredForForm:= <False>
UIA_IsDockPatternAvailable:= <False>
UIA_IsExpandCollapsePatternAvailable:= <False>
UIA_IsGridItemPatternAvailable:= <False>
UIA_IsGridPatternAvailable:= <False>
UIA_IsInvokePatternAvailable:= <False>
UIA_IsMultipleViewPatternAvailable:= <False>
UIA_IsRangeValuePatternAvailable:= <False>
UIA_IsScrollPatternAvailable:= <False>
UIA_IsScrollItemPatternAvailable:= <True>
UIA_IsSelectionItemPatternAvailable:= <False>
UIA_IsSelectionPatternAvailable:= <False>
UIA_IsTablePatternAvailable:= <False>
UIA_IsTableItemPatternAvailable:= <False>
UIA_IsTextPatternAvailable:= <True>
UIA_IsTogglePatternAvailable:= <False>
UIA_IsTransformPatternAvailable:= <False>
UIA_IsValuePatternAvailable:= <False>
UIA_IsWindowPatternAvailable:= <False>
UIA_ValueIsReadOnly:= <True>
UIA_RangeValueValue:= <0>
UIA_RangeValueIsReadOnly:= <True>
UIA_RangeValueMinimum:= <0>
UIA_RangeValueMaximum:= <0>
UIA_RangeValueLargeChange:= <0>
UIA_RangeValueSmallChange:= <0>
UIA_ScrollHorizontalScrollPercent:= <0>
UIA_ScrollHorizontalViewSize:= <100>
UIA_ScrollVerticalScrollPercent:= <0>
UIA_ScrollVerticalViewSize:= <100>
UIA_ScrollHorizontallyScrollable:= <False>
UIA_ScrollVerticallyScrollable:= <False>
UIA_SelectionCanSelectMultiple:= <False>
UIA_SelectionIsSelectionRequired:= <False>
UIA_GridRowCount:= <0>
UIA_GridColumnCount:= <0>
UIA_GridItemRow:= <0>
UIA_GridItemColumn:= <0>
UIA_GridItemRowSpan:= <1>
UIA_GridItemColumnSpan:= <1>
UIA_DockDockPosition:= <5>
UIA_ExpandCollapseExpandCollapseState:= <3>
UIA_MultipleViewCurrentView:= <0>
UIA_WindowCanMaximize:= <False>
UIA_WindowCanMinimize:= <False>
UIA_WindowWindowVisualState:= <0>
UIA_WindowWindowInteractionState:= <0>
UIA_WindowIsModal:= <False>
UIA_WindowIsTopmost:= <False>
UIA_SelectionItemIsSelected:= <False>
UIA_TableRowOrColumnMajor:= <2>
UIA_ToggleToggleState:= <2>
UIA_TransformCanMove:= <False>
UIA_TransformCanResize:= <False>
UIA_TransformCanRotate:= <False>
UIA_IsLegacyIAccessiblePatternAvailable:= <True>
UIA_LegacyIAccessibleChildId:= <0>
UIA_LegacyIAccessibleName:= <Shut down>
UIA_LegacyIAccessibleRole:= <41>
UIA_LegacyIAccessibleState:= <0>
UIA_IsDataValidForForm:= <True>
UIA_ProviderDescription:= <[pid:6944,providerId:0x0 Main(parent link):Unidentified Provider (unmanaged:Windows.UI.Xaml.dll)]>
UIA_IsItemContainerPatternAvailable:= <False>
UIA_IsVirtualizedItemPatternAvailable:= <False>
UIA_IsSynchronizedInputPatternAvailable:= <False>

 

Edited by milos83
Posted (edited)

anyway, what you want to do is EXTREMLY dangerous and should never be done lightly. Instead, modify the shutdown button by using policy

https://superuser.com/questions/1019041/how-to-make-the-power-button-show-a-prompt-in-windows-10

 

dude, if you hook that, and your program screws up then you mess the whole box up. don't mess with hooking. If you think you can handle writing in C++ then go for it. be prepared to do a lot of rebooting as your attempts will fail, especially with that button.

Edited by Earthshine

My resources are limited. You must ask the right questions

 

Posted
5 minutes ago, Earthshine said:

Messages are intercepted using Windows Hooks . You need to research that. I do not believe junkew's UDF does this.

Talking about _WinAPI_SetWinEventHook ?

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
×
×
  • Create New...