StrokesPlus.net
Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Options
Go to last post Go to first unread
Rob Otter  
#1 Posted : Tuesday, November 24, 2020 5:55:36 AM(UTC)
Rob Otter

Rank: Advanced Member

Reputation:

Groups: Approved
Joined: 10/26/2020(UTC)
Posts: 50
Germany
Location: Darmstadt

Thanks: 15 times
Was thanked: 2 time(s) in 2 post(s)
I have some trouble with determining my OneNote application:

When using the magnifier icon of "Module Name (EXE)" on tab "App Definition" for a new application, it gives "onenoteim.exe" which looks quite reasonable.
But when getting the name with sp.ForegroundWindow().Process.MainModule.ModuleName, it says "applicationframehost.exe" which is more generic and I suspect there may be more applications encountered with this name, which would make my script react on unwanted applications.
So, why is this difference and how would I get "onenoteim.exe"? OneNote is installed as a MS AppStore app, if that helps.
Edit: But on other AppStore apps, this does not happen and getting the exe name works fine. Hm.

Edited by user Tuesday, November 24, 2020 6:07:46 AM(UTC)  | Reason: Not specified

Rob  
#2 Posted : Tuesday, November 24, 2020 9:00:41 AM(UTC)
Rob

Rank: Administration

Reputation:

Groups: Translators, Members, Administrators
Joined: 1/11/2018(UTC)
Posts: 1,349
United States
Location: Tampa, FL

Thanks: 28 times
Was thanked: 416 time(s) in 354 post(s)
Yeah, Store apps can often run inside a container (ApplicationFrameHost.exe), and that container is technically the owner of the app and the foreground window.

When getting a window by cursor location, ApplicationFrameHost.exe only returns for the border of the application; anywhere inside that rectangle returns the details of the actual app which is being hosted.

The script below checks for ApplicationFrameHost.exe and uses the center of the window to find the EXE name instead.
Code:
var fgWindow = sp.ForegroundWindow();
var fgWindowEXE = fgWindow.Process.MainModule.ModuleName;

if(fgWindowEXE === "ApplicationFrameHost.exe")
{
    //Use center of window as point to locate window and get EXE name
    var fgWindowRect = fgWindow.Rectangle;
    var fgWindowLocation = new Point(fgWindowRect.X + parseInt(fgWindowRect.Width / 2), fgWindowRect.Y + parseInt(fgWindowRect.Height / 2));
    fgWindowEXE = sp.WindowFromPoint(fgWindowLocation, false).Process.MainModule.ModuleName;
}

sp.MessageBox(fgWindowEXE, "fgWindowEXE");

if(fgWindowEXE === "onenoteim.exe")
{
    sp.MessageBox("OneNote", "Found!");
}

Edited by user Tuesday, November 24, 2020 3:06:43 PM(UTC)  | Reason: Not specified

thanks 1 user thanked Rob for this useful post.
Rob Otter on 11/24/2020(UTC)
Rob Otter  
#3 Posted : Tuesday, November 24, 2020 9:34:32 AM(UTC)
Rob Otter

Rank: Advanced Member

Reputation:

Groups: Approved
Joined: 10/26/2020(UTC)
Posts: 50
Germany
Location: Darmstadt

Thanks: 15 times
Was thanked: 2 time(s) in 2 post(s)
Thanks! I was not aware of such a sophisticated distinction... I would have never been able to solve that on my own!
Users browsing this topic
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.