Jump to content

Recommended Posts

I wanted to see if I could manage to use IAppVisibility (Win8) in one of my scripts.

(it seems the name was changed in Release Preview but MSDN wasn't updated)

It took some time but I learned to make tlb file and made definitions for GetAppVisibilityOnMonitor and IsLauncherVisible methods (working good as far as I can tell), but I would like Advise and Unadvise too if possible, but I don't know how...

See definition on above link.

Only example I found is some (too advanced for me to translate) c++ code. Here. But it compiles and runs fine at least.

trancexx is doing a similar thing in maybe that can be used somehow?

Anyone have a clue?

Test script with the working funcs:

#include <WinAPI.au3>

;===============================================================================
#interface "IAppVisibility"
Global Const $sCLSID_AppVisibility = "{7E5FE3D9-985F-4908-91F9-EE19F9FD1514}"
Global Const $sIID_IAppVisibility = "{2246EA2D-CAEA-4444-A3C4-6DE827E44313}"
; Definition
Global Const $tagIAppVisibility = "GetAppVisibilityOnMonitor hresult(ptr;int*);" & _
"IsLauncherVisible hresult(int*);" & _
"Advise hresult(ptr;dword*);" & _
"Unadvise hresult(dword);"
;==============================================================================

Local $oAppVisibility = ObjCreateInterface($sCLSID_AppVisibility, $sIID_IAppVisibility, $tagIAppVisibility)

;~ MsgBox(0, @ScriptName, IsObj($oAppVisibility))
;~ ConsoleWrite(IsObj($oAppVisibility) & @CRLF)

If Not IsObj($oAppVisibility) Then
ConsoleWrite("NOT IsObj" & @LF)
MsgBox(0, "", "NOT IsObj")
Exit
EndIf

HotKeySet("ö", "_IsLauncherVisible")
HotKeySet("å", "_GetAppVisibilityOnMonitor")

$oMyError = ObjEvent("AutoIt.Error", "ErrFunc") ; Install a custom error handler

$callback=DllCallbackRegister("_MonitorEnumProc","int","ptr;ptr;ptr;lparam")
Global $Monitor
DllCall("user32.dll","int","EnumDisplayMonitors","ptr",0,"ptr",0,"ptr",DllCallbackGetPtr($callback),"lparam",10)

While 1
Sleep(1000)
WEnd

Func _IsLauncherVisible()
Local $bVisible
$iRet = $oAppVisibility.IsLauncherVisible($bVisible)
;~ If @error Then ;Enable this and disable AutoIt.Error if on Alpha
;~ MsgBox(0, @ScriptName, @error)
;~ EndIf
ToolTip("1: " & $iRet & @CRLF & "2: " & $bVisible)
EndFunc

Func _GetAppVisibilityOnMonitor()
Local $iMode
$iRet = $oAppVisibility.GetAppVisibilityOnMonitor($Monitor, $iMode)
ToolTip("1: " & $iRet & @CRLF & "2: " & $iMode)
EndFunc

; This is a custom error handler
Func ErrFunc()
$HexNumber = Hex($oMyError.number, 8)
MsgBox(0, "", "We intercepted a COM Error !" & @CRLF & _
"Number is: " & $HexNumber & @CRLF & _
"WinDescription is: " & $oMyError.windescription)
$iEventError = 1 ; Use to check when a COM Error occurs
EndFunc ;==>ErrFunc

Func _MonitorEnumProc($hMonitor, $hdcMonitor, $lprect, $lparam)
MsgBox(0, "Monitor", "Monitor handle: " & $hMonitor & @CRLF & "LPARAM: " & $lparam)
$Monitor = $hMonitor
EndFunc

Here's tlb stuff:

==================================================================================

coclass AppVisibility;
CLSID = {7E5FE3D9-985F-4908-91F9-EE19F9FD1514};

// Implemented interface: <Interface> IAppVisibility

==================================================================================

Interface IAppVisibility;
IID = {2246EA2D-CAEA-4444-A3C4-6DE827E44313};
// Inherits from: IUnknown {00000000-0000-0000-C000-000000000046}

1.
STDCALL FUNC PUREVIRTUAL;
HRESULT GetAppVisibilityOnMonitor(
[in]
hMonitor,
[out] int* pMode
);

2.
STDCALL FUNC PUREVIRTUAL;
HRESULT IsLauncherVisible(
[out] int* pfVisible
);

3.
STDCALL FUNC PUREVIRTUAL;
HRESULT Advise(
[in]
* pCallback,
[out] dword* pdwCookie
);

4.
STDCALL FUNC PUREVIRTUAL;
HRESULT Unadvise(
[in] dword dwCookie
);


==================================================================================

enum MONITOR_APP_VISIBILITY;
{
MAV_UNKNOWN = 0,
MAV_NO_APP_VISIBLE = 1,
MAV_APP_VISIBLE = 2
};


==================================================================================

Interface IAppVisibilityEvents;
IID = {6584CE6B-7D82-49C2-89C9-C6BC02BA8C38};
// Inherits from: IUnknown {00000000-0000-0000-C000-000000000046}

1.
STDCALL FUNC PUREVIRTUAL;
HRESULT AppVisibilityOnMonitorChanged(
[in]
hMonitor,
[in]
previousMode,
[in]
currentMode
);

2.
STDCALL FUNC PUREVIRTUAL;
HRESULT LauncherVisibilityChange(
[in] int currentVisibleState
);


==================================================================================
Edited by AdmiralAlkex
Link to comment
Share on other sites

You just have to realize that object is pointer to pointer pointing to set of function pointers. After that the soultion reveals itself.

I'll show you what I mean if no one else does it in the meantime, when I get home. You see, I'm at the beach now :D.

♡♡♡

.

eMyvnE

Link to comment
Share on other sites

trancexx is doing a similar thing in maybe that can be used somehow?

Anyone have a clue?

I think you are on the right track, but the example is for IDispatch-Events. The event-interface for IAppVisibility is not that difficult and sophosticated. Create a DLLStruct for the object and the vTable-Struct with all methods using DLLCallbackRegister / ...GetPtr. Now just pass this reference to Advise. I'll hack something together on my Win8 VM :D

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Link to comment
Share on other sites

This piece of code works for me. Some parts of _AppVisibilityEvents_GetPtr could be replaced with AutoItObject, but I think that would be overkill :D

#include <WinAPI.au3>


Global Const $sIID_IAppVisibilityEvents = "{6584CE6B-7D82-49C2-89C9-C6BC02BA8C38}"
Global Const $sIID_IUnknown = "{00000000-0000-0000-C000-000000000046}"
Global Const $sVTable_IAppVisibilityEvents = "ptr QueryInterface; ptr AddRef; ptr Release; ptr AppVisibilityOnMonitorChanged; ptr LauncherVisibilityChange;"

Func __AppVisibilityEvents_QueryInterface($pSelf, $pRIID, $pObj)
    #forceref $pSelf, $pRIID, $pObj
    ConsoleWrite("__AppVisibilityEvents_QueryInterface called " & $pSelf & "    " & _WinAPI_StringFromGUID($pRIID) & "    ")
    Local $tStruct = DllStructCreate("ptr", $pObj)
    Switch _WinAPI_StringFromGUID($pRIID)
        Case $sIID_IUnknown
            DllStructSetData($tStruct, 1, $pSelf)
            ConsoleWrite("IUnknown" & @CRLF)
            Return 0
        Case $sIID_IAppVisibilityEvents
            DllStructSetData($tStruct, 1, $pSelf)
            ConsoleWrite("IAppVisibilityEvents" & @CRLF)
            Return 0
    EndSwitch
    ConsoleWrite("~ E_NOINTERFACE" & @CRLF)
    Return 0x80004002 ; E_NOINTERFACE
EndFunc   ;==>__AppVisibilityEvents_QueryInterface

Func __AppVisibilityEvents_AddRef($pSelf)
    #forceref $pSelf
    ConsoleWrite("__AppVisibilityEvents_AddRef called" & @CRLF)
    Return 0x80004001 ; E_NOTIMPL
EndFunc   ;==>__AppVisibilityEvents_AddRef

Func __AppVisibilityEvents_Release($pSelf)
    #forceref $pSelf
    ConsoleWrite("__AppVisibilityEvents_Release called" & @CRLF)
    Return 0x80004001 ; E_NOTIMPL
EndFunc   ;==>__AppVisibilityEvents_Release

Func _AppVisibilityEvents_AppVisibilityOnMonitorChanged($pSelf, $hMonitor, $previousMode, $currentMode)
    ConsoleWrite("_AppVisibilityEvents_AppVisibilityOnMonitorChanged called: " & $hMonitor & " " & $previousMode & " " & $currentMode & @CRLF)
    Return 0x80004001 ; E_NOTIMPL
EndFunc

Func _AppVisibilityEvents_LauncherVisibilityChange($pSelf, $currentVisibleState);
    ConsoleWrite("_AppVisibilityEvents_LauncherVisibilityChange called: " & $currentVisibleState & @CRLF)
    Return 0x80004001 ; E_NOTIMPL
EndFunc

Func _AppVisibilityEvents_GetPtr()
    Local Static $tObj = DllStructCreate("ptr"), $tTable
    If Not DllStructGetData($tObj, 1) Then
        $tTable = DllStructCreate($sVTable_IAppVisibilityEvents)
        DllStructSetData($tObj, 1, DllStructGetPtr($tTable))
        DllStructSetData($tTable, 1, DllCallbackGetPtr(DllCallbackRegister("__AppVisibilityEvents_QueryInterface", "long", "ptr;ptr;ptr")))
        DllStructSetData($tTable, 2, DllCallbackGetPtr(DllCallbackRegister("__AppVisibilityEvents_AddRef", "long", "ptr")))
        DllStructSetData($tTable, 3, DllCallbackGetPtr(DllCallbackRegister("__AppVisibilityEvents_Release", "long", "ptr")))
        DllStructSetData($tTable, 4, DllCallbackGetPtr(DllCallbackRegister("_AppVisibilityEvents_AppVisibilityOnMonitorChanged", "long", "ptr;ptr;int;int")))
        DllStructSetData($tTable, 5, DllCallbackGetPtr(DllCallbackRegister("_AppVisibilityEvents_LauncherVisibilityChange", "long", "ptr;int")))
    EndIf
    Return DllStructGetPtr($tObj)
EndFunc



;===============================================================================
#interface "IAppVisibility"
Global Const $sCLSID_AppVisibility = "{7E5FE3D9-985F-4908-91F9-EE19F9FD1514}"
Global Const $sIID_IAppVisibility = "{2246EA2D-CAEA-4444-A3C4-6DE827E44313}"
; Definition
Global Const $tagIAppVisibility = "GetAppVisibilityOnMonitor hresult(ptr;int*);" & _
        "IsLauncherVisible hresult(int*);" & _
        "Advise hresult(ptr;dword*);" & _
        "Unadvise hresult(dword);"
;==============================================================================

Local $oAppVisibility = ObjCreateInterface($sCLSID_AppVisibility, $sIID_IAppVisibility, $tagIAppVisibility)

;~ MsgBox(0, @ScriptName, IsObj($oAppVisibility))
;~ ConsoleWrite(IsObj($oAppVisibility) & @CRLF)

If Not IsObj($oAppVisibility) Then
    ConsoleWrite("NOT IsObj" & @LF)
    MsgBox(0, "", "NOT IsObj")
    Exit
EndIf

Global $dwEventsCookie
$oAppVisibility.Advise(_AppVisibilityEvents_GetPtr(), $dwEventsCookie)
OnAutoItExitRegister("_UnadviseEvents")

HotKeySet("ö", "_IsLauncherVisible")
HotKeySet("å", "_GetAppVisibilityOnMonitor")

$oMyError = ObjEvent("AutoIt.Error", "ErrFunc") ; Install a custom error handler

$callback=DllCallbackRegister("_MonitorEnumProc","int","ptr;ptr;ptr;lparam")
Global $Monitor
DllCall("user32.dll","int","EnumDisplayMonitors","ptr",0,"ptr",0,"ptr",DllCallbackGetPtr($callback),"lparam",10)

While 1
    Sleep(1000)
WEnd

Func _UnadviseEvents()
    $oAppVisibility.Unadvise($dwEventsCookie)
EndFunc

Func _IsLauncherVisible()
    Local $bVisible
    $iRet = $oAppVisibility.IsLauncherVisible($bVisible)
;~   If @error Then   ;Enable this and disable AutoIt.Error if on Alpha
;~       MsgBox(0, @ScriptName, @error)
;~   EndIf
    ToolTip("1: " & $iRet & @CRLF & "2: " & $bVisible)
EndFunc

Func _GetAppVisibilityOnMonitor()
    Local $iMode
    $iRet = $oAppVisibility.GetAppVisibilityOnMonitor($Monitor, $iMode)
    ToolTip("1: " & $iRet & @CRLF & "2: " & $iMode)
EndFunc

; This is a custom error handler
Func ErrFunc()
    $HexNumber = Hex($oMyError.number, 8)
    MsgBox(0, "", "We intercepted a COM Error !" & @CRLF & _
            "Number is: " & $HexNumber & @CRLF & _
            "WinDescription is: " & $oMyError.windescription)
    $iEventError = 1 ; Use to check when a COM Error occurs
EndFunc   ;==>ErrFunc

Func _MonitorEnumProc($hMonitor, $hdcMonitor, $lprect, $lparam)
    MsgBox(0, "Monitor", "Monitor handle: " & $hMonitor & @CRLF & "LPARAM: " & $lparam)
    $Monitor = $hMonitor
EndFunc

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Link to comment
Share on other sites

I could kiss you guys, you are awesome! :D

Edit: PS, for anyone reading this thread in the future, there is also a dll alternative, IsImmersiveProcess in User32.dll

Edited by AdmiralAlkex
Link to comment
Share on other sites

And girls :D

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

And girls :D

Oh, she's with us :huh:

guy

noun

a male. When used to refer to two or more people, the gender restriction is lifted such that one or more of those people may be female

Edited by AdmiralAlkex
Link to comment
Share on other sites

Oh, I learn something new every day :D

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

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

×
×
  • Create New...