0

I have an ActiveX control written in C# which operates a scanner from the browser using WIA. Everything works fine except the WIA CommonDialog pops under the browser window. How can I get it to show up on top of the browser?

wiaDialog = new WIA.CommonDialog();
wiaImage = wiaDialog.ShowAcquireImage(WiaDeviceType.ScannerDeviceType,  WiaImageIntent.UnspecifiedIntent, WiaImageBias.MaximizeQuality,                               wiaFormatJPEG, false, false, false);

[Edit]

Thanks very much to Noseratio for putting me onto the right track. The suggestion to use BringWindowToTop invoked via a timer before popping up the dialog does not quite work. Instead the function to use is SetForegroundWindow. The code is as follows (invoked from a System.Timer.Timer prior to opening the scan dialog):

public static void scanDialogToTop(Object caller, EventArgs theArgs) {  
    scanner.theTimer.Stop();  
    foreach (Process p in Process.GetProcesses()) {  
        if (p.MainWindowTitle.StartsWith("Scan using")) {  
            SetForegroundWindow(p.MainWindowHandle);  
            break;  
        }  
     }  
}  

See this article for a more complete discussion.

Community
  • 1
  • 1
Jon
  • 703
  • 3
  • 15
  • 34

1 Answers1

1

It does not look like you can specify a parent window for ShowAcquireImage. If the caption of the popup window is static, you could use FindWindow to find the popup's handle. If ShowAcquireImage is a blocking call (doesn't return until the popup window is closed), before calling it you'd need to setup a timer and call FindWindow upon a timer event. I also suspect the WIA popup is created on a different thread (you could check that with Spy++). If that's the case, you could use the following hack to give the WIA popup window focus. Otherwise you just do BringWindowToTop.

Community
  • 1
  • 1
noseratio
  • 59,932
  • 34
  • 208
  • 486