windows 10 Printer Extension is launched behind the Devices and Printers folder RRS feed

  • Question

  • As per the link

    "The Printer Extension Sample demonstrates how to create a UI that is generally launched as the topmost window. But in some cases, the UI will not be shown in the foreground, such as when the process that caused the UI to be invoked is running at a different integrity level, or when the process is compiled for a different processor architecture. In this case, the printer extension should call FlashWindowEx to request user permission to come to the foreground by flashing the icon in the taskbar."

    The above mentioned behaviour we have seen with the sample Printer Extension when launched from Devices and Printers folder. The Sample Printer Extension is launched behind the Devices and Printers folder. I can able to over come this issue by calling the following small function

    public static void SetForegroundWindowInternal(IntPtr hWnd)
            if(!IsWindow(hWnd)) return;
            //relation time of SetForegroundWindow lock
                    IntPtr lockTimeOut = IntPtr.Zero;
            IntPtr  hCurrWnd = GetForegroundWindow();
            UInt32 dwThisTID = GetCurrentThreadId(),
                  dwCurrTID = GetWindowThreadProcessId(hCurrWnd, UIntPtr.Zero);
            //we need to bypass some limitations from Microsoft :)
            if(dwThisTID != dwCurrTID)
            AttachThreadInput(dwThisTID, dwCurrTID, true);

                           SystemParametersInfo((uint)SPI.SPI_GETFOREGROUNDLOCKTIMEOUT, 0, lockTimeOut, 0);

                           SystemParametersInfo((uint)SPI.SPI_SETFOREGROUNDLOCKTIMEOUT, 0, IntPtr.Zero, (uint)(SPIF.SPIF_SENDWININICHANGE | SPIF.SPIF_UPDATEINIFILE));

            if(dwThisTID != dwCurrTID)
                            SystemParametersInfo((uint)SPI.SPI_SETFOREGROUNDLOCKTIMEOUT, 0, lockTimeOut, (uint)(SPIF.SPIF_SENDWININICHANGE | SPIF.SPIF_UPDATEINIFILE));
            AttachThreadInput(dwThisTID, dwCurrTID, false);


    in the printer extension sample code as follows:

    // Display a modal/non-modal window based on the 'WindowModal' parameter.

                    if (eventArgs.WindowModal)


                        // Flash the window to draw the user's attention. This is required
                        // because the printer extension may be drawn behind the parent window.
                        // The return value of FlashWindow can be safely ignored if there is no need
                        // to know if the window has focus or not.

    Is there any potential issue with the above method? Do we have any other solution to bring the Printer Extension in foreground? 

    • Edited by SBag Wednesday, August 5, 2015 4:05 AM
    Tuesday, July 14, 2015 11:52 AM