Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the Monitor Screen Resolution from a hWnd?

Tags:

How to get the monitor screen resolution from a hWnd?

I am using a hWnd because the window could be located on any one of multiple monitors.

i.e. the hWnd top/left coordinate is on a Monitor that has a Screen Resolution of 800 x 600.

I program in a language called PL/B and it allows calling Windows API.

What Window APIs can be used?

like image 749
Gerhard Weiss Avatar asked Jan 28 '10 16:01

Gerhard Weiss


People also ask

How do I find my screen resolution in C++?

h> Display* disp = XOpenDisplay(NULL); Screen* scrn = DefaultScreenOfDisplay(disp); int height = scrn->height; int width = scrn->width; with the linker option -lX11 .

How do I scale my screen to fit my monitor?

Adjust size and color To scale up everything on your screen, select the Start button, then select Settings > System > Display, and change the Scale drop-down menu under Scale & Layout to a larger percentage.


1 Answers

Here's a C++ code example that works for me:

HMONITOR monitor = MonitorFromWindow(hwnd, MONITOR_DEFAULTTONEAREST); MONITORINFO info; info.cbSize = sizeof(MONITORINFO); GetMonitorInfo(monitor, &info); int monitor_width = info.rcMonitor.right - info.rcMonitor.left; int monitor_height = info.rcMonitor.bottom - info.rcMonitor.top; 
like image 62
sidewinderguy Avatar answered Oct 23 '22 15:10

sidewinderguy