Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9222869
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T03:56:16+00:00 2026-06-18T03:56:16+00:00

I am trying to get monitor data from the windows API. The GetSystemMetrics() command

  • 0

I am trying to get monitor data from the windows API.
The GetSystemMetrics() command returns the wrong width in pixels.
According to Microsoft’s website this is because I need to SetProcessDPIAware()

which means I should preferably be able to create an application manifest which I do not understand.

In searching for an equally low level alternative I found the multiple display monitors functions and structs. I must pass HMONITOR to access the rect structure I want but getting HMONITOR is where I am having issues.

MonitorFromWindow(hwnd,MONITOR_DEFAULTTOPRIMARY)
This command is out of scope- strange because GetMonitorInfo() [which I need HMONITOR for] doesn’t cause any issues. I already have windows.h and windowsx.h included. Am I missing a library or what is the issue?

On a separate note, after looking there it became evident that it might also be nice to make the monitor used user-adjustable. SM_CMONITORS should return a count but I would like to know how to convert these numbers to the HMONITOR data I need to get monitor specific information.

::Edit::

I am putting the edit here because the “comment” feature does not provide me with enough space to place the code clip which was requested

Also, I am using GNU GCC with MinGW

#include <iostream>//using these libraries
#include <Windowsx.h>
#include <windows.h>

using namespace std;

int main()
{
    //should print screen width in pixels

    LPMONITORINFO target;
        //create a monitor info struct to store the data to
    HMONITOR Hmon = MonitorFromWindow(hwnd,MONITOR_DEFAULTTOPRIMARY);
        //create a handle to the main monitor
        //(should start at top left of screen with (0,0) as apposed to other monitors i believe)
        //if i could gather aditional info on what monitors are available that might be           useful
    GetMonitorInfo(Hmon, target);
        //Get the necessary data and store it to target

    cout << "bottom of selected monitor in pixels: " << target->rcMonitor.bottom
         << "Top of the selected monitor" << target->rcMonitor.top
         << "right extreme of selected monitor" << target->rcMonitor.right
         << "left extreme of selected monitor" << target->rcMonitor.left;

    return 0;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T03:56:17+00:00Added an answer on June 18, 2026 at 3:56 am

    If you want to use features that appeared after Windows 95/Windows NT 4, you must specify the WINVER before compiling.

    Windows 2000 is WINVER 0x0500, so the compile line needs to add -DWINVER=0x500 in order to see the MONITOR_DEFAULTTOPRIMARY constant.

    You need to allocate a MONITORINFO struct, not a pointer to a MONITORINFO struct, and intialize the cbSize field so that Windows knows what information to populate, so in your code:

    MONITORINFO target;
    target.cbSize = sizeof(MONITORINFO);
    
    HMONITOR hMon = MonitorFromWindow(GetDesktopWindow(), MONITOR_DEFAULTTOPRIMARY);
    GetMonitorInfo(hMon, &target);
    

    And then display using:

     target.rcMonitor
    

    instead of

    target->rcMonitor
    

    Using SetProcessDPIAware(), is a feature of Windows Vista, so WINVER needs to be set to 0x0600, but the headers shipped with MinGW don’t appear to be a complete set of headers for Windows Vista – That function definition is missing, but is present in the Windows 7 SDK headers (I don’t have the Windows Vista SDK at hand to check it on).

    So, using a manifest seems like an easier solution than pulling the newer APIs.

    Monitor handles are meant to be an opaque representation of a monitor – i.e. the value you get should not be used for anything other than other monitor functions. If you want to walk the monitor structures, you should use the EnumDisplayMonitors function, and an appropriate callback routine.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to get only the service name from the data i am
I'm trying get the visible portion of UIImage from an UIImageView . UIImageView takes
I'm trying to monitor my core data usage but all the Core Data instruments
I'm trying to send a very basic XML string from a Windows Phone application
I'm trying to get a the app data for the applications currently available on
I'm trying to load data from a csv file to my rails database. this
I am trying to monitor some of the MBeans from JMX server in BAM.
I am trying to parse data I am getting from an arduino robot I
I am trying to create a highchart line graph using data from a .csv
I'm currently calling the Facebook graph API from one of my actions which returns

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.