clshuai 发表于 2009-7-27 14:33:25

会动的眼睛

http://www.mybat.cn/forum.php?mod=viewthread&tid=4493&extra=page%3D3
其中有四个gui,两个移动,两个固定
转载,共同分享
#include <GUIConstants.au3>

Dim $loc, $loc1, $locA, $locB,$GUI,$WS_POPUP,$WS_EX_TOPMOST,$WS_EX_TOOLWINDOW

Global Const $_pos_x = 910

Global Const $_pos_y = 680

Global Const $_color_l = 0xff0000

Global Const $_color_r = 0x0000ff

Global Const $_size_face = 40

Global Const $_width_face = 8

Global Const $_size_eye = 10



Global $_mov = ($_size_face/2-$_width_face)*0.4+$_width_face/2



$GUI = GUICreate("Left",$_pos_x+25+$_size_face,$_pos_y+45+$_size_face,0,0, $WS_POPUP, BitOr($WS_EX_TOPMOST, $WS_EX_TOOLWINDOW))

GUISetBkColor($_color_l)

$a = CreateRoundRectRgn($_pos_x+25,$_pos_y+45,$_size_face,$_size_face,300,300)

$b = CreateRoundRectRgn($_pos_x+25+$_width_face/2,$_pos_y+45+$_width_face/2,$_size_face-$_width_face,$_size_face-$_width_face,300,300)

$c = CreateRoundRectRgn($_pos_x+25+$_size_face,$_pos_y+45,$_size_face,$_size_face,300,300)

$d = CreateRoundRectRgn($_pos_x+25+$_width_face/2+$_size_face,$_pos_y+45+$_width_face/2,$_size_face-$_width_face,$_size_face-$_width_face,300,300)

$GUI2 = GUICreate("Right",$_pos_x+25+$_size_face+$_size_face,$_pos_y+45+$_size_face,0,0,$WS_POPUP, BitOr($WS_EX_TOPMOST, $WS_EX_TOOLWINDOW))

GUISetBkColor($_color_r)

$Gui3 = GUICreate("Eye 1",$_size_eye,$_size_eye,$_pos_x+35++$_width_face/2,$_pos_y+55++$_width_face/2,$WS_POPUP, BitOr($WS_EX_TOPMOST, $WS_EX_TOOLWINDOW))

GUISetBkColor($_color_r)

$Gui4 = GUICreate("Eye 2",$_size_eye,$_size_eye,$_pos_x+35+$_width_face/2+$_size_face,$_pos_y+55+$_width_face/2,$WS_POPUP, BitOr($WS_EX_TOPMOST, $WS_EX_TOOLWINDOW))

GUISetBkColor($_color_l)

CombineRgn($a,$b)

CombineRgn($c,$d)

SetWindowRgn($GUI,$a)

SetWindowRgn($GUI2,$c)



RoundGUI($GUI3, 1,1,$_size_eye,$_size_eye)

RoundGUI($GUI4, 1,1,$_size_eye,$_size_eye)



GUISetState(@SW_SHOW,$GUI)

GUISetState(@SW_SHOW,$GUI2)

GUISetState(@SW_SHOW,$GUI3)

GUISetState(@SW_SHOW,$GUI4)



While 1

    $msg = GUIGetMsg()

    $pos = MouseGetPos()

    $GUIPos1= WinGetPos("Eye 1")

    $GUIPos2= WinGetPos("Eye 2")

    If $msg = $GUI_EVENT_CLOSE Then Exit



      If $loc <> $Pos Or $loc1 <> $Pos Then

            $loc = ""

            If $pos > $GUIPos1 And $GuiPos1 < $_pos_x+25+$_size_face-$_size_eye-$_mov then

                $loc = $GuiPos1+1

            ElseIf $pos < $GUIPos1 And $GUIPos1 > $_pos_x+25+$_mov Then

                $loc = $GuiPos1-1

            Else

                $loc = $GuiPos1

            EndIf

            

            $loc1 = ""

            If $pos > $GUIPos1 And $GuiPos1 < $_pos_y+45+$_size_face-$_size_eye-$_mov then

                $loc1 = $GuiPos1+1

            ElseIf $pos < $GUIPos1 And $GUIPos1 > $_pos_y+45+$_mov Then

                $loc1 = $GuiPos1-1

            Else

                $loc1 = $GuiPos1

            EndIf

            

            WinMove("Eye 1", "", $loc, $loc1)

      EndIf



    If $locA < $Pos-1 Or $locA > $Pos+1 Or $locB <> $Pos Then

            $locA = ""

            If $pos > $GUIPos2 And $GuiPos2 < $_pos_x+25+$_size_face+$_size_face-$_size_eye-$_mov then

                $locA = $GuiPos2+1

            ElseIf $pos < $GUIPos2 And $GUIPos2 > $_pos_x+25+$_size_face+$_mov Then

                $locA = $GuiPos2-1

            Else

                $locA = $GuiPos2

            EndIf

            

            $locB = ""

            If $pos > $GUIPos2 And $GuiPos2 < $_pos_y+45+$_size_face-$_size_eye-$_mov then

                $locB = $GuiPos2+1

            ElseIf $pos < $GUIPos2 And $GUIPos2 > $_pos_y+45+$_mov Then

                $locB = $GuiPos2-1

            Else

                $locB = $GuiPos2

            EndIf

            

            WinMove("Eye 2", "", $locA, $locB)

      EndIf

    Sleep(50)

WEnd



Func SetWindowRgn($h_win, $rgn)

    DllCall("user32.dll", "long", "SetWindowRgn", "hwnd", $h_win, "long", $rgn, "int", 1)

EndFunc



Func CreatePolyRgn($pt)

    Local $ALTERNATE = 1

    Local $buffer = ""



    $pt = StringSplit($pt,",")

    For $i = 1 to $pt

      $buffer = $buffer & "int;"

    Next

    $buffer = StringTrimRight($buffer,1)

    $lppt = DllStructCreate($buffer)

    For $i = 1 to $pt

      DllStructSetData($lppt,$i,$pt[$i])

    Next

    $ret = DllCall("gdi32.dll","long","CreatePolygonRgn","ptr",DllStructGetPtr($lppt),"int",Int($pt / 2),"int",$ALTERNATE)

    Return $ret

EndFunc



Func CreateRoundRectRgn($l, $t, $w, $h, $e1, $e2)

    $ret = DllCall("gdi32.dll", "long", "CreateRoundRectRgn", "long", $l, "long", $t, "long", $l + $w, "long", $t + $h, "long", $e1, "long", $e2)

    Return $ret

EndFunc



Func CombineRgn(ByRef $rgn1, ByRef $rgn2)

    DllCall("gdi32.dll", "long", "CombineRgn", "long", $rgn1, "long", $rgn1, "long", $rgn2, "int", 3)

EndFunc



Func RoundGUI($h_win, $i_x1, $i_y1, $i_x3, $i_y3)

    Dim $pos, $ret, $ret2

    $pos = WinGetPos($h_win)

    $ret = DllCall("gdi32.dll", "long", "CreateRoundRectRgn", "long", $i_x1, "long", $i_y1, "long", $pos, "long", $pos, "long", $i_x3, "long", $i_y3)

    If $ret Then

      $ret2 = DllCall("user32.dll", "long", "SetWindowRgn", "hwnd", $h_win, "long", $ret, "int", 1)

      If $ret2 Then

            Return 1

      Else

            Return 0

      EndIf

    Else

      Return 0

    EndIf

EndFunc;==>RoundGUI
页: [1]
查看完整版本: 会动的眼睛