Jump to content
Sign in to follow this  
kman

Dual Monitor Help

Recommended Posts

kman

I am running this script to display an image depending on the active window. We run dual monitors and I would like this image to display on which ever monitor the active window is on. Is this possible? Thank you!

Const $WIDTH = 500
Const $HEIGHT = 25
$westdest ="C:\Meds\campus\west.gif"
$eastdest ="C:\Meds\campus\east.gif"

$XPOS = -1
$YPOS = 0

Run("\\hmmrpt\Meds\MED-Update.exe","\\hmmrpt\Meds")

ProcessWait("hmm.exe")

While 1
    If WinActive("WEST **MMLIVE**") Then
    SplashImageOn("", $westdest, $WIDTH, $HEIGHT, $XPOS, $YPOS, 17)
    Else
    If WinActive("EAST **MMLIVE**") Then
    SplashImageOn("", $eastdest, $WIDTH, $HEIGHT, $XPOS, $YPOS, 17)
    Else 
        SplashOff()
    EndIf
    EndIf

    If Not ProcessExists("HMM.exe") Then
    Exit
    EndIf
    Sleep(2500)
WEnd

Share this post


Link to post
Share on other sites
flyingboz

get the active window coordinates, and use them to calculate where you want to display the image.

edit: call WinGetPos() , and use that to calculate your $xpos, $ypos

Edited by flyingboz

Reading the help file before you post... Not only will it make you look smarter, it will make you smarter.

Share this post


Link to post
Share on other sites
herewasplato

get the active window coordinates,...

WinGetPos()

[size="1"][font="Arial"].[u].[/u][/font][/size]

Share this post


Link to post
Share on other sites
kman

Thank you both for your help!! I have it close to doing what Im looking for but it is putting the image at the default posistion (the top left corner of the window). How do I get the image to be placed in the center of the active window? Im stuck there.

Const $WIDTH = 500
Const $HEIGHT = 25
Dim $MousePos[2]
$westdest ="C:\Meds\campus\west.gif"
$eastdest ="C:\Meds\campus\east.gif"


ProcessWait("hmm.exe")

While 1
    $wsize=WinGetPos("WEST **MMLIVE**")
    If WinActive("WEST **MMLIVE**") Then
    SplashImageOn("", $westdest, $WIDTH, $HEIGHT, $wsize[0], $wsize[1], 17)
    
    Else 
        SplashOff()

    EndIf

    If Not ProcessExists("HMM.exe") Then
    Exit
    EndIf
    Sleep(2500)
WEnd

Share this post


Link to post
Share on other sites
John117

you could use this . . .Then if you knew the size of the gui you could add/subtract the return to equal the center . . .

$size = WinGetPos("")
MsgBox(0, "Active window stats (x,y,width,height):", $size[0] & " " & $size[1] & " " & $size[2] & " " & $size[3])

Share this post


Link to post
Share on other sites
kman

The active window could always be different sizes, full screen, half screen depending on the user. After getting the xy coordinates of the active window by using wingetpos how can you get the spalshimage to always be at x=-1 y=-1 (centered).

Share this post


Link to post
Share on other sites
John117

When I first responded (From work) - I had three monitors to test this with. Laptop + 2 externals. From home I only have the laptop . . . give this a whirl and let me know. -Just run it . . . activate a window somewhere, then press Esc . . . You should see how it works. -just a little formula, but I needed to get the concept out of my head too :P

#include <GuiConstants.au3>
HotKeySet("{ESC}", "Test")

While 1
    $nMsg = GUIGetMsg()
    Select
        Case $nMsg = $GUI_EVENT_CLOSE
            Exit
    EndSelect
WEnd

Func Test()
    $size = WinGetPos("Dual Monitor Help - AutoIt Forums - Microsoft Internet Explorer")
Global $Width = ($size[2]/2)
Global $Height = ($size[3]/2)
Global $Left = (($Width/2)+$size[0])
Global $Top = (($Height/2)+$size[1])
    ;MsgBox(0, "Active window stats (x,y,width,height):", $size[0] & " " & $size[1] & " " & $size[2] & " " & $size[3])
    ;GUICreate ( "title" [, width [, height [, left [, top [, style [, exStyle [, parent]]]]]]] )
    $Form1 = GUICreate("Form1", $Width, $Height, $Left, $Top)
    GUISetState(@SW_SHOW)
    sleep(1500)
    GUISetState(@SW_Hide)
EndFunc   ;==>Test

Right now it is set up to adjust the popup size according to the size of the open window. It will be centeredf half the height and width. Change as needed.

To test this . . .

leave this page open . . .

run the script . . .

make sure this page is not not minimized . . .

press esc . . .

wait 1.5sec . . .

move this page around, resize it.

Press esc . . .

Ta . . .

da . .

;)

Edited by Hatcheda

Share this post


Link to post
Share on other sites
John117

ok, im back at work now and it works three for three. (All three monitors) If you want to make it not centered, or more left, up, down, right . . . Just adjust the formula. If you want the banner a set size, just hard code the $width, $Height section. -THis took a lot of effort, so please let me know how it's working for you.

Share this post


Link to post
Share on other sites
kman

Sorry for the delay, been catching up from the long weekend and trying this in between.

Thank you very much, this has helped me out quite a bit! I do have to hard code the height and width to match the image size I have. I think because of this it throws off your formula for centering the Y position or $Left variable. I know that the default position for center of X and Y is -1. I cant figure out how to incorporate that to get the left positioning base on wingetpos. Please let me know if anymore information is needed.

Share this post


Link to post
Share on other sites
John117

This was a good challange :P Thanks!

#include <GuiConstants.au3>
HotKeySet("{ESC}", "Test")
$destination = @Systemdir & "\oobe\images\mslogo.jpg"
While 1
    $nMsg = GUIGetMsg()
    Select
        Case $nMsg = $GUI_EVENT_CLOSE
            Exit
    EndSelect
WEnd
Func Test()
    $size = WinGetPos("Dual Monitor Help - AutoIt Forums - Microsoft Internet Explorer")
Global $Width = 500
Global $Height = 25
; Active window (width / 2) - Splash Image (width / 2) added to Starting position of active window centers
; Active window (Height / 2) - Splash Image (Height / 2) added to Starting position of active window centers
Global $X = ((($size[2]/2)-($Width/2))+$size[0])
Global $Y = ((($size[3]/2)-($Height/2))+$size[1])
;MsgBox(0, "Active window stats (x,y,width,height):", $size[0] & " " & $size[1] & " " & $size[2] & " " & $size[3])
;GUICreate ( "title" [, width [, height [, left [, top [, style [, exStyle [, parent]]]]]]] )
;$Form1 = GUICreate("Form1", $Width, $Height, $X, $Y)
SplashImageOn("Splash Screen", $Destination,  $Width, $Height, $X, $Y)
sleep(1500)
SplashOff()
EndFunc   ;==>Test

Please note that this centers on the window, not he monitor. As such, if you reduce the window, and move it around, the splash will follow it.

Test: reduce the size of this ie and try it with this still open on both monitors. (one instance at a time)

Edited by Hatcheda

Share this post


Link to post
Share on other sites
kman

Dude! That worked perfect!! That formula for $X was the kicker and I used your previous formula for $Y, as I had that set to my needs already. Your time and effort is very much appreciated as I have been working on and off of this thing for the last week or two. Thank You!!

Share this post


Link to post
Share on other sites
John117

no prob, I learned the whole thing while trying to help you! :P which is a good reason to help ;)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×