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

[AU3基础] 求助。PNG做界面 按钮效果..

  [复制链接]
发表于 2012-8-3 15:42:11 | 显示全部楼层 |阅读模式


求助怎么样实现。鼠标移动到 最大化,最小化,关闭 那里的时候。替换一个别的PNG。
并可以点击。进行操作 。。。。以下代码是根据 298311657 的 《图片按钮+多张PNG图片做GUI背景示例》修改的

附上代码。求大大们指导下!
#Region ;**** 参数创建于 ACNWrapper_GUI ****
#AutoIt3Wrapper_UseX64=n
#EndRegion ;**** 参数创建于 ACNWrapper_GUI ****
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GDIPlus.au3>
#include <WinAPI.au3>
#include <Thread.au3>

_RTEmptyWorkingSet();Thread.au3里的函数,减少内存占用的
Global $hGUIxx
Global $Width = 480, $Height = 320
Global $PanBtnRect[3],$topbutton[3],$topbuttonhoverimg[3],$topbuttondownimg[3],$topbuttontip[3]

_GDIPlus_Startup()

$hGUI = GUICreate("CrossDoor_Player", $Width, $Height, -1, -1, $WS_CAPTION, $WS_EX_LAYERED)
#region 窗体背景
$bg = _GDIPlus_ImageLoadFromFile("ok.png")
$hGraphic = _GDIPlus_ImageGetGraphicsContext($bg)
$Bgbitmap = _GDIPlus_BitmapCreateFromGraphics($Width, $Height, $hGraphic)
$hGraphic2 = _GDIPlus_ImageGetGraphicsContext($Bgbitmap)
_GDIPlus_GraphicsDrawImageRect($hGraphic2, $bg, 0, 0, $Width, $Height)

$logo = _GDIPlus_ImageLoadFromFile("logo.png")
_GDIPlus_GraphicsDrawImageRect($hGraphic2, $logo, 1, 1, 478, 20)
$mini = _GDIPlus_ImageLoadFromFile("btn_mini_highlight.png")
_GDIPlus_GraphicsDrawImageRect($hGraphic2, $mini, 380, 0, 28, 20)
$max = _GDIPlus_ImageLoadFromFile("btn_max_highlight.png")
_GDIPlus_GraphicsDrawImageRect($hGraphic2, $max, 408, 0, 28, 20)
$close = _GDIPlus_ImageLoadFromFile("btn_close_highlight.png")
_GDIPlus_GraphicsDrawImageRect($hGraphic2, $close, 436, 0, 39, 20)
SetBitmap($hGUI, $Bgbitmap)
GUISetState()

#region 创建控件窗口,所有控件在此窗口建立
$ControlGUI = GUICreate("ControlGUI", 480, 340, 32, -20, $WS_POPUP, $WS_EX_LAYERED + $WS_EX_MDICHILD, $hGUI)
GUISetFont(11, 400, -1, "Comic Sans MS")
GUISetBkColor(0x123456, $ControlGUI)


                
GUISetState()
GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")
GUIRegisterMsg($WM_SYSCOMMAND, "WM_SYSCOMMAND")
GUIRegisterMsg($WM_NCHITTEST, "WM_NCHITTEST")


While 1
        Sleep(1000)
WEnd

Func WM_COMMAND($hWnd, $iMsg, $iwParam, $ilParam) ;命令消息回调函数
        Dim $iIDFrom = BitAND($iwParam, 0xFFFF)
        Dim $iCode = BitShift($iwParam, 16)
        Dim $hControl = GUICtrlGetHandle($iIDFrom)
;~         Switch $iIDFrom
;~                 Case $hTestBtn
;~                         Switch $iCode
;~                                 Case 0
;~                                         MsgBox(0,"测试按钮!", GUICtrlRead($hText))
;~                         EndSwitch
;~                 Case $hExitBtn
;~                         Switch $iCode
;~                                 Case 0
;~                                         jindt()
;~                         EndSwitch
;~         EndSwitch
EndFunc

Func WM_SYSCOMMAND($hWnd, $Msg, $wParam, $lParam)
        Local $nID = BitAND($wParam, 0x0000FFFF)
        Switch $nID
                Case 0xf060
                        If $hWnd = $HGui Then
                                Exit
                        Else
                                GUIDelete($hWnd)
                        EndIf
        EndSwitch
EndFunc   ;==>WM_SYSCOMMAND

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 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

本帖子中包含更多资源

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

×
发表于 2012-8-3 16:25:03 | 显示全部楼层
回复 1# z3519251


    参考这个贴子。
 楼主| 发表于 2012-8-3 16:31:49 | 显示全部楼层
回复  z3519251


    参考这个贴子。
freedom 发表于 2012-8-3 16:25



请问 参考那个帖子 ??
 楼主| 发表于 2012-8-3 16:45:59 | 显示全部楼层
怎么没人来帮帮忙呢 ??
发表于 2012-8-3 17:34:50 | 显示全部楼层
回复 4# z3519251


    http://www.autoitx.com/thread-28704-1-1.html

不好意思,刚才没有发起。现在可以了。
发表于 2012-8-3 21:56:10 | 显示全部楼层
本帖最后由 298311657 于 2012-8-3 21:59 编辑


#NoTrayIcon
#Region ;**** 参数创建于 ACNWrapper_GUI ****
#AutoIt3Wrapper_UseX64=n
#EndRegion ;**** 参数创建于 ACNWrapper_GUI ****
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GuiButton.au3>
#include <GDIPlus.au3>

Global $IconInfo[3][5]

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
EndFunc   ;==>IconInfo_Loading

Global $hGUI
Global $Width = 480, $Height = 320

_GDIPlus_Startup()


$hGUI = GUICreate("CrossDoor", $Width, $Height, -1, -1, $WS_POPUP, $WS_EX_LAYERED)
$cmdMini = GUICtrlCreateButton("", 380, 0, 28, 20)
GUICtrlSetTip(-1, "最小化窗口")
$cmdMax = GUICtrlCreateButton("", 408, 0, 28, 20)
GUICtrlSetTip(-1, "最大化窗口")
$cmdClose = GUICtrlCreateButton("", 436, 0, 39, 20)
GUICtrlSetTip(-1, "关闭窗口")
Global $Buttoninfo[3] = [GUICtrlGetHandle($cmdMini), GUICtrlGetHandle($cmdMax), GUICtrlGetHandle($cmdClose)]


IconInfo_Loading()
$bg = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\ok.png")
$hGraphic = _GDIPlus_ImageGetGraphicsContext($bg)
$Bgbitmap = _GDIPlus_BitmapCreateFromGraphics($Width, $Height, $hGraphic)
$hGraphic2 = _GDIPlus_ImageGetGraphicsContext($Bgbitmap)
_GDIPlus_GraphicsDrawImageRect($hGraphic2, $bg, 0, 0, $Width, $Height)

$Ban = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\logo.png")
_GDIPlus_GraphicsDrawImageRect($hGraphic2, $Ban, 1, 1, 478, 20)

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")
        _GDIPlus_GraphicsDrawImageRect($hGraphic2, $IconInfo[$i][0], $x, $y, $w, $h)
Next

SetBitmap($hGUI, $Bgbitmap)
GUISetState()

$ControlGUI = GUICreate("ControlGUI", 207, 23, 32, 40, $WS_POPUP, $WS_EX_LAYERED + $WS_EX_MDICHILD, $hGUI)
GUISetFont(11, 400, -1, "Comic Sans MS")
GUISetBkColor(0x123456, $ControlGUI)
$hinput = GUICtrlCreateInput("", 0, 0, 207, 23)
_API_SetLayeredWindowAttributes($ControlGUI, 0x123456, 195)
GUISetState()

GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
GUIRegisterMsg($WM_NCHITTEST, "WM_NCHITTEST")

AdlibRegister("ReduceMem", 60000) ;定时清理内存

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
        EndSwitch
        Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_COMMAND

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

        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

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 _ReduceMemory($i_PID = -1);内存释放函数
        If $i_PID <> -1 Then
                Local $ai_Handle = DllCall("kernel32.dll", "int", "OpenProcess", "int", 0x1f0fff, "int", False, "int", $i_PID)
                Local $ai_Return = DllCall("psapi.dll", "int", "EmptyWorkingSet", "long", $ai_Handle[0])
                DllCall("kernel32.dll", "int", "CloseHandle", "int", $ai_Handle[0])
        Else
                Local $ai_Return = DllCall("psapi.dll", "int", "EmptyWorkingSet", "long", -1)
        EndIf
        Return $ai_Return[0]
EndFunc   ;==>_ReduceMemory

Func ReduceMem()
        _ReduceMemory(@AutoItPID)
EndFunc   ;==>ReduceMem
发表于 2012-8-4 10:01:20 | 显示全部楼层
像你这个效果完全没必要用PNG图片。普通的JPG或bmp图片就OK了,更简单
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-12-27 16:55 , Processed in 0.074912 second(s), 23 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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