 |
|
 |
You have a few typos on this page...
Then we change the code from: CRect rect;
Rect.left = 0;
Rect.top = 0;
Rect.right = rect.left + ::GetSystemMetrics(SM_CYSCREEN);
Rect.bottom = rect.top + ::GetSystemMetrics(SM_CXSCREEN);
To CRect rect;
Rect.left = ::GetSystemMetrics(SM_XVIRTUALSCREEN);
Rect.top = ::GetSystemMetrics(SM_YVIRTUALSCREEN);
Rect.right = rect.left + ::GetSystemMetrics(SM_CYVIRTUALSCREEN);
Rect.bottom = rect.top + ::GetSystemMetrics(SM_CXVIRTUALSCREEN);
First off, copying and pasting this code doesn't work because you changed the case of rect to Rect... should be CRect Rect; instead of CRect rect;
Secondly, you switched the x and y on the last 2 lines there... made the width of the rect equal to the height of the screen and the height of the rect to the width of the screen. Confused me for a second when i copied and pasted the code. otherwise, it works great. thanks!
Levi
|
|
|
|
 |
|
 |
I am writing a program for a Scoreboard that contains a SplitterWnd, the upper Window (ScoreboardWnd) displays the whole screen with (Period Time, Scores, .. etc). The lower window contains all the Input’s and Buttons to administrate the Scoreboard.
I now want to display only the ScoreboardWnd on another VGA screen (Full mode).
I have looked at the CMonitor class and tested it properly.
On a Laptop with a 2nd VGA out I connected a 2nd TFT screen to see how the program works.
Now a few questions: How can I display out from a SplitterWnd a window on the 2nd screen?
On the laptop the whole program should be displayed.
The program is made with VC 7.xx!
It would be great if you have a sample for such a case I described above. Great work by the way!
Thanks in advance
Best regards
Karl Bahr
|
|
|
|
 |
|
 |
I haven't tried this on my home machine yet, but my 4 monitors are set up as such:
+---+
| 1 |
+---+---+---+
| 2 | 3 | 4 |
+---+---+---+
Assuming 1024x768 for each monitor (for simplicity), looking at the above code, wouldn't this simply return the total size as a simple 3072x1536 rectangular area? So if you're assuming this rectangle as your screen saver's "canvas", you're essentially wasting 1/3 of all your calculations on a non-existing area?
I think the "clean" solution is really still to enumerate all the monitors individually, get the current resolution for each, and (this is the part I'm not sure of) figure out the physical layout like the Display control panel utility does (what APIs can be used to figure out this part?)
[edit]
ASCII art sucks!
[/edit]
|
|
|
|
 |
|
 |
I've had the same problem with multiple monitors - especially when the user decides to rearrange or remove a monitor (first having the primary monitor to the left and then moving it to the right). It turns out that GetSystemMetrics does not return a consistent value - a SM_CXVIRTUALSCREEN of 3000+ when there really are just two 1024 monitors. I think this is a more sound solution:
BOOL CALLBACK EnumMonitorCallback(
HMONITOR hMonitor, // handle to display monitor
HDC hdcMonitor, // handle to monitor-appropriate device context
LPRECT lprcMonitor, // pointer to monitor intersection rectangle
LPARAM dwData // data passed from EnumDisplayMonitors
)
{
LPRECT rct = (LPRECT)dwData;
UnionRect(rct, rct, lprcMonitor);
return TRUE;
}
void GetFullScreenRect(LPRECT inRct)
{
RECT rct={0,0,0,0};
EnumDisplayMonitors (
NULL, // handle to a display device context
NULL, // specifies a clipping rectangle
EnumMonitorCallback, // pointer to a callback function
(LPARAM)&rct // data passed to the callback function
);
CopyRect(inRct, &rct);
}
IMHO, the virtual desktop simply cant be trusted
/M
|
|
|
|
 |
|
 |
Your solution works like a champ!
I liked it best because it should handle more than two monitors.
Thanks
|
|
|
|
 |
|
 |
COOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOL!!! Voll fett!
The best solution about this problem I've seen up to now. Simple and short. I love this piece of code.
THANKS A LOT.
|
|
|
|
 |
|
 |
Hi,
I've noticed that if I have a window stretched over two monitors, when the screensaver stops, the window is only one monitor wide. This is a real pain when using Visual Studio, because I have to keep resizing the main window so it covers both screens again.
Any thoughts on how I can prevent this?
Cheers,
Steve.
|
|
|
|
 |
|
 |
It is possible to adapt the program so that it can open to a video in a system multimonitor?
Any Idea?
Thanks...Javier.
|
|
|
|
 |
|
 |
First of all thanks for sharing code on codeproject.
I think the code above will not work correctly. To begin with, you are assigning height of virtual desktop as width of your rectangle and width of desktop as height which is wrong...
CRect rect;
Rect.left = ::GetSystemMetrics(SM_XVIRTUALSCREEN);
Rect.top = ::GetSystemMetrics(SM_YVIRTUALSCREEN);
Rect.right = rect.left + ::GetSystemMetrics(SM_CYVIRTUALSCREEN);
Rect.bottom = rect.top + ::GetSystemMetrics(SM_CXVIRTUALSCREEN);
I think what you mean or what you should mean is this
Rect.right = rect.left + ::GetSystemMetrics(SM_CXVIRTUALSCREEN);
Rect.bottom = rect.top + ::GetSystemMetrics(SM_CYVIRTUALSCREEN);
Even then it won't be correct, because in case of two monitors, if I have my secondary monitor on my left side and primary on the right side, rect.left is going to be negative and
Rect.right = rect.left + ::GetSystemMetrics(SM_CXVIRTUALSCREEN);
is still going to give you a wrong value
So correct code to calculate virtual desktop rect would be
CRect rc_virtual_screen;
int virtual_desktop_width = ::GetSystemMetrics(SM_CXVIRTUALSCREEN);
int virtual_desktop_height = ::GetSystemMetrics(SM_CYVIRTUALSCREEN);
rc_virtual_screen.left = ::GetSystemMetrics(SM_XVIRTUALSCREEN);
rc_virtual_screen.top = ::GetSystemMetrics(SM_YVIRTUALSCREEN);
if (rc_virtual_screen.left < 0)
{
// secondary monitor is on the left side
CRect rc_desktop;
::GetWindowRect(GetDesktopWindow()->GetSafeHwnd(), &rc_desktop);
rc_virtual_screen.right = rc_desktop.right;
rc_virtual_screen.bottom = rc_desktop.bottom;
}
else
{
// secondary monitor is on the right side, primary on left
ASSERT(rc_virtual_screen.left == 0);
rc_virtual_screen.right = virtual_desktop_width;
rc_virtual_screen.bottom = virtual_desktop_height;
}
Again this code will work correctly for only two monitors, I did not think about cases with more than two monitors
I did not download your zip file and compile it, just read the article and saw the problem, maybe you did it correctly in the demo project.
Yawar
|
|
|
|
 |
|
 |
Thank you!
When I first used this it was for one computer system only, and one configuration of monitors. I'm sure the code you just gave will help for someone else using multi monitors. However this was only a basic introduction and no code will work for every situation.
Again, Thanks for the code!
Jonathan 'nonny' Newman
blog.nonny.com [^]
|
|
|
|
 |
|
 |
Jonny Newman wrote:
no code will work for every situation
Unfortunately, this statement is true for many applications around. Bad as it is, taking it as an excuse to ignore known issues is pretty much topping it. Of course there are limitations, that is you have to find a good balancing between development effort and result.
In this case, however, I cannot see how this statement could ever be valid, since the win32 API provides you with all you ever need. Although Yawar Maajed raised a valid point he fails to solve the problem, as the calls to GetSystemMetrics return bounding rectangles as opposed to the true region. In particular, if your monitors use different resolutions you'll run into trouble, as your painting will most likely appear clipped on either of your displays. So you should call a combination of EnumDisplayMonitors and GetMonitorInfo to retrieve the true extents of your painting rectangles.
.f
|
|
|
|
 |
|
 |
My mistake! I had an old Microsoft SDK installed on my computer...
|
|
|
|
 |
|
 |
I'm using VC6 to compile and I'm getting a "error LNK2001: unresolved external symbol _xGetSystemMetrics@4"... Been looking everywhere on the Net and still can't find which .LIB I should be linkin' with
|
|
|
|
 |
|
 |
What is the problem here ?
Deleting intermediate files and output files for project 'multiscreen - Win32 Debug'.
--------------------Configuration: multiscreen - Win32 Debug--------------------
Compiling resources...
Compiling...
StdAfx.cpp
Compiling...
multiscreen.cpp
multiscreenDlg.cpp
Generating Code...
Linking...
multiscreen.obj : error LNK2001: unresolved external symbol "public: int __thiscall CSaverWindow::Create(struct HWND__ *)" (?Create@CSaverWindow@@QAEHPAUHWND__@@@Z)
multiscreen.obj : error LNK2001: unresolved external symbol "public: __thiscall CSaverWindow::CSaverWindow(void)" (??0CSaverWindow@@QAE@XZ)
Debug/multiscreen.exe : fatal error LNK1120: 2 unresolved externals
Error executing link.exe.
multiscreen.exe - 3 error(s), 0 warning(s)
|
|
|
|
 |
|
 |
I think you should include the "SaverWindow.h" and "SaverWindow.cpp" in your project.
|
|
|
|
 |
|
 |
In order to get rid of that linker error you must define the COMPILE_MULTIMON_STUBS in your code like this:
#define COMPILE_MULTIMON_STUBS
#include "multimon.h"
And that should fix it (at least it did for me).
|
|
|
|
 |
|
 |
I stand corrected. Still, a very good saying.
"If at first you don't succeed.....you must be installing Windows..."
Windoze CP - Windows without the cr*p (Now with automatic bug eliminator!)
Hey so what if I'm a geek! Byte me!
|
|
|
|
 |
|
 |
CWnd::CreateEx(WS_EX_TOPMOST, myWndClass, #8220;#8221;, WS_POPUP | WS_VISIBLE,
rect.left, rect.top, rectWidth(), rect.Height(), hwndParent, NULL );
Do you see #8220;#8221;, ?
|
|
|
|
 |
|
 |
Thats odd. They are supposed to be quotation marks. Dreamweaver must have put them as a different text encoding or something. I'll change that now.
"If at first you don't succeed.....you must be installing Windows..."
Windoze CP - Windows without the cr*p (Now with automatic bug eliminator!)
Hey so what if I'm a geek! Byte me!
|
|
|
|
 |
|
|
 |
|
 |
Thanks Nish.
Its always nice to have a fan
"If at first you don't succeed.....you must be installing Windows..."
Windoze CP - Windows without the cr*p (Now with automatic bug eliminator!)
Hey so what if I'm a geek! Byte me!
|
|
|
|
 |
|
|
 |
|
 |
Nishant S wrote:
Fa?? Fa-what? Fan????
Don't worry Nish. I know how high your regard me and its not unusual to envy someone of my intellect and prowess.
"If at first you don't succeed.....you must be installing Windows..."
Windoze CP - Windows without the cr*p (Now with automatic bug eliminator!)
Hey so what if I'm a geek! Byte me!
|
|
|
|
 |
|
|
 |
|
 |
We are all standing on the shoulders of giants
"If at first you don't succeed.....you must be installing Windows..."
Windoze CP - Windows without the cr*p (Now with automatic bug eliminator!)
Hey so what if I'm a geek! Byte me!
|
|
|
|
 |