找回密码
 加入
搜索
查看: 12985|回复: 19

[AU3基础] 【已解决】无标题窗口移动问题

 火.. [复制链接]
发表于 2012-5-6 07:38:31 | 显示全部楼层 |阅读模式
本帖最后由 zerobin 于 2012-5-6 09:08 编辑

一个桌面浮动工具。
目前两个问题拦着我
1、几个按钮老在闪,如何不闪。
2、窗口怎么不能移动,是 消息循环模式 与 onevent模式 导致的吗?

请指教,我新学,23点搞到现在。。。。。。。都通宵了。搞不出来。睡不着。
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Misc.au3>
#include <ButtonConstants.au3>
#NoTrayIcon
;
 Opt("GUIOnEventMode",1)
Local $label1, $label2, $label3, $label4, $label5

$Form1 = GUICreate("float", 120, 21, @DesktopWidth/2-50, 10, $WS_POPUP, $WS_EX_TOPMOST);, $WS_EX_TOOLWINDOW)
GUISetOnEvent($GUI_EVENT_CLOSE, "SpecialEvents")
GUICtrlSetOnEvent($Form1, "mouseCHK")
        
While 1
$label1 = GUICtrlCreateButton("C",  0, 1, 20, 20,$BS_FLAT)
;        GUICtrlSetBkColor( $label1 , $GUI_BKCOLOR_TRANSPARENT)
        GUICtrlSetOnEvent($label1,"_go1")
$label2 = GUICtrlCreateButton("D",  21, 1, 20, 20,$BS_FLAT)
;        GUICtrlSetBkColor( $label2 , $GUI_BKCOLOR_TRANSPARENT)
        GUICtrlSetOnEvent($label2,"_go2")
$label3 = GUICtrlCreateButton("E",  42, 1, 20, 20,$BS_FLAT)
;        GUICtrlSetBkColor( $label3 , $GUI_BKCOLOR_TRANSPARENT)
        GUICtrlSetOnEvent($label3,"_go3")
$label4 = GUICtrlCreateButton("F",  63, 1, 20, 20,$BS_FLAT)
;        GUICtrlSetBkColor( $label4 , $GUI_BKCOLOR_TRANSPARENT)
        GUICtrlSetOnEvent($label4,"_go4")
$label5 = GUICtrlCreateButton("R",  84, 1, 20, 20,$BS_FLAT)
;        GUICtrlSetBkColor( $label5 , $GUI_BKCOLOR_TRANSPARENT)
        GUICtrlSetOnEvent($label5,"_go5")
GUISetState(@SW_SHOW)
WEnd

Func _go1()
        ShellExecute("C:")                
EndFunc
Func _go2()
        ShellExecute("D:")                
EndFunc
Func _go3()
        ShellExecute("E:")                
EndFunc
Func _go4()
        ShellExecute("F:")                
EndFunc
Func _go5()
        ShellExecute("R:")                
EndFunc

;mouseCHK
Func mouseCHK()
    $MS = GUIGetCursorInfo($Form1)
        MsgBox(0,"","test") 
   If $MS[4] =$Form1 Then move()
EndFunc   

;==>move
Func move()
    Local $PosDiff[2], $MousePos, $WinPos
    $MousePos = MouseGetPos()
    $WinPos = WinGetPos($Form1, "")
    $PosDiff[0] = $WinPos[0] - $MousePos[0]
    $PosDiff[1] = $WinPos[1] - $MousePos[1]
    While _IsPressed("01", DllOpen("user32.dll"))
        $MousePos = MouseGetPos()
        WinMove($Form1, "", $MousePos[0] + $PosDiff[0], $MousePos[1] + $PosDiff[1])
        Sleep(10)
    WEnd
EndFunc   

Func SpecialEvents()
            Exit
EndFunc   ;==>SpecialEvents
 楼主| 发表于 2012-5-6 07:39:59 | 显示全部楼层
本帖最后由 zerobin 于 2012-5-6 07:41 编辑

12行 改为  GUICtrlSetOnEvent($GUI_EVENT_PRIMARYDOWN, "mouseCHK") 也是不能移动窗口。怎么办呀
发表于 2012-5-6 07:50:39 | 显示全部楼层
把14行移动到30行之后,然后加个sleep
While 1        
        Sleep(100)
WEnd
 楼主| 发表于 2012-5-6 07:55:30 | 显示全部楼层
把14行移动到30行之后,然后加个sleep
haijie1223 发表于 2012-5-6 07:50


这个解决了问题1,按钮不闪了,谢谢。理解了,原来的太快了。。

问题2请问怎么解决还,这样改了还是不能移动窗口呀
发表于 2012-5-6 08:32:26 | 显示全部楼层
回复 4# zerobin



代码开始添加
#include <StaticConstants.au3>
    在13行添加
GUICtrlCreateLabel("",0,0,104, 41,$SS_CENTERIMAGE, $GUI_WS_EX_PARENTDRAG)
 楼主| 发表于 2012-5-6 08:34:50 | 显示全部楼层
回复  zerobin

代码开始添加
#include
    在13行添加
GUICtrlCreateLabel("",0,0,104, 41,$SS ...
haijie1223 发表于 2012-5-6 08:32


端着早饭在等呢,吃完就试。谢谢
发表于 2012-5-6 08:39:06 | 显示全部楼层
都是别人的代码,为什么不用看起来舒服点的。。
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Misc.au3>
#include <ButtonConstants.au3>
#NoTrayIcon
Opt("GUIOnEventMode",1)
Local $label1, $label2, $label3, $label4, $label5
$Form1 = GUICreate("float", 104, 41, @DesktopWidth/2-50, 10, $WS_POPUP, $WS_EX_TOPMOST);, $WS_EX_TOOLWINDOW)
GUISetOnEvent($GUI_EVENT_CLOSE, "SpecialEvents")
$label1 = GUICtrlCreateButton("C",  0, 1, 20, 20,$BS_FLAT)
;       GUICtrlSetBkColor( $label1 , $GUI_BKCOLOR_TRANSPARENT)
       GUICtrlSetOnEvent($label1,"_go")
$label2 = GUICtrlCreateButton("D",  21, 1, 20, 20,$BS_FLAT)
;       GUICtrlSetBkColor( $label2 , $GUI_BKCOLOR_TRANSPARENT)
       GUICtrlSetOnEvent($label2,"_go")
$label3 = GUICtrlCreateButton("E",  42, 1, 20, 20,$BS_FLAT)
;       GUICtrlSetBkColor( $label3 , $GUI_BKCOLOR_TRANSPARENT)
       GUICtrlSetOnEvent($label3,"_go")
$label4 = GUICtrlCreateButton("F",  63, 1, 20, 20,$BS_FLAT)
;        GUICtrlSetBkColor( $label4 , $GUI_BKCOLOR_TRANSPARENT)
       GUICtrlSetOnEvent($label4,"_go")
$label5 = GUICtrlCreateButton("R",  84, 1, 20, 20,$BS_FLAT)
;       GUICtrlSetBkColor( $label5 , $GUI_BKCOLOR_TRANSPARENT)
       GUICtrlSetOnEvent($label5,"_go")
GUIRegisterMsg($WM_NCHITTEST,"WM_NCHITTEST")
GUISetState(@SW_SHOW)

While 1
    Sleep(1000)
WEnd

Func _go()
        ShellExecute(GUICtrlRead(@GUI_CtrlId)&":")               
EndFunc

Func WM_NCHITTEST($hWnd, $iMsg, $iwParam, $ilParam)
if ($hWnd = $Form1 ) and ($iMsg = $WM_NCHITTEST) then Return $HTCAPTION
EndFunc

Func SpecialEvents()
        Exit
EndFunc   ;==>SpecialEvents
发表于 2012-5-6 08:42:00 | 显示全部楼层
回复  zerobin



代码开始添加
#include
    在13行添加
GUICtrlCreateLabel("",0,0,104, 41,$SS ...
haijie1223 发表于 2012-5-6 08:32


改后倒是可以移动了,但是弹不出文件夹了
发表于 2012-5-6 08:46:51 | 显示全部楼层
回复 8# whitehead


#NoTrayIcon
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Misc.au3>
#include <ButtonConstants.au3>
#include <StaticConstants.au3>
;
Opt("GUIOnEventMode", 1)
Local $label1, $label2, $label3, $label4, $label5

$Form1 = GUICreate("float", 104, 41, @DesktopWidth / 2 - 50, 10, $WS_POPUP, BitOR($WS_EX_TOPMOST, $GUI_WS_EX_PARENTDRAG));, $WS_EX_TOOLWINDOW
GUISetOnEvent($GUI_EVENT_CLOSE, "SpecialEvents")
GUICtrlSetOnEvent($Form1, "mouseCHK")
$label1 = GUICtrlCreateButton("C", 0, 1, 20, 20, $BS_FLAT)
;        GUICtrlSetBkColor( $label1 , $GUI_BKCOLOR_TRANSPARENT)
GUICtrlSetOnEvent($label1, "_go1")
$label2 = GUICtrlCreateButton("D", 21, 1, 20, 20, $BS_FLAT)
;        GUICtrlSetBkColor( $label2 , $GUI_BKCOLOR_TRANSPARENT)
GUICtrlSetOnEvent($label2, "_go2")
$label3 = GUICtrlCreateButton("E", 42, 1, 20, 20, $BS_FLAT)
;        GUICtrlSetBkColor( $label3 , $GUI_BKCOLOR_TRANSPARENT)
GUICtrlSetOnEvent($label3, "_go3")
$label4 = GUICtrlCreateButton("F", 63, 1, 20, 20, $BS_FLAT)
;        GUICtrlSetBkColor( $label4 , $GUI_BKCOLOR_TRANSPARENT)
GUICtrlSetOnEvent($label4, "_go4")
$label5 = GUICtrlCreateButton("R", 84, 1, 20, 20, $BS_FLAT)
;        GUICtrlSetBkColor( $label5 , $GUI_BKCOLOR_TRANSPARENT)
GUICtrlSetOnEvent($label5, "_go5")
GUICtrlCreateLabel("", 0, 0, 104, 41, $SS_CENTERIMAGE, $GUI_WS_EX_PARENTDRAG)
GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
GUISetState(@SW_SHOW)
While 1
        Sleep(100)
WEnd


Func _go1()
        ShellExecute("C:\")
EndFunc   ;==>_go1
Func _go2()
        ShellExecute("D:\")
EndFunc   ;==>_go2
Func _go3()
        ShellExecute("E:\")
EndFunc   ;==>_go3
Func _go4()
        ShellExecute("F:\")
EndFunc   ;==>_go4
Func _go5()
        ShellExecute("R:\")
EndFunc   ;==>_go5



;mouseCHK
Func mouseCHK()
        $MS = GUIGetCursorInfo($Form1)
        MsgBox(0, "", "test")
        If $MS[4] = $Form1 Then move()
EndFunc   ;==>mouseCHK

;==>move
Func move()
        Local $PosDiff[2], $MousePos, $WinPos
        $MousePos = MouseGetPos()
        $WinPos = WinGetPos($Form1, "")
        $PosDiff[0] = $WinPos[0] - $MousePos[0]
        $PosDiff[1] = $WinPos[1] - $MousePos[1]
        While _IsPressed("01", DllOpen("user32.dll"))
                $MousePos = MouseGetPos()
                WinMove($Form1, "", $MousePos[0] + $PosDiff[0], $MousePos[1] + $PosDiff[1])
                Sleep(10)
        WEnd
EndFunc   ;==>move

Func SpecialEvents()
        Exit
EndFunc   ;==>SpecialEvents

评分

参与人数 1贡献 +2 收起 理由
whitehead + 2

查看全部评分

发表于 2012-5-6 08:58:55 | 显示全部楼层
回复  whitehead
haijie1223 发表于 2012-5-6 08:46


楼主的两个问题解决了
 楼主| 发表于 2012-5-6 09:06:36 | 显示全部楼层
是啊。谢谢。看来还是要再建一个 标签 才可以。
GUISetOnEvent($GUI_EVENT_CLOSE, "SpecialEvents")
GUICtrlSetOnEvent($Form1, "mouseCHK")
$label1 = GUICtrlCreateButton("C", 0, 1, 20, 20, $BS_FLAT)
;        GUICtrlSetBkColor( $label1 , $GUI_BKCOLOR_TRANSPARENT)
GUICtrlSetOnEvent($label1, "_go1")
$label2 = GUICtrlCreateButton("D", 21, 1, 20, 20, $BS_FLAT)
;        GUICtrlSetBkColor( $label2 , $GUI_BKCOLOR_TRANSPARENT)
GUICtrlSetOnEvent($label2, "_go2")
$label3 = GUICtrlCreateButton("E", 42, 1, 20, 20, $BS_FLAT)
;        GUICtrlSetBkColor( $label3 , $GUI_BKCOLOR_TRANSPARENT)
GUICtrlSetOnEvent($label3, "_go3")
$label4 = GUICtrlCreateButton("F", 63, 1, 20, 20, $BS_FLAT)
;        GUICtrlSetBkColor( $label4 , $GUI_BKCOLOR_TRANSPARENT)
GUICtrlSetOnEvent($label4, "_go4")
$label5 = GUICtrlCreateButton("R", 84, 1, 20, 20, $BS_FLAT)
;        GUICtrlSetBkColor( $label5 , $GUI_BKCOLOR_TRANSPARENT)
GUICtrlSetOnEvent($label5, "_go5")
GUICtrlCreateLabel("█", 104, 0, 6, 21, $SS_CENTERIMAGE, $GUI_WS_EX_PARENTDRAG)
GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
GUISetState(@SW_SHOW)
或者
GUISetOnEvent($GUI_EVENT_CLOSE, "SpecialEvents")
GUICtrlSetOnEvent($Form1, "mouseCHK")
GUICtrlCreateLabel("█", 104, 0, 6, 21, $SS_CENTERIMAGE, $GUI_WS_EX_PARENTDRAG)
GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
$label1 = GUICtrlCreateButton("C",  0, 1, 20, 20,$BS_FLAT)
;        GUICtrlSetBkColor( $label1 , $GUI_BKCOLOR_TRANSPARENT)
        GUICtrlSetOnEvent($label1,"_go1")
$label2 = GUICtrlCreateButton("D",  21, 1, 20, 20,$BS_FLAT)
;        GUICtrlSetBkColor( $label2 , $GUI_BKCOLOR_TRANSPARENT)
        GUICtrlSetOnEvent($label2,"_go2")
$label3 = GUICtrlCreateButton("E",  42, 1, 20, 20,$BS_FLAT)
;        GUICtrlSetBkColor( $label3 , $GUI_BKCOLOR_TRANSPARENT)
        GUICtrlSetOnEvent($label3,"_go3")
$label4 = GUICtrlCreateButton("F",  63, 1, 20, 20,$BS_FLAT)
;        GUICtrlSetBkColor( $label4 , $GUI_BKCOLOR_TRANSPARENT)
        GUICtrlSetOnEvent($label4,"_go4")
$label5 = GUICtrlCreateButton("R",  84, 1, 20, 20,$BS_FLAT)
;        GUICtrlSetBkColor( $label5 , $GUI_BKCOLOR_TRANSPARENT)
        GUICtrlSetOnEvent($label5,"_go5")
GUISetState(@SW_SHOW)
都可以了。
今天就到这了,实现了我要的功能。
下一步就是给他做成半透明的。
再次感谢上面为我解惑的前辈。
 楼主| 发表于 2012-5-6 09:07:31 | 显示全部楼层
回复 9# haijie1223

谢谢
 楼主| 发表于 2012-5-6 09:07:53 | 显示全部楼层
回复 10# whitehead

谢谢
 楼主| 发表于 2012-5-6 09:08:12 | 显示全部楼层
回复 7# 502762378


    谢谢。
发表于 2012-5-6 09:23:51 | 显示全部楼层
回复 13# zerobin

不客气
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-12-22 21:04 , Processed in 0.335182 second(s), 24 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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