Jump to content

move window


oMBRa
 Share

Recommended Posts

I make a script that creates a window that follow my mouse cursor, but when i reach the bottom of the desktop the window disappear, so I have to make the window go up to the mouse when it disappears. How to do it? ( like how does Magnify of autoitt info tool)

Link to comment
Share on other sites

I did but then the window move up to the mouse and then come down again.. this is the script:

#include <WindowsConstants.au3>
#include <GuiConstantsEx.au3>
#include <GDIPlus.au3>
#include <ScreenCapture.au3>
HotKeySet("{F2}", "Chiudi")
Opt('MustDeclareVars', 1)

_Main()

Func _Main()
    Sleep(10)
    Local $hGUI1, $hGUI2, $hImage, $hGraphic1, $hGraphic2,$PosM,$PosW
    $hGUI2 = GUICreate("Zoomed", 400, 300, 0, 400, -1, $WS_EX_TOPMOST)
    GUISetState()
    
    _GDIPlus_Startup ()
     Do
    $PosM = MouseGetPos()
    _ScreenCapture_Capture (@DesktopDir & "\GDIPlus_Image.jpg",$PosM[0] - 100,$PosM[1] - 100,$PosM[0] + 100,$PosM[1] + 100, False)
    $hImage =   _GDIPlus_ImageLoadFromFile (@DesktopDir & "\GDIPlus_Image.jpg")
    $hGraphic2 = _GDIPlus_GraphicsCreateFromHWND ($hGUI2)
    _GDIPlus_GraphicsDrawImageRectRect ($hGraphic2, $hImage, 0, 0, 200, 200, 0, 0, 400, 300)
    _GDIPlus_GraphicsDispose ($hGraphic2)
    _GDIPlus_ImageDispose ($hImage)
    $PosW = WinGetPos("Zoomed")
        WinMove("Zoomed", "",$PosM[0] + 100,$PosM[1] + 100)
    Sleep(10)
    Until GUIGetMsg() = $GUI_EVENT_CLOSE

EndFunc   

Func Chiudi()
        _GDIPlus_Shutdown ()
    FileDelete(@DesktopDir& "\GDIPlus_Image.jpg")
    Exit
EndFunc
Link to comment
Share on other sites

I did but then the window move up to the mouse and then come down again.. this is the script:

#include <WindowsConstants.au3>
#include <GuiConstantsEx.au3>
#include <GDIPlus.au3>
#include <ScreenCapture.au3>
HotKeySet("{F2}", "Chiudi")
Opt('MustDeclareVars', 1)

_Main()

Func _Main()
    Sleep(10)
    Local $hGUI1, $hGUI2, $hImage, $hGraphic1, $hGraphic2,$PosM,$PosW
    $hGUI2 = GUICreate("Zoomed", 400, 300, 0, 400, -1, $WS_EX_TOPMOST)
    GUISetState()
    
    _GDIPlus_Startup ()
     Do
    $PosM = MouseGetPos()
    _ScreenCapture_Capture (@DesktopDir & "\GDIPlus_Image.jpg",$PosM[0] - 100,$PosM[1] - 100,$PosM[0] + 100,$PosM[1] + 100, False)
    $hImage =   _GDIPlus_ImageLoadFromFile (@DesktopDir & "\GDIPlus_Image.jpg")
    $hGraphic2 = _GDIPlus_GraphicsCreateFromHWND ($hGUI2)
    _GDIPlus_GraphicsDrawImageRectRect ($hGraphic2, $hImage, 0, 0, 200, 200, 0, 0, 400, 300)
    _GDIPlus_GraphicsDispose ($hGraphic2)
    _GDIPlus_ImageDispose ($hImage)
    $PosW = WinGetPos("Zoomed")
        WinMove("Zoomed", "",$PosM[0] + 100,$PosM[1] + 100)
    Sleep(10)
    Until GUIGetMsg() = $GUI_EVENT_CLOSE

EndFunc   

Func Chiudi()
        _GDIPlus_Shutdown ()
    FileDelete(@DesktopDir& "\GDIPlus_Image.jpg")
    Exit
EndFunc

#include <WindowsConstants.au3>
#include <GuiConstantsEx.au3>
#include <GDIPlus.au3>
#include <ScreenCapture.au3>
HotKeySet("{F2}", "Chiudi")
Opt('MustDeclareVars', 1)

_Main()

Func _Main()
    Sleep(10)
    Local $hGUI1, $hGUI2, $hImage, $hGraphic1, $hGraphic2,$PosM,$PosW,$xvar,$yvar;<<<<2 extra variables
    $hGUI2 = GUICreate("Zoomed", 400, 300, 0, 400, -1, $WS_EX_TOPMOST)
    GUISetState()
    
    _GDIPlus_Startup ()
     Do
    $PosM = MouseGetPos()
    _ScreenCapture_Capture (@DesktopDir & "\GDIPlus_Image.jpg",$PosM[0] - 100,$PosM[1] - 100,$PosM[0] + 100,$PosM[1] + 100, False)
    $hImage =   _GDIPlus_ImageLoadFromFile (@DesktopDir & "\GDIPlus_Image.jpg")
    $hGraphic2 = _GDIPlus_GraphicsCreateFromHWND ($hGUI2)
    _GDIPlus_GraphicsDrawImageRectRect ($hGraphic2, $hImage, 0, 0, 200, 200, 0, 0, 400, 300)
    _GDIPlus_GraphicsDispose ($hGraphic2)
    _GDIPlus_ImageDispose ($hImage)
    $PosW = WinGetPos("Zoomed")
        
;___________________added code here____________________________
        if $PosM[0] + 100 + 400 > @DesktopWidth Then
            $xvar = @DesktopWidth - 400
        Else
            $xvar = $PosM[0] + 100
        EndIf
        
        if $PosM[1] + 100 + 300 > @DesktopHeight Then
            $yvar = @DesktopHeight - 300
        Else
            $yvar = $PosM[1] + 100
        EndIf
;______________________________________________________________     
    
        WinMove("Zoomed", "",$xvar,$yvar)
        
        
    Sleep(10)
    Until GUIGetMsg() = $GUI_EVENT_CLOSE

EndFunc  

Func Chiudi()
        _GDIPlus_Shutdown ()
    FileDelete(@DesktopDir& "\GDIPlus_Image.jpg")
    Exit
EndFunc

This fixes it, but don't grade it based on style ;)

Edited by maxlarue
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...