回复 16# 沉默的斗鱼
改這樣 你就可以知道 按鈕到底是誰在控制的 也可以達到你要的目錄 分別 做動作
#include <WinAPI.au3>
#include <GDIPlus.au3>
Opt("TrayAutoPause", 0)
OnAutoItExitRegister("DisposeAll")
_GDIPlus_Startup()
Global $GT = "GUI Title", $ImgA[3], $PosA[7][2], $BBT[5], $BBTA[5][3], $But[3], $ButA[3][3], $BBTNum = 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("",450, 99, 157, 30); tab buttons
$LAB1=$PosA[1][0]
$PosA[2][0] = GUICtrlCreateLabel("",350 , 150, 157, 30)
$LAB2=$PosA[2][0]
$PosA[3][0] = GUICtrlCreateLabel("",200, 165, 157, 30)
$LAB3=$PosA[3][0]
$PosA[4][0] = GUICtrlCreateLabel("",100, 198, 157, 30)
$LAB4=$PosA[4][0]
$PosA[$BBTNum + 1][0] = GUICtrlCreateLabel("", 137, 402, 160, 35); save button
$PosA[$BBTNum + 2][0] = GUICtrlCreateLabel("", 317, 402, 160, 35); close button
For $i = 1 To $BBTNum + 2
$PosA[$i][1] = 0
Next
; tab button 1
$BBT[1] = GUICreate($GT, 165, 227, 450, 100, 0x80000000, BitOR(0x00080000, 0x00000008, 0x00000040, 0x08000000), $USWin)
DrawImg2($BBTA, 1, $ImgA, "", 10, 4, "Comic Sans MS", 11)
SetBitmap($BBT[1], $BBTA[1][2], 255); set the first tab button as pressed
; tab button 2
$BBT[2] = GUICreate($GT, 165, 227, 350, 133, 0x80000000, BitOR(0x00080000, 0x00000008, 0x00000040, 0x08000000), $USWin)
DrawImg3($BBTA, 2, $ImgA, "", 10, 4, "Comic Sans MS", 11)
SetBitmap($BBT[2], $BBTA[2][0], 255)
; tab button 3
$BBT[3] = GUICreate($GT, 165, 227, 200, 166, 0x80000000, BitOR(0x00080000, 0x00000008, 0x00000040, 0x08000000), $USWin)
DrawImg($BBTA, 3, $ImgA, "", 10, 4, "Comic Sans MS", 11)
SetBitmap($BBT[3], $BBTA[3][0], 255)
; tab button 4
$BBT[4] = GUICreate($GT, 165, 227, 100, 199, 0x80000000, BitOR(0x00080000, 0x00000008, 0x00000040, 0x08000000), $USWin)
DrawImg($BBTA, 4, $ImgA, "", 10, 4, "Comic Sans MS", 11)
SetBitmap($BBT[4], $BBTA[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])
; 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[1])
GUISetState(@SW_SHOW, $But[2])
; 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[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($BBT[$i], $BBTA[$i][1], 255)
$PosA[$i][1] = 1
EndIf
Case 1; pressed - change tab
If $PosA[$i][1] <> 2 Then
SetBitmap($BBT[$curr], $BBTA[$curr][0], 255)
SetBitmap($BBT[$i], $BBTA[$i][2], 255)
$PosA[$i][1] = 2
;$prev = $curr
$curr = $i
IF $PosA[$i][0]=$LAB1 Then
_WinAPI_ShowMsg("這是第1個按鈕")
EndIf
IF $PosA[$i][0]=$LAB2 Then
_WinAPI_ShowMsg("這是第2個按鈕")
EndIf
IF $PosA[$i][0]=$LAB3 Then
_WinAPI_ShowMsg("這是第3個按鈕")
EndIf
IF $PosA[$i][0]=$LAB4 Then
_WinAPI_ShowMsg("這是第4個按鈕")
EndIf
ExitLoop
EndIf
EndSwitch
Sleep(10)
WEnd
If $curr <> $i Then SetBitmap($BBT[$i], $BBTA[$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 - $BBTNum], $ButA[$i - $BBTNum][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 - $BBTNum], $ButA[$i - $BBTNum][2], 255)
$PosA[$i][1] = 2
EndIf
Case Else; not on button, pressed
If $PosA[$i][1] <> 3 Then
SetBitmap($But[$i - $BBTNum], $ButA[$i - $BBTNum][1], 255)
$PosA[$i][1] = 3
EndIf
EndSwitch
Sleep(10)
WEnd
If $pos[4] = $PosA[$i][0] 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][0], 255)
$PosA[$i][1] = 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][0])
_GDIPlus_BitmapDispose($BBTA[$i][1])
_GDIPlus_BitmapDispose($BBTA[$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 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[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
|