c++ - EnumDisplayMonitors callback -
I am trying to use EnumDisplayMonitors to create a dynamic array of each monitor and archive the DISPLAY_DEVICE structure. Why is not the following code correct?
BOOL callback MyInfoEnumProc (HMONITOR hMonitor, HDC HDC monitor, LPRECT LCR monitor, LPARAM dwData) {MONITORINFOEX iMonitor; IMonitor.cbSize = sizeof (MONITORINFOEX); GetMonitorInfo (hMonitor, and iMonitor); If (iMonitor.dwFlags == DISPLAY_DEVICE_MIRRORING_DRIVER) {return true; } Else {* reinterpret_cast & lt; Screenshare * * (dwData) = ScreenAir (& amp; iMonitor); Back true; }; } called
ScreenArrayMonerArere [15]; Int i = 0; EnumDisplayMonitors (NULL, NULL, MyInfoEnumProc, reinterpret_cast & lt; LPARAM & gt; (and Monearre [i ++])); The first in the array (Monierre [[0]) gives correct information for the second monitor, but the monorail [1] is the maximum value.
Edit: The method I used to solve was implementing a function I created:
Monearre * mA = reinterpret_cast & lt; Monearre * & gt; (DwData); Majority & gt; AddScreen (& amp; iMonitor);
Callback is called once for every monitor, but your callback is via Not growing every time it is called array. Instead, you have to do more about it:
struct ScreenArrayInfo {ScreenArray * Array; Int calculation; Int Maxcount; }; BOOL Callback MyInfoEnumProc (HMONITOR H Monitor, HDC HDC Monitor, LPRECT LCR Monitor, LPARAM dwData) {MONITORINFOEX iMonitor; IMonitor.cbSize = sizeof (MONITORINFOEX); GetMonitorInfo (hMonitor, and iMonitor); If (iMonitor.dwFlags == DISPLAY_DEVICE_MIRRORING_DRIVER) {return true; } Else {ScreenArrayInfo * info = reinterpret_cast & lt; ScreenArrayInfo * & gt; (DwData); If (info-> calculation == info-> MaxCount) return false; Info- & gt; Array [info-> Count] = screenAir (& amp; iMonitor); Info- & gt; Calculation ++; Back true; }; } ScreenEir Monierere [15]; Screenshare information; Info.Array = Monirere; Info.Count = 0; Info.MaxCount = 15; EnumDisplayMonitors (NULL, NULL, & MyInfoEnumProc, reinterpret_cast & lt; LPARAM & gt; (& amp; info)); Alternatively:
#include & lt; Vector & gt; BOOL Callback MyInfoEnumProc (HMONITOR H Monitor, HDC HDC Monitor, LPRECT LCR Monitor, LPARAM dwData) {MONITORINFOEX iMonitor; IMonitor.cbSize = sizeof (MONITORINFOEX); GetMonitorInfo (hMonitor, and iMonitor); If (iMonitor.dwFlags == DISPLAY_DEVICE_MIRRORING_DRIVER) {return true; } And {reinterpret_cast & lt; Std :: vector & lt; Screen Array & gt; * & Gt; (DwData) - & gt; Push_back (ScreenAir (& amp; iMonitor)); Back true; }; } Std :: vector & lt; ScreenArray & gt; MonitorArray; EnumDisplayMonitors (NULL, NULL, and MyInfoEnumProc, reinterpret_cast & lt; LPARAM & gt; (& amp; Monierrere));
Comments
Post a Comment