用winapi获取监视器友好名称 [英] get monitor friendly name with winapi

查看:88
本文介绍了用winapi获取监视器友好名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在控制面板中获取监视器名称。我用这个代码



I want get monitor name as in control panel. I use this code

DISPLAY_DEVICE lpDisplayDevice = new DISPLAY_DEVICE(0); // OUT
DISPLAY_DEVICE monitor_name = new DISPLAY_DEVICE(0);
int devNum = 0;
while (EnumDisplayDevices(null, (uint)devNum, ref lpDisplayDevice, 0))
  {
     lpDisplayDevice.DeviceName.Trim());
     Console.WriteLine("DeviceString =" + lpDisplayDevice.DeviceString.Trim());
     EnumDisplayDevices(lpDisplayDevice.DeviceName, 0, ref monitor_name, 0);
     Console.WriteLine("Monitor name =" + monitor_name.DeviceString.Trim());
      ++devNum;
 }



但这会让我回复 \\.\DISPLAY4 。我看了这个主题 url msdn [ ^ ]但只能用c语言找到解决方案。


but this return me \\.\DISPLAY4 . I watch this topic url msdn[^] but find solution only in c language.

推荐答案

引用:

但只能用c语言找到解决方案

but find solution only in c language





ok,我们暂时假设这就是全部......你可以把c语言部分包装成一个dll并且你不能用它来解决它吗?



否则,因为c代码可能只是调用win32 api,所以从c#中调出它们?



ok, lets assume for the moment that that's all there is .. you could wrap the c language parts into a dll and pinvoke it couldn't you ?

else, since the c code is likely just calling win32 api's anyway, pinvoke them from c# ?


为什么不试试Windo管理仪器(WMI)?这可能会容易得多(但确实如此:在一些计算机上,WMI存在缺陷,需要修复......)。
Why don't you try Windows Management Instrumentation (WMI)? That could be much easier (but true: on some comuters, WMI is defect and needs to be repaired...).


这篇关于用winapi获取监视器友好名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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