Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you get CreateWindowEx() to create the window on a specific monitor?

I've determined that I can use GetSystemMetrics(SM_CMONITORS) to query the number of attached monitors, but is there any way to control what monitor CreateWindowEx() uses for the window?

like image 523
dicroce Avatar asked Dec 02 '09 18:12

dicroce


2 Answers

Yes, by the "x" and "y" arguments. Use EnumDisplayMonitors (pass two nulls) to enumerate the monitors. Your MonitorEnumProc callback gets a RECT* to the monitor's display rectangle. You'd get a negative RECT.right if a monitor is located at the left of your main one.

like image 92
Hans Passant Avatar answered Sep 24 '22 00:09

Hans Passant


Each monitor simply displays some part of the desktop, so showing the window on a particular monitor is a matter of moving the window to the part of the desktop displayed by that monitor. When you call CreateWindowEx (or CreateWindow) you can specify x and y coordinates for the window, so displaying it on a particular monitor simply means specifying coordinates that fall within the area displayed by that monitor.

You can find the work areas for the monitors on a system with GetMonitorInfo.

like image 41
Jerry Coffin Avatar answered Sep 25 '22 00:09

Jerry Coffin