Home > Windows API > Get work area rectangle along with main rectangle of desktop

Get work area rectangle along with main rectangle of desktop

Use GetMonitorInfo.

MONITORINFO miMonInfo = { 0 };
miMonInfo.cbSize = sizeof( miMonInfo ); 

// Get associated monitor for our window
HMONITOR hMonitor = MonitorFromWindow( GetSafeHwnd(),
				  MONITOR_DEFAULTTONEAREST ); 

// Get monitor information
GetMonitorInfo( hMonitor, &miMonInfo );   

// miMonInfo.rcWork    --> Work area rectangle
// miMonInfo.rcMonitor --> Monitor display rectangle

To get name of monitor use MONITORINFOEX instead of MONITORINFO and set cbSize member to sizeof( MONITORINFOEX ).

Some other monitor related functions in which you will be interested include

  • MonitorFromPoint
  • MonitorFromRect
  • EnumDisplayMonitors
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: