找回密码
 加入
搜索
查看: 10902|回复: 5

[GUI管理] PNG按钮需要鼠标移动到指定的位置才能显示的问题[已解决]

[复制链接]
发表于 2014-7-27 23:36:50 | 显示全部楼层 |阅读模式
本帖最后由 austere 于 2014-7-30 17:13 编辑

问题如下~  运行后

鼠标移动到指定的位置后

怎么样才能不用鼠标移动到PNG控件的位置也能显示出来呢?
代码是在别人的基础上修改的,现在附上代码,需要的图片已经打包可以直接下载
华为网盘下载地址:下载
论坛下载:

代码如下:
#NoTrayIcon
#Region ;**** 参数创建于 ACNWrapper_GUI ****
#AutoIt3Wrapper_UseX64=n
#EndRegion ;**** 参数创建于 ACNWrapper_GUI ****
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GuiButton.au3>
#include <GDIPlus.au3>
#include <Sound.au3>
#include <wmp.au3>
#include <GuiAVI.au3>

Global $IconInfo[5][5]
Global $hGUI, $bg, $hGraphic2, $hGraphic, $Bgbitmap, $a
Global $Width = 800, $Height = 600

_GDIPlus_Startup()
$a = 1
$hGUI = GUICreate("CrossDoor", $Width, $Height, -1, -1, $WS_POPUP, $WS_EX_LAYERED)
$cmdMini = GUICtrlCreateButton("", 708, -2, 28, 20)
GUICtrlSetTip(-1, "最小化窗口")
$cmdMax = GUICtrlCreateButton("", 735, -2, 28, 20)
GUICtrlSetTip(-1, "最大化窗口")
$cmdClose = GUICtrlCreateButton("", 762, -2, 39, 20)
GUICtrlSetTip(-1, "关闭窗口")
$zuo = GUICtrlCreateButton("", 200, 550, 40, 40)
$you = GUICtrlCreateButton("", 550, 550, 40, 40)
Global $Buttoninfo[5] = [GUICtrlGetHandle($cmdMini), GUICtrlGetHandle($cmdMax), GUICtrlGetHandle($cmdClose), GUICtrlGetHandle($zuo), GUICtrlGetHandle($you)]

IconInfo_Loading()
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")
GUIRegisterMsg($WM_NCHITTEST, "WM_NCHITTEST")
show()
GUISetState()

Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE
_WinAPI_DeleteObject($Bgbitmap)
_GDIPlus_GraphicsDispose($hGraphic2)
_GDIPlus_GraphicsDispose($hGraphic)
_GDIPlus_Shutdown()


Func WM_NOTIFY($hWnd, $Msg, $wParam, $lParam)
        Local Const $BCN_HOTITEMCHANGE = -1249
        Local $tNMBHOTITEM = DllStructCreate("hwnd hWndFrom;int IDFrom;int Code;dword dwFlags", $lParam)
        Local $nNotifyCode = DllStructGetData($tNMBHOTITEM, "Code")
        Local $nID = DllStructGetData($tNMBHOTITEM, "IDFrom")
        Local $hCtrl = DllStructGetData($tNMBHOTITEM, "hWndFrom")
        Local $dwFlags = DllStructGetData($tNMBHOTITEM, "dwFlags")
        Switch $nNotifyCode
                Case $BCN_HOTITEMCHANGE; Win XP 支持
                        If BitAND($dwFlags, 0x10) = 0x10 Then
                                FlashCtl($hCtrl, True)
                        ElseIf BitAND($dwFlags, 0x20) = 0x20 Then
                                FlashCtl($hCtrl, False)
                        EndIf
        EndSwitch
        Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY

Func WM_COMMAND($hWnd, $iMsg, $iwParam, $ilParam)
        Dim $iIDFrom = BitAND($iwParam, 0xFFFF)
        Dim $iCode = BitShift($iwParam, 16)

        Switch $iIDFrom
                Case $cmdMini
                        If $iCode = $BN_CLICKED Then WinSetState($hWnd, "", @SW_MINIMIZE)
                Case $cmdMax
                        If $iCode = $BN_CLICKED Then WinSetState($hWnd, "", @SW_MAXIMIZE)
                Case $cmdClose
                        If $iCode = $BN_CLICKED Then Exit
                Case $you
                        If $iCode = $BN_CLICKED And $a < 4 Then
                                $a = $a + 1
                                MsgBox(0, "", $a, 0.3)
                                show()
                        Else
                                MsgBox(0, "", "已经是最后一张了,不要再点了哦")
                        EndIf
                Case $zuo
                        If $iCode = $BN_CLICKED And $a > 1 Then
                                $a = $a - 1
                                MsgBox(0, "", $a, 0.3)
                                show()
                        EndIf
        EndSwitch
        Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_COMMAND

Func FlashCtl($hControl, $iFlag)
        _GDIPlus_GraphicsClear($hGraphic2, 0x00FFFFFF)
        _GDIPlus_GraphicsDrawImageRect($hGraphic2, $bg, 0, 0, $Width, $Height)

        For $i = 0 To UBound($Buttoninfo) - 1
                $trect = _WinAPI_GetWindowRect($Buttoninfo[$i])
                $x = DllStructGetData($trect, "left")
                $y = DllStructGetData($trect, "top")
                $w = DllStructGetData($trect, "right") - DllStructGetData($trect, "left")
                $h = DllStructGetData($trect, "Bottom") - DllStructGetData($trect, "top")
                $trect = _WinAPI_GetWindowRect($hGUI)
                $x = $x - DllStructGetData($trect, "left")
                $y = $y - DllStructGetData($trect, "top")
                If $iFlag And $hControl = $Buttoninfo[$i] Then
                        _GDIPlus_GraphicsDrawImageRect($hGraphic2, $IconInfo[$i][1], $x, $y, $w, $h)
                Else
                        _GDIPlus_GraphicsDrawImageRect($hGraphic2, $IconInfo[$i][0], $x, $y, $w, $h)
                EndIf
        Next
        SetBitmap($hGUI, $Bgbitmap)
        Sleep(30)
EndFunc   ;==>FlashCtl


Func SetBitmap($hGUI, $hImage, $iOpacity = 255)
        Local $hScrDC, $hMemDC, $hBitmap, $hOld, $pSize, $tSize, $pSource, $tSource, $pBlend, $tBlend
        $hScrDC = _WinAPI_GetDC(0)
        $hMemDC = _WinAPI_CreateCompatibleDC($hScrDC)
        $hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage)
        $hOld = _WinAPI_SelectObject($hMemDC, $hBitmap)
        $tSize = DllStructCreate($tagSIZE)
        $pSize = DllStructGetPtr($tSize)
        DllStructSetData($tSize, "X", _GDIPlus_ImageGetWidth($hImage))
        DllStructSetData($tSize, "Y", _GDIPlus_ImageGetHeight($hImage))
        $tSource = DllStructCreate($tagPOINT)
        $pSource = DllStructGetPtr($tSource)
        $tBlend = DllStructCreate($tagBLENDFUNCTION)
        $pBlend = DllStructGetPtr($tBlend)
        DllStructSetData($tBlend, "Alpha", $iOpacity)
        DllStructSetData($tBlend, "Format", 1)
        _WinAPI_UpdateLayeredWindow($hGUI, $hScrDC, 0, $pSize, $hMemDC, $pSource, 0, $pBlend, $ULW_ALPHA)
        _WinAPI_SelectObject($hMemDC, $hOld)
        _WinAPI_ReleaseDC(0, $hScrDC)
        _WinAPI_DeleteDC($hMemDC)
        _WinAPI_DeleteObject($hBitmap)
EndFunc   ;==>SetBitmap


Func WM_NCHITTEST($hWnd, $iMsg, $iwParam, $ilParam)
        Switch $hWnd
                Case $hGUI
                        Switch $iMsg
                                Case $WM_NCHITTEST
                                        Return $HTCAPTION
                        EndSwitch
        EndSwitch
        Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NCHITTEST

Func _API_SetLayeredWindowAttributes($hwnd, $i_transcolor, $Transparency = 255, $isColorRef = False)
        Local Const $AC_SRC_ALPHA = 1
        Local Const $ULW_ALPHA = 2
        Local Const $LWA_ALPHA = 0x2
        Local Const $LWA_COLORKEY = 0x1
        If Not $isColorRef Then
                $i_transcolor = Hex(String($i_transcolor), 6)
                $i_transcolor = Execute('0x00' & StringMid($i_transcolor, 5, 2) & StringMid($i_transcolor, 3, 2) & StringMid($i_transcolor, 1, 2))
        EndIf
        Local $Ret = DllCall("user32.dll", "int", "SetLayeredWindowAttributes", "hwnd", $hwnd, "long", $i_transcolor, "byte", $Transparency, "long", $LWA_COLORKEY + $LWA_ALPHA)
        If @error Then
                Return SetError(@error, 0, 0)
        ElseIf $Ret[0] = 0 Then
                Return SetError(4, 0, 0)
        Else
                Return 1
        EndIf
EndFunc   ;==>_API_SetLayeredWindowAttributes


Func show()
        $bg = _GDIPlus_ImageLoadFromFile(@ScriptDir & "" & $a & ".jpg")
        $hGraphic = _GDIPlus_ImageGetGraphicsContext($bg)
        $Bgbitmap = _GDIPlus_BitmapCreateFromGraphics($Width, $Height, $hGraphic)
        $hGraphic2 = _GDIPlus_ImageGetGraphicsContext($Bgbitmap)
        _GDIPlus_GraphicsDrawImageRect($hGraphic2, $bg, 0, 0, $Width, $Height)
        SetBitmap($hGUI, $Bgbitmap)
EndFunc   ;==>show

Func IconInfo_Loading()
        $IconInfo[0][0] = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\btn_mini_highlight.png")
        $IconInfo[0][1] = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\btn_mini_down.png")
        $IconInfo[0][2] = False

        $IconInfo[1][0] = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\btn_max_highlight.png")
        $IconInfo[1][1] = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\btn_max_down.png")
        $IconInfo[1][2] = False

        $IconInfo[2][0] = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\btn_close_highlight.png")
        $IconInfo[2][1] = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\btn_close_down.png")
        $IconInfo[2][2] = False
        
        $IconInfo[3][0] = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\1.png")
        $IconInfo[3][1] = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\2.png")
        $IconInfo[3][2] = False
        
        $IconInfo[4][0] = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\3.png")
        $IconInfo[4][1] = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\4.png")
        $IconInfo[4][2] = False
EndFunc   ;==>IconInfo_Loading

本帖子中包含更多资源

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

×
 楼主| 发表于 2014-7-28 17:43:36 | 显示全部楼层
..... 有没有大大帮忙解决一下啊~~
发表于 2014-7-29 18:37:26 | 显示全部楼层
同来学习,大大们出来吧
发表于 2014-7-29 19:19:52 | 显示全部楼层
在show()函数的最后一行运行一下刷新函数FlashCtl($hGUI, True)
Func show()
        $bg = _GDIPlus_ImageLoadFromFile(@ScriptDir & "" & $a & ".jpg")
        $hGraphic = _GDIPlus_ImageGetGraphicsContext($bg)
        $Bgbitmap = _GDIPlus_BitmapCreateFromGraphics($Width, $Height, $hGraphic)
        $hGraphic2 = _GDIPlus_ImageGetGraphicsContext($Bgbitmap)
        _GDIPlus_GraphicsDrawImageRect($hGraphic2, $bg, 0, 0, $Width, $Height)
        SetBitmap($hGUI, $Bgbitmap)
       FlashCtl($hGUI, True)
EndFunc   ;==>show
 楼主| 发表于 2014-7-30 17:12:48 | 显示全部楼层
回复 4# haijie1223


    高手~~  谢谢大神一阵见血的解决了问题~
发表于 2014-8-2 16:42:59 | 显示全部楼层
貌似不错哦。~~~~~~~~~
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-12-22 15:15 , Processed in 0.092993 second(s), 24 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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