纯png背景和按钮界面,如何再添加按钮和更改按钮尺寸和添加鼠标动作?
个人比较喜欢图片做的GUI,经搜索发现论坛有发哥从英文论坛转帖的png按钮实例,编译环境是自由天空au3最新版
原贴链接
http://www.autoit3.cn/forum.php?mod=viewthread&tid=27066&highlight=png%2B%B0%B4%C5%A5http://www.autoit3.cn/forum.php?mod=viewthread&tid=27066&highlight=png%2B%B0%B4%C5%A5
我常识着做一个有6个不同大小的png按钮,依据发哥的转帖做界面,琢磨了好久遇到困难始终无法解决,只能向论坛长老和大神求教
想做的png演示界面
请教的问题:
一,要添加6个或者更多不同大小的png按钮,但是依据原始贴我只能添加3个按钮并且按钮都不执行鼠标动作(就是按下或者按上图片不变化,也没有执行动作)
二,原始帖子中图片按钮是用i定义的,执行动作时用的case 0 ,case 1这种,如何写成case 按钮1,case按钮2这种?
我做的源码;发哥原贴地址链接http://www.autoit3.cn/forum.php?mod=viewthread&tid=27066&highlight=png%2B%B0%B4%C5%A5
#include <WinAPI.au3>
#include <GDIPlus.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
Opt("TrayAutoPause", 0)
OnAutoItExitRegister("DisposeAll")
_GDIPlus_Startup()
;Global $GT = "GUI Title", $ImgA,$ImgA1,$ImgA2, $PosA, $Tab, $TabA, $But, $ButA, $TabNum = 4
Global $GT = " PNG图片按钮示例", $ImgA,$ImgA1,$ImgA2,$PosA, $Tab, $TabA, $But, $ButA, $TabNum = 4
;定义界面大小
$width77 =799
$height77 = 407
;定义界面大小
;AAA第一个图片按钮
$ImgA = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\anniu1a.png")
$ImgA = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\annniu1b.png")
$ImgA = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\anniu1a.png")
;AAA第一个图片按钮
;AAA第个二图片按钮
$ImgA1 = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\anniu2a.png")
$ImgA1 = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\anniu2b.png")
$ImgA1 = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\anniu2a.png")
;AAA第个二图片按钮
;AAA第个三图片按钮
$ImgA2 = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\anniu3a.png")
$ImgA2 = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\anniu3b.png")
$ImgA2 = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\anniu3a.png")
;AAA第个三图片按钮
;AAA第个三图片按钮
;第四个按钮我怎么也就添加不上去了
;AAA这是设限第一层背景图片
Local $Img1 = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\bg.png")
;AAA这是设限第一层背景图片
;AAA这是设限第二层背景图片
Local $Img2 = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\bg1.png")
;AAA这是设限第二层背景图片
; main GUI with title
Global $USWin = GUICreate($GT,$width77, $height77, (@DesktopWidth-$width77)/2,(@DesktopHeight-$height77)/2, 0x80000000, BitOR(0x00080000, 0x00000008));, 0x80)
Local $hGraphic1a = _GDIPlus_GraphicsCreateFromHWND(_WinAPI_GetDesktopWindow())
Local $hBitmapa = _GDIPlus_BitmapCreateFromGraphics(799, 407, $hGraphic1a);这是设置界面背景的地方
Local $hGraphic2a = _GDIPlus_ImageGetGraphicsContext($hBitmapa)
;这是设置第一层背景的地方
_GDIPlus_GraphicsDrawImageRect($hGraphic2a, $Img1,0, 0, 799, 407)
;这是设置第一层背景的地方
;这是设置第二层背景的地方
_GDIPlus_GraphicsDrawImageRect($hGraphic2a, $Img2,0, 0, 799, 407)
;这是设置第二层背景的地方
_GDIPlus_GraphicsDrawString_($hGraphic2a, $GT, 0, 11, "Comic Sans MS", 12)
_GDIPlus_GraphicsDispose($hGraphic2a)
_GDIPlus_GraphicsDispose($hGraphic1a)
SetBitmap($USWin, $hBitmapa, 255)
_GDIPlus_GraphicsDispose($hBitmapa)
_GDIPlus_ImageDispose($Img1)
_GDIPlus_ImageDispose($Img2)
$PosA = GUICtrlCreateLabel("", 0, 198, 157, 30)
$PosA[$TabNum + 1] = GUICtrlCreateLabel("", 137, 402, 160, 35); save button
$PosA[$TabNum + 2] = GUICtrlCreateLabel("", 317, 402, 160, 35); close button
For $i = 1 To $TabNum + 2
$PosA[$i] = 0
next
; 第一个按钮的位置设置(310, 175,是设置位置的,前两个数值不知道是干什么用的)
$But = GUICreate($GT, 245, 38, 342, 175, 0x80000000, BitOR(0x00080000, 0x00000008, 0x00000040, 0x08000000), $USWin)
DrawImg($ButA, 1, $ImgA, "这是第一个按钮", 10, 4, "Comic Sans MS", 11)
SetBitmap($But, $ButA, 255)
; 第一个按钮的位置设置
; 第二个按钮的位置设置(文字提示的长度我不知道从哪里更改)
$But = GUICreate($GT, 345, 38, 455, 125, 0x80000000, BitOR(0x00080000, 0x00000008, 0x00000040, 0x08000000), $USWin)
DrawImg($ButA, 2, $ImgA1, "这是第二个按钮", 10, 4, "Comic Sans MS", 11)
SetBitmap($But, $ButA, 255)
; 第二个按钮的位置设置
; 第三个按钮的位置设置
$But = GUICreate($GT, 645, 38, 628, 75, 0x80000000, BitOR(0x00080000, 0x00000008, 0x00000040, 0x08000000), $USWin)
DrawImg($ButA, 3, $ImgA2, "这是第三个按钮", 10, 4, "Comic Sans MS", 11)
SetBitmap($But, $ButA, 255)
; 第三个按钮的位置设置
; release loaded images
_GDIPlus_ImageDispose($ImgA)
_GDIPlus_ImageDispose($ImgA)
_GDIPlus_ImageDispose($ImgA)
_GDIPlus_ImageDispose($ImgA)
; tab controls GUI
$AGUI_Text = GUICreate($GT, 528, 440, 0, 0, 0x80000000, BitOR(0x00080000, 0x00000040), $USWin)
GUISetBkColor(0x003842, $AGUI_Text)
GUICtrlCreateLabel("", 160, 60, 335, 325); label used to hide tab control
GUICtrlSetBkColor(-1, -2)
$TabC = GUICtrlCreateTab(160, 60, 335, 325, -1, 0x00100000)
_WinAPI_SetLayeredWindowAttributes($AGUI_Text, 0x003842, 255)
; show all GUIs - kind of like an animation effect
GUISetState(@SW_SHOW, $USWin)
For $i = 1 To $TabNum
GUISetState(@SW_SHOW, $Tab[$i])
Next
GUISetState(@SW_SHOW, $But)
GUISetState(@SW_SHOW, $But)
GUISetState(@SW_SHOW, $But)
GUISetState(@SW_SHOW, $AGUI_Text)
; set the first tab button as pressed
$curr = 1
;$prev = 0
While 1
For $i = 1 To $TabNum + 2; 4 tabs + 2 buttons
Switch $i
Case 1 To $TabNum; tab buttons - 2-state
If $curr = $i Then ContinueLoop; don't check the state of the current tab
$pos = GUIGetCursorInfo($USWin)
If $pos = $PosA[$i] Then
If $pos = 1 Then ExitLoop
If $pos = 1 Then ExitLoop
While $pos = $PosA[$i]
If GUIGetMsg() = -3 Then Exit
$pos = GUIGetCursorInfo($USWin)
Switch $pos
Case 0; not pressed
If $PosA[$i] <> 1 Then
SetBitmap($Tab[$i], $TabA[$i], 255)
$PosA[$i] = 1
EndIf
Case 1; pressed - change tab
If $PosA[$i] <> 2 Then
SetBitmap($Tab[$curr], $TabA[$curr], 255)
SetBitmap($Tab[$i], $TabA[$i], 255)
GUICtrlSendMsg($TabC, 0x1300 + 48, $i - 1, 0)
$PosA[$i] = 2
;$prev = $curr
$curr = $i
ExitLoop
EndIf
EndSwitch
Sleep(10)
WEnd
If $curr <> $i Then SetBitmap($Tab[$i], $TabA[$i], 255)
$PosA[$i] = 0
EndIf
Case Else; save and close buttons - 3-state
$pos = GUIGetCursorInfo($USWin)
If $pos = $PosA[$i] Then
If $pos = 1 Then ExitLoop
If $pos = 1 Then ExitLoop
While $pos = $PosA[$i]
$pos = GUIGetCursorInfo($USWin)
Switch $pos
Case 0; not pressed
If $PosA[$i] <> 1 Then
SetBitmap($But[$i - $TabNum], $ButA[$i - $TabNum], 255)
$PosA[$i] = 1
EndIf
Case 1
While $pos = 1; holding pressed
$pos = GUIGetCursorInfo($USWin)
Switch $pos
Case $PosA[$i]; on button, pressed
If $PosA[$i] <> 2 Then
SetBitmap($But[$i - $TabNum], $ButA[$i - $TabNum], 255)
$PosA[$i] = 2
EndIf
Case Else; not on button, pressed
If $PosA[$i] <> 3 Then
SetBitmap($But[$i - $TabNum], $ButA[$i - $TabNum], 255)
$PosA[$i] = 3
EndIf
EndSwitch
Sleep(10)
WEnd
If $pos = $PosA[$i] Then
Switch $i - $TabNum
Case 1; 第一个按钮动作从这里产生(不知道怎么改成 case $But 执行某一个动作,case $But 执行某一个动作这样子的)
MsgBox(0 + 262144, $GT, "Saved")
Case 2; 第二个按钮动作从这里产生
Exit
EndSwitch
EndIf
EndSwitch
Sleep(10)
WEnd
SetBitmap($But[$i - $TabNum], $ButA[$i - $TabNum], 255)
$PosA[$i] = 0
EndIf
EndSwitch
Next
Switch GUIGetMsg(); this is for tab controls
Case -3
Exit
EndSwitch
Sleep(10)
WEnd
Func DisposeAll()
For $i = 1 To 2
_GDIPlus_BitmapDispose($ButA[$i])
_GDIPlus_BitmapDispose($ButA[$i])
_GDIPlus_BitmapDispose($ButA[$i])
Next
EndFunc ;==>DisposeAll
;按钮的大小可以从这里设置,但是成统一的大小89*89了
Func DrawImg(ByRef $RetA, $indx, $Imgs, $text, $xx, $yy, $sFont = "Comic Sans MS", $nSize = 10, $ncol = "000000", $iFormat = 0)
For $i = 0 To 2
Local $hGraphic1 = _GDIPlus_GraphicsCreateFromHWND(_WinAPI_GetDesktopWindow())
Local $hBitmap = _GDIPlus_BitmapCreateFromGraphics(89, 89, $hGraphic1)
Local $hGraphic2 = _GDIPlus_ImageGetGraphicsContext($hBitmap)
_GDIPlus_GraphicsDrawImageRect($hGraphic2, $Imgs[$i], 0, 0, 89, 89)
_GDIPlus_GraphicsDrawString_($hGraphic2, $text, $xx, $yy, $sFont, $nSize, $ncol, $iFormat)
_GDIPlus_GraphicsDispose($hGraphic2)
_GDIPlus_GraphicsDispose($hGraphic1)
$RetA[$indx][$i] = $hBitmap
Next
EndFunc ;==>DrawImg
Func _GDIPlus_GraphicsDrawString_($hGraphics, $sString, $nX, $nY, $sFont = "Comic Sans MS", $nSize = 10, $ncol = "000000", $iFormat = 0)
If StringLeft($ncol, 2) = "0x" Then $ncol = StringTrimLeft($ncol, 2)
Local $hBrush = _GDIPlus_BrushCreateSolid("0xFF" & $ncol)
Local $hFormat = _GDIPlus_StringFormatCreate($iFormat)
Local $hFamily = _GDIPlus_FontFamilyCreate($sFont)
Local $hFont = _GDIPlus_FontCreate($hFamily, $nSize)
Local $tLayout = _GDIPlus_RectFCreate($nX, $nY, 0, 0)
Local $aInfo = _GDIPlus_GraphicsMeasureString($hGraphics, $sString, $hFont, $tLayout, $hFormat)
Local $aResult = _GDIPlus_GraphicsDrawStringEx($hGraphics, $sString, $hFont, $aInfo, $hFormat, $hBrush)
Local $iError = @error
_GDIPlus_FontDispose($hFont)
_GDIPlus_FontFamilyDispose($hFamily)
_GDIPlus_StringFormatDispose($hFormat)
_GDIPlus_BrushDispose($hBrush)
Return SetError($iError, 0, $aResult)
EndFunc ;==>_GDIPlus_GraphicsDrawString_
Func SetBitmap($hGUI, $hImage, $iOpacity)
Local $hScrDC = _WinAPI_GetDC(0)
Local $hMemDC = _WinAPI_CreateCompatibleDC($hScrDC)
Local $hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage)
Local $hOld = _WinAPI_SelectObject($hMemDC, $hBitmap)
$tSize = DllStructCreate("long X;long Y")
$pSize = DllStructGetPtr($tSize)
DllStructSetData($tSize, "X", _GDIPlus_ImageGetWidth($hImage))
DllStructSetData($tSize, "Y", _GDIPlus_ImageGetHeight($hImage))
$tSource = DllStructCreate("long X;long Y")
$pSource = DllStructGetPtr($tSource)
$tBlend = DllStructCreate("byte Op;byte Flags;byte Alpha;byte Format")
$pBlend = DllStructGetPtr($tBlend)
DllStructSetData($tBlend, "Alpha", $iOpacity)
DllStructSetData($tBlend, "Format", 1)
_WinAPI_UpdateLayeredWindow($hGUI, $hScrDC, 0, $pSize, $hMemDC, $pSource, 0, $pBlend, 0x02)
_WinAPI_ReleaseDC(0, $hScrDC)
_WinAPI_SelectObject($hMemDC, $hOld)
_WinAPI_DeleteObject($hBitmap)
_WinAPI_DeleteDC($hMemDC)
EndFunc ;==>SetBitmap
图片素材和未完工源码压缩包上传,求大神帮忙解决问题。
#Region ;**** 参数创建于 ACNWrapper_GUI ****
#AutoIt3Wrapper_UseX64=n
#EndRegion ;**** 参数创建于 ACNWrapper_GUI ****
#include "_plusCtrl.au3"
$GUI = GUICreate("plusCtrl示例", 799, 407)
$hplusForm = plusCreateBitmapGui($GUI, @ScriptDir & "\bg.png");使用PNG图片创建异形窗口。必须先设置背景,再创建控件
Local $tSkin1_png = plusSkin(@ScriptDir & "\anniu1a.png", @ScriptDir & "\anniu1b.png", @ScriptDir & "\anniu1a.png")
Local $tSkin2_png = plusSkin(@ScriptDir & "\anniu2a.png", @ScriptDir & "\anniu2b.png", @ScriptDir & "\anniu2a.png")
Local $tSkin3_png = plusSkin(@ScriptDir & "\anniu3a.png", @ScriptDir & "\anniu3b.png", @ScriptDir & "\anniu3a.png")
Local $tSkin4_png = plusSkin(@ScriptDir & "\anniu4a.png", @ScriptDir & "\anniu4b.png", @ScriptDir & "\anniu4a.png")
Local $tSkin5_png = plusSkin(@ScriptDir & "\anniu5a.png", @ScriptDir & "\anniu5b.png", @ScriptDir & "\anniu5a.png")
Local $tSkin6_png = plusSkin(@ScriptDir & "\anniu6a.png", @ScriptDir & "\anniu6b.png", @ScriptDir & "\anniu6a.png")
$plusBtn1 = plusCreateButton("按钮一", 337, 180, 91, 91, $tSkin1_png);创建plusCtrl
plusCtrlSetColor(-1, 0xFF33A5B0);设置plusCtrl文本颜色,颜色值为ARGB格式
plusCtrlSetEvent(-1, "plusCtrlEvent");设置plusCtrl点击事件的响应函数
$plusBtn2 = plusCreateButton("按钮二", 453, 118, 97, 94, $tSkin2_png);创建plusCtrl
plusCtrlSetEvent(-1, "plusCtrlEvent");设置plusCtrl点击事件的响应函数
$plusBtn3 = plusCreateButton("按钮三", 600, 58, 119, 132, $tSkin3_png);创建plusCtrl
plusCtrlSetEvent(-1, "plusCtrlEvent");设置plusCtrl点击事件的响应函数
$plusBtn4 = plusCreateButton("按钮四", 350, 288, 96, 100, $tSkin4_png);创建plusCtrl
plusCtrlSetEvent(-1, "plusCtrlEvent");设置plusCtrl点击事件的响应函数
;下面两个按钮使用GUIGetMsg()消息模式响应点击
$plusBtn5 = plusCreateButton("按钮五", 492, 261, 105, 107, $tSkin5_png);创建plusCtrl
$plusBtn6 = plusCreateButton("按钮六", 635, 201, 121, 123, $tSkin6_png);创建plusCtrl
plusBitmapGuiSetState($GUI);使用plusCreateBitmapGui函数设置背景后,必须使用此函数显示窗口
GUIRegisterMsg($WM_NCHITTEST, "WM_NCHITTEST");窗口拖动
While 1
Switch GUIGetMsg()
Case $GUI_EVENT_CLOSE
Exit
Case $plusBtn5
MsgBox(0,"提示","按钮的文字为:" & plusCtrlRead($plusBtn5))
Case $plusBtn6
MsgBox(0,"提示","按钮的文字为:" & plusCtrlRead($plusBtn6))
EndSwitch
WEnd
Func plusCtrlEvent($iCtrl)
Switch $iCtrl
Case $plusBtn1
MsgBox(0,"提示","按钮的文字为:" & plusCtrlRead($iCtrl))
Case $plusBtn2
MsgBox(0,"提示","按钮的文字为:" & plusCtrlRead($iCtrl))
Case $plusBtn3
MsgBox(0,"提示","按钮的文字为:" & plusCtrlRead($iCtrl))
Case $plusBtn4
MsgBox(0,"提示","按钮的文字为:" & plusCtrlRead($iCtrl))
EndSwitch
EndFunc
Func WM_NCHITTEST($hWnd, $iMsg, $iwParam, $ilParam)
Switch $hWnd
Case $GUI
Switch $iMsg
Case $WM_NCHITTEST
Return $HTCAPTION
EndSwitch
Case Else
Return $HTCLIENT
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc ;==>WM_NCHITTEST 回复 1# 沉默的斗鱼
樓主改的有問題................
在你的 180 跟 181 中間加入
ConsoleWrite("這是第"&$i&"個按鈕")
然後 你在 原始 的一樣的位置 加入
ConsoleWrite("這是第"&$i&"個按鈕")
這兩個你執行看看
原始的 第一個按鈕第二個按鈕 第三個按鈕 第四個按鈕依序而且 每個 $I 對應的按鈕都是對的
1 就是 12就是2
而你的並不是這樣...............
表示你中間改的有問題 本帖最后由 kk_lee69 于 2018-4-24 22:03 编辑
回复 1# 沉默的斗鱼
; 第一個按鈕的位置設置(310, 175,是設置位置的,前兩個數值不知道是幹什麼用的)
你真的有認真研究??
GUICreate
創建 GUI 窗口.
GUICreate ( "標題" [, 寬度 [, 高度 [, 左側 [, 頂部 [, 樣式 [, 擴展樣式 [, 父窗]]]]]]] )
手冊上面基礎的 一個函數你要跟我說 不知道 前兩個位置是幹嘛的?? 回复 1# 沉默的斗鱼
把我改的 跟你的圖片放一起你就可以知道.........
首先 我改了 tab button 1~4 的位置如果你只改這個位置那麼你的按鈕功能就會失效
所以你還得改 $PosA~ $PosA 的位置
那個位置其實它是建立了 四個 空白的 GUICtrlCreateLabel
而 GUICtrlCreateLabel 本身就會響應 點擊事件
#include <WinAPI.au3>
#include <GDIPlus.au3>
Opt("TrayAutoPause", 0)
OnAutoItExitRegister("DisposeAll")
_GDIPlus_Startup()
Global $GT = "GUI Title", $ImgA, $PosA, $Tab, $TabA, $But, $ButA, $TabNum = 4
; loading images
$ImgA = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\anniu1a.png")
$ImgA = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\anniu1b.png")
$ImgA = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\anniu4a.png")
Local $Img1 = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\bg.png")
Local $Img2 = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\title_button.png")
; main GUI with title
Global $USWin = GUICreate($GT, 528, 440, -1, -1, 0x80000000, BitOR(0x00080000, 0x00000008));, 0x80)
Local $hGraphic1a = _GDIPlus_GraphicsCreateFromHWND(_WinAPI_GetDesktopWindow())
Local $hBitmapa = _GDIPlus_BitmapCreateFromGraphics(528, 440, $hGraphic1a)
Local $hGraphic2a = _GDIPlus_ImageGetGraphicsContext($hBitmapa)
_GDIPlus_GraphicsDrawImageRect($hGraphic2a, $Img1, 88, 0, 440, 440)
_GDIPlus_GraphicsDrawImageRect($hGraphic2a, $Img2, 138, 5, 198, 45)
_GDIPlus_GraphicsDrawString_($hGraphic2a, $GT, 148, 11, "Comic Sans MS", 12)
_GDIPlus_GraphicsDispose($hGraphic2a)
_GDIPlus_GraphicsDispose($hGraphic1a)
SetBitmap($USWin, $hBitmapa, 255)
_GDIPlus_GraphicsDispose($hBitmapa)
_GDIPlus_ImageDispose($Img1)
_GDIPlus_ImageDispose($Img2)
; position labels for all buttons
$PosA = GUICtrlCreateLabel("",400, 99, 157, 30); tab buttons
$PosA = GUICtrlCreateLabel("",300 , 132, 157, 30)
$PosA = GUICtrlCreateLabel("",200, 165, 157, 30)
$PosA = GUICtrlCreateLabel("",100, 198, 157, 30)
$PosA[$TabNum + 1] = GUICtrlCreateLabel("", 137, 402, 160, 35); save button
$PosA[$TabNum + 2] = GUICtrlCreateLabel("", 317, 402, 160, 35); close button
For $i = 1 To $TabNum + 2
$PosA[$i] = 0
Next
; tab button 1
$Tab = GUICreate($GT, 165, 227, 400, 100, 0x80000000, BitOR(0x00080000, 0x00000008, 0x00000040, 0x08000000), $USWin)
DrawImg($TabA, 1, $ImgA, "Tab 1", 10, 4, "Comic Sans MS", 11)
SetBitmap($Tab, $TabA, 255); set the first tab button as pressed
; tab button 2
$Tab = GUICreate($GT, 165, 227, 300, 133, 0x80000000, BitOR(0x00080000, 0x00000008, 0x00000040, 0x08000000), $USWin)
DrawImg($TabA, 2, $ImgA, "Tab 2", 10, 4, "Comic Sans MS", 11)
SetBitmap($Tab, $TabA, 255)
; tab button 3
$Tab = GUICreate($GT, 165, 227, 200, 166, 0x80000000, BitOR(0x00080000, 0x00000008, 0x00000040, 0x08000000), $USWin)
DrawImg($TabA, 3, $ImgA, "Tab 3", 10, 4, "Comic Sans MS", 11)
SetBitmap($Tab, $TabA, 255)
; tab button 4
$Tab = GUICreate($GT, 165, 227, 100, 199, 0x80000000, BitOR(0x00080000, 0x00000008, 0x00000040, 0x08000000), $USWin)
DrawImg($TabA, 4, $ImgA, "Tab 4", 10, 4, "Comic Sans MS", 11)
SetBitmap($Tab, $TabA, 255)
; save button
$But = GUICreate($GT, 345, 38, 138, 405, 0x80000000, BitOR(0x00080000, 0x00000008, 0x00000040, 0x08000000), $USWin)
DrawImg($ButA, 1, $ImgA, "Save", 10, 4, "Comic Sans MS", 11)
SetBitmap($But, $ButA, 255)
; close button
$But = GUICreate($GT, 345, 38, 318, 405, 0x80000000, BitOR(0x00080000, 0x00000008, 0x00000040, 0x08000000), $USWin)
DrawImg($ButA, 2, $ImgA, "Close", 10, 4, "Comic Sans MS", 11)
SetBitmap($But, $ButA, 255)
; release loaded images
_GDIPlus_ImageDispose($ImgA)
_GDIPlus_ImageDispose($ImgA)
_GDIPlus_ImageDispose($ImgA)
; tab controls GUI
$AGUI_Text = GUICreate($GT, 528, 440, 0, 0, 0x80000000, BitOR(0x00080000, 0x00000040), $USWin)
GUISetBkColor(0x003842, $AGUI_Text)
GUICtrlCreateLabel("", 160, 60, 335, 325); label used to hide tab control
GUICtrlSetBkColor(-1, -2)
$TabC = GUICtrlCreateTab(160, 60, 335, 325, -1, 0x00100000)
GUICtrlCreateTabItem("T1")
$1 = GUICtrlCreateButton("Button 1", 200, 100, 100, 25)
GUICtrlSetState(-1, 2048)
GUICtrlCreateTabItem("T2")
$2 = GUICtrlCreateButton("Button 2", 200, 150, 100, 25)
GUICtrlSetState(-1, 2048)
GUICtrlCreateTabItem("T3")
$3 = GUICtrlCreateButton("Button 3", 200, 200, 100, 25)
GUICtrlSetState(-1, 2048)
GUICtrlCreateTabItem("T4")
$4 = GUICtrlCreateButton("Button 4", 200, 250, 100, 25)
GUICtrlSetState(-1, 2048)
GUICtrlCreateTabItem("")
_WinAPI_SetLayeredWindowAttributes($AGUI_Text, 0x003842, 255)
; show all GUIs - kind of like an animation effect
GUISetState(@SW_SHOW, $USWin)
For $i = 1 To $TabNum
GUISetState(@SW_SHOW, $Tab[$i])
Next
GUISetState(@SW_SHOW, $But)
GUISetState(@SW_SHOW, $But)
GUISetState(@SW_SHOW, $AGUI_Text)
; set the first tab button as pressed
$curr = 1
;$prev = 0
While 1
For $i = 1 To $TabNum + 2; 4 tabs + 2 buttons
Switch $i
Case 1 To $TabNum; tab buttons - 2-state
If $curr = $i Then ContinueLoop; don't check the state of the current tab
$pos = GUIGetCursorInfo($USWin)
If $pos = $PosA[$i] Then
If $pos = 1 Then ExitLoop
If $pos = 1 Then ExitLoop
While $pos = $PosA[$i]
If GUIGetMsg() = -3 Then Exit
$pos = GUIGetCursorInfo($USWin)
Switch $pos
Case 0; not pressed
If $PosA[$i] <> 1 Then
SetBitmap($Tab[$i], $TabA[$i], 255)
$PosA[$i] = 1
EndIf
Case 1; pressed - change tab
If $PosA[$i] <> 2 Then
SetBitmap($Tab[$curr], $TabA[$curr], 255)
SetBitmap($Tab[$i], $TabA[$i], 255)
GUICtrlSendMsg($TabC, 0x1300 + 48, $i - 1, 0)
$PosA[$i] = 2
;$prev = $curr
$curr = $i
ConsoleWrite("這是第"&$i&"個按鈕")
ExitLoop
EndIf
EndSwitch
Sleep(10)
WEnd
If $curr <> $i Then SetBitmap($Tab[$i], $TabA[$i], 255)
$PosA[$i] = 0
EndIf
Case Else; save and close buttons - 3-state
$pos = GUIGetCursorInfo($USWin)
If $pos = $PosA[$i] Then
If $pos = 1 Then ExitLoop
If $pos = 1 Then ExitLoop
While $pos = $PosA[$i]
$pos = GUIGetCursorInfo($USWin)
Switch $pos
Case 0; not pressed
If $PosA[$i] <> 1 Then
SetBitmap($But[$i - $TabNum], $ButA[$i - $TabNum], 255)
$PosA[$i] = 1
EndIf
Case 1
While $pos = 1; holding pressed
$pos = GUIGetCursorInfo($USWin)
Switch $pos
Case $PosA[$i]; on button, pressed
If $PosA[$i] <> 2 Then
SetBitmap($But[$i - $TabNum], $ButA[$i - $TabNum], 255)
$PosA[$i] = 2
EndIf
Case Else; not on button, pressed
If $PosA[$i] <> 3 Then
SetBitmap($But[$i - $TabNum], $ButA[$i - $TabNum], 255)
$PosA[$i] = 3
EndIf
EndSwitch
Sleep(10)
WEnd
If $pos = $PosA[$i] Then
Switch $i - $TabNum
Case 1; save button pressed
MsgBox(0 + 262144, $GT, "Saved")
Case 2; close button pressed
Exit
EndSwitch
EndIf
EndSwitch
Sleep(10)
WEnd
SetBitmap($But[$i - $TabNum], $ButA[$i - $TabNum], 255)
$PosA[$i] = 0
EndIf
EndSwitch
Next
Switch GUIGetMsg(); this is for tab controls
Case -3
Exit
Case $1, $2, $3, $4
MsgBox(0 + 262144, $GT, "You have pressed a Button")
EndSwitch
Sleep(10)
WEnd
Func DisposeAll()
For $i = 1 To $TabNum
_GDIPlus_BitmapDispose($TabA[$i])
_GDIPlus_BitmapDispose($TabA[$i])
_GDIPlus_BitmapDispose($TabA[$i])
Next
For $i = 1 To 2
_GDIPlus_BitmapDispose($ButA[$i])
_GDIPlus_BitmapDispose($ButA[$i])
_GDIPlus_BitmapDispose($ButA[$i])
Next
EndFunc ;==>DisposeAll
Func DrawImg(ByRef $RetA, $indx, $Imgs, $text, $xx, $yy, $sFont = "Comic Sans MS", $nSize = 10, $ncol = "000000", $iFormat = 0)
For $i = 0 To 2
Local $hGraphic1 = _GDIPlus_GraphicsCreateFromHWND(_WinAPI_GetDesktopWindow())
Local $hBitmap = _GDIPlus_BitmapCreateFromGraphics(165, 38, $hGraphic1)
Local $hGraphic2 = _GDIPlus_ImageGetGraphicsContext($hBitmap)
_GDIPlus_GraphicsDrawImageRect($hGraphic2, $Imgs[$i], 0, 0, 165, 38)
_GDIPlus_GraphicsDrawString_($hGraphic2, $text, $xx, $yy, $sFont, $nSize, $ncol, $iFormat)
_GDIPlus_GraphicsDispose($hGraphic2)
_GDIPlus_GraphicsDispose($hGraphic1)
$RetA[$indx][$i] = $hBitmap
Next
EndFunc ;==>DrawImg
Func _GDIPlus_GraphicsDrawString_($hGraphics, $sString, $nX, $nY, $sFont = "Comic Sans MS", $nSize = 10, $ncol = "000000", $iFormat = 0)
If StringLeft($ncol, 2) = "0x" Then $ncol = StringTrimLeft($ncol, 2)
Local $hBrush = _GDIPlus_BrushCreateSolid("0xFF" & $ncol)
Local $hFormat = _GDIPlus_StringFormatCreate($iFormat)
Local $hFamily = _GDIPlus_FontFamilyCreate($sFont)
Local $hFont = _GDIPlus_FontCreate($hFamily, $nSize)
Local $tLayout = _GDIPlus_RectFCreate($nX, $nY, 0, 0)
Local $aInfo = _GDIPlus_GraphicsMeasureString($hGraphics, $sString, $hFont, $tLayout, $hFormat)
Local $aResult = _GDIPlus_GraphicsDrawStringEx($hGraphics, $sString, $hFont, $aInfo, $hFormat, $hBrush)
Local $iError = @error
_GDIPlus_FontDispose($hFont)
_GDIPlus_FontFamilyDispose($hFamily)
_GDIPlus_StringFormatDispose($hFormat)
_GDIPlus_BrushDispose($hBrush)
Return SetError($iError, 0, $aResult)
EndFunc ;==>_GDIPlus_GraphicsDrawString_
Func SetBitmap($hGUI, $hImage, $iOpacity)
Local $hScrDC = _WinAPI_GetDC(0)
Local $hMemDC = _WinAPI_CreateCompatibleDC($hScrDC)
Local $hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage)
Local $hOld = _WinAPI_SelectObject($hMemDC, $hBitmap)
$tSize = DllStructCreate("long X;long Y")
$pSize = DllStructGetPtr($tSize)
DllStructSetData($tSize, "X", _GDIPlus_ImageGetWidth($hImage))
DllStructSetData($tSize, "Y", _GDIPlus_ImageGetHeight($hImage))
$tSource = DllStructCreate("long X;long Y")
$pSource = DllStructGetPtr($tSource)
$tBlend = DllStructCreate("byte Op;byte Flags;byte Alpha;byte Format")
$pBlend = DllStructGetPtr($tBlend)
DllStructSetData($tBlend, "Alpha", $iOpacity)
DllStructSetData($tBlend, "Format", 1)
_WinAPI_UpdateLayeredWindow($hGUI, $hScrDC, 0, $pSize, $hMemDC, $pSource, 0, $pBlend, 0x02)
_WinAPI_ReleaseDC(0, $hScrDC)
_WinAPI_SelectObject($hMemDC, $hOld)
_WinAPI_DeleteObject($hBitmap)
_WinAPI_DeleteDC($hMemDC)
EndFunc ;==>SetBitmap
回复 4# kk_lee69
谢谢大佬热心,小弟刚看见大佬改的代码,
或许是小弟表述不清楚吧
这个当然清楚,但是我的意思是它在我改的这个窗体上上不起作用,是靠这个Local $hBitmapa = _GDIPlus_BitmapCreateFromGraphics(799, 407, $hGraphic1a)来定义窗体大小的
此外,我的意思是不需要tab,我是单纯想要6个不同背景和尺寸的png按钮添加动作,如果按照发哥的转帖,我直接把tab和按钮背景换了就行了
按钮大小可以从这里更改,
但是源代码里改成统一大小了,我需要的是按钮1,安按钮2,按钮3尺寸都不一样大。
今晚琢磨着已经把6个按钮(不要tab!!!!)添加上去了,但是按钮和动作无效
按钮无动作,png按钮不能自定义大小,这是现在遇到的问题,我把我今晚改的代码上传,劳烦大神再看一下。
如有表述不妥冒犯之处大神谅解。
下面是把6个按钮图片按钮放上去的代码,;发哥原贴地址链接http://www.autoit3.cn/forum.php?mod=viewthread&tid=27066&highlight=png%2B%B0%B4%C5%A5
;这是把6个按钮图片按钮放上去的代码,但无法定义每个按钮大小和鼠标动作
#include <WinAPI.au3>
#include <GDIPlus.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
Opt("TrayAutoPause", 0)
OnAutoItExitRegister("DisposeAll")
_GDIPlus_Startup()
;Global $GT = "GUI Title", $ImgA,$ImgA1,$ImgA2, $PosA, $Tab, $TabA, $But, $ButA, $TabNum = 4
Global $GT = " PNG图片按钮示例", $ImgA,$ImgA1,$ImgA2,$ImgA3,$ImgA4,$ImgA5,$PosA, $Tab, $TabA, $But, $ButA, $TabNum = 4
;定义界面大小
$width77 =799
$height77 = 407
;定义界面大小
;AAA第一个图片按钮
$ImgA = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\anniu1a.png")
$ImgA = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\annniu1b.png")
$ImgA = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\anniu1a.png")
;AAA第一个图片按钮
;AAA第个二图片按钮
$ImgA1 = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\anniu2a.png")
$ImgA1 = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\anniu2b.png")
$ImgA1 = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\anniu2a.png")
;AAA第个二图片按钮
;AAA第个三图片按钮
$ImgA2 = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\anniu3a.png")
$ImgA2 = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\anniu3b.png")
$ImgA2 = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\anniu3a.png")
;AAA第个三图片按钮
;AAA第个三图片按钮
;第四个按钮我怎么也就添加不上去了
$ImgA3 = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\anniu4a.png")
$ImgA3 = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\anniu4b.png")
$ImgA3 = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\anniu4a.png")
;;第四个按钮我怎么也就添加不上去了
$ImgA4 = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\anniu5a.png")
$ImgA4 = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\anniu5b.png")
$ImgA4 = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\anniu5a.png")
;;第四个按钮我怎么也就添加不上去了
$ImgA5 = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\anniu6a.png")
$ImgA5 = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\anniu6b.png")
$ImgA5 = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\anniu6a.png")
;AAA这是设限第一层背景图片
Local $Img1 = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\bg.png")
;AAA这是设限第一层背景图片
;AAA这是设限第二层背景图片
;Local $Img2 = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\bg1.png")
;AAA这是设限第二层背景图片
; main GUI with title
Global $USWin = GUICreate($GT,$width77, $height77, (@DesktopWidth-$width77)/2,(@DesktopHeight-$height77)/2, 0x80000000, BitOR(0x00080000, 0x00000008));, 0x80)
Local $hGraphic1a = _GDIPlus_GraphicsCreateFromHWND(_WinAPI_GetDesktopWindow())
Local $hBitmapa = _GDIPlus_BitmapCreateFromGraphics(799, 407, $hGraphic1a);这是设置界面背景的地方
Local $hGraphic2a = _GDIPlus_ImageGetGraphicsContext($hBitmapa)
;这是设置第一层背景的地方
_GDIPlus_GraphicsDrawImageRect($hGraphic2a, $Img1,0, 0, 799, 407)
;这是设置第一层背景的地方
;这是设置第二层背景的地方
;_GDIPlus_GraphicsDrawImageRect($hGraphic2a, $Img2,0, 0, 799, 407)
;这是设置第二层背景的地方
_GDIPlus_GraphicsDrawString_($hGraphic2a, $GT, 0, 11, "Comic Sans MS", 12)
_GDIPlus_GraphicsDispose($hGraphic2a)
_GDIPlus_GraphicsDispose($hGraphic1a)
SetBitmap($USWin, $hBitmapa, 255)
_GDIPlus_GraphicsDispose($hBitmapa)
_GDIPlus_ImageDispose($Img1)
;_GDIPlus_ImageDispose($Img2)
$PosA = GUICtrlCreateLabel("", 0, 198, 157, 30)
$PosA[$TabNum + 1] = GUICtrlCreateLabel("", 137, 402, 160, 35); save button
$PosA[$TabNum + 2] = GUICtrlCreateLabel("", 317, 402, 160, 35); close button
$PosA[$TabNum + 3] = GUICtrlCreateLabel("", 517, 402, 160, 35); close button
For $i = 1 To $TabNum + 2
$PosA[$i] = 8
next
; 第一个按钮的位置设置(310, 175,是设置位置的,前两个数值不知道是干什么用的)
$But = GUICreate($GT, 245, 38, 312, 125, 0x80000000, BitOR(0x00080000, 0x00000008, 0x00000040, 0x08000000), $USWin)
DrawImg($ButA, 1, $ImgA, "", 10, 4, "Comic Sans MS", 11)
SetBitmap($But, $ButA, 255)
; 第一个按钮的位置设置
; 第二个按钮的位置设置(文字提示的长度我不知道从哪里更改)
$But = GUICreate($GT, 345, 38, 455, 125, 0x80000000, BitOR(0x00080000, 0x00000008, 0x00000040, 0x08000000), $USWin)
DrawImg($ButA, 2, $ImgA1, "这是第二个按钮", 10, 4, "Comic Sans MS", 11)
SetBitmap($But, $ButA, 255)
; 第二个按钮的位置设置
; 第三个按钮的位置设置
$But = GUICreate($GT, 645, 38, 628, 75, 0x80000000, BitOR(0x00080000, 0x00000008, 0x00000040, 0x08000000), $USWin)
DrawImg($ButA, 3, $ImgA2, "这是第三个按钮", 10, 4, "Comic Sans MS", 11)
SetBitmap($But, $ButA, 255)
; 第三个按钮的位置设置
; 第三个按钮的位置设置
$But = GUICreate($GT, 545, 338, 318, 305, 0x80000000, BitOR(0x00080000, 0x00000008, 0x00000040, 0x08000000), $USWin)
DrawImg($ButA, 4, $ImgA3, "这是第四个按钮", 10, 4, "Comic Sans MS", 11)
SetBitmap($But, $ButA, 255)
; 第三个按钮的位置设置
; 第三个按钮的位置设置
$But = GUICreate($GT, 545, 338, 500, 290, 0x80000000, BitOR(0x00080000, 0x00000008, 0x00000040, 0x08000000), $USWin)
DrawImg($ButA, 5, $ImgA4, "这是第五个按钮", 10, 4, "Comic Sans MS", 11)
SetBitmap($But, $ButA, 255)
; 第三个按钮的位置设置
; 第三个按钮的位置设置
$But = GUICreate($GT, 645, 38, 648, 258, 0x80000000, BitOR(0x00080000, 0x00000008, 0x00000040, 0x08000000), $USWin)
DrawImg($ButA, 6, $ImgA5, "这是第六个按钮", 10, 4, "Comic Sans MS", 11)
SetBitmap($But, $ButA, 255)
; 第三个按钮的位置设置
; release loaded images
_GDIPlus_ImageDispose($ImgA)
_GDIPlus_ImageDispose($ImgA)
_GDIPlus_ImageDispose($ImgA)
_GDIPlus_ImageDispose($ImgA)
_GDIPlus_ImageDispose($ImgA)
_GDIPlus_ImageDispose($ImgA)
_GDIPlus_ImageDispose($ImgA)
_GDIPlus_ImageDispose($ImgA)
; tab controls GUI
$AGUI_Text = GUICreate($GT, 528, 440, 0, 0, 0x80000000, BitOR(0x00080000, 0x00000040), $USWin)
GUISetBkColor(0x003842, $AGUI_Text)
GUICtrlCreateLabel("", 160, 60, 335, 325); label used to hide tab control
GUICtrlSetBkColor(-1, -2)
_WinAPI_SetLayeredWindowAttributes($AGUI_Text, 0x003842, 255)
; show all GUIs - kind of like an animation effect
GUISetState(@SW_SHOW, $USWin)
For $i = 1 To $TabNum
GUISetState(@SW_SHOW, $Tab[$i])
Next
GUISetState(@SW_SHOW, $But)
GUISetState(@SW_SHOW, $But)
GUISetState(@SW_SHOW, $But)
GUISetState(@SW_SHOW, $But)
GUISetState(@SW_SHOW, $But)
GUISetState(@SW_SHOW, $But)
GUISetState(@SW_SHOW, $AGUI_Text)
; set the first tab button as pressed
$curr = 1
;$prev = 0
While 1
For $i = 1 To $TabNum + 2; 4 tabs + 2 buttons
Switch $i
Case 1 To $TabNum; tab buttons - 2-state
If $curr = $i Then ContinueLoop; don't check the state of the current tab
$pos = GUIGetCursorInfo($USWin)
If $pos = $PosA[$i] Then
If $pos = 1 Then ExitLoop
If $pos = 1 Then ExitLoop
While $pos = $PosA[$i]
If GUIGetMsg() = -3 Then Exit
$pos = GUIGetCursorInfo($USWin)
Switch $pos
Case 0; not pressed
If $PosA[$i] <> 1 Then
SetBitmap($Tab[$i], $TabA[$i], 255)
$PosA[$i] = 1
EndIf
EndSwitch
WEND
ENDIF
Case Else; save and close buttons - 3-state
$pos = GUIGetCursorInfo($USWin)
If $pos = $PosA[$i] Then
If $pos = 1 Then ExitLoop
If $pos = 1 Then ExitLoop
While $pos = $PosA[$i]
$pos = GUIGetCursorInfo($USWin)
Switch $pos
Case 0; not pressed
If $PosA[$i] <> 1 Then
SetBitmap($But[$i - $TabNum], $ButA[$i - $TabNum], 255)
$PosA[$i] = 1
EndIf
Case 1
While $pos = 1; holding pressed
$pos = GUIGetCursorInfo($USWin)
Switch $pos
Case $PosA[$i]; on button, pressed
If $PosA[$i] <> 2 Then
SetBitmap($But[$i - $TabNum], $ButA[$i - $TabNum], 255)
$PosA[$i] = 2
EndIf
Case Else; not on button, pressed
If $PosA[$i] <> 3 Then
SetBitmap($But[$i - $TabNum], $ButA[$i - $TabNum], 255)
$PosA[$i] = 3
EndIf
EndSwitch
Sleep(10)
WEnd
If $pos = $PosA[$i] Then
Switch $i - $TabNum
Case 1; 第一个按钮动作从这里产生(不知道怎么改成 case $But 执行某一个动作,case $But 执行某一个动作这样子的)
MsgBox(0 + 262144, $GT, "Saved")
Case 2; 第二个按钮动作从这里产生
Exit
EndSwitch
EndIf
EndSwitch
Sleep(10)
WEnd
SetBitmap($But[$i - $TabNum], $ButA[$i - $TabNum], 255)
$PosA[$i] = 0
EndIf
EndSwitch
Next
Switch GUIGetMsg(); this is for tab controls
Case -3
Exit
EndSwitch
Sleep(10)
WEnd
Func DisposeAll()
For $i = 1 To 6
_GDIPlus_BitmapDispose($ButA[$i])
_GDIPlus_BitmapDispose($ButA[$i])
_GDIPlus_BitmapDispose($ButA[$i])
_GDIPlus_BitmapDispose($ButA[$i])
_GDIPlus_BitmapDispose($ButA[$i])
_GDIPlus_BitmapDispose($ButA[$i])
Next
EndFunc ;==>DisposeAll
;按钮的大小可以从这里设置,但是成统一的大小89*89了
Func DrawImg(ByRef $RetA, $indx, $Imgs, $text, $xx, $yy, $sFont = "Comic Sans MS", $nSize = 10, $ncol = "000000", $iFormat = 0)
For $i = 0 To UBound($Imgs)-1
Local $hGraphic1 = _GDIPlus_GraphicsCreateFromHWND(_WinAPI_GetDesktopWindow())
Local $hBitmap = _GDIPlus_BitmapCreateFromGraphics(89, 89, $hGraphic1)
Local $hGraphic2 = _GDIPlus_ImageGetGraphicsContext($hBitmap)
_GDIPlus_GraphicsDrawImageRect($hGraphic2, $Imgs[$i],$xx, $yy, 89, 89)
_GDIPlus_GraphicsDrawString_($hGraphic2, $text, $xx, $yy, $sFont, $nSize, $ncol, $iFormat)
_GDIPlus_GraphicsDispose($hGraphic2)
_GDIPlus_GraphicsDispose($hGraphic1)
$RetA[$indx][$i] = $hBitmap
Next
EndFunc ;==>DrawImg
Func _GDIPlus_GraphicsDrawString_($hGraphics, $sString, $nX, $nY, $sFont = "Comic Sans MS", $nSize = 10, $ncol = "000000", $iFormat = 0)
If StringLeft($ncol, 2) = "0x" Then $ncol = StringTrimLeft($ncol, 2)
Local $hBrush = _GDIPlus_BrushCreateSolid("0xFF" & $ncol)
Local $hFormat = _GDIPlus_StringFormatCreate($iFormat)
Local $hFamily = _GDIPlus_FontFamilyCreate($sFont)
Local $hFont = _GDIPlus_FontCreate($hFamily, $nSize)
Local $tLayout = _GDIPlus_RectFCreate($nX, $nY, 0, 0)
Local $aInfo = _GDIPlus_GraphicsMeasureString($hGraphics, $sString, $hFont, $tLayout, $hFormat)
Local $aResult = _GDIPlus_GraphicsDrawStringEx($hGraphics, $sString, $hFont, $aInfo, $hFormat, $hBrush)
Local $iError = @error
_GDIPlus_FontDispose($hFont)
_GDIPlus_FontFamilyDispose($hFamily)
_GDIPlus_StringFormatDispose($hFormat)
_GDIPlus_BrushDispose($hBrush)
Return SetError($iError, 0, $aResult)
EndFunc ;==>_GDIPlus_GraphicsDrawString_
Func SetBitmap($hGUI, $hImage, $iOpacity)
Local $hScrDC = _WinAPI_GetDC(0)
Local $hMemDC = _WinAPI_CreateCompatibleDC($hScrDC)
Local $hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage)
Local $hOld = _WinAPI_SelectObject($hMemDC, $hBitmap)
$tSize = DllStructCreate("long X;long Y")
$pSize = DllStructGetPtr($tSize)
DllStructSetData($tSize, "X", _GDIPlus_ImageGetWidth($hImage))
DllStructSetData($tSize, "Y", _GDIPlus_ImageGetHeight($hImage))
$tSource = DllStructCreate("long X;long Y")
$pSource = DllStructGetPtr($tSource)
$tBlend = DllStructCreate("byte Op;byte Flags;byte Alpha;byte Format")
$pBlend = DllStructGetPtr($tBlend)
DllStructSetData($tBlend, "Alpha", $iOpacity)
DllStructSetData($tBlend, "Format", 1)
_WinAPI_UpdateLayeredWindow($hGUI, $hScrDC, 0, $pSize, $hMemDC, $pSource, 0, $pBlend, 0x02)
_WinAPI_ReleaseDC(0, $hScrDC)
_WinAPI_SelectObject($hMemDC, $hOld)
_WinAPI_DeleteObject($hBitmap)
_WinAPI_DeleteDC($hMemDC)
EndFunc ;==>SetBitmap
回复 5# 沉默的斗鱼
你沒照我上面的測試 你的按鈕 本來是有效的... 現在你的按鈕無效的..........
另外....按鈕 跟 TAB框一點關係都沒有........
你要先弄懂人家的 每一段程式在做啥 為什麼要這樣做
你才可能去改它的程式...... 回复 5# 沉默的斗鱼
大神,我最终需要的效果是http://www.autoit3.cn/attachments/month_1804/18042418161fe7162f90cbd000.png
就是全图片png按钮,不要按钮上的文字提示,恳请大神支招。 本帖最后由 kk_lee69 于 2018-4-25 00:18 编辑
回复 5# 沉默的斗鱼
TAB 我幫你拿掉了
只有圖片 跟按鈕 還是 拿發哥的改
剩下的自己再改吧.................
圖片用你的
請實際 執行 並且按按看
另外GUICreate 是子窗時子窗的座標限制在 父窗 的客戶區內
這就是 為何 你下的 數值 無法作用問題
#AutoIt3Wrapper_Res_Fileversion=1.1.0.0
#include <WinAPI.au3>
#include <GDIPlus.au3>
Opt("TrayAutoPause", 0)
OnAutoItExitRegister("DisposeAll")
_GDIPlus_Startup()
Global $GT = "GUI Title", $ImgA, $PosA, $BBT, $BBTA, $But, $ButA, $BBTNum = 4
; loading images
$ImgA = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\anniu1a.png")
$ImgA = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\anniu1b.png")
$ImgA = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\anniu4a.png")
Local $Img1 = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\bg.png")
Local $Img2 = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\title_button.png")
; main GUI with title
Global $USWin = GUICreate($GT, 528, 440, -1, -1, 0x80000000, BitOR(0x00080000, 0x00000008));, 0x80)
Local $hGraphic1a = _GDIPlus_GraphicsCreateFromHWND(_WinAPI_GetDesktopWindow())
Local $hBitmapa = _GDIPlus_BitmapCreateFromGraphics(528, 440, $hGraphic1a)
Local $hGraphic2a = _GDIPlus_ImageGetGraphicsContext($hBitmapa)
_GDIPlus_GraphicsDrawImageRect($hGraphic2a, $Img1, 88, 0, 440, 440)
_GDIPlus_GraphicsDrawImageRect($hGraphic2a, $Img2, 138, 5, 198, 45)
_GDIPlus_GraphicsDrawString_($hGraphic2a, $GT, 148, 11, "Comic Sans MS", 12)
_GDIPlus_GraphicsDispose($hGraphic2a)
_GDIPlus_GraphicsDispose($hGraphic1a)
SetBitmap($USWin, $hBitmapa, 255)
_GDIPlus_GraphicsDispose($hBitmapa)
_GDIPlus_ImageDispose($Img1)
_GDIPlus_ImageDispose($Img2)
; position labels for all buttons
$PosA = GUICtrlCreateLabel("",400, 99, 157, 30); tab buttons
$PosA = GUICtrlCreateLabel("",300 , 132, 157, 30)
$PosA = GUICtrlCreateLabel("",200, 165, 157, 30)
$PosA = GUICtrlCreateLabel("",100, 198, 157, 30)
$PosA[$BBTNum + 1] = GUICtrlCreateLabel("", 137, 402, 160, 35); save button
$PosA[$BBTNum + 2] = GUICtrlCreateLabel("", 317, 402, 160, 35); close button
For $i = 1 To $BBTNum + 2
$PosA[$i] = 0
Next
; tab button 1
$BBT = GUICreate($GT, 165, 227, 400, 100, 0x80000000, BitOR(0x00080000, 0x00000008, 0x00000040, 0x08000000), $USWin)
DrawImg($BBTA, 1, $ImgA, "按鈕 1", 10, 4, "Comic Sans MS", 11)
SetBitmap($BBT, $BBTA, 255); set the first tab button as pressed
; tab button 2
$BBT = GUICreate($GT, 165, 227, 300, 133, 0x80000000, BitOR(0x00080000, 0x00000008, 0x00000040, 0x08000000), $USWin)
DrawImg($BBTA, 2, $ImgA, "按鈕 2", 10, 4, "Comic Sans MS", 11)
SetBitmap($BBT, $BBTA, 255)
; tab button 3
$BBT = GUICreate($GT, 165, 227, 200, 166, 0x80000000, BitOR(0x00080000, 0x00000008, 0x00000040, 0x08000000), $USWin)
DrawImg($BBTA, 3, $ImgA, "按鈕 3", 10, 4, "Comic Sans MS", 11)
SetBitmap($BBT, $BBTA, 255)
; tab button 4
$BBT = GUICreate($GT, 165, 227, 100, 199, 0x80000000, BitOR(0x00080000, 0x00000008, 0x00000040, 0x08000000), $USWin)
DrawImg($BBTA, 4, $ImgA, "按鈕 4", 10, 4, "Comic Sans MS", 11)
SetBitmap($BBT, $BBTA, 255)
; save button
$But = GUICreate($GT, 345, 38, 138, 405, 0x80000000, BitOR(0x00080000, 0x00000008, 0x00000040, 0x08000000), $USWin)
DrawImg($ButA, 1, $ImgA, "Save", 10, 4, "Comic Sans MS", 11)
SetBitmap($But, $ButA, 255)
; close button
$But = GUICreate($GT, 345, 38, 318, 405, 0x80000000, BitOR(0x00080000, 0x00000008, 0x00000040, 0x08000000), $USWin)
DrawImg($ButA, 2, $ImgA, "Close", 10, 4, "Comic Sans MS", 11)
SetBitmap($But, $ButA, 255)
; release loaded images
_GDIPlus_ImageDispose($ImgA)
_GDIPlus_ImageDispose($ImgA)
_GDIPlus_ImageDispose($ImgA)
; show all GUIs - kind of like an animation effect
GUISetState(@SW_SHOW, $USWin)
For $i = 1 To $BBTNum
GUISetState(@SW_SHOW, $BBT[$i])
Next
GUISetState(@SW_SHOW, $But)
GUISetState(@SW_SHOW, $But)
; set the first tab button as pressed
$curr = 1
;$prev = 0
While 1
For $i = 1 To $BBTNum + 2; 4 tabs + 2 buttons
Switch $i
Case 1 To $BBTNum; tab buttons - 2-state
If $curr = $i Then ContinueLoop; don't check the state of the current tab
$pos = GUIGetCursorInfo($USWin)
If $pos = $PosA[$i] Then
If $pos = 1 Then ExitLoop
If $pos = 1 Then ExitLoop
While $pos = $PosA[$i]
If GUIGetMsg() = -3 Then Exit
$pos = GUIGetCursorInfo($USWin)
Switch $pos
Case 0; not pressed
If $PosA[$i] <> 1 Then
SetBitmap($BBT[$i], $BBTA[$i], 255)
$PosA[$i] = 1
EndIf
Case 1; pressed - change tab
If $PosA[$i] <> 2 Then
SetBitmap($BBT[$curr], $BBTA[$curr], 255)
SetBitmap($BBT[$i], $BBTA[$i], 255)
_WinAPI_ShowMsg("這是第"&$i&"個按鈕")
$PosA[$i] = 2
;$prev = $curr
$curr = $i
ExitLoop
EndIf
EndSwitch
Sleep(10)
WEnd
If $curr <> $i Then SetBitmap($BBT[$i], $BBTA[$i], 255)
$PosA[$i] = 0
EndIf
Case Else; save and close buttons - 3-state
$pos = GUIGetCursorInfo($USWin)
If $pos = $PosA[$i] Then
If $pos = 1 Then ExitLoop
If $pos = 1 Then ExitLoop
While $pos = $PosA[$i]
$pos = GUIGetCursorInfo($USWin)
Switch $pos
Case 0; not pressed
If $PosA[$i] <> 1 Then
SetBitmap($But[$i - $BBTNum], $ButA[$i - $BBTNum], 255)
$PosA[$i] = 1
EndIf
Case 1
While $pos = 1; holding pressed
$pos = GUIGetCursorInfo($USWin)
Switch $pos
Case $PosA[$i]; on button, pressed
If $PosA[$i] <> 2 Then
SetBitmap($But[$i - $BBTNum], $ButA[$i - $BBTNum], 255)
$PosA[$i] = 2
EndIf
Case Else; not on button, pressed
If $PosA[$i] <> 3 Then
SetBitmap($But[$i - $BBTNum], $ButA[$i - $BBTNum], 255)
$PosA[$i] = 3
EndIf
EndSwitch
Sleep(10)
WEnd
If $pos = $PosA[$i] Then
Switch $i - $BBTNum
Case 1; save button pressed
MsgBox(0 + 262144, $GT, "Saved")
Case 2; close button pressed
Exit
EndSwitch
EndIf
EndSwitch
Sleep(10)
WEnd
SetBitmap($But[$i - $BBTNum], $ButA[$i - $BBTNum], 255)
$PosA[$i] = 0
EndIf
EndSwitch
Next
Switch GUIGetMsg(); this is for tab controls
Case -3
Exit
EndSwitch
Sleep(10)
WEnd
Func DisposeAll()
For $i = 1 To $BBTNum
_GDIPlus_BitmapDispose($BBTA[$i])
_GDIPlus_BitmapDispose($BBTA[$i])
_GDIPlus_BitmapDispose($BBTA[$i])
Next
For $i = 1 To 2
_GDIPlus_BitmapDispose($ButA[$i])
_GDIPlus_BitmapDispose($ButA[$i])
_GDIPlus_BitmapDispose($ButA[$i])
Next
EndFunc ;==>DisposeAll
Func DrawImg(ByRef $RetA, $indx, $Imgs, $text, $xx, $yy, $sFont = "Comic Sans MS", $nSize = 10, $ncol = "000000", $iFormat = 0)
For $i = 0 To 2
Local $hGraphic1 = _GDIPlus_GraphicsCreateFromHWND(_WinAPI_GetDesktopWindow())
Local $hBitmap = _GDIPlus_BitmapCreateFromGraphics(165, 38, $hGraphic1)
Local $hGraphic2 = _GDIPlus_ImageGetGraphicsContext($hBitmap)
_GDIPlus_GraphicsDrawImageRect($hGraphic2, $Imgs[$i], 0, 0, 165, 38)
_GDIPlus_GraphicsDrawString_($hGraphic2, $text, $xx, $yy, $sFont, $nSize, $ncol, $iFormat)
_GDIPlus_GraphicsDispose($hGraphic2)
_GDIPlus_GraphicsDispose($hGraphic1)
$RetA[$indx][$i] = $hBitmap
Next
EndFunc ;==>DrawImg
Func _GDIPlus_GraphicsDrawString_($hGraphics, $sString, $nX, $nY, $sFont = "Comic Sans MS", $nSize = 10, $ncol = "000000", $iFormat = 0)
If StringLeft($ncol, 2) = "0x" Then $ncol = StringTrimLeft($ncol, 2)
Local $hBrush = _GDIPlus_BrushCreateSolid("0xFF" & $ncol)
Local $hFormat = _GDIPlus_StringFormatCreate($iFormat)
Local $hFamily = _GDIPlus_FontFamilyCreate($sFont)
Local $hFont = _GDIPlus_FontCreate($hFamily, $nSize)
Local $tLayout = _GDIPlus_RectFCreate($nX, $nY, 0, 0)
Local $aInfo = _GDIPlus_GraphicsMeasureString($hGraphics, $sString, $hFont, $tLayout, $hFormat)
Local $aResult = _GDIPlus_GraphicsDrawStringEx($hGraphics, $sString, $hFont, $aInfo, $hFormat, $hBrush)
Local $iError = @error
_GDIPlus_FontDispose($hFont)
_GDIPlus_FontFamilyDispose($hFamily)
_GDIPlus_StringFormatDispose($hFormat)
_GDIPlus_BrushDispose($hBrush)
Return SetError($iError, 0, $aResult)
EndFunc ;==>_GDIPlus_GraphicsDrawString_
Func SetBitmap($hGUI, $hImage, $iOpacity)
Local $hScrDC = _WinAPI_GetDC(0)
Local $hMemDC = _WinAPI_CreateCompatibleDC($hScrDC)
Local $hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage)
Local $hOld = _WinAPI_SelectObject($hMemDC, $hBitmap)
$tSize = DllStructCreate("long X;long Y")
$pSize = DllStructGetPtr($tSize)
DllStructSetData($tSize, "X", _GDIPlus_ImageGetWidth($hImage))
DllStructSetData($tSize, "Y", _GDIPlus_ImageGetHeight($hImage))
$tSource = DllStructCreate("long X;long Y")
$pSource = DllStructGetPtr($tSource)
$tBlend = DllStructCreate("byte Op;byte Flags;byte Alpha;byte Format")
$pBlend = DllStructGetPtr($tBlend)
DllStructSetData($tBlend, "Alpha", $iOpacity)
DllStructSetData($tBlend, "Format", 1)
_WinAPI_UpdateLayeredWindow($hGUI, $hScrDC, 0, $pSize, $hMemDC, $pSource, 0, $pBlend, 0x02)
_WinAPI_ReleaseDC(0, $hScrDC)
_WinAPI_SelectObject($hMemDC, $hOld)
_WinAPI_DeleteObject($hBitmap)
_WinAPI_DeleteDC($hMemDC)
EndFunc ;==>SetBitmap
回复 8# kk_lee69
大神你太厉害了,我从去年把这个代码琢磨到现在了,过一段时间琢磨一阵子,始终找不到头绪,大神你好厉害呀。
问题得到解决,心情非常激动,连夜测试,基本可以实现我的需求,但是仍有一事不明,比如给按钮2添加动作,执行一次后第二次就会鼠标按上和按下按钮图片不会更改,按下其他按钮后再按下按钮2方能执行动作和变换按钮背景图片,不知道这是为何,
此外,把每个按钮设置成不同尺寸这一点,小弟始终找不到头绪和方法,知道改的地方,但无法下手更改,恳请大神支招呀! 回复 9# 沉默的斗鱼
你為何要用這個例子?? 論壇很多更簡單的其實 發哥這個算是蠻複雜的
老實說我不看你的程式 是 我根本也還搞不懂 它的做法尤其它加了很多的陣列作變化
你亂改 就會產生 我說的 一開始你的按鈕幾乎是錯誤的 號碼同樣一顆 我第一次按 他說4號按鈕 第二次按 他說 1號按鈕
這就表示 你動了他的陣列 卻又沒搞清它的邏輯.... 回复 8# kk_lee69
谢谢大神,想到一个笨办法了,png只能是统一大小,那就把png放成统一大小,把上面显示的图像放成不同大小就可以啦。
比如;都是89*89图像
这是图像占据88像素的按钮1
我们可以把按钮2用ps处理小,但画布是89*89,图像是40*40
这就可以解决png按钮设置不同大小了,方法虽笨,但能解决问题。大神见笑啦! 回复 9# 沉默的斗鱼
改好了 既然知道是哪個函數控管
多幾個一樣的不就好了
#include <WinAPI.au3>
#include <GDIPlus.au3>
Opt("TrayAutoPause", 0)
OnAutoItExitRegister("DisposeAll")
_GDIPlus_Startup()
Global $GT = "GUI Title", $ImgA, $PosA, $BBT, $BBTA, $But, $ButA, $BBTNum = 4
; loading images
$ImgA = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\anniu1a.png")
$ImgA = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\anniu1b.png")
$ImgA = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\anniu4a.png")
Local $Img1 = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\bg.png")
Local $Img2 = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\title_button.png")
; main GUI with title
Global $USWin = GUICreate($GT, 528, 440, -1, -1, 0x80000000, BitOR(0x00080000, 0x00000008));, 0x80)
Local $hGraphic1a = _GDIPlus_GraphicsCreateFromHWND(_WinAPI_GetDesktopWindow())
Local $hBitmapa = _GDIPlus_BitmapCreateFromGraphics(528, 440, $hGraphic1a)
Local $hGraphic2a = _GDIPlus_ImageGetGraphicsContext($hBitmapa)
_GDIPlus_GraphicsDrawImageRect($hGraphic2a, $Img1, 88, 0, 440, 440)
_GDIPlus_GraphicsDrawImageRect($hGraphic2a, $Img2, 138, 5, 198, 45)
_GDIPlus_GraphicsDrawString_($hGraphic2a, $GT, 148, 11, "Comic Sans MS", 12)
_GDIPlus_GraphicsDispose($hGraphic2a)
_GDIPlus_GraphicsDispose($hGraphic1a)
SetBitmap($USWin, $hBitmapa, 255)
_GDIPlus_GraphicsDispose($hBitmapa)
_GDIPlus_ImageDispose($Img1)
_GDIPlus_ImageDispose($Img2)
; position labels for all buttons
$PosA = GUICtrlCreateLabel("",450, 99, 157, 30); tab buttons
$PosA = GUICtrlCreateLabel("",350 , 132, 157, 30)
$PosA = GUICtrlCreateLabel("",200, 165, 157, 30)
$PosA = GUICtrlCreateLabel("",100, 198, 157, 30)
$PosA[$BBTNum + 1] = GUICtrlCreateLabel("", 137, 402, 160, 35); save button
$PosA[$BBTNum + 2] = GUICtrlCreateLabel("", 317, 402, 160, 35); close button
For $i = 1 To $BBTNum + 2
$PosA[$i] = 0
Next
; tab button 1
$BBT = GUICreate($GT, 165, 227, 450, 100, 0x80000000, BitOR(0x00080000, 0x00000008, 0x00000040, 0x08000000), $USWin)
DrawImg2($BBTA, 1, $ImgA, "按鈕 1", 10, 4, "Comic Sans MS", 11)
SetBitmap($BBT, $BBTA, 255); set the first tab button as pressed
; tab button 2
$BBT = GUICreate($GT, 165, 227, 350, 133, 0x80000000, BitOR(0x00080000, 0x00000008, 0x00000040, 0x08000000), $USWin)
DrawImg3($BBTA, 2, $ImgA, "按鈕 2", 10, 4, "Comic Sans MS", 11)
SetBitmap($BBT, $BBTA, 255)
; tab button 3
$BBT = GUICreate($GT, 165, 227, 200, 166, 0x80000000, BitOR(0x00080000, 0x00000008, 0x00000040, 0x08000000), $USWin)
DrawImg($BBTA, 3, $ImgA, "按鈕 3", 10, 4, "Comic Sans MS", 11)
SetBitmap($BBT, $BBTA, 255)
; tab button 4
$BBT = GUICreate($GT, 165, 227, 100, 199, 0x80000000, BitOR(0x00080000, 0x00000008, 0x00000040, 0x08000000), $USWin)
DrawImg($BBTA, 4, $ImgA, "按鈕 4", 10, 4, "Comic Sans MS", 11)
SetBitmap($BBT, $BBTA, 255)
; save button
$But = GUICreate($GT, 345, 38, 138, 405, 0x80000000, BitOR(0x00080000, 0x00000008, 0x00000040, 0x08000000), $USWin)
DrawImg($ButA, 1, $ImgA, "Save", 10, 4, "Comic Sans MS", 11)
SetBitmap($But, $ButA, 255)
; close button
$But = GUICreate($GT, 345, 38, 318, 405, 0x80000000, BitOR(0x00080000, 0x00000008, 0x00000040, 0x08000000), $USWin)
DrawImg($ButA, 2, $ImgA, "Close", 10, 4, "Comic Sans MS", 11)
SetBitmap($But, $ButA, 255)
; release loaded images
_GDIPlus_ImageDispose($ImgA)
_GDIPlus_ImageDispose($ImgA)
_GDIPlus_ImageDispose($ImgA)
; show all GUIs - kind of like an animation effect
GUISetState(@SW_SHOW, $USWin)
For $i = 1 To $BBTNum
GUISetState(@SW_SHOW, $BBT[$i])
Next
GUISetState(@SW_SHOW, $But)
GUISetState(@SW_SHOW, $But)
; set the first tab button as pressed
$curr = 1
;$prev = 0
While 1
For $i = 1 To $BBTNum + 2; 4 tabs + 2 buttons
Switch $i
Case 1 To $BBTNum; tab buttons - 2-state
If $curr = $i Then ContinueLoop; don't check the state of the current tab
$pos = GUIGetCursorInfo($USWin)
If $pos = $PosA[$i] Then
If $pos = 1 Then ExitLoop
If $pos = 1 Then ExitLoop
While $pos = $PosA[$i]
If GUIGetMsg() = -3 Then Exit
$pos = GUIGetCursorInfo($USWin)
Switch $pos
Case 0; not pressed
If $PosA[$i] <> 1 Then
SetBitmap($BBT[$i], $BBTA[$i], 255)
$PosA[$i] = 1
EndIf
Case 1; pressed - change tab
If $PosA[$i] <> 2 Then
SetBitmap($BBT[$curr], $BBTA[$curr], 255)
SetBitmap($BBT[$i], $BBTA[$i], 255)
_WinAPI_ShowMsg("這是第"&$i&"個按鈕")
$PosA[$i] = 2
;$prev = $curr
$curr = $i
ExitLoop
EndIf
EndSwitch
Sleep(10)
WEnd
If $curr <> $i Then SetBitmap($BBT[$i], $BBTA[$i], 255)
$PosA[$i] = 0
EndIf
Case Else; save and close buttons - 3-state
$pos = GUIGetCursorInfo($USWin)
If $pos = $PosA[$i] Then
If $pos = 1 Then ExitLoop
If $pos = 1 Then ExitLoop
While $pos = $PosA[$i]
$pos = GUIGetCursorInfo($USWin)
Switch $pos
Case 0; not pressed
If $PosA[$i] <> 1 Then
SetBitmap($But[$i - $BBTNum], $ButA[$i - $BBTNum], 255)
$PosA[$i] = 1
EndIf
Case 1
While $pos = 1; holding pressed
$pos = GUIGetCursorInfo($USWin)
Switch $pos
Case $PosA[$i]; on button, pressed
If $PosA[$i] <> 2 Then
SetBitmap($But[$i - $BBTNum], $ButA[$i - $BBTNum], 255)
$PosA[$i] = 2
EndIf
Case Else; not on button, pressed
If $PosA[$i] <> 3 Then
SetBitmap($But[$i - $BBTNum], $ButA[$i - $BBTNum], 255)
$PosA[$i] = 3
EndIf
EndSwitch
Sleep(10)
WEnd
If $pos = $PosA[$i] Then
Switch $i - $BBTNum
Case 1; save button pressed
MsgBox(0 + 262144, $GT, "Saved")
Case 2; close button pressed
Exit
EndSwitch
EndIf
EndSwitch
Sleep(10)
WEnd
SetBitmap($But[$i - $BBTNum], $ButA[$i - $BBTNum], 255)
$PosA[$i] = 0
EndIf
EndSwitch
Next
Switch GUIGetMsg(); this is for tab controls
Case -3
Exit
EndSwitch
Sleep(10)
WEnd
Func DisposeAll()
For $i = 1 To $BBTNum
_GDIPlus_BitmapDispose($BBTA[$i])
_GDIPlus_BitmapDispose($BBTA[$i])
_GDIPlus_BitmapDispose($BBTA[$i])
Next
For $i = 1 To 2
_GDIPlus_BitmapDispose($ButA[$i])
_GDIPlus_BitmapDispose($ButA[$i])
_GDIPlus_BitmapDispose($ButA[$i])
Next
EndFunc ;==>DisposeAll
Func DrawImg(ByRef $RetA, $indx, $Imgs, $text, $xx, $yy, $sFont = "Comic Sans MS", $nSize = 10, $ncol = "000000", $iFormat = 0)
For $i = 0 To 2
Local $hGraphic1 = _GDIPlus_GraphicsCreateFromHWND(_WinAPI_GetDesktopWindow())
Local $hBitmap = _GDIPlus_BitmapCreateFromGraphics(165, 38, $hGraphic1)
Local $hGraphic2 = _GDIPlus_ImageGetGraphicsContext($hBitmap)
_GDIPlus_GraphicsDrawImageRect($hGraphic2, $Imgs[$i], 0, 0, 165, 38)
_GDIPlus_GraphicsDrawString_($hGraphic2, $text, $xx, $yy, $sFont, $nSize, $ncol, $iFormat)
_GDIPlus_GraphicsDispose($hGraphic2)
_GDIPlus_GraphicsDispose($hGraphic1)
$RetA[$indx][$i] = $hBitmap
Next
EndFunc ;==>DrawImg
Func DrawImg2(ByRef $RetA, $indx, $Imgs, $text, $xx, $yy, $sFont = "Comic Sans MS", $nSize = 10, $ncol = "000000", $iFormat = 0)
For $i = 0 To 2
Local $hGraphic1 = _GDIPlus_GraphicsCreateFromHWND(_WinAPI_GetDesktopWindow())
Local $hBitmap = _GDIPlus_BitmapCreateFromGraphics(165, 38, $hGraphic1)
Local $hGraphic2 = _GDIPlus_ImageGetGraphicsContext($hBitmap)
_GDIPlus_GraphicsDrawImageRect($hGraphic2, $Imgs[$i], 0, 0, 46, 46)
_GDIPlus_GraphicsDrawString_($hGraphic2, $text, $xx, $yy, $sFont, $nSize, $ncol, $iFormat)
_GDIPlus_GraphicsDispose($hGraphic2)
_GDIPlus_GraphicsDispose($hGraphic1)
$RetA[$indx][$i] = $hBitmap
Next
EndFunc ;==>DrawImg
Func DrawImg3(ByRef $RetA, $indx, $Imgs, $text, $xx, $yy, $sFont = "Comic Sans MS", $nSize = 10, $ncol = "000000", $iFormat = 0)
For $i = 0 To 2
Local $hGraphic1 = _GDIPlus_GraphicsCreateFromHWND(_WinAPI_GetDesktopWindow())
Local $hBitmap = _GDIPlus_BitmapCreateFromGraphics(165, 128, $hGraphic1)
Local $hGraphic2 = _GDIPlus_ImageGetGraphicsContext($hBitmap)
_GDIPlus_GraphicsDrawImageRect($hGraphic2, $Imgs[$i], 0, 0, 128, 128)
_GDIPlus_GraphicsDrawString_($hGraphic2, $text, $xx, $yy, $sFont, $nSize, $ncol, $iFormat)
_GDIPlus_GraphicsDispose($hGraphic2)
_GDIPlus_GraphicsDispose($hGraphic1)
$RetA[$indx][$i] = $hBitmap
Next
EndFunc ;==>DrawImg
Func _GDIPlus_GraphicsDrawString_($hGraphics, $sString, $nX, $nY, $sFont = "Comic Sans MS", $nSize = 10, $ncol = "000000", $iFormat = 0)
If StringLeft($ncol, 2) = "0x" Then $ncol = StringTrimLeft($ncol, 2)
Local $hBrush = _GDIPlus_BrushCreateSolid("0xFF" & $ncol)
Local $hFormat = _GDIPlus_StringFormatCreate($iFormat)
Local $hFamily = _GDIPlus_FontFamilyCreate($sFont)
Local $hFont = _GDIPlus_FontCreate($hFamily, $nSize)
Local $tLayout = _GDIPlus_RectFCreate($nX, $nY, 0, 0)
Local $aInfo = _GDIPlus_GraphicsMeasureString($hGraphics, $sString, $hFont, $tLayout, $hFormat)
Local $aResult = _GDIPlus_GraphicsDrawStringEx($hGraphics, $sString, $hFont, $aInfo, $hFormat, $hBrush)
Local $iError = @error
_GDIPlus_FontDispose($hFont)
_GDIPlus_FontFamilyDispose($hFamily)
_GDIPlus_StringFormatDispose($hFormat)
_GDIPlus_BrushDispose($hBrush)
Return SetError($iError, 0, $aResult)
EndFunc ;==>_GDIPlus_GraphicsDrawString_
Func SetBitmap($hGUI, $hImage, $iOpacity)
Local $hScrDC = _WinAPI_GetDC(0)
Local $hMemDC = _WinAPI_CreateCompatibleDC($hScrDC)
Local $hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage)
Local $hOld = _WinAPI_SelectObject($hMemDC, $hBitmap)
$tSize = DllStructCreate("long X;long Y")
$pSize = DllStructGetPtr($tSize)
DllStructSetData($tSize, "X", _GDIPlus_ImageGetWidth($hImage))
DllStructSetData($tSize, "Y", _GDIPlus_ImageGetHeight($hImage))
$tSource = DllStructCreate("long X;long Y")
$pSource = DllStructGetPtr($tSource)
$tBlend = DllStructCreate("byte Op;byte Flags;byte Alpha;byte Format")
$pBlend = DllStructGetPtr($tBlend)
DllStructSetData($tBlend, "Alpha", $iOpacity)
DllStructSetData($tBlend, "Format", 1)
_WinAPI_UpdateLayeredWindow($hGUI, $hScrDC, 0, $pSize, $hMemDC, $pSource, 0, $pBlend, 0x02)
_WinAPI_ReleaseDC(0, $hScrDC)
_WinAPI_SelectObject($hMemDC, $hOld)
_WinAPI_DeleteObject($hBitmap)
_WinAPI_DeleteDC($hMemDC)
EndFunc ;==>SetBitmap
回复 11# 沉默的斗鱼
不用這麼麻煩本身函數就可以 放大縮小 回复 10# kk_lee69
比如给按钮2添加动作,执行一次后第二次就会鼠标按上和按下按钮图片不会更改,按下其他按钮后再按下按钮2方能执行动作和变换按钮背景图片,不知道这是为何,
这个问题也可以解决,不用循环变量就可以解决“按钮2添加动作,执行一次后第二次就会鼠标按上和按下按钮图片不会更改,按下其他按钮后再按下按钮2方能执行动作和变换按钮背景图片”的问题Case 1; pressed - change tab
If $PosA Then
SetBitmap($BBT[$curr], $BBTA[$curr], 255)
SetBitmap($BBT, $BBTA, 255)
RunWait("BeiKelSystem319.exe")
_WinAPI_ShowMsg("這是第"&2&"個按鈕")
$PosA = 2
;$prev = $curr把这里改成绝对值就可以了,但是其他按钮加动作用这办法就不会了。原谅小弟基础差对变量头疼吧。
如果不嫌小弟啰嗦帮忙分离成每按一个按钮执行动作而不是用变量定义整体动作。谢谢谢
用函数能解决,我知道,对你大神来说是小菜一碟,可是对我来说就是一座大山,我都不好意思让你再教我了。
我知道,论坛上有很多png按钮例子,说实话我都挨个研究了,或许有点夸大吧,但是我觉得发哥这个转帖含金量极高,代码很值得研究,最重要的一点,和其他函数混用不冲突,所以就一直琢磨这个脚本呢。