找回密码
 加入
搜索
查看: 3351|回复: 3

[系统综合] 已解决 请教,写了个程序,窗口关不掉

[复制链接]
发表于 2013-10-25 10:53:51 | 显示全部楼层 |阅读模式
本帖最后由 ainizm 于 2013-10-25 23:56 编辑

做了个工具,现在程序有2问题,
1.剪贴后的窗口关不掉(用标题栏关);
2.我希望能剪贴图的窗口关掉后,程序不退出,鼠标热键能继续剪贴图
请教高手指点。

#include <Misc.au3>
#include <ScreenCapture.au3>

#include <GUIConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
Opt("GUIOneventMode",1)

$WinMain  = GUICreate("截图 V1.0", 55, 20, 88, 728, -1, BitOR($WS_EX_TOOLWINDOW,$WS_EX_TOPMOST,$WS_EX_WINDOWEDGE));,$WS_POPUP无边框 ;创建主窗口
GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")  ;当一个系统按钮被点击时调用一个用户自定义函数(UDF).
$Button0  = GUICtrlCreateButton("开始", 0, 0, 55, 20, 0)
GUICtrlSetOnEvent(-1, "AButton1Click");为指定控件的点击行为定义一个用户函数.
GUISetState(@SW_SHOW)                          ;显示当前窗口
Global $ScreenSaveToBit,$hpath,$bPos,$aPos,$hBmp,$hpath,$hWnd,$WinSub1,$I
$dll = DllOpen("user32.dll")
While 1
        Sleep(100)
WEnd

Func AButton1Click()
        While 1
    Sleep ( 10 )
    If _IsPressed("01", $dll) Then
                If _IsPressed("02", $dll) Then
                        $aPos = MouseGetPos()
                        MsgBox(0, "鼠标坐标 X,Y:", $aPos[0] & "," & $aPos[1],1)
                        While 1
                                If _IsPressed("01", $dll) Then
                                         $bPos = MouseGetPos()
                                        ;MsgBox(4096, "鼠标坐标 X,Y:", $bPos[0] & "," & $bPos[1])
                                        jietu()
                                        xianshi()
                                        ExitLoop
                                EndIf
                        WEnd
                EndIf
    EndIf
WEnd
EndFunc

DllClose($dll)

Func jietu()
        $hpath = "C:\Documents and Settings\Administrator\桌面\33.bmp"
        ; 当前窗口截图
        $hBmp =  _ScreenCapture_Capture($hpath, $aPos[0] , $aPos[1], $bPos[0], $bPos[1])
EndFunc

Func xianshi()
        Sleep(200)
        GUICreate( "22.jpg" , $bPos[0]-$aPos[0] , $bPos[1]-$aPos[1] , $aPos[0] , $aPos[1] , -1, BitOR($WS_EX_TOOLWINDOW,$WS_EX_TOPMOST,$WS_EX_WINDOWEDGE));,$WS_POPUP无边框
        GUISetOnEvent($GUI_EVENT_CLOSE, "AForm2Close")
        FileInstall("C:\Documents and Settings\Administrator\桌面\33.bmp", "C:\Documents and Settings\Administrator\桌面\22.jpg");包含并装入指定文件到编译后的脚本程序中.FileInstall ( "源文件", "目标路径" [, 标志] )
        GUICtrlCreatePic("C:\Documents and Settings\Administrator\桌面\22.jpg" , 0 , 0 , $bPos[0]-$aPos[0] , $bPos[1]-$aPos[1])
        GUISetState(@SW_SHOW)  
        FileDelete("C:\Documents and Settings\Administrator\桌面\22.jpg")
EndFunc  

Func AForm1Close()
        Exit
EndFunc       

Func AForm2Close()
        FileDelete("C:\Documents and Settings\Administrator\桌面\22.jpg")
        GUISetState(@SW_HIDE)               
        Exit
EndFunc       

Func _Exit()
        Exit
EndFunc
发表于 2013-10-25 18:21:51 | 显示全部楼层
本帖最后由 mikezunya 于 2013-10-25 18:23 编辑

如果想点击窗口的X来关闭,以及隐藏的话,下午测试了 能力有限没实现,可以用HotKeySet  弄个热键到AButton1Click()下,是可以实现你的要求。希望能对你有所帮助
发表于 2013-10-25 20:07:51 | 显示全部楼层
## 鼠标左右键同时按下开始截图,向右下角划出适当区域松开任意键指定范围

#include <Misc.au3>
#include <ScreenCapture.au3>
#include <WindowsConstants.au3>

Opt('GUIOneventMode', 1)

Global $dll = DllOpen('user32.dll'), $bPos, $aPos, $hWnd

GUICreate('截图 V1.0', 55, 20, 88, 728, -1, BitOR($WS_EX_TOOLWINDOW, $WS_EX_TOPMOST, $WS_EX_WINDOWEDGE));,$WS_POPUP无边框 ;创建主窗口
GUISetOnEvent(-3, '_Exit') ;当一个系统按钮被点击时调用一个用户自定义函数(UDF).
GUICtrlCreateButton('开始', 0, 0, 55, 20)
GUICtrlSetOnEvent(-1, 'AButton1Click');为指定控件的点击行为定义一个用户函数.
GUISetState() ;显示当前窗口

While 1
        Sleep(100)
WEnd

Func AButton1Click()
        AdlibRegister('_CKIsPressed')
EndFunc   ;==>AButton1Click

Func _CKIsPressed()
        If Not _IsPressed('01', $dll) Or Not _IsPressed('02', $dll) Then Return
        AForm2Close()
        $aPos = MouseGetPos()
        While _IsPressed('01', $dll) And _IsPressed('02', $dll)
                Sleep(1)
        WEnd
        $bPos = MouseGetPos()
        If ($bPos[0] - $aPos[0]) <= 4 Or ($bPos[1] - $aPos[1]) <= 4 Then Return        ;小于5*5不截图
        Local $hpath = 'tmp.jpg'
        _ScreenCapture_Capture($hpath, $aPos[0], $aPos[1], $bPos[0], $bPos[1])
        If Not FileExists($hpath) Then Return MsgBox(48, '失败', '未成功截图')
        $hWnd = GUICreate('', $bPos[0] - $aPos[0], $bPos[1] - $aPos[1], $aPos[0] - 3, $aPos[1] - 21, -1, BitOR($WS_EX_TOOLWINDOW, $WS_EX_TOPMOST, $WS_EX_WINDOWEDGE));,$WS_POPUP无边框
        GUISetOnEvent(-3, 'AForm2Close')
        GUICtrlCreatePic($hpath, 0, 0, $bPos[0] - $aPos[0] + 1, $bPos[1] - $aPos[1] + 1)
        GUISetState(@SW_SHOW)
        FileDelete($hpath)
EndFunc   ;==>_CKIsPressed

Func AForm2Close()
        If IsHWnd($hWnd) Then GUIDelete($hWnd)
EndFunc   ;==>AForm2Close

Func _Exit()
        DllClose($dll)
        Exit
EndFunc   ;==>_Exit
 楼主| 发表于 2013-10-25 23:55:28 | 显示全部楼层
本帖最后由 ainizm 于 2013-10-25 23:59 编辑

回复 3# afan


    还是高手厉害,谢了,不过为什么对角中间老是出一条绿线,能解决吗
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-9-28 19:27 , Processed in 0.082595 second(s), 24 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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