Jump to content

_WinAttach()!


MrCreatoR
 Share

Recommended Posts

Hi all,

This example is show, that window can be "attached" (like magnetic) to edges of the screen (or other app)...

But there is one(?) problem - when you drag the window, the script is paused, so you will see the results (of "attaching" process) only after release the mouse (ending of draging).

If this will be fixed(?), then not only this function will be much usefull, and more others (in fact, all our scripts will be much productive and practical :shocked: ).

here we go...

$AttachRange = 70
$AttachSpeed = 100

$HwndGui = GUICreate("Attach Window GUI to screen edges")

GUICtrlCreateLabel("Drag me to the edges of your screen ;-) ", 50, 50, 350)
GUICtrlSetFont(-1, 14)

GUISetState()

While 1
    $Msg = GUIGetMsg()
    If $Msg = -3 Then Exit
    _WinAttach($HwndGui, $AttachRange, $AttachSpeed)
WEnd

Func _WinAttach($hWnd, $AttachRange=20, $AttachSpeed=3)
    Local $OldOpt = Opt("WinTitleMatchMode", 4)
    Local $WinPosArr = WinGetPos($hWnd)
    Local $WidthHeightArr = WinGetClientSize($hWnd)
    If IsArray($WinPosArr) And IsArray($WidthHeightArr) Then
        Local $xPos = $WinPosArr[0] 
        Local $yPos = $WinPosArr[1]
        Local $Width = $WidthHeightArr[0]
        Local $Height = $WinPosArr[3]
        Local $TrayPosHeight = WinGetPos("classname=Shell_TrayWnd")
        If IsArray($TrayPosHeight) Then $TrayPosHeight = $TrayPosHeight[3]
        If $xPos >= (@DesktopWidth-($Width+$AttachRange)) And ($xPos+$Width-15) < (@DesktopWidth-22) Then
            Local $xDestPos = @DesktopWidth-$Width
            While $xPos < $xDestPos
                Sleep(100/$AttachSpeed)
                WinMove($hWnd, "", $xPos, $yPos)
                $xPos += 5
            WEnd
        EndIf
        If $xPos <= $AttachRange And $xPos > 8 Then
            Local $xDestPos = -2
            While $xPos > $xDestPos
                Sleep(100/$AttachSpeed)
                WinMove($hWnd, "", $xPos, $yPos)
                $xPos -= 5
            WEnd
        EndIf
        
        If $yPos >= (@DesktopHeight-($TrayPosHeight+$Height+$AttachRange)) And _
            ($TrayPosHeight+$yPos+$Height-15) < (@DesktopHeight-22) Then
            Local $yDestPos = @DesktopHeight-$Height-$TrayPosHeight+4
            While $yPos < $yDestPos
                Sleep(100/$AttachSpeed)
                WinMove($hWnd, "", $xPos, $yPos)
                $yPos += 5
            WEnd
        EndIf
        If $yPos <= $AttachRange And $yPos > 8 Then
            Local $yDestPos = -2
            While $yPos > $yDestPos
                Sleep(100/$AttachSpeed)
                WinMove($hWnd, "", $xPos, $yPos)
                $yPos -= 5
            WEnd
        EndIf
    EndIf
    Opt("WinTitleMatchMode", $OldOpt)
EndFunc
Edited by MsCreatoR

 

Spoiler

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

Spoiler

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

 

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Link to comment
Share on other sites

Link to comment
Share on other sites

  • 6 months later...

Very nice but... It doesn't attach to other GUI's if you could send a parameter that was just an array with all of the other gui's it should be magnetic to that would make it better...

kinda like...

$array[0] = 2 ; I have two other gui's that it should attach too
$array[1] = $Hwnd1
$array[2] = $HWnd2
_WinAttach( $Hwnd3, 20, 3, $array )

thus making hwnd3 'magnetic' or 'sticky' to hwnd1 & hwnd2....

[center][/center]

Link to comment
Share on other sites

All:

Check this topic, there is a solution mutch more better! <_< (thanks to Siao and eltorro).

P.S

Updated first post.

Edited by MsCreatoR

 

Spoiler

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

Spoiler

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

 

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

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...