Command for moving applications between two monitors

rowead's picture

I've upgraded my workstation and now I have 2 x 21 inch monitors. to make it easier to manage my programs I created this Dragon macro to swap applications between monitors

Declare Function GetWindowRect Lib "USER32" ( ByVal hWnd As Long, lpRect As RECT) As Long

Const SWP_NOZORDER = &H4 'Ignores the hWndInsertAfter.
Const SWP_NOSIZE = &H1

Declare Function SetWindowPos Lib "user32" ( _
ByVal hwnd As Long, ByVal hWndInsertAfter As Long, _
ByVal x As Long, ByVal y As Long, ByVal cx As Long, _
ByVal cy As Long, ByVal wFlags As Long) As Long

Type RECT
rLeft As Long
rTop As Long
rRight As Long
rBottom As Long
End Type
Declare Function GetForegroundWindow Lib "user32" () As Long
Declare Function GetWindowRect Lib "USER32" ( ByVal hWnd As Long, lpRect As RECT) As Long

Sub Main
Dim r As rect, h As Long
Const MONITOR_WIDTH = 1280
Dim xAdd As Long

h = GetForegroundWindow

GetWindowRect h, r
If r.rLeft >= MONITOR_WIDTH Then
' on the right hand side
xAdd = -MONITOR_WIDTH
Else
' on the left hand side
xAdd = MONITOR_WIDTH
End If
SetWindowPos h, SWP_NOZORDER + SWP_NOSIZE, r.rLeft + xAdd, r.rtop, r.rRight - r.rLeft, r.rBottom - r.rTop, 0
End Sub

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
KnowBrainer's picture

That looks like a great

That looks like a great command but there is a much simpler “non-command” option which would be to stretch your Desktop across both monitors and simply use NaturallySpeaking’s built in Switch to <name of window> command to jump back and forth.  When you stretch your Desktop across multiple monitors you have the additional advantage of being able to see multiple pages.  We can view 12 pages of a Microsoft Word document on our 4 30 inch monitors employing this technique.  You can also pre-size your Windows and decide which monitor you want them to land on in most of your programs.  The next time you double click a folder or program, it'll land on the right monitor and in the right size.  You can also move your mouse across the different monitors without interruption.

 

 

Lunis Orcutt - Developer of KnowBrainer  (DNS Command Software)

A Nuance Gold Certified Endorsed Vendor

rowead's picture

When developing it is nice

When developing it is nice to have doco on one screen and programming on another. Or chat sessions. I wanted an easier way to arrange my apps. Having a screen go over 4 monitors is way too much

Hello, In unimacro I

Hello,

In unimacro I implemented task switching with an additional command, which can be in this (my) case "other display" (having (only) two displays).

Implementation is with shortcut keys which can be defined in my screen properties (NVIDIA) windows.

See the unimacro page on tasks and look for "task other display".

Quintijn

rowead's picture

Short cut keys? How about

Short cut keys? How about voice commands?

Read unimacro page above...

Read unimacro page above... The voice commands execute the shortcut keys. (And they can used by hand as well.)

Quintijn

There are some basic vocola

There are some basic vocola commands available as samples which will allow you to resize and move application windows. They could probably be quite easily adapted to one's particular screen layout. VoicePower has some built-in commands for resizing and moving which work across two monitors, for example "place program monitor 2".

Hello rowead and all the

Hello rowead and all the others,

for all who can/like to spend some bucks
(US-$ 40) take a look at UltraMon:
http://www.realtimesoft.com/ultramon/
You can really do a lot of useful things
with that tool (e. g. "Smart Taskbar"):
http://www.realtimesoft.com/ultramon/tour/
http://www.realtimesoft.com/ultramon/tour/smart_taskbar.asp

I'm using UltraMon with DNS 9.1 prof.,
you can access UltraMon via its COM-Interface.
http://www.realtimesoft.com/ultramon/tour/scripting.asp

Greetings
Udo

Before splashing out, NB

Before splashing out,

NB Vista support is still under development (and has been for some time so it seems):

http://www.realtimesoft.com/multimon/forum/messages.asp?Topic=7781&tmpl=...

Graham

I just got a second monitor,

I just got a second monitor, and have been trying to use the macro that was posted to begin this thread. Unfortunately, I get the following error message: Line 1, Position 77, expecting a valid data type (e.g. Integer).

If you really want to enjoy

If you really want to enjoy the use of two monitors, take a look at VoicePower. Our exclusive technology includes (always expanding) support for two monitors. VoicePower provides quick and easy speech commands to:
1) Position your active application on one of your monitors.
2) Switch to any open program while simultaneously positioning the program on one of the monitors.
3) Opening an email attachment while simultaneously positioning the attachment on one of your monitors.
4) Opening any document while positioning it on one of your monitors.
5) Positioning or dragging your mouse anywhere on one of your monitors.
6) Optionally, displaying a screen grid on one your monitors as a reference for (5).
7) Displaying some 80 lessons and demonstrations as well as lists of well over 10,000 speech commands on one of your monitors as you continue to work in your applications on another monitor.

For more about VoicePower, visit us on the web at www.voiceteach.com.

Ron

No, thanks. I was really

No, thanks. I was really hoping for advice on the macro that started this thread. Could we keep the responses on that topic? If you want to advertise, that's fine, but it seems you could at least offer a constructive solution to my question.

I posted because the thread

I posted because the thread indicated that people have tried many different things, but nothing really seemed to work.
My apologies.
Ron

Thank you, Ron. I'm sorry if

Thank you, Ron.

I'm sorry if I sounded a little arch, but I was happy to get an e-mail saying that someone had responded to this thread, and then to find out that the response really didn't have anything for me.

I'm sure that Voice Power is a very helpful application, but I tend to be a do it yourself kind of computer user.

Matt

rowead's picture

move the definition for the

move the definition for the function:

Declare Function GetWindowRect Lib "USER32" ( ByVal hWnd As Long, lpRect As RECT) As Long

To below the definition for type RECT. That should make it work.

Sorry for the mess, but i had to take some code out of a shared library file and did not really check if I put it into the function properly.

actually, that line is

actually, that line is already in the macro, below the definition for type RECT. It looks to me like that line is in there twice, in other words. If I comment out the first occurrence, nothing happens when I run the macro.

seems like there ought to be some code like this somewhere in the expanse of the Internet, but I haven't been able to find it.

rowead's picture

Just delete that duplicate

Just delete that duplicate GetWindowRect. although when I tested this it didn't seem to do anything.

I'm sure it did before I posted here. Just tested. I had the parameters wrong on 'SetWindowPos'. Here is the correct code.

'================================
Option Explicit

Const SWP_NOZORDER = &H4 'Ignores the hWndInsertAfter.
Const SWP_NOSIZE = &H1

Declare Function SetWindowPos Lib "user32" ( _
ByVal hwnd As Long, ByVal hWndInsertAfter As Long, _
ByVal x As Long, ByVal y As Long, ByVal cx As Long, _
ByVal cy As Long, ByVal wFlags As Long) As Long

Type RECT
rLeft As Long
rTop As Long
rRight As Long
rBottom As Long
End Type
Declare Function GetWindowRect Lib "USER32" ( ByVal hWnd As Long, lpRect As RECT) As Long
Declare Function GetForegroundWindow Lib "user32" () As Long

Sub Main
Dim r As rect, h As Long
Const MONITOR_WIDTH = 1280
Dim xAdd As Long, x As Long

h = GetForegroundWindow

GetWindowRect h, r
If r.rLeft >= MONITOR_WIDTH Then
' on the right hand side
xAdd = -MONITOR_WIDTH
Else
' on the left hand side
xAdd = MONITOR_WIDTH
End If
x = SetWindowPos( h, 0, r.rLeft + xAdd, r.rtop, r.rRight - r.rLeft, r.rBottom - r.rTop, SWP_NOZORDER + SWP_NOSIZE )
MsgBox CStr(x)
End Sub

'===========================================

Thank you! That did it.

Thank you! That did it.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.




view recent posts