MoveanExternalApplicationtotheFrontoftheScreen我正在运行的应用程序需要调用一个单独的应用程序来进行扫描。我通过启动一个新的System.Diagnostics.Process来调用另一个应用程序。完成此过程后,我将调用一个方法来为应用程序提供焦点。我尝试了两种不同的方法来聚焦外部应用程序,但都没有用。有人可以帮忙吗?这是代码:使用System.Runtime.InteropServices;[DllImport("user32.dll")]privatestaticexternboolShowWindow(IntPtrhWnd,uintwindowStyle);[DllImport("user32.dll")]privatestaticexternboolSetWindowPos(IntPtrhWnd,IntPtrhWndInsertAfter,intx,inty,intcx,intcy,uintuFlags);[DllImport("user32.dll")]privatestaticexternboolSetForegroundWindow(IntPtrhWnd);privatestaticvoidGiveSpecifiedAppTheFocus(intprocessID{try{Processp=Process.GetProcessById(processID);ShowWindow(p.MainWindowHandle,1);SetWindowPos(p.MainWindowHandle,newIntPtr(-1),0,0,0,0,3);//SetForegroundWindow(p.MainWindowHandle);}catch{throw;}}第一种情况使用ShowWindow和SetWindowPos方法,另一种使用SetForegroundWindow方法。两者都行不通……我是在使用错误的方法,还是在我使用的代码中存在错误?谢谢你们!使用SetWindowPos,但当您不想让窗口位于最顶层时再次调用它,将第二个参数设置为-2(HWND_NOTOPMOST)而不是-1(HWND_TOPMOST)尝试将您的进程设置为后台,即:this.SendToBack();这只是另一种解决方案,部分修复。以上就是C#学习教程:把外部应用移到屏幕最前面,分享全部内容。如果对你有用,需要进一步了解C#学习教程,希望大家多多关注。本文收集自网络,不代表立场。如涉及侵权,请点击右侧联系管理员删除。如需转载请注明出处:
