找回密码
 加入
搜索
查看: 4132|回复: 6

[图形处理] (已解决)关于使用GUIRegisterMsg消息的问题

  [复制链接]
发表于 2011-3-30 20:50:56 | 显示全部楼层 |阅读模式
本帖最后由 gto250 于 2011-3-30 22:20 编辑


#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3>
#include <Misc.au3>
#include <WinAPI.au3>
#include <GDIPlus.au3>
#include <ScreenCapture.au3>
Opt("GUIOnEventMode", 1)

_GDIPlus_Startup()
Dim $p_x = 5
Dim $p_y = 5
Dim $p_w = 180
Dim $p_h = 220
Dim $c_w = 80
Dim $c_h = 100
Dim $k = 0
$hGUI = GUICreate("Form1", 600, 400, 192, 124)
GUISetOnEvent($GUI_EVENT_CLOSE, "close")
$Pic1 = GUICtrlCreatePic(@ScriptDir & "\dd.jpg", $p_x, $p_y, $p_w, $p_h, BitOR($SS_NOTIFY, $WS_GROUP, $WS_BORDER, $WS_CLIPSIBLINGS))
GUISetState()
$hChild = GUICreate("Form2", 80, 100, ($p_w - $c_w) / 2 + 5, ($p_h - $c_h) / 2 + 5, $WS_POPUP, $WS_EX_MDICHILD, $hGUI)
GUICtrlCreateLabel("", 0, 0, 100, 100, -1, $GUI_WS_EX_PARENTDRAG)
GUISetBkColor(0x0054E3)
GUIRegisterMsg(0x0203, "_SaveCapture")
GUIRegisterMsg(0x0003, "MY_WM_MOVEING")
WinSetTrans($hChild, "", 100)
GUISetState()


While 1
        Sleep(1000)
WEnd

Func _SaveCapture($hWnd, $iMsg, $iwParam, $ilParam)

        If $hWnd = WinGetHandle($hChild) Then

                _ScreenCapture_CaptureWnd(@ScriptDir & "\020202.jpg", $hChild)
        EndIf
EndFunc   ;==>_SaveCapture

Func MY_WM_MOVEING($hWnd, $Msg, $wParam, $lParam)
        If $hWnd = WinGetHandle($hChild) Then
                $GUI_xy = WinGetPos($hGUI)
                $Child_xy = WinGetPos($hChild)
                $GUI_m_xy = GUIGetCursorInfo($hGUI)
                $Child_m_xy = GUIGetCursorInfo($hChild)
                $iLeft = $GUI_xy[0] + $p_x + 5
                $iTop = $GUI_xy[1] + $p_y + 32
                $iRight = $GUI_xy[0] + $p_w + $p_x + 1
                $iBottom = $GUI_xy[1] + $p_h + $p_y + 26
                If $Child_xy[0] < $iLeft Then
                        _WinAPI_Mouse_Event(0x0004)
                        WinMove($hWnd, "", $iLeft + 1, Default, Default, Default, 1)
                        ;_WinAPI_Mouse_Event(0x0002)
                EndIf
                If $Child_xy[1] < $iTop Then
                        _WinAPI_Mouse_Event(0x0004)
                        WinMove($hWnd, "", Default, $iTop + 1, Default, Default, 1)
                        ;_WinAPI_Mouse_Event(0x0002)
                EndIf
                If $Child_xy[0] + $c_w > $iRight Then
                        _WinAPI_Mouse_Event(0x0004)
                        WinMove($hWnd, "", $iRight - $c_w - 1, Default, Default, Default, 1)
                        ; _WinAPI_Mouse_Event(0x0002)
                EndIf
                If $Child_xy[1] + $c_h > $iBottom Then
                        _WinAPI_Mouse_Event(0x0004)
                        WinMove($hWnd, "", Default, $iBottom - $c_h - 1, Default, Default, 1)
                        ; _WinAPI_Mouse_Event(0x0002)
                EndIf

        EndIf
EndFunc   ;==>MY_WM_MOVEING

Func close()
        Exit
EndFunc   ;==>close


上面的代码我要实现的功能是,左键双击淡蓝色的框,就在当前目录下生成一张截图,但是不知道什么原因,这个代码不成功!
帮忙看下。我自己检查的结果就是Func _SaveCapture($hWnd, $iMsg, $iwParam, $ilParam)根本就获取不到$hWnd=$hChild
图片的话,大家可以选择任意的图片。只要改名为dd.jpg放在脚本目录下即可

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?加入

×
发表于 2011-3-30 21:11:37 | 显示全部楼层
帮你顶起来吧。我也不知道了!
发表于 2011-3-30 21:22:54 | 显示全部楼层
我也不知道!继续关注。
发表于 2011-3-30 21:43:07 | 显示全部楼层
本帖最后由 afan 于 2011-3-30 21:45 编辑

在控件上双击时是不会有 WM_LBUTTONDBLCLK 消息的

btw,5000贴在这里诞生…

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?加入

×
 楼主| 发表于 2011-3-30 21:54:09 | 显示全部楼层
那不用控件的话要怎么改呢?
发表于 2011-3-30 21:57:15 | 显示全部楼层
本帖最后由 afan 于 2011-3-30 21:59 编辑

用 WM_COMMAND 消息也行~
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3>
#include <Misc.au3>
#include <WinAPI.au3>
#include <GDIPlus.au3>
#include <ScreenCapture.au3>
Opt("GUIOnEventMode", 1)

_GDIPlus_Startup()
Dim $p_x = 5
Dim $p_y = 5
Dim $p_w = 180
Dim $p_h = 220
Dim $c_w = 80
Dim $c_h = 100
Dim $k = 0
$hGUI = GUICreate("Form1", 600, 400, 192, 124)
GUISetOnEvent($GUI_EVENT_CLOSE, "close")
$Pic1 = GUICtrlCreatePic(@ScriptDir & "\dd.jpg", $p_x, $p_y, $p_w, $p_h, BitOR($SS_NOTIFY, $WS_GROUP, $WS_BORDER, $WS_CLIPSIBLINGS))
GUISetState()
$hChild = GUICreate("Form2", 80, 100, ($p_w - $c_w) / 2 + 5, ($p_h - $c_h) / 2 + 5, $WS_CHILD + $WS_POPUP, $WS_EX_MDICHILD, $hGUI) 
GUISetBkColor(0x0054E3)
$Label = GUICtrlCreateLabel("", 0, 0, 100, 100, -1, $GUI_WS_EX_PARENTDRAG)
WinSetTrans($hChild, "", 100)
GUISetState()

GUIRegisterMsg(0x0111, '_WM_COMMAND')
GUIRegisterMsg(0x0003, "MY_WM_MOVEING")

While 1
        Sleep(1000)
WEnd

Func _WM_COMMAND($hWnd, $msg, $wParam, $lParam)
        #forceref $hWnd, $Msg
        If BitAND($wParam, 0xFFFF) = $Label And BitShift($wParam, 16) Then
                _ScreenCapture_CaptureWnd(@ScriptDir & "\020202.jpg", $hChild)
        EndIf
EndFunc   ;==>_WM_COMMAND

Func MY_WM_MOVEING($hWnd, $msg, $wParam, $lParam)
        If $hWnd = $hChild Then
                $GUI_xy = WinGetPos($hGUI)
                $Child_xy = WinGetPos($hChild)
                $GUI_m_xy = GUIGetCursorInfo($hGUI)
                $Child_m_xy = GUIGetCursorInfo($hChild)
                $iLeft = $GUI_xy[0] + $p_x + 5
                $iTop = $GUI_xy[1] + $p_y + 32
                $iRight = $GUI_xy[0] + $p_w + $p_x + 1
                $iBottom = $GUI_xy[1] + $p_h + $p_y + 26
                If $Child_xy[0] < $iLeft Then
                        _WinAPI_Mouse_Event(0x0004)
                        WinMove($hWnd, "", $iLeft + 1, Default, Default, Default, 1)
                        ;_WinAPI_Mouse_Event(0x0002)
                EndIf
                If $Child_xy[1] < $iTop Then
                        _WinAPI_Mouse_Event(0x0004)
                        WinMove($hWnd, "", Default, $iTop + 1, Default, Default, 1)
                        ;_WinAPI_Mouse_Event(0x0002)
                EndIf
                If $Child_xy[0] + $c_w > $iRight Then
                        _WinAPI_Mouse_Event(0x0004)
                        WinMove($hWnd, "", $iRight - $c_w - 1, Default, Default, Default, 1)
                        ; _WinAPI_Mouse_Event(0x0002)
                EndIf
                If $Child_xy[1] + $c_h > $iBottom Then
                        _WinAPI_Mouse_Event(0x0004)
                        WinMove($hWnd, "", Default, $iBottom - $c_h - 1, Default, Default, 1)
                        ; _WinAPI_Mouse_Event(0x0002)
                EndIf

        EndIf
EndFunc   ;==>MY_WM_MOVEING

Func close()
        Exit
EndFunc   ;==>close
 楼主| 发表于 2011-3-30 22:20:00 | 显示全部楼层
非常感谢!!!
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-5-19 17:13 , Processed in 0.087492 second(s), 25 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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