检测何时连接了新显示器 [英] Detect when new display is connected

查看:48
本文介绍了检测何时连接了新显示器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个需要两个显示的应用程序:一个用于控制面板,另一个用于输出.我的意思是:如果只有一个显示,则应用程序会在上面显示两种形式,但是如果有两种,则输出形式转到另一种形式.问题在于,这仅在启动应用程序时发生.换句话说,如果在连接第二个显示器之前应用程序已经在运行,则除非用户手动将输出发送到新的显示器(假设他们知道如何做),否则什么也不会发生.我想要的是,当连接了新的显示器时,即使在应用程序运行时,输出表单也会自动发送给它.我认为这与轮询线程中的端口有关,但我不知道该怎么做.任何人都可以帮忙吗?如果有更好的解决方案,我会很高兴地欢迎您.

I'm writing an application that requires two displays: one for the control panel, the other for the output. What I have is this: if there's only one display, the application shows both forms on it but if there are two, the output form goes to the other. The problem is that this only happens when the application is started. In other words, if the application is already running before the second display is connected, nothing happens unless the user sends the output to the new display manually (assuming they know how to do it). What I want is that when a new display is connected, the output form is automatically sent to it even while the application is running. I think it has to do with polling a port in a thread but I don't know how to do it. Can anyone help with how to do it? If there is a better solution, I'll gladly welcome it.

(我会提供部分代码,但我是通过电话输入的)

(I would have provided some part of the code but I'm typing this from a phone)

推荐答案

此处的新人:有一个示例可以为您提供帮助.尝试这样的事情:

There's an example which should help you. Try something like this:

protected override void WndProc(ref Message m) 
{
    const uint WM_DISPLAYCHANGE = 0x007e;

    // Listen for operating system messages. 
    switch (m.Msg)
    {
        case WM_DISPLAYCHANGE:

            // The WParam value is the new bit depth
            uint width = (uint)(m.LParam & 0xffff);
            uint height = (uint)(m.LParam >> 16);
            break;                
    }
    base.WndProc(ref m);
}

这篇关于检测何时连接了新显示器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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