我有一个程序失去了重点的问题。这不是我的计划。我如何编写第二个程序,每隔1-2秒将焦点设置到该窗口?有可能做到这一点吗?如何将焦点设置到另一个窗口?
7
A
回答
8
你可以,如果你想带一些其他程序/过程
[DllImport("coredll.dll")]
static extern bool SetForegroundWindow (IntPtr hWnd);
private void BringToFront(Process pTemp)
{
SetForegroundWindow(pTemp.MainWindowHandle);
}
+11
在Windows上,你应该使用'user32.dll',因为'coredll.dll'是Windows Mobile的! –
2
使用间谍++或其他UI工具,以找到您想要对焦的窗口类名使用下面的Win32 API,说其:focusWindowClassName 。然后添加以下功能:
[DllImport("USER32.DLL")]
public static extern bool SetForegroundWindow(IntPtr hWnd);
[System.Runtime.InteropServices.DllImport("User32.dll")]
public static extern bool ShowWindow(IntPtr handle, int nCmdShow);
[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
Then:
IntPrt hWnd = FindWindow("focusWindowClassName", null); // this gives you the handle of the window you need.
// then use this handle to bring the window to focus or forground(I guessed you wanted this).
// sometimes the window may be minimized and the setforground function cannot bring it to focus so:
/*use this ShowWindow(IntPtr handle, int nCmdShow);
*there are various values of nCmdShow 3, 5 ,9. What 9 does is:
*Activates and displays the window. If the window is minimized or maximized, *the system restores it to its original size and position. An application *should specify this flag when restoring a minimized window */
ShowWindow(hWnd, 9);
//The bring the application to focus
SetForegroundWindow(hWnd);
// you wanted to bring the application to focus every 2 or few second
// call other window as done above and recall this window again.
相关问题
- 1. Jquery - 将焦点设置到窗口
- 2. 将焦点设置到uifigure窗口
- 3. 将键盘焦点设置到一个窗口
- 4. 如何使用WatiN将焦点设置到浏览器窗口
- 5. 如何将焦点设置到子窗口而不刷新它?
- 6. 如何设置另一个窗口?
- 7. 找到一个窗口并设置它的焦点
- 8. 如何在wxWidgets中将键盘焦点设置为NULL窗口?
- 9. 如何将一个窗口连接到另一个窗口
- 10. 如何将一个窗口添加到另一个窗口?
- 11. 将焦点设置到虚拟机中的窗口
- 12. 弹出窗口设置焦点
- 13. 显示未设置焦点的窗口
- 14. 替代模糊()设置窗口焦点?
- 15. 在Gtkada中设置窗口焦点
- 16. 将焦点更改为VB.NET中的另一个窗口
- 17. PySide如何将焦点设置到新的窗口,如果不存在
- 18. 将页面加载之前将焦点转移到另一个窗口
- 19. 如何将焦点设置在弹出窗口弹出窗口的最后一个元素上
- 20. 将焦点窗口置于前面
- 21. 如何将焦点设置到jQuery对话窗口中的文本框?
- 22. IE8:如何将焦点设置到弹出窗口而不闪烁橙色
- 23. 将窗口位置锁定到另一个窗口?
- 24. 如何将焦点设置到一个datepicker场
- 25. 如何将焦点设置到iPhone中的下一个uitextfield?
- 26. 如何将一个窗口与另一个窗口连接?
- 27. 如何将一个窗口“嵌入”另一个窗口
- 28. 如何将一些信息从一个窗口拖放到另一个窗口?
- 29. 如何在JavaScript模式窗口上设置焦点?
- 30. 如何将OpenCV窗口设置为点击窗口?
你是说你想让焦点在你的程序和其他第二个程序之间每隔一秒进行一次切换吗?或者在你的应用程序中想每隔2秒将其他程序放在前面(以防再次返回)? – Faraday
它是一个程序(不同的程序过程)还是你的孩子形式? –
它的不同的程序,我想我的程序只能把它聚焦...... – Endiss