#include <Constants.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3>
#include <Memory.au3>
#include "Resource.au3"
Global $Global_BackGroundArray[4][1]
Func ResCtrlCreatePic($L,$T,$W,$H,$ResType,$ResName, _
$ResLanguage = -1,$ModuleName = "",$Style = 0,$ExStyle = 0)
$ImageHandle = ResGetImage($ResType,$ResName,$ResLanguage,$ModuleName)
if @error Then Return SetError(1,0,0)
$ImageType = @extended
$ControlID = CtrlCreatePic($ImageHandle,$ImageType,$L,$T,$W,$H,$Style,$ExStyle)
if @error Then Return SetError(2,0,0)
Return SetError(0,$ImageType,$ControlID)
EndFunc
Func ResCtrlCreatePicEx($L,$T,$W,$H,$Text,$ResType,$ResName,$ResLanguage = -1, _
$ModuleName = "",$Style = 0,$ExStyle = 0,$FontColor=0,$FontSize=8.5,$FomtWeight=400 _
,$FontAttribute=2,$Fontname="",$FontQuality=2)
$ImageHandle = ResGetImage($ResType,$ResName,$ResLanguage,$ModuleName)
if @error Then Return SetError(1,0,0)
$ImageType = @extended
$ControlID = CtrlCreatePicEx($ImageHandle,$ImageType,$L,$T,$W,$H,$Text,$Style, _
$ExStyle,$FontColor,$FontSize,$FomtWeight,$FontAttribute,$Fontname,$FontQuality)
if @error Then Return SetError(2,0,0)
Return SetError(0,$ImageType,$ControlID)
EndFunc
Func ResCtrlCreate_Button($L,$T,$W,$H,$ResType,$ResName, _
$ResLanguage = -1,$ModuleName = "",$Style = 0,$ExStyle = 0,$ReSize = False)
$ImageHandle = ResGetImage($ResType,$ResName,$ResLanguage,$ModuleName)
if @error Then Return SetError(1,0,0)
$ImageType = @extended
if ($ReSize) Then
$SizeArray = GetImageSize($ImageHandle)
if @error Then
DeleteObj($ImageHandle,$ImageType)
Return SetError(2,0,0)
EndIf
$W = $SizeArray[0]
$H = $SizeArray[1]
EndIf
$ControlID = CtrlCreate_Button($ImageHandle,$ImageType,$L,$T,$W,$H,$Style,$ExStyle)
if @error Then Return SetError(3,0,0)
Return SetError(0,$ImageType,$ControlID)
EndFunc
Func ResSetBackGroundBmp($hWnd,$ResType,$ResName,$ResLanguage = -1 _
,$ModuleName = "",$DeletOldImage = True)
$hImage = ResGetImage($ResType,$ResName,$ResLanguage,$ModuleName)
if @error Then Return SetError(1,0,False)
Local $ImageType = @extended
if ($ImageType <> 1) Then DeleteObj($hImage,$ImageType)
$SizeArray = GetImageSize($hImage)
if @error Then
DeleteObj($hImage,$ImageType)
Return SetError(2,0,False)
EndIf
$BmpWidth = $SizeArray[0]
$BmpHeight = $SizeArray[1]
SetBackGroundBmp($hWnd,$hImage,$BmpWidth,$BmpHeight,$DeletOldImage)
if @error Then
DeleteObj($hImage,$ImageType)
Return SetError(3,0,False)
EndIf
Return SetError(0,0,True)
EndFunc
Func ResSndPlaySound($ResType,$ResName,$ResLanguage = -1,$ModuleName = "",$LOOP = False)
$ByteStruct = ResGet($ResType,$ResName,$ResLanguage,$ModuleName)
if @error Then Return SetError(1,0,False)
$LPVOID = DllStructGetPtr($ByteStruct)
SndPlaySound($LPVOID,$LOOP)
if @error Then Return SetError(2,0,False)
Return SetError(0,0,True)
EndFunc
Func CtrlCreatePic($ImageHandle,$ImageType,$L,$T,$W,$H,$Style = 0,$ExStyle = 0)
Local $SS_ICON_RES = 0x00000003,$SS_ENHMETAFILE_RES = 0x0000000F
Local $SS_BITMAP_RES = 0x0000000E,$SS_REALSIZECONTROL_RES = 0x00000040
Switch $ImageType
Case 1 ;BITMAP
$ImageStyle = BitOR($Style,$SS_BITMAP_RES,$SS_REALSIZECONTROL_RES)
Case 4 ;ENHMETAFILE
$ImageStyle = BitOR($Style,$SS_ENHMETAFILE_RES,$SS_REALSIZECONTROL_RES)
Case 3,5 ;INCON OR CURSOR
$ImageStyle = BitOR($Style,$SS_ICON_RES,$SS_REALSIZECONTROL_RES)
Case Else
Return SetError(1,0,0)
EndSwitch
$ControlID = GUICtrlCreateLabel("",$L,$T,$W,$H,$ImageStyle,$ExStyle)
CtrlSetImage($ControlID,$ImageHandle,$ImageType)
if @error Then Return SetError(2,0,0)
Return SetError(0,$ImageType,$ControlID)
EndFunc
Func CtrlCreatePicEx($ImageHandle,$ImageType,$L,$T,$W,$H,$Text,$Style = 0,$ExStyle = 0, _
$FontColor=0,$FontSize=8.5,$FomtWeight=400,$FontAttribute=0,$Fontname="",$FontQuality=2)
Local $SS_BITMAP_RES = 0x0000000E,$SS_REALSIZECONTROL_RES = 0x00000040
Local $SS_ICON_RES = 0x00000003,$SS_CENTER_RES = 0x01,$SS_CENTERIMAGE_RES = 0x0200
Local $SS_ENHMETAFILE_RES = 0x0000000F
Switch $ImageType
Case 1 ;BITMAP
$ImageStyle = BitOR($Style,$SS_BITMAP_RES,$SS_REALSIZECONTROL_RES)
Case 4 ;ENHMETAFILE
$ImageStyle = BitOR($Style,$SS_ENHMETAFILE_RES,$SS_REALSIZECONTROL_RES)
Case 3,5 ;INCON OR CURSOR
$ImageStyle = BitOR($Style,$SS_ICON_RES,$SS_REALSIZECONTROL_RES)
Case Else
Return SetError(1,0,0)
EndSwitch
$ControlID1 = GUICtrlCreateLabel("",$L,$T,$W,$H,$ImageStyle,$ExStyle)
CtrlSetImage($ControlID1,$ImageHandle,$ImageType)
if @error Then
GUICtrlDelete($ControlID1)
Return SetError(2,0,0)
EndIf
$ControlID2 = GUICtrlCreateLabel($Text,$L,$T,$W,$H,BitOR($SS_CENTER_RES,$SS_CENTERIMAGE_RES))
GUICtrlSetColor(-1,$FontColor)
GUICtrlSetBkColor(-1,-2);-2 $GUI_BKCOLOR_TRANSPARENT
GUICtrlSetFont(-1,$FontSize,$FomtWeight,$FontAttribute,$Fontname,$FontQuality)
Return SetError(0,$ImageType,$ControlID1)
EndFunc
Func DeletePicEx($ControlID)
GUICtrlDelete($ControlID)
GUICtrlDelete($ControlID + 1)
EndFunc
Func SetPosPicEx($ControlID,$L,$T,$W,$H)
GUICtrlSetPos($ControlID,$L,$T,$W,$H)
GUICtrlSetPos($ControlID + 1,$L,$T,$W,$H)
EndFunc
Func SetStatePicEx($ControlID,$State)
GUICtrlSetState($ControlID,$State)
GUICtrlSetState($ControlID + 1,$State)
EndFunc
Func SetStylePicEx($ControlID,$Style,$ExStyle)
GUICtrlSetStyle($ControlID,$Style,$ExStyle)
EndFunc
Func CtrlCreate_Button($ImageHandle,$ImageType,$L,$T,$W,$H,$Style = 0,$ExStyle = 0)
Local $BS_ICON_RES = 0x0040,$BS_BITMAP_RES = 0x0080
Switch $ImageType
Case 1 ;BITMAP
$ImageStyle = BitOR($Style,$BS_BITMAP_RES)
Case 3 ;ICON
$ImageStyle = BitOR($Style,$BS_ICON_RES)
Case Else
Return SetError(1,0,0)
EndSwitch
$ControlID = GUICtrlCreateButton("",$L,$T,$W,$H,$ImageStyle,$ExStyle)
CtrlSetImage($ControlID,$ImageHandle,$ImageType)
if @error Then Return SetError(2,0,0)
Return SetError(0,$ImageType,$ControlID)
EndFunc
Func CtrlSetImage($ControlID,$ImageHandle,$ImageType,$DeletOldImage = False)
;$ImageType
;$ImageType = 1 ==> BITMAP
;$ImageType = 3 ==> ICON
;$ImageType = 4 ==> ENHMETAFILE
;$ImageType = 5 ==> CURSOR
;$ControlID Of STATIC Control Or Button Control
Local $ControHandle = $ControlID,$STM_SETIMAGE_RES = 0x0172,$IMAGE_ENHMETAFILE_RES = 3
Local $IMAGE_BITMAP_RES = 0,$IMAGE_ICON_RES = 1,$IMAGE_CURSOR_RES = 2 , $RthImage = 0
Local $BM_SETIMAGE_RES = 0xF7
if Not IsHWnd($ControlID) Then $ControHandle = GUICtrlGetHandle($ControlID)
Local $Class = _WinAPI_GetClassName($ControHandle)
Select
Case $Class == "Button"
Switch $ImageType
Case 1 ;BITMAP
if ($DeletOldImage) Then $OldImage = CtrlGetOldImage($ControlID)
Local $OldImageType = @extended
$RthImage = _SendMessage($ControHandle,$BM_SETIMAGE_RES,$IMAGE_BITMAP_RES,$ImageHandle)
if ($DeletOldImage And $OldImage <> $ImageHandle _
And $OldImage) Then DeleteObj($OldImage,$OldImageType)
Case 3 ;ICON
if ($DeletOldImage) Then $OldImage = CtrlGetOldImage($ControlID)
Local $OldImageType = @extended
$RthImage = _SendMessage($ControHandle,$BM_SETIMAGE_RES,$IMAGE_ICON_RES,$ImageHandle)
if ($DeletOldImage And $OldImage <> $ImageHandle _
And $OldImage) Then DeleteObj($OldImage,$OldImageType)
Case Else
Return SetError(3,0,False)
EndSwitch
Case $Class == "Static"
Switch $ImageType
Case 1 ;BITMAP
if ($DeletOldImage) Then $OldImage = CtrlGetOldImage($ControlID)
Local $OldImageType = @extended
$RthImage = _SendMessage($ControHandle,$STM_SETIMAGE_RES,$IMAGE_BITMAP_RES,$ImageHandle)
if ($DeletOldImage And $OldImage <> $ImageHandle _
And $OldImage) Then DeleteObj($OldImage,$OldImageType)
Case 4 ;ENHMETAFILE
if ($DeletOldImage) Then $OldImage = CtrlGetOldImage($ControlID)
Local $OldImageType = @extended
$RthImage = _SendMessage($ControHandle,$STM_SETIMAGE_RES,$IMAGE_ENHMETAFILE_RES,$ImageHandle)
if ($DeletOldImage And $OldImage <> $ImageHandle _
And $OldImage) Then DeleteObj($OldImage,$OldImageType)
Case 3 ;ICON
if ($DeletOldImage) Then $OldImage = CtrlGetOldImage($ControlID)
Local $OldImageType = @extended
$RthImage = _SendMessage($ControHandle,$STM_SETIMAGE_RES,$IMAGE_ICON_RES,$ImageHandle)
if ($DeletOldImage And $OldImage <> $ImageHandle _
And $OldImage) Then DeleteObj($OldImage,$OldImageType)
Case 5 ;CURSOR
if ($DeletOldImage) Then $OldImage = CtrlGetOldImage($ControlID)
Local $OldImageType = @extended
$RthImage = _SendMessage($ControHandle,$STM_SETIMAGE_RES,$IMAGE_CURSOR_RES,$ImageHandle)
if ($DeletOldImage And $OldImage <> $ImageHandle _
And $OldImage) Then DeleteObj($OldImage,$OldImageType)
Case Else
Return SetError(3,0,False)
EndSwitch
if IsHWnd($ControlID) Then $ControlID = _WinAPI_GetDlgCtrlID($ControlID)
$ControHandle = GUICtrlGetHandle($ControlID + 1)
if ($ControHandle) Then _WinAPI_RedrawWindow($ControHandle,0,0,$RDW_INVALIDATE)
Case Else
Return SetError(2,0,False)
EndSelect
if ($RthImage) Then DeleteObj($RthImage,$ImageType)
Return SetError(0,0,True)
EndFunc
Func CtrlGetOldImage($ControlID)
; Return $OldImage Or Zero
;$ImageType = @extended
;$ImageType = 1 ==> BITMAP
;$ImageType = 3 ==> ICON
;$ImageType = 4 ==> ENHMETAFILE
;$ImageType = 5 ==> CURSOR
Local $ControHandle = $ControlID,$STM_GETIMAGE_RES = 0x0173,$IMAGE_ENHMETAFILE_RES = 3
Local $IMAGE_BITMAP_RES = 0,$IMAGE_ICON_RES = 1,$IMAGE_CURSOR_RES = 2 , $OldImage = 0
Local $BM_GETIMAGE_RES = 0x00F6
if Not IsHWnd($ControlID) Then $ControHandle = GUICtrlGetHandle($ControlID)
Local $Class = _WinAPI_GetClassName($ControHandle)
Select
Case $Class == "Button"
$OldImage = _SendMessage($ControHandle,$BM_GETIMAGE_RES,$IMAGE_BITMAP_RES,0)
if ($OldImage) Then Return SetError(0,1,$OldImage)
$OldImage = _SendMessage($ControHandle,$BM_GETIMAGE_RES,$IMAGE_ICON_RES,0)
if ($OldImage) Then Return SetError(0,3,$OldImage)
Return SetError(1,0,0)
Case $Class == "Static"
$OldImage = _SendMessage($ControHandle,$STM_GETIMAGE_RES,$IMAGE_BITMAP_RES,0)
if ($OldImage) Then Return SetError(0,1,$OldImage)
$OldImage = _SendMessage($ControHandle,$STM_GETIMAGE_RES,$IMAGE_ICON_RES,0)
if ($OldImage) Then Return SetError(0,3,$OldImage)
$OldImage = _SendMessage($ControHandle,$STM_GETIMAGE_RES,$IMAGE_CURSOR_RES,0)
if ($OldImage) Then Return SetError(0,5,$OldImage)
$OldImage = _SendMessage($ControHandle,$STM_GETIMAGE_RES,$IMAGE_ENHMETAFILE_RES,0)
if ($OldImage) Then Return SetError(0,4,$OldImage)
Return SetError(1,0,0)
Case Else
Return SetError(2,0,0)
EndSelect
EndFunc
Func SetBackGroundBmp($hWnd,$hBmpImage,$BmpWidth,$BmpHeight,$DeletOldImage = True)
Local $GuiTest = False , $UBound = UBound($Global_BackGroundArray)
For $i = 0 To $UBound - 1
if ($Global_BackGroundArray[$i][0] = $hWnd) Then
$GuiTest = True
ExitLoop
EndIf
Next
if ($GuiTest = False) Then ReDim $Global_BackGroundArray[$UBound + 1][4]
if ($DeletOldImage) And ($Global_BackGroundArray[$i][1]) _
Then _WinAPI_DeleteObject($Global_BackGroundArray[$i][1])
$Global_BackGroundArray[$i][0] = $hWnd
$Global_BackGroundArray[$i][1] = $hBmpImage
$Global_BackGroundArray[$i][2] = $BmpWidth
$Global_BackGroundArray[$i][3] = $BmpHeight
GUIRegisterMsg($WM_ERASEBKGND,"WM_ERASEBKGND")
_WinAPI_RedrawWindow($hWnd)
EndFunc
Func RemoveBackGroundBmp($hWnd,$DeletImage = True)
Local $GuiTest = False , $UBound = UBound($Global_BackGroundArray)
Local $NewBackGroundArray[$UBound - 1][4]
For $i = 0 To $UBound - 1
if ($Global_BackGroundArray[$i][0] = $hWnd) Then
$GuiTest = True
ExitLoop
EndIf
Next
if ($GuiTest = True) Then
For $i = 0 To $UBound - 1
if ($Global_BackGroundArray[$i][0] = $hWnd) Then ContinueLoop
$NewBackGroundArray[$i][0] = $Global_BackGroundArray[$i][0]
$NewBackGroundArray[$i][1] = $Global_BackGroundArray[$i][1]
$NewBackGroundArray[$i][2] = $Global_BackGroundArray[$i][2]
$NewBackGroundArray[$i][3] = $Global_BackGroundArray[$i][3]
Next
$Global_BackGroundArray = $NewBackGroundArray
Else
Return SetError(1,0,False)
EndIf
_WinAPI_RedrawWindow($hWnd)
Return SetError(0,0,True)
EndFunc
Func WM_ERASEBKGND($hWnd, $Msg, $wParam, $lParam)
Local $GuiTest = False , $UBound = UBound($Global_BackGroundArray)
Local $BGhWnd = WindowFromDC($wParam)
if Not @error Then
For $i = 0 To $UBound - 1
if ($Global_BackGroundArray[$i][0] = $BGhWnd) Then
$GuiTest = True
ExitLoop
EndIf
Next
if ($GuiTest) Then
$Pos = WinGetClientSize($BGhWnd)
$hdc = _WinAPI_CreateCompatibleDC($wParam)
$HGDIOBJ = _WinAPI_SelectObject($hdc,$Global_BackGroundArray[$i][1])
StretchBlt($wParam,0,0,$Pos[0],$Pos[1],$hdc,0,0,$Global_BackGroundArray[$i][2], _
$Global_BackGroundArray[$i][3],$SRCCOPY)
$HGDIOBJ = _WinAPI_SelectObject($hdc,$HGDIOBJ)
_WinAPI_DeleteDC($hdc)
Return True
EndIf
EndIf
EndFunc
Func SndPlaySound($Ptr,$LOOP = False)
;File Type Or Format File.wav
Local $SND_MEMORY = 4, $SND_ASYNC = 1 ,$SND_SYNC = 0,$SND_NODEFAULT = 2 , _
$SND_LOOP = 0x0008 , $SND_NOSTOP = 0x0010 ,$SND_FILENAME = 0x00020000
Local $fuSound = BitOR($SND_MEMORY,$SND_ASYNC,$SND_NODEFAULT)
if ($LOOP) Then $fuSound = BitOR($fuSound,$SND_LOOP)
$BOOL = DllCall("winmm.dll", "int", "sndPlaySound","ptr",$Ptr,"UINT",$fuSound)
If @error Or $BOOL[0] = 0 Then Return SetError(1,0,False)
Return SetError(0,0,True)
EndFunc
Func DeleteObj($Object,$ObjectType)
Switch $ObjectType
Case 1
if (_WinAPI_DeleteObject($Object)) Then Return True
Case 2
if (DeleteMetaFile($Object)) Then Return True
Case 3
if (_WinAPI_DestroyIcon($Object)) Then Return True
Case 4
if (DeleteEnhMetaFile($Object)) Then Return True
Case 5
if (DestroyCursor($Object)) Then Return True
EndSwitch
Return SetError(1,0,False)
EndFunc
Func StretchBlt($hdcDest,$nXOriginDest,$nYOriginDest,$nWidthDest,$nHeightDest,$hdcSrc,$nXOriginSrc, _
$nYOriginSrc,$nWidthSrc,$nHeightSrc,$dwRop)
$Rt = DllCall("Gdi32.dll" ,"BOOL","StretchBlt","ptr",$hdcDest,"int",$nXOriginDest,"int",$nYOriginDest,"int",$nWidthDest , _
"int",$nHeightDest,"ptr",$hdcSrc,"int",$nXOriginSrc,"int",$nYOriginSrc,"int",$nWidthSrc,"int",$nHeightSrc,"DWORD",$dwRop)
if @error Or $Rt[0] = 0 Then Return SetError(1,0,0)
Return SetError(0,0,$Rt[0])
EndFunc
Func WindowFromDC($hDC)
$HWND = DllCall("User32.dll","ptr","WindowFromDC","ptr",$hdc)
if @error Or $HWND[0] = 0 Then Return SetError(1,0,0)
Return SetError(0,0,$HWND[0])
EndFunc
Func GetImageSize($hBmp)
Local $ntagBITMAPINFO = "DWORD biSize;LONG biWidth;LONG biHeight;USHORT biPlanes;" & _
"USHORT biBitCount;DWORD biCompression;DWORD biSizeImage;LONG biXPelsPerMeter;" & _
"LONG biYPelsPerMeter;DWORD biClrUsed;DWORD biClrImportant;BYTE RGBQUAD[4]"
Local $vBITMAPINFO = DllStructCreate($ntagBITMAPINFO)
DllStructSetData($vBITMAPINFO,"biSize",(DllStructGetSize($vBITMAPINFO) - 4))
Local $hDC = _WinAPI_CreateCompatibleDC(0)
if @error Then
_WinAPI_DeleteDC($hDC)
Return SetError(1,0,0)
EndIf
_WinAPI_GetDIBits($hDC,$hBmp,0,0,0,DllStructGetPtr($vBITMAPINFO),0)
if @error Then
_WinAPI_DeleteDC($hDC)
Return SetError(2,0,0)
EndIf
_WinAPI_DeleteDC($hDC)
Local $biWidth = DllStructGetData($vBITMAPINFO,"biWidth")
Local $biHeight = DllStructGetData($vBITMAPINFO,"biHeight")
Local $SizeArray[2]
$SizeArray[0] = $biWidth
$SizeArray[1] = $biHeight
Return $SizeArray
EndFunc
Func DeleteMetaFile($hmf)
$BOOL = DllCall("Gdi32.dll","BOOL","DeleteMetaFile","ptr",$hmf)
if @error Or $BOOL[0] = 0 Then Return SetError(1,0,False)
Return SetError(0,0,True)
EndFunc
Func DeleteEnhMetaFile($hemf)
$BOOL = DllCall("Gdi32.dll","BOOL","DeleteEnhMetaFile","ptr",$hemf)
if @error Or $BOOL[0] = 0 Then Return SetError(1,0,False)
Return SetError(0,0,True)
EndFunc
Func DestroyCursor($hCursor)
$BOOL = DllCall("User32.dll","BOOL","DestroyCursor","ptr",$hCursor)
if @error Or $BOOL[0] = 0 Then Return SetError(1,0,False)
Return SetError(0,0,True)
EndFunc