MouseGetPos: Why do I only get "ApplicationFrameHost.exe" when the mouse is over "uwp app"? Topic is solved

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
User avatar
6Tom
Posts: 33
Joined: 26 Dec 2022, 21:28

MouseGetPos: Why do I only get "ApplicationFrameHost.exe" when the mouse is over "uwp app"?

Post by 6Tom » 20 Jan 2023, 03:53

Hi friends,
I've got a problem. Why can't I get the real path of "uwp app"?

Code: Select all

#Requires AutoHotkey v2.0

#y::
{
    MouseGetPos( , , &ID_)
    MsgBox(WinGetProcessPath("ahk_id " ID_))
}

For example, for the following uwp applications, I think I should get these paths:

  • Win11 Settings:
    C:\Windows\ImmersiveControlPanel\SystemSettings.exe
  • Defender:
    C:\Program Files\WindowsApps\Microsoft.SecHealthUI_1000.22621.1.0_x64__8wekyb3d8bbwe\SecHealthUI.exe
  • Microsoft Store:
    C:\Program Files\WindowsApps\Microsoft.WindowsStore_22210.1401.16.0_x64__8wekyb3d8bbwe\WinStore.App.exe
  • Email:
    C:\Program Files\WindowsApps\microsoft.windowscommunicationsapps_16005.14326.21256.0_x64__8wekyb3d8bbwe\HxOutlook.exe
  • Calculator:
    C:\Program Files\WindowsApps\Microsoft.WindowsCalculator_11.2210.0.0_x64__8wekyb3d8bbwe\CalculatorApp.exe

But in fact, all I get is: C:\Windows\System32\ApplicationFrameHost.exe

Can someone help me with that?

swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: MouseGetPos: Why do I only get "ApplicationFrameHost.exe" when the mouse is over "uwp app"?

Post by swagfag » 20 Jan 2023, 05:14

if u pass the "correct" hwnd, ud get these paths. if u pass the hwnd of the ApplicationFrameHost container (inside which all UWP apps live and also just so happens to be the "the window under the mouse cursor." as reported by GetMousePos), ud get the path of ApplicationFrameHost.exe

User avatar
6Tom
Posts: 33
Joined: 26 Dec 2022, 21:28

Re: MouseGetPos: Why do I only get "ApplicationFrameHost.exe" when the mouse is over "uwp app"?

Post by 6Tom » 20 Jan 2023, 07:03

Thanks for helping, swagfag!

I tried a few things with your instructions. But because I'm new, I still have some problems that cannot be solved. Please don't mind if I continue to ask.

I found that this path can only be obtained by using ProcessGetPath(xxx). ("xxx" means "the pid of this process I saw in the windows task manager".)

WinGetProcessPath("ahk_pid " xxx) doesn't work. It told me Error: Target window not found. My understanding is that the process with pid "xxx" is not a window. Therefore, window functions cannot be used to obtain relevant information.

So if I don't use my eyes to look at the windows task manager, how can I get "xxx"?

ntepa
Posts: 428
Joined: 19 Oct 2022, 20:52

Re: MouseGetPos: Why do I only get "ApplicationFrameHost.exe" when the mouse is over "uwp app"?  Topic is solved

Post by ntepa » 20 Jan 2023, 08:43

Try this:

Code: Select all

#y::
{
    MouseGetPos(,,&Win)
    TrueWindow := 0
    if WinGetProcessName(win) == "ApplicationFrameHost.exe" {
        DllCall("EnumChildWindows", "ptr", win, "ptr", CallbackCreate(EnumChildWindows, "F"), "uint", 0)
        MsgBox WinGetProcessPath(TrueWindow)
    }

    EnumChildWindows(hwnd) {
        if WinGetProcessName(hwnd) != "ApplicationFrameHost.exe" {
            TrueWindow := hwnd
            return false
        }
        return true
    }
}

User avatar
6Tom
Posts: 33
Joined: 26 Dec 2022, 21:28

Re: MouseGetPos: Why do I only get "ApplicationFrameHost.exe" when the mouse is over "uwp app"?

Post by 6Tom » 20 Jan 2023, 09:06

It's perfect!

Thanks for your warm help again, ntepa.

Without your help, I'm not able to use DllCall to solve this problem at my current level.

teadrinker
Posts: 4331
Joined: 29 Mar 2015, 09:41
Contact:

Re: MouseGetPos: Why do I only get "ApplicationFrameHost.exe" when the mouse is over "uwp app"?

Post by teadrinker » 20 Jan 2023, 19:33

6Tom wrote: I'm not able to use DllCall to solve this problem at my current level.
Easier:

Code: Select all

#y:: {
    fn := (hWnd) => (WinGetProcessName(hWnd) = 'ApplicationFrameHost.exe')
    MouseGetPos ,, &hWnd
    if fn(hWnd) {
        for hCtrl in WinGetControlsHwnd(hWnd)
            bool := fn(hCtrl)
        until !bool && hWnd := hCtrl
    }
    MsgBox WinGetProcessPath(hWnd)
}

User avatar
6Tom
Posts: 33
Joined: 26 Dec 2022, 21:28

Re: MouseGetPos: Why do I only get "ApplicationFrameHost.exe" when the mouse is over "uwp app"?

Post by 6Tom » 20 Jan 2023, 22:35

Amazing!

It also works well! Let me study its principle.

Thanks a lot for sharing, teadrinker.

ludamo
Posts: 44
Joined: 25 Mar 2015, 02:21

Re: MouseGetPos: Why do I only get "ApplicationFrameHost.exe" when the mouse is over "uwp app"?

Post by ludamo » 22 Jan 2023, 23:04

Perhaps another solution.

Code: Select all

#Requires AutoHotkey v2.0+

#y:: {
DllCall("GetCursorPos", "int64P", &pt64 := 0)
hWndP := DllCall("WindowFromPoint","int64", pt64)
MsgBox(WinGetProcessName(hWndP))
}

User avatar
6Tom
Posts: 33
Joined: 26 Dec 2022, 21:28

Re: MouseGetPos: Why do I only get "ApplicationFrameHost.exe" when the mouse is over "uwp app"?

Post by 6Tom » 23 Jan 2023, 04:33

Yeah, it works well, too!

Thank you for sharing another method, ludamo.

teadrinker
Posts: 4331
Joined: 29 Mar 2015, 09:41
Contact:

Re: MouseGetPos: Why do I only get "ApplicationFrameHost.exe" when the mouse is over "uwp app"?

Post by teadrinker » 23 Jan 2023, 08:03

Yeah, this mostly works, but some areas of a window may still return "ApplicationFrameHost.exe".

just me
Posts: 9458
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: MouseGetPos: Why do I only get "ApplicationFrameHost.exe" when the mouse is over "uwp app"?

Post by just me » 23 Jan 2023, 10:54

This might work too until MicroSoft decides to change the class names or order of the controls used by the ApplicationFrameHost:

Code: Select all

#Requires AutoHotkey v2.0.0

#y:: {
   MouseGetPos( , , &HWND)
   MsgBox(WinGetProcessPathUWP(HWND))
}

WinGetProcessPathUWP(HWND) { ; HWND = handle of a top-level window
   Static AFW := "ApplicationFrameWindow", WUCCW1 := "Windows.UI.Core.CoreWindow1"
   Return WinGetProcessPath(WinGetClass(HWND) = AFW ? ControlGetHwnd(WUCCW1, HWND) : HWND)
}

User avatar
6Tom
Posts: 33
Joined: 26 Dec 2022, 21:28

Re: MouseGetPos: Why do I only get "ApplicationFrameHost.exe" when the mouse is over "uwp app"?

Post by 6Tom » 23 Jan 2023, 12:14

just me wrote:
23 Jan 2023, 10:54
This might work too until MicroSoft decides to change the class names or order of the controls used by the ApplicationFrameHost:
Indeed it is. This seems to be very efficient until some big changes.

Thank you, just me.

TheCoderNick
Posts: 1
Joined: 01 Feb 2023, 10:07

Re: MouseGetPos: Why do I only get "ApplicationFrameHost.exe" when the mouse is over "uwp app"?

Post by TheCoderNick » 01 Feb 2023, 10:58

A bit more complex code, but more versatile.

Code: Select all

/*
    WinGetListWithChildren() - Returns an array of all windows and their information.
    @param FilterCallback - A callback function that takes a single parameter, the window information, and returns true if the window should be included in the returned array.
    @return An array of window information.
    @example
        WinGetListWithChildren((window) => window.ProcessName == "Notepad.exe")
*/
WinGetListWithChildren(FilterCallback?) {
    WindowArray := []

    for hwnd in WinGetList() {
        GetAllProcessesRecursive(hwnd, &WindowArray)
    }

    GetAllProcessesRecursive(hwnd, &WindowArray, level := 0, parentHwnd := -1) {
        if WinGetProcessName(hwnd) == 'ApplicationFrameHost.exe' {
            for hwnd_ in WinGetControlsHwnd(hwnd) {
                GetAllProcessesRecursive(hwnd_, &WindowArray, level++, hwnd)
            }
        } else {
            WindowArray.push({
                HWND: hwnd,
                Level: level,
                ProcessName: WinGetProcessName(hwnd),
                Title: WinGetTitle(hwnd),
                Text: WinGetText(hwnd),
                Parent: parentHwnd == -1 ? unset : {
                    HWND: parentHwnd,
                    ProcessName: WinGetProcessName(parentHwnd),
                    Title: WinGetTitle(parentHwnd),
                    Text: WinGetText(parentHwnd)
                },
                Match: (this, hwnd) => this.HasOwnProp("Parent") && this.Parent.HWND == hwnd || this.HWND == hwnd
            })
        }
    }

    if IsSet(FilterCallback) {
        FilteredWindowArray := []
        for i, process in WindowArray {
            if FilterCallback(process) {
                FilteredWindowArray.push(process)
            }
        }
        return FilteredWindowArray
    }

    return WindowArray
}

^y:: {
    MouseGetPos(, , &HWND)
    window := WinGetListWithChildren((window) => window.Match(HWND)).Pop()
    MsgBox(window.ProcessName)
}

User avatar
6Tom
Posts: 33
Joined: 26 Dec 2022, 21:28

Re: MouseGetPos: Why do I only get "ApplicationFrameHost.exe" when the mouse is over "uwp app"?

Post by 6Tom » 01 Feb 2023, 13:58

Thanks, TheCoderNick.

A lot of information can be gotten from the array, which will be very useful.

Post Reply

Return to “Ask for Help (v2)”