none
Gets a handle of UWP RRS feed

  • Question

  • When I open calculator, according to the above scheme, I cannot get the handle, only when I minimize calculator, can I get the handle, may I ask why, is there any way that I can get the handle all the time?Thank you
    Wednesday, September 4, 2019 7:38 AM

All replies

  • Hi,

    Please elaborate on your problem description so that we can help you solve the problem.

    1. Which above scheme means.

    2. Can you tell us why you are doing this, and if you know why, maybe we can provide other solutions.

    Best regards.


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, September 4, 2019 8:53 AM
  • Hi,

        Process[] anotherApps = Process.GetProcessesByName("Calculator");
    
    
        while (anotherApps[0].MainWindowHandle.ToInt32() == 0)
        {
            anotherApps[0].Refresh();
        }
        if (anotherApps[0].MainWindowHandle.ToInt32() != 0)
        {
            Console.WriteLine("successTest" + anotherApps[0].MainWindowHandle.ToInt32());
            Console.ReadKey();
        }

    I tried to get the handle of UWP app named Calculator using above code, but the problem is that it seems I only can get the correct result when I minimum the Calculator to taskbar, when I put the Calculator to top-level, the handle is always zero, so it always refresh.

    Note that if I try to get a win32 app handle, the above code can work well. But if I try to get UWP apps like calculator or map or ..., it occurs above problem.

    Regards,

    KOBE


    Thursday, September 5, 2019 8:06 AM
  • Hi,

    In general, UWP apps are sandboxed apps, and you can't get window handles directly.

    The calculator application is built using C++/Win RT and is currently open sourced, which may have a built-in Win32 module that allows the handle to be captured when the window is minimized, but this is a special case and does not have universality.

    Best regards.


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, September 5, 2019 9:19 AM
  • I've tried UWP programs that come with calculators, Movies &TV,MAP, etc., and they all have these problems, so I don't think it's an accident.
    Thursday, September 5, 2019 12:17 PM
  • Hi

    It is because UWP apps doesn't have MainWindow. The window which you see as Main with max, min, close buttons  is owned by ApplicationFrameHost.exe process and UWP CoreWindow is child of that window. Try with following way

    1) Get process  

    2) Get that process thread 

    3) enum thread windows by EnumThreadWindows


    Make the community better together


    Thursday, September 5, 2019 4:38 PM