设置活动窗口 [英] Set active window

查看:217
本文介绍了设置活动窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图让一个应用程序,给出了一个地震式的下拉HUD控制台。我能得到它来显示和隐藏窗口,但我无法弄清楚如何显示它之后将其设置为活动窗口。使用API​​赢即时通讯来电显示和隐藏窗口。我试过SetForegroundWindow(的IntPtr的HWND)和SetFocus的(IntPtr的的hWnd)无济于事。任何人有什么想法?



http://pastebin.com/DgtJJGiv

 公共无效ShowApp()
{
IntPtr的H = FindWindow函数(NULL,C:\\\ \\Windows\\system32\\cmd.exe);
的ShowWindow(H,SW_SHOW);
// EnableWindow(h时,真正的);
是否隐藏= FALSE;
//将焦点设置到控制台窗口

SetForegroundWindow(H);
System.Diagnostics.Debug.WriteLine(H);
}


解决方案

我找到答案在这里:
如何显示在C#在前面的形式



WINAPI方法不正确为我工作,但该做的:

  form.TopMost = TRUE; 
form.TopMost = FALSE;



我本来只设置最顶层为真,但我遇到了与显示形式背后的对话框的问题。似乎设置最顶层为true拉的形式向前方并保持在那里。将其设置为false并不将其推回,但允许在前面显示的其他形式。我仍然有焦点问题,所以我结束了以下准备:

  form.Activate(); 


I'm trying to make an app that gives a quake style drop-down HUD console. I can get it to show and hide the window, but I can't figure out how to set it as the active window after showing it. Im using Win API calls to show and hide the window. I've tried SetForegroundWindow(IntPtr hWnd) and SetFocus(IntPtr hWnd) to no avail. Anyone have any ideas?

http://pastebin.com/DgtJJGiv

public void ShowApp()
{
    IntPtr h = FindWindow(null, "C:\\Windows\\system32\\cmd.exe");
    ShowWindow(h, SW_SHOW);
    //EnableWindow(h, true);
    isHidden = false;
        // set focus to console window

    SetForegroundWindow(h);
    System.Diagnostics.Debug.WriteLine(h);
}

解决方案

I found an answer here: How to show form in front in C#

The winAPI approaches were not working correctly for me but this did:

form.TopMost = true;
form.TopMost = false;

I originally was only setting TopMost to true but I ran into problems with dialog boxes displaying behind the form. It appears that setting TopMost to true pulls the form to the front and holds it there. Setting it to false doesn't push it back but does allow other forms to be shown in front. I was still having problems with focus so I ended up going with the following:

form.Activate();

这篇关于设置活动窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆