PNG按钮需要鼠标移动到指定的位置才能显示的问题[已解决]
本帖最后由 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
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 =
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], $x, $y, $w, $h)
Else
_GDIPlus_GraphicsDrawImageRect($hGraphic2, $IconInfo[$i], $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 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 = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\btn_mini_highlight.png")
$IconInfo = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\btn_mini_down.png")
$IconInfo = False
$IconInfo = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\btn_max_highlight.png")
$IconInfo = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\btn_max_down.png")
$IconInfo = False
$IconInfo = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\btn_close_highlight.png")
$IconInfo = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\btn_close_down.png")
$IconInfo = False
$IconInfo = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\1.png")
$IconInfo = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\2.png")
$IconInfo = False
$IconInfo = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\3.png")
$IconInfo = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\4.png")
$IconInfo = False
EndFunc ;==>IconInfo_Loading
{:face (394):}..... 有没有大大帮忙解决一下啊~~ 同来学习,大大们出来吧 在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
回复 4# haijie1223
高手~~谢谢大神一阵见血的解决了问题~ 貌似不错哦。~~~~~~~~~
页:
[1]