Jump to content

Translucent label on pic control


funkey
 Share

Recommended Posts

Here is my newest function. I hope this is usefull and i hope there are not to much faults in it.

The function transformes a label control into a pic control and sets a picture to the control.

Thats why GuiCtrlSetData can not work anymore. But you can now set the text you want to the control.

Have fun!

#region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Res_LegalCopyright=funkey
#AutoIt3Wrapper_UseX64=n
#endregion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <GDIPlus.au3>
#include <Array.au3>
Global $sFile1 = StringReplace(@AutoItExe, "AutoIt3.exe", "") & '\Examples\GUI\msoobe.jpg'
Global $sFile2 = StringReplace(@AutoItExe, "AutoIt3.exe", "") & '\Examples\GUI\mslogo.jpg'
Global $hGui = GUICreate("Test", 500, 500)
Global $nTab = GUICtrlCreateTab(10, 10, 480, 480)
GUICtrlCreateTabItem("Tab1")
Global $nPic1 = GUICtrlCreatePic($sFile1, 20, 50, 460, 420, 0)
Global $nLbl = GUICtrlCreateLabel("Text-Label", 100, 100, 100, 30)
GUICtrlSetCursor(-1, 0)
_LabelMakeTranslucent(-1, $nPic1, 0x50000000, 0xFFFFFFFF)
GUICtrlCreateLabel("Text-Label", 100, 135, 100, 30, 0x201)
GUICtrlSetCursor(-1, 0)
_LabelMakeTranslucent(-1, $nPic1, 0x50000000, 0xFFFFFFFF)
GUICtrlCreateLabel("Text-Label", 100, 170, 100, 30, 0x202)
GUICtrlSetCursor(-1, 0)
_LabelMakeTranslucent(-1, $nPic1, 0x50000000, 0xFFFFFFFF)
GUICtrlCreateLabel("This is a translucent label", 100, 335, 200, 31, 0x201)
_LabelMakeTranslucent(-1, $nPic1)
GUICtrlCreateLabel("This is a transparent label", 300, 335, 200, 31, 0x201)
GUICtrlCreateTabItem("Tab2")
Global $nPic2 = GUICtrlCreatePic($sFile2, 20, 50, 460, 420, 0)
GUICtrlCreateLabel("Translucent label", 30, 200, 100, 30, 0x201)
_LabelMakeTranslucent(-1, $nPic2, 0x50FF00FF)
GUICtrlCreateLabel("Transparent label", 30, 250, 100, 30, 0x201)
GUICtrlCreateTabItem("")
GUISetState()
Sleep(1000)
_LabelMakeTranslucent($nLbl, $nPic1, 0x305555f5, 0xFFf0f000, 1, "New Text")
Do
Until GUIGetMsg() = -3
Func _LabelMakeTranslucent($nLbl, $nPic, $TransColor = 0x30FFFFFF, $FontColor = 0xFF000000, $StartGdip = 1, $sText = "", $iSize = 8, $sFontName = "Arial", $iStyle = 0)
 Local $hLbl = GUICtrlGetHandle($nLbl)
 Local $hPic = GUICtrlGetHandle($nPic)
 Local $hImage = _SendMessage($hPic, 371)
 Local $hParent = _WinAPI_GetParent($hLbl)
 Local $Style = _WinAPI_GetWindowLong($hLbl, -16)
 Local $iSS_CENTER = BitAND($Style, 0x1)
 Local $iSS_RIGHT = BitAND($Style, 0x2)
 Local $iSS_CENTERIMAGE = BitAND($Style, 0x200)
 Local $IsPic = BitAND($Style, 0xE)
 ConsoleWrite($IsPic & @CR)
 If $sText = "" Then $sText = GUICtrlRead($nLbl)
 If $IsPic = 0xE Then
  $iSS_CENTER = BitAND(GUICtrlRead($nLbl), 0x1)
  $iSS_RIGHT = BitAND(GUICtrlRead($nLbl), 0x2)
  $iSS_CENTERIMAGE = BitAND(GUICtrlRead($nLbl), 0x200)
 Else
  GUICtrlSetData($nLbl, $Style) ;remember the old style in text
  If $iSS_CENTER Then $Style = BitXOR($Style, 0x1) ;delete SS_CENTER
  _WinAPI_SetWindowLong($hLbl, -16, BitOR($Style, 0x200, 0xE))
 EndIf
 Local $aLblPos = ControlGetPos($hParent, "", $hLbl)
 Local $aPicPos = ControlGetPos($hParent, "", $nPic)
 If $StartGdip Then _GDIPlus_Startup()
 Local $hBitmap = _GDIPlus_BitmapCreateFromHBITMAP($hImage)
 Local $hBitmap2 = _GDIPlus_BitmapCloneArea($hBitmap, $aLblPos[0] - $aPicPos[0], $aLblPos[1] - $aPicPos[1], $aLblPos[2], $aLblPos[3])
 Local $hGraphics = _GDIPlus_ImageGetGraphicsContext($hBitmap2)
 Local $hBrushArea = _GDIPlus_BrushCreateSolid($TransColor)
 _GDIPlus_GraphicsFillRect($hGraphics, 0, 0, $aLblPos[2], $aLblPos[3], $hBrushArea)
 Local $hBrushText = _GDIPlus_BrushCreateSolid($FontColor)
 Local $hFormat = _GDIPlus_StringFormatCreate()
 Local $hFontFamily = _GDIPlus_FontFamilyCreate($sFontName)
 Local $hFont = _GDIPlus_FontCreate($hFontFamily, $iSize, $iStyle)
 Local $tLayout = _GDIPlus_RectFCreate()
 If $iSS_CENTERIMAGE Then DllStructSetData($tLayout, 2, $aLblPos[3] / 2 - $iSize + 1) ;vertictal center
 Local $aInfo = _GDIPlus_GraphicsMeasureString($hGraphics, $sText, $hFont, $tLayout, $hFormat)
 If $iSS_CENTER Then DllStructSetData($aInfo[0], 1, ($aLblPos[2] - DllStructGetData($aInfo[0], 3)) / 2) ;horizontal center
 If $iSS_RIGHT Then DllStructSetData($aInfo[0], 1, $aLblPos[2] - DllStructGetData($aInfo[0], 3) - 1) ; right
 _GDIPlus_GraphicsDrawStringEx($hGraphics, $sText, $hFont, $aInfo[0], $hFormat, $hBrushText)
 Local $hImageNew = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap2)
 _WinAPI_DeleteObject(GUICtrlSendMsg($nLbl, 370, 0, $hImageNew))
 _WinAPI_DeleteObject($hImageNew)
 _GDIPlus_ImageDispose($hBitmap)
 _GDIPlus_ImageDispose($hBitmap2)
 _GDIPlus_BrushDispose($hBrushArea)
 _GDIPlus_BrushDispose($hBrushText)
 _GDIPlus_FontDispose($hFont)
 _GDIPlus_FontFamilyDispose($hFontFamily)
 _GDIPlus_StringFormatDispose($hFormat)
 _GDIPlus_GraphicsDispose($hGraphics)
 If $StartGdip Then _GDIPlus_Shutdown()
EndFunc   ;==>_LabelMakeTranslucent
Edited by funkey

Programming today is a race between software engineers striving to
build bigger and better idiot-proof programs, and the Universe
trying to produce bigger and better idiots.
So far, the Universe is winning.

Link to comment
Share on other sites

Cool.

I just added a fade border for fun

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Res_LegalCopyright=funkey
#AutoIt3Wrapper_UseX64=n
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#Include <GDIPlus.au3>
#Include <Array.au3>
Global $sFile1 = StringReplace(@AutoItExe, "AutoIt3.exe", "") & '\Examples\GUI\msoobe.jpg'
Global $sFile2 = StringReplace(@AutoItExe, "AutoIt3.exe", "") & '\Examples\GUI\mslogo.jpg'
Global $hGui = GUICreate("Test", 500, 500)
Global $nTab = GUICtrlCreateTab(10, 10,480, 480)
GUICtrlCreateTabItem("Tab1")
Global $nPic1 = GUICtrlCreatePic($sFile1, 20, 50, 460, 420, 0)
GUICtrlCreateLabel("Text-Label", 100, 100, 100, 30)
_LabelMakeTranslucent(-1, $nPic1)
GUICtrlCreateLabel("This is a translucent label", 100, 335, 200, 31)
_LabelMakeTranslucent(-1, $nPic1)
GUICtrlCreateLabel("This is a transparent label", 300, 335, -1, -1, 0x201)
GUICtrlCreateTabItem("Tab2")
Global $nPic2 = GUICtrlCreatePic($sFile2, 20, 50, 460, 420, 0)
GUICtrlCreateLabel("Translucent label", 30, 200, 100, 20)
_LabelMakeTranslucent(-1, $nPic2, 0x80FFFFFF, 0xFFFF0000)
GUICtrlCreateLabel("Transparent label", 30, 250, 100, 20, 0x201)
GUICtrlCreateTabItem("")
GUISetState()
Do
Until GUIGetMsg() = -3
Func _LabelMakeTranslucent($nLbl, $nPic, $TransColor = 0x40FFFFFF, $FontColor = 0xFF000000, $iSize = 8, $sFontName = "Arial", $iStyle = 0)
Local $sText = GUICtrlRead($nLbl)
Local $hLbl = GUICtrlGetHandle($nLbl)
Local $hPic = GUICtrlGetHandle($nPic)
Local $hImage = _SendMessage($hPic, 371)
Local $hParent = _WinAPI_GetParent($hlbl)
_WinAPI_SetWindowLong($hLbl, -16, BitOR(_WinAPI_GetWindowLong($hLbl, -16), 512, 14))
Local $aLblPos = ControlGetPos($hParent, "", $hLbl)
Local $aPicPos = ControlGetPos($hParent, "", $nPic)
_GDIPlus_Startup()
Local $hBitmap = _GDIPlus_BitmapCreateFromHBITMAP($hImage)
Local $hGraphics = _GDIPlus_GraphicsCreateFromHWND($hlbl)
Local $hBitmap2 = _GDIPlus_BitmapCloneArea($hBitmap, $aLblPos[0] - $aPicPos[0], $aLblPos[1] - $aPicPos[1], $aLblPos[2], $aLblPos[3])
Local $hBackbuffer = _GDIPlus_ImageGetGraphicsContext($hBitmap2)
$hBitmap2=_fadeborder2($hBitmap2,"0xFFFFFF","33","15")
Local $hBrushArea = _GDIPlus_BrushCreateSolid($TransColor)
;_GDIPlus_GraphicsFillRect($hBackbuffer, 0, 0, $aLblPos[2], $aLblPos[3], $hBrushArea)
Local $hBrushText = _GDIPlus_BrushCreateSolid($FontColor)
Local $hFormat = _GDIPlus_StringFormatCreate()
Local $hFontFamily = _GDIPlus_FontFamilyCreate($sFontName)
Local $hFont = _GDIPlus_FontCreate($hFontFamily, $iSize, $iStyle)
Local $tLayout = _GDIPlus_RectFCreate(0, $aLblPos[3]/2 - $iSize + 1)
Local $aInfo = _GDIPlus_GraphicsMeasureString($hGraphics, $sText, $hFont, $tLayout, $hFormat)
DllStructSetData($aInfo[0], 1, ($aLblPos[2] - DllStructGetData($aInfo[0], 3)) / 2)
_GDIPlus_GraphicsDrawStringEx($hBackbuffer, $sText, $hFont, $aInfo[0], $hFormat, $hBrushText)
Local $hImageNew = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap2)
_WinAPI_DeleteObject(GUICtrlSendMsg($nLbl, 370, 0, $hImageNew))
_WinAPI_DeleteObject($hImageNew)
_GDIPlus_ImageDispose($hBitmap)
_GDIPlus_ImageDispose($hBitmap2)
_GDIPlus_BrushDispose($hBrushArea)
_GDIPlus_BrushDispose($hBrushText)
_GDIPlus_FontDispose($hFont)
_GDIPlus_FontFamilyDispose($hFontFamily)
_GDIPlus_StringFormatDispose($hFormat)
_GDIPlus_GraphicsDispose($hBackbuffer)
_GDIPlus_GraphicsDispose($hGraphics)
_GDIPlus_Shutdown()
EndFunc
Func _fadeborder2($hBitmap, $col1, $faded, $depth)
    $gwt = _GDIPlus_ImageGetWidth($hBitmap)
    $ght = _GDIPlus_ImageGetHeight($hBitmap)
    $hGraphics = _GDIPlus_ImageGetGraphicsContext($hBitmap)
    _GDIPlus_GraphicsSetSmoothingMode($hGraphics, 4)
$fadechange=int($faded/$depth)
For $i=0 To $depth
    $iC1 = StringReplace($col1, "0x", "0x"&$fadechange*$i)
     Global $hBrush = _GDIPlus_BrushCreateSolid($iC1)
         _GDIPlus_GraphicsFillRect($hGraphics, $i, $i, $gwt-($i*2), $ght-($i*2), $hBrush)
    _GDIPlus_BrushDispose($hBrush)
Next
    _GDIPlus_GraphicsDispose($hGraphics)
    Return $hBitmap
EndFunc
Edited by picea892
Link to comment
Share on other sites

Thank you for testing.

I'm glad you like it.

Programming today is a race between software engineers striving to
build bigger and better idiot-proof programs, and the Universe
trying to produce bigger and better idiots.
So far, the Universe is winning.

Link to comment
Share on other sites

I updated my function. See post#1.

Programming today is a race between software engineers striving to
build bigger and better idiot-proof programs, and the Universe
trying to produce bigger and better idiots.
So far, the Universe is winning.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...