Processing Ajax...

Title

Message

Confirm

Confirm

Confirm

Confirm

Are you sure you want to delete this item?

Confirm

Are you sure you want to delete this item?

Confirm

Are you sure?

User Image
Witchy2
23 discussion posts
Hi,

I'm testing GetMainWindowByAppID() on DF8.0 with the following code:

Code

using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;

public static class DisplayFusionFunction
{
public static void Run()
{

      uint appID = BFS.Application.Start("c:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe", "");
      int count = 0;
while (true)
{
 IntPtr foo = BFS.Application.GetMainWindowByAppID(appID);
 if (foo != IntPtr.Zero)
 break;

BFS.General.ThreadWait(250);
if (++count >= 30000 / 250) // loop for 30 seconds
return;
}

        IntPtr windowHandle = BFS.Application.GetMainWindowByAppID(appID);
        uint monitormonitorID = BFS.Monitor.GetMonitorIDByWindow(windowHandle);
        string output = "";
        output += string.Format("appID 0x{0}: Handle: {1} Monitor: {2} " + Environment.NewLine, appID.ToString(), windowHandle.ToString("x8"), BFS.Monitor.GetMonitorIDByWindow(windowHandle));
        BFS.Dialog.ShowMessageInfoMonospaced(output);
        bool bar = BFS.Window.MoveToMonitor(2, windowHandle);
}
}


windowHandle is always returned as 0 so the monitor move never happens. I know the window is created OK since the 'list open window information' script shows it and its handle so is there a fault in GetMainWindowByAppID()?

Cheers!
Oct 4, 2016 (modified Oct 17, 2016)  • #1
User Image
Witchy2
23 discussion posts
*Bump*

Is nobody else using this function?
Oct 11, 2016  • #2
User Image
Collin Chaffin
69 discussion posts
Have you tried this? (works in my published functions using it):

uint firefox = BFS.Application.GetAppIDByFile("*firefox.exe");
cmd = BFS.Application.Start("C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe", "");
for(int i = 0; (i < 50) && (!BFS.Application.IsAppRunningByAppID(firefox)); i++)
BFS.General.Sleep(100);
IntPtr mainWindow = BFS.Application.GetMainWindowByAppID(firefox);
//if we failed to get the windows, exit the function
if (mainWindow == IntPtr.Zero)
return;
//TODO: DO STUFF HERE WITH mainWindow

Hope this helps!

Collin
Collin Chaffin's profile on WallpaperFusion.com
Oct 11, 2016  • #3
User Image
Witchy2
23 discussion posts
Hi Colin,

Thanks for the quick response! That script assumes FF is already running (GetAppIDByFile) so moves my original FF window (which it CAN get the appID for) to monitor 2 and starts the new instance on monitor 1.

If I change it to be (for example) the arduino IDE I get the same issue - if there's nothing of that name running then GetMonitorIDByWindow returns zero after starting the app.

Cheers!
Oct 11, 2016  • #4
User Image
Collin Chaffin
69 discussion posts
If you try the code it will work. I literally grabbed those first lines from a working function that starts multiple copies of a couple programs, so it will actually handle that as well.

I am guessing your issue actually lies in your pause loop, anyway it looks similar to your code but if you test it you will find it does have different results - if you get some time please do try those lines of code in a new function and I think you'll find they work I have been using them for several major revisions now pretty much since external scripted functions were added I believe it was back in v7 where you should still see some of the originally scripted functions in the library under my name.

Thanks!

Collin
Collin Chaffin's profile on WallpaperFusion.com
Oct 11, 2016  • #5
User Image
Witchy2
23 discussion posts
Hi Collin,

There must be something with the way my machine launches firefox. Your script assumes an instance is already running otherwise it doesn't execute but maybe that's just because there's other things happening outside the snippet you've sent?

This code works for 7-zip and puts the window on monitor 2:

Code

uint cmd = BFS.Application.Start("C:\\Program Files (x86)\\7-zip\\7zFM.exe", "");
        for (int i = 0; (i < 50) && (!BFS.Application.IsAppRunningByAppID(cmd)); i++)
            BFS.General.Sleep(100);
        IntPtr mainWindow = BFS.Application.GetMainWindowByAppID(cmd);
        //if we failed to get the windows, exit the function
        if (mainWindow == IntPtr.Zero)
            return;
        
        uint monitormonitorID = BFS.Monitor.GetMonitorIDByWindow(mainWindow);
        bool bar = BFS.Window.MoveToMonitor(2, mainWindow);


but if I change the executable for firefox it fails. Just looking at why....

Cheers!
Oct 12, 2016  • #6
User Image
Witchy2
23 discussion posts
...and I'm now in a world of firefox bugs. Essentially I can't do what I want to do using firefox, the profiles, -new-instance and other CLI options don't work as documented and in the case of -new-instance are marked as WONTFIX. Which is nice.

I'll just have to loop through the window text instead and fire off the ones that aren't there.

Cheers!
Oct 12, 2016  • #7
Keith Lammers (BFS)'s profile on WallpaperFusion.com
We're seeing similar issues with the GetMainWindowByAppID() function here as well. We've added it to our list to fix up :)

Thanks!
Oct 12, 2016  • #8
User Image
Witchy2
23 discussion posts
Hi Keith,

Thanks for that! I'm not sure it's actually a DF issue given what I read yesterday though. Firefox seems to want to be a single instance no matter what you do, so even if you fire off 4 windows or tabs they all have one PID meaning all you can do is search by window title. There's a similar problem with Java apps like the Arduino IDE.

Cheers

Witchy
Oct 13, 2016  • #9
Keith Lammers (BFS)'s profile on WallpaperFusion.com
Ah yep, that makes sense. We tested with Firefox, Chrome, and Notepad++. All of those would definitely have this issue. Thanks for the update!
Oct 13, 2016  • #10
Subscribe to this discussion topic using RSS
Was this helpful?  Login to Vote(-)  Login to Vote(-)