I am not c++ programmer, I just use c. So this may be not correct. But this c algorithm should work.
Basically windows 95 and nt does not support multiple monitors. Anyway, why C::B requires multiple
monitors support? There are many warys of getting single monitor geometry, if you ignore multiple
monitors.
+static HMONITOR APIENTRY (*MonitorFromWindowProc) (HWND, DWORD) = NULL;
+static BOOL APIENTRY (*GetMonitorInfoProc) (HMONITOR, LPMONITORINFO) = NULL;
void PlaceWindow(wxWindow *w, cbPlaceDialogMode mode, bool enforce)
{
+ int MultiMonOk = 1;
...
...
- hMonitor = MonitorFromWindow((HWND) referenceWindow->GetHandle(), MONITOR_DEFAULTTONEAREST);
+ if (MonitorFromWindowProc) {
+ /* MonitorFromWindowProc already set */
+ hMonitor = (*MonitorFromWindowProc)((HWND) referenceWindow->GetHandle(),
MONITOR_DEFAULTTONEAREST);
+ } else {
+ /* check API availability */
+ MonitorFromWindowProc =
+ (HMONITOR APIENTRY (*) (HWND, DWORD))
+ GetProcAddress(GetModuleHandle("user32.dll"), "MonitorFromWindow");
+ if (MonitorFromWindowProc)
+ hMonitor = (*MonitorFromWindowProc)((HWND) referenceWindow->GetHandle(), MONITOR_DEFAULTTONEAREST);
+ else {
+ /* API not available, maybe Win95 or NT 3/4. */
+ MultiMonOk = 0;
+ }
+ }
+ if (MultiMonOk) {
mi.cbSize = sizeof(mi);
- GetMonitorInfo(hMonitor, &mi);
+ if (GetMonitorInfoProc) {
+ (*GetMonitorInfoProc)(hMonitor, &mi);
+ } else {
+ GetMonitorInfoProc =
+ (BOOL APIENTRY (*) (HMONITOR, LPMONITORINFO))
+#ifdef UNICODE
+ GetProcAddress(GetModuleHandle("user32.dll"), "GetMonitorInfoW");
+#else
+ GetProcAddress(GetModuleHandle("user32.dll"), "GetMonitorInfoA");
+#endif
+ if (GetMonitorInfoProc) (*GetMonitorInfoProc)(hMonitor, &mi);
+ else {
+ /* not possible, unknown error */
+ goto genericRect;
+ }
+ }
r = mi.rcWork;
+ } else {
+genericRect:
+ HWND hDesktop;
+ int rc;
+ hDesktop = GetDesktopWindow();
+ /* if (hDesktop == NULL) criticalErrorExit(); */
+ rc = GetWindowRect(hDesktop, &r);
+ /* if (rc==0) error(); */
+ }
...
}
I think you should convert this to proper C++ version.
Insteadd of GetDesktopWindow(), you can use GetSystemMetrics with SM_CXSCREEN and SM_CYSCREEN (maybe). I have installed platform SDK and documentation includes all windows specific APIs.
I think this kind of runtime checking of API is used in many windows porting of unix programs like perl etc.
In test, windows rectangle's right bottom part returns 1 point right down the region. If resolution is 1024x768, then
returned point is {(0, 0), (1024, 768)}. Not {(0, 0), (1023, 767) }