找回密码
 加入
搜索
查看: 2680|回复: 9

象QQ缩放的窗口控制怎么写?

[复制链接]
发表于 2008-6-26 21:53:37 | 显示全部楼层 |阅读模式
一个最基本的窗口代码,感谢顽固不化和xtybfgu指点以及借鉴sanmoking 的代码,这个问题已经成为过去,完美解决了上下左右窗口缩放的问题,代码如下,特放出与朋友们分享。
[au3]
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

$Form1 = GUICreate("Form1", 200, 500, -1, -1, -1, $WS_EX_TOPMOST)
GUISetState(@SW_SHOW)



While 1
        $winpos = WinGetPos($Form1)
        $mousepos = MouseGetPos()
        $Msg = GUIGetMsg()
        Switch $Msg
                Case $GUI_EVENT_CLOSE
                        Exit

        EndSwitch


        If Abs($mousepos[0] - $winpos[0] - $winpos[2] / 2) < $winpos[2] / 2 + 1 And Abs($mousepos[1] - $winpos[1] - $winpos[3] / 2) < $winpos[3] / 2 + 1 Then
                If $winpos[0] = 0 And $winpos[1] = 0 Then
                        WinMove($Form1, "", @DesktopWidth / 2 - 150 / 2, @DesktopHeight / 2 - $winpos[3] / 2, 150, 150, 1)
                EndIf

                If $winpos[0] = 0 And $winpos[1] <> 0 Then
                        WinMove($Form1, "", 0, $winpos[1], 200, $winpos[3], 1)
                EndIf
                If $winpos[1] = 0 And $winpos[0] <> 0 Then
                        WinMove($Form1, "", $winpos[0], 0, $winpos[2], 500, 1)
                EndIf
                If @DesktopWidth - $winpos[0] - 2 = 0 Then
                        WinMove($Form1, "", @DesktopWidth - 200, $winpos[1], 200, $winpos[3], 1)
                EndIf
                If @DesktopHeight - $winpos[1] - 2 = 0 Then
                        WinMove($Form1, "", $winpos[0], @DesktopHeight - 500, $winpos[2], 500, 1)
                EndIf
                Sleep(1)
        ElseIf $winpos[0] <= 0 Then

                WinMove($Form1, "", 0, $winpos[1], 2, $winpos[3], 1)
        ElseIf $winpos[1] <= 0 Then
                WinMove($Form1, "", $winpos[0], 0, $winpos[2], 2, 1)
        ElseIf @DesktopWidth - $winpos[0] - $winpos[2] <= 0 Then
                WinMove($Form1, "", @DesktopWidth - 2, $winpos[1], 2, $winpos[3], 1)

        ElseIf @DesktopHeight - $winpos[1] - $winpos[3] <= 0 Then
                WinMove($Form1, "", $winpos[0], @DesktopHeight - 2, $winpos[2], 2, 1)
        EndIf



WEnd
[/au3]

[ 本帖最后由 wxlgh521 于 2008-6-28 18:58 编辑 ]
发表于 2008-6-26 22:51:37 | 显示全部楼层
做一下,思索一下,,,继续改。。。。。
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

$Form1 = GUICreate("Form1", 179, 444, 332, 137)
GUISetState(@SW_SHOW)


While 1
        $GUIXY=WinGetPos("Form1")
        if $GUIXY[1]<30 and $GUIXY[3]>2 then 
                WinMove("Form1","",$GUIXY[0],0)
                sleep(500)
                for $i=$GUIxy[3] to 2 step -10
                        WinMove("Form1","",$GUIXY[0],0,$GUIXY[2],$i)
                Next
        EndIf
        
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit

        EndSwitch
WEnd
发表于 2008-6-27 11:55:00 | 显示全部楼层
原帖由 xtybfgu 于 2008-6-27 10:42 发表
只搞了左边的了。



#include 
#include 
Opt("GUIOnEventMode", 1)
opt("MouseCoordMode",0)
$Form1 = GUICreate("Form1", 179, 444, 332, 137)
GUISetOnEvent($GUI_EVENT_CLOSE, "CLOS ... 

哈哈,不错呀。有个情况和我一样,就是拖到中间后还会自动跑到边上。。。。。是不是要加个窗口移动事件呀?
发表于 2008-6-27 11:59:47 | 显示全部楼层
左边和顶部容易搞点。。。右边和下边就烦琐了。
 楼主| 发表于 2008-6-28 19:01:13 | 显示全部楼层
谢谢大家,右边和下面都完美解决了
发表于 2008-6-28 20:05:30 | 显示全部楼层
你的代码测试有问题。 。。。在XP SP3下测试失败。。。要像QQ一样,还有得改呢。
发表于 2009-7-30 23:23:41 | 显示全部楼层
顶一下老帖,
发表于 2009-7-31 09:04:36 | 显示全部楼层
不错,学习一下,觉得还需要改下才像QQ嘛,就是靠左或者右应该把窗体上下拉全屏才行吧:)呵呵
发表于 2009-7-31 11:49:19 | 显示全部楼层
程序是要根据个人要达到的目的来写,而不是要完全照搬他人,当然你的程序目标就是完全模拟人家的例外。
发表于 2010-7-22 21:22:18 | 显示全部楼层
好东西,向高手学习了。
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-5-23 02:31 , Processed in 0.078417 second(s), 20 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表