Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include-once
- #cs
- Tên hàm........: - _IconCtrl_Create
- Mô tả..........: - Tạo icon control bao gồm tên/chữ cái, icon được lấy từ tệp hình ảnh (*.bmp, *.png, *.jpg,...) và biểu tượng (*.ico), có hỗ trợ nền trong suốt.
- - Control này có chức năng hover, và có thể sử dụng như một control bình thường tạo ra từ GUICtrlCreate...
- - Lưu ý phải thêm hàm _GDIPlus_Startup() để không bị lỗi.
- Cú pháp........: _IconCtrl_Create($Text, $Image, $Left, $Top, $Width, $Height, [$IconSize = 40, [$Fore = 0xFF000000, [$Back = 0xFFFFFFFF, [$Mask = 0xFF1090F0, [$Font = "Segoe UI", [$Size = 8, [$Style = 1]]]]]]])
- Tham số........: - $Text - Chuỗi kí tự, tên gán vào icon.
- - $Image - Đường dẫn đến tệp hình ảnh, biểu tượng.
- - $Left, $Top - Vị trí offset trong GUI.
- - $Width, $Height - Kích cỡ control.
- - $IconSize [optinal] - Kích cỡ của icon.
- - $Fore [optional] - Màu của chữ (dạng ARGB).
- - $Back [optional] - Màu nền, nên dùng trùng với màu GUI (dạng ARBG).
- - $Mask [optional] - Phần màu phủ lên control khi hover.
- - $Font [optional] - Tên font chữ:
- Segoe UI - Font mặc định
- - $Size [optinal] - Kích thước font chữ:
- 9 - Cỡ mặc định
- - $Style [optional] - Kiểu chữ:
- 0 - Bình thường.
- 1 - In đậm (mặc định).
- 2 - In nghiêng.
- 4 - Gạch chân.
- 8 - Gạch ngang giữa.
- Giá trị trả về.: - Control ID - Mã ID của control.
- Author.........: by fb.com/wuuyi123
- -------------------------------------------------------------
- Tên hàm........: - _IconCtrl_SetText($Ctrl, $Text)
- - Thay đổi text cho icon control.
- Tên hàm........: - _IconCtrl_SetColor($Ctrl, $Fore, $Back = -1, $Mask = -1)
- - Thay đổi màu cho icon control.
- Tên hàm........: - _IconCtrl_SetFont($Ctrl, $Font, $Size = -1, $Style = -1)
- - Thay đổi font cho icon control.
- #ce
- #include <GDIPlus.au3>
- #include <Array.au3>
- #include "GUICtrlOnHover.au3"
- Global $__aIconCtrlList[1] = [0]
- Global Const $__tStrIcon = "hwnd hwnd;int ctrl;wchar text[255];" & _
- "int width;int height;int fore;int back;" & _
- "wchar font[255];byte size;byte style;" & _
- "wchar image[500];int iconsize;int mask;"
- Func _IconCtrl_Create($Text, $Image, $Left, $Top, $Width, $Height, $IconSize = 40, $Fore = 0xFF000000, $Back = 0xFFFFFFFF, $Mask = 0xFF1090F0, $Font = "Segoe UI", $Size = 8, $Style = 1)
- Local $Str = DllStructCreate($__tStrIcon)
- _ArrayAdd($__aIconCtrlList, $Str)
- $__aIconCtrlList[0] += 1
- $Str.text = $Text
- $Str.fore = $Fore
- $Str.back = $Back
- $Str.mask = $Mask
- $Str.font = $Font
- $Str.size = $Size
- $Str.style = $Style
- $Str.image = $Image
- $Str.width = $Width
- $Str.height = $Height
- $Str.iconsize = $IconSize
- $Str.ctrl = GUICtrlCreatePic("", $Left, $Top, $Width, $Height)
- GUICtrlSetState($Str.ctrl, 16)
- GUICtrlSetCursor($Str.ctrl, 0)
- __DrawTextIcon($Str)
- _GUICtrl_OnHoverRegister($Str.ctrl, "_RenderIcon", "_RenderIcon")
- Return $Str.ctrl
- EndFunc
- Func _IconCtrl_SetText($Ctrl, $Text)
- Local $Struct = __GetStructFromCtrl($Ctrl)
- $Struct.text = $Text
- __DrawTextIcon($Struct)
- EndFunc
- Func _IconCtrl_SetColor($Ctrl, $Fore, $Back = -1, $Mask = -1)
- Local $Struct = __GetStructFromCtrl($Ctrl)
- $Struct.fore = $Fore
- If Not $Back = -1 Then $Struct.back = $Back
- If Not $Mask = -1 Then $Struct.mask = $Mask
- __DrawTextIcon($Struct)
- EndFunc
- Func _IconCtrl_SetFont($Ctrl, $Font, $Size = -1, $Style = -1)
- Local $Struct = __GetStructFromCtrl($Ctrl)
- $Struct.font = $Font
- If Not $Size = -1 Then $Struct.size = $Size
- If Not $Style = -1 Then $Struct.style = $Style
- __DrawTextIcon($Struct)
- EndFunc
- ;==================================================================================================
- Func __GetStructFromCtrl($Ctrl)
- Local $Struct
- If $__aIconCtrlList[0] = 0 Then Return False
- For $i = $__aIconCtrlList[0] To 1 Step -1
- $Struct = $__aIconCtrlList[$i]
- If $Struct.ctrl == $Ctrl Then Return $Struct
- Next
- Return False
- EndFunc
- Func _RenderIcon($Ctrl, $Mode)
- Local $Struct = __GetStructFromCtrl($Ctrl)
- __DrawTextIcon($Struct, $Mode)
- EndFunc
- Func __DrawTextIcon($Struct, $Mode = 0)
- If Not IsDllStruct($Struct) Then Return
- Local $Size = $Struct.iconsize
- Local $tBmp = _GDIPlus_BitmapCreateFromScan0($Struct.width, $Struct.height)
- Local $hGfx = _GDIPlus_ImageGetGraphicsContext($tBmp)
- _GDIPlus_GraphicsSetTextRenderingHint($hGfx, 5)
- _GDIPlus_GraphicsClear($hGfx, $Struct.back)
- Local $hImg = _GDIPlus_ImageLoadFromFile($Struct.image)
- $hImg = _GDIPlus_ImageResize($hImg, $Size, $Size)
- Local $iW = Round($Size/2), $OffX = Round($Struct.width/2-$iW), $OffY = Round($OffX/2)
- _GDIPlus_GraphicsDrawImage($hGfx, $hImg, $OffX, $OffY)
- __DrawText($hGfx, $Struct.text, $Struct.width, $Struct.height, $Struct.fore, $Struct.font, $Struct.size, $Struct.style)
- If $Mode = 1 Then
- _GDIPlus_GraphicsClear($hGfx, $Struct.mask - 0xE0000000)
- Local $hPen = _GDIPlus_PenCreate($Struct.mask, 2)
- _GDIPlus_GraphicsDrawRect($hGfx, 0, 0, $Struct.width, $Struct.height, $hPen)
- _GDIPlus_PenDispose($hPen)
- EndIf
- _GDIPlus_ImageDispose($hImg)
- Local $hBmp = _GDIPlus_BitmapCreateDIBFromBitmap($tBmp)
- _WinAPI_DeleteObject(GUICtrlSendMsg($Struct.ctrl, 0x172, 0, $hBmp))
- _GDIPlus_GraphicsDispose($hGfx)
- _GDIPlus_BitmapDispose($tBmp)
- _WinAPI_DeleteObject($hBmp)
- EndFunc
- Func __DrawText($hGraphic, $Text, $Width, $Height, $Color = 0xFF000000, $Font = "Segoe UI", $Size = 8, $Style = 1)
- Local $hFormat = _GDIPlus_StringFormatCreate()
- Local $hFamily = _GDIPlus_FontFamilyCreate($Font)
- Local $hFont = _GDIPlus_FontCreate($hFamily, $Size, $Style)
- Local $tLayout = _GDIPlus_RectFCreate(0, 0, $Width, $Height)
- _GDIPlus_StringFormatSetAlign($hFormat, 1)
- _GDIPlus_StringFormatSetLineAlign($hFormat, 2)
- Local $hBrush = _GDIPlus_BrushCreateSolid($Color)
- _GDIPlus_GraphicsDrawStringEx($hGraphic, $Text, $hFont, $tLayout, $hFormat, $hBrush)
- _GDIPlus_StringFormatDispose($hFormat)
- _GDIPlus_FontFamilyDispose($hFamily)
- _GDIPlus_FontDispose($hFont)
- _GDIPlus_BrushDispose($hBrush)
- EndFunc
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement