Multiple Montitor Programming


I have written a program to detach a 2nd display from the desktop programatically (ie not using the control panel display settings).

The relvant lines of code to do this are shown below.

    video_mode.dmFields =  DM_POSITION | DM_PELSWIDTH | DM_PELSHEIGHT ;
    video_mode.dmPelsHeight = 0;                        // pixel height & width of the screen,
    video_mode.dmPelsWidth = 0;                         // both must be 0 to detach from desktop

    rtn1 = ChangeDisplaySettingsEx(display_device.DeviceName, &video_mode, NULL, CDS_UPDATEREGISTRY, NULL);

THis works and detaches the monitor from the desktop and i can get a handle to the screen and draw to it no problems. The problem is however when the screen saver comes on. When the screen saver comes on, the second display, which i detached from the desktop using my software, re-attaches itself to the dektop when the screen saver goes off. This is obviously undesired since i want my process to have sole control over what goes onto that screen at all times screen saver or not.

Does anyone have any suggestions as to how to keep control of the second independant display after the screen saver?

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

I've never done this, but I've written a screen saver so my suggestions are as follows:

You are able to get the state of the screen saver running using SystemParametersInfo like so:
SystemParametersInfo(SPI_GETSCREENSAVERRUNNING, 0, &boolval, 0);

you can check to see if it's been switched from running to not running on a timer and then re-do your code...

also you can trap the WM_SYSCOMMAND message and check for a wparam of SC_SCREENSAVE ... this gets sent to all top-level windows when the screen saver is being activated... you can process this message by returning FALSE to stop the screen saver from kicking in.

maybe more research into those leads will yield your answer.
  You can try this.
video_mode.dmFields =  DM_POSITION ;

And remove these two fields DM_PELSWIDTH | DM_PELSHEIGHT .

I presume that you got the video_mode structure thru a call to EnumDisplaySettings.


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Development

From novice to tech pro — start learning today.