回复 1# 沉默的斗鱼
把我改的 跟你的圖片放一起 你就可以知道.........
首先 我改了 tab button 1~4 的位置 如果你只改這個位置 那麼你的按鈕功能就會失效
所以你還得改 $PosA[1][0]~ $PosA[4][0] 的位置
那個位置其實它是建立了 四個 空白的 GUICtrlCreateLabel
而 GUICtrlCreateLabel 本身就會響應 點擊事件
#include <WinAPI.au3>
#include <GDIPlus.au3>
Opt("TrayAutoPause", 0)
OnAutoItExitRegister("DisposeAll")
_GDIPlus_Startup()
Global $GT = "GUI Title", $ImgA[3], $PosA[7][2], $Tab[5], $TabA[5][3], $But[3], $ButA[3][3], $TabNum = 4
; loading images
$ImgA[0] = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\anniu1a.png")
$ImgA[1] = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\anniu1b.png")
$ImgA[2] = _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[1][0] = GUICtrlCreateLabel("",400, 99, 157, 30); tab buttons
$PosA[2][0] = GUICtrlCreateLabel("",300 , 132, 157, 30)
$PosA[3][0] = GUICtrlCreateLabel("",200, 165, 157, 30)
$PosA[4][0] = GUICtrlCreateLabel("",100, 198, 157, 30)
$PosA[$TabNum + 1][0] = GUICtrlCreateLabel("", 137, 402, 160, 35); save button
$PosA[$TabNum + 2][0] = GUICtrlCreateLabel("", 317, 402, 160, 35); close button
For $i = 1 To $TabNum + 2
$PosA[$i][1] = 0
Next
; tab button 1
$Tab[1] = 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[1], $TabA[1][2], 255); set the first tab button as pressed
; tab button 2
$Tab[2] = 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[2], $TabA[2][0], 255)
; tab button 3
$Tab[3] = 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[3], $TabA[3][0], 255)
; tab button 4
$Tab[4] = 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[4], $TabA[4][0], 255)
; save button
$But[1] = 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[1], $ButA[1][0], 255)
; close button
$But[2] = 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[2], $ButA[2][0], 255)
; release loaded images
_GDIPlus_ImageDispose($ImgA[0])
_GDIPlus_ImageDispose($ImgA[1])
_GDIPlus_ImageDispose($ImgA[2])
; 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[1])
GUISetState(@SW_SHOW, $But[2])
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[4] = $PosA[$i][0] Then
If $pos[3] = 1 Then ExitLoop
If $pos[2] = 1 Then ExitLoop
While $pos[4] = $PosA[$i][0]
If GUIGetMsg() = -3 Then Exit
$pos = GUIGetCursorInfo($USWin)
Switch $pos[2]
Case 0; not pressed
If $PosA[$i][1] <> 1 Then
SetBitmap($Tab[$i], $TabA[$i][1], 255)
$PosA[$i][1] = 1
EndIf
Case 1; pressed - change tab
If $PosA[$i][1] <> 2 Then
SetBitmap($Tab[$curr], $TabA[$curr][0], 255)
SetBitmap($Tab[$i], $TabA[$i][2], 255)
GUICtrlSendMsg($TabC, 0x1300 + 48, $i - 1, 0)
$PosA[$i][1] = 2
;$prev = $curr
$curr = $i
ConsoleWrite("這是第"&$i&"個按鈕")
ExitLoop
EndIf
EndSwitch
Sleep(10)
WEnd
If $curr <> $i Then SetBitmap($Tab[$i], $TabA[$i][0], 255)
$PosA[$i][1] = 0
EndIf
Case Else; save and close buttons - 3-state
$pos = GUIGetCursorInfo($USWin)
If $pos[4] = $PosA[$i][0] Then
If $pos[3] = 1 Then ExitLoop
If $pos[2] = 1 Then ExitLoop
While $pos[4] = $PosA[$i][0]
$pos = GUIGetCursorInfo($USWin)
Switch $pos[2]
Case 0; not pressed
If $PosA[$i][1] <> 1 Then
SetBitmap($But[$i - $TabNum], $ButA[$i - $TabNum][1], 255)
$PosA[$i][1] = 1
EndIf
Case 1
While $pos[2] = 1; holding pressed
$pos = GUIGetCursorInfo($USWin)
Switch $pos[4]
Case $PosA[$i][0]; on button, pressed
If $PosA[$i][1] <> 2 Then
SetBitmap($But[$i - $TabNum], $ButA[$i - $TabNum][2], 255)
$PosA[$i][1] = 2
EndIf
Case Else; not on button, pressed
If $PosA[$i][1] <> 3 Then
SetBitmap($But[$i - $TabNum], $ButA[$i - $TabNum][1], 255)
$PosA[$i][1] = 3
EndIf
EndSwitch
Sleep(10)
WEnd
If $pos[4] = $PosA[$i][0] 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][0], 255)
$PosA[$i][1] = 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][0])
_GDIPlus_BitmapDispose($TabA[$i][1])
_GDIPlus_BitmapDispose($TabA[$i][2])
Next
For $i = 1 To 2
_GDIPlus_BitmapDispose($ButA[$i][0])
_GDIPlus_BitmapDispose($ButA[$i][1])
_GDIPlus_BitmapDispose($ButA[$i][2])
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[0], $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
|