Introduction

If you use Windows XP and a dual monitor, this article will prove to be useful. The code will launch the display control 'applet' and send it keystrokes (the same way you would if you use keyboard navigation) to extend the monitor to the secondary attached monitor.

Background

It is a known fact that using multiple monitors can help improve your productivity. Some people find it confusing when using more than one monitor - this article is not meant for them. You can dock, let's say your email client/calendar on one monitor and your source code editor (Eclipse) on the other one. Or you can dock your music player on one monitor and the article you are pretending to read on the other.

Using the Code

The code is a complete application packaged into a single class file. All you have to do to use the code is:

java MultiMon

A brief explanation of how the code achieves the desired result is discussed below:

First the display panel is launched using:

Runtime.getRuntime().exec("control.exe desk.cpl,@0,3");

This will also cause the third tab in the display control panel to be selected.

Create an instance of the java.awt.Robot class, this class will help us send the desired key strokes to the display control panel.

We then use...

robot.keyPress(KeyEvent.VK_D + KeyEvent.ALT_MASK);

... to send keystrokes, as in the case above ALT+D to the display control panel. And so on...

The keystrokes the code sends out is the same as the ones that you would use if you were to use the keyboard only to toggle the monitor.

Invoke the program using the batch file or compile the source code and run the generated class file.

Note: For ease of use, the class is not included in any package, but is in the default package. However it is a recommended approach to always use packages for the classes.

Of course, you need to make sure that JDK is installed on your machine.

Points of Interest

Ideally you would like to implement such an application in a Win32 technology using the Windows API to achieve the necessary result. But then, I've just used Java...

I just learnt how lazy I can get and I'm not the only one looking at the Google results for requests for such a solution. I spent less than an hour researching and writing this code. In case you have any positive comments, I'd be glad to hear them.

Certain graphic cardset manufacturers like nVidia have software that provides 'enhanced' desktop extensions. These may be better than the extension that XP provides.

Shog -
1) Perhaps if you read what the article says it might make more sense. It says this is applicable for XP.
2) I really don't need to make applications work well on multi-monitor systems. Thanks for the input anyway. Perhaps you may want to consider spending your time on learning that ?

I read the article. I saw a problem with the article. I posted a reply noting the problem with the article.
If you don't understand it, then ask for clarification. Putting vague expressions of confusion in a numbered list doesn't make you look any less confused.

I read the article. I saw a problem with the article. I posted a reply noting the problem with the article.
If you don't understand it, then ask for clarification. Putting vague expressions of confusion in a numbered list doesn't make you look any less confused.

If you did find a problem with the article, I'd be glad to resolve it.
You were asked for clarification, refer to my earlier response.
Oh yes and reading stuff may also help you.

ontrolling Windows settings by faking input events to system dialogs is unreliable, dangerous...

"unreliable" - yes. This application is not guaranteed to work.

"dangerous" - I'll add a disclaimer to the article -

All users please note - "The code in this application is meant for personal usage, it is not authorized for usage in the real time, mission critical or health provider software. I will not be responsible for any & all losses by usage or non usage of this program not limited to and including bsod, earthquake, fire & divorce" If it works for you, that's good. If it doesn't keep the forums clean, go whine to your mama.