CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    Jun 2010
    Posts
    4

    Detect Current Display/Screen

    Hello,

    I want to build a tiny application in Windows Vista. It should tell me, whether it (the application window itself) is displayed on the screen of a laptop or on an external screen. I'd like to use C++ in VisualStudio 08.

    I seriously don't have a clue about programming for Windows, don't even know which way to approach this problem or which libraries to use. I would totally appreciate if someone of you guys/girls could help me out with a quick hint.

    Cheers, Seb

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: Detect Current Display/Screen

    Victor Nijegorodov

  3. #3
    Join Date
    Aug 2000
    Location
    New York, NY, USA
    Posts
    5,656

    Re: Detect Current Display/Screen

    I am not sure you CAN tell which monitor is external.
    The suggested GetMonitorInfo function will return a device (adapter) name like “\\.\DISPLAY1”. How would that help?
    Vlad - MS MVP [2007 - 2012] - www.FeinSoftware.com
    Convenience and productivity tools for Microsoft Visual Studio:
    FeinWindows - replacement windows manager for Visual Studio, and more...

  4. #4
    Join Date
    Jun 2010
    Posts
    4

    Re: Detect Current Display/Screen

    Hi again, and thanks for both answers!

    The Multiple Displays Monitor Functions was exactly what I was looking for, I hope..at least, it feels good. When I understood Vladimir right, you can't yet tell which monitor is external, since one could use the external monitor as primary display.

    On the other hand, with making a WQL Query on the WmiMonitorConnectionParams (by stupidly altering about two lines of the example code as seen on http://msdn.microsoft.com/en-us/libr...=VS.85%29.aspx ), I can distinguish between an internal and an external display.

    Well, now I'm not yet quite sure if I can map these both informations...or if i don't see the simple solution..

  5. #5
    Join Date
    Jun 2010
    Posts
    4

    Re: Detect Current Display/Screen

    Ok, I have to do it another way, because:

    GetMonitorInfo gives me \\.\DISPLAY1
    WMIMonitorID querying gives me sth. like DISPLAY\LGD0032\7&14066721&0&UID50331920_0
    MonitorConnectionParams querying gives me 2147483648 for internal and sth. else for all external screens

    that's pretty much it...i must have missed something, because this looks not too good for mapping, no clue how to proceed from there

    anyone does?

  6. #6
    Join Date
    Aug 2000
    Location
    New York, NY, USA
    Posts
    5,656

    Re: Detect Current Display/Screen

    Quote Originally Posted by SebGarcia View Post
    ...MonitorConnectionParams querying gives me 2147483648 for internal and sth. else for all external screens
    That is actually a pretty interesting result: 2147483648 is 0x8000000 in hex. The highest bit set in the result usually indicate some special condition. Could you possibly use that?
    Vlad - MS MVP [2007 - 2012] - www.FeinSoftware.com
    Convenience and productivity tools for Microsoft Visual Studio:
    FeinWindows - replacement windows manager for Visual Studio, and more...

  7. #7
    Join Date
    Jun 2010
    Posts
    4

    Re: Detect Current Display/Screen

    yes, the 0x8000000 is the flag (http://msdn.microsoft.com/en-us/library/ff546605.aspx) for an internal display.

    actually i have all the information i need, just the link is missing
    * a window is positioned on \\.\DISPLAY1 or \\.\DISPLAY2 and this monitor is primary or not
    * MISSING: \\.\DISPLAY1 == \DISPLAY\LGD0032\7&14066721&0&UID50331920_1 or
    \DISPLAY\NEC6692\7&14066721&0&UID50331921_1
    * \DISPLAY\..... is internal or external

    and this is the problem...or..the challenge

    tricky tricky

    puh...more infos:
    * WMIMonitorConnectionParams and WMIMonitorID classes give me an InstanceName "\DISPLAY\LGD0032\..." etc.
    * EnumDisplayDevices and Victors GetMonitorInfo functions give me a DeviceName "\\.\DISPLAY1" etc.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured