Jump to content

Recommended Posts

Posted (edited)

In this thread it was discussed about fading out a label from dark to white.  So I suggested to use an ownerdraw label to perform such a task.  After a bit of searching, I did not find good example, on this forum, of doing it with a label.  So there you go :

; From Nine
#include <WinAPIDiag.au3>
#include <GDIPlus.au3>
#include <GUIConstants.au3>

; Blend - Fade - Text - OWNERDRAW - label

Opt("MustDeclareVars", True)

Global Const $tagDRAWITEMSTRUCT = "uint CtlType;uint CtlID;uint itemID;uint itemAction;uint itemState;hwnd hwndItem;hwnd hDC;" & $tagRECT & ";ulong_ptr itemData;"
Global Const $SS_OWNERDRAW = 0x0D

Example()

Func Example()
  _GDIPlus_Startup()

  Local $hGUI = GUICreate("Example", 400, 200, -1, -1, $WS_OVERLAPPEDWINDOW)
  GUISetBkColor(0xFFFF00)
  Local $idLabel = GUICtrlCreateLabel("", 75, 20, 250, 40, $SS_OWNERDRAW)

  GUIRegisterMsg($WM_DRAWITEM, WM_DRAWITEM)

  GUISetState()

  While True
    Switch GUIGetMsg()
      Case $GUI_EVENT_CLOSE
        ExitLoop
      Case $idLabel
        ConsoleWrite("Label was clicked" & @CRLF)
    EndSwitch
  WEnd

  _GDIPlus_Shutdown()
EndFunc   ;==>Example

Func WM_DRAWITEM($hWnd, $iMsg, $wParam, $lParam)
  Local $tData = DllStructCreate($tagDRAWITEMSTRUCT, $lParam)

  Local $hGraphic = _GDIPlus_GraphicsCreateFromHDC($tData.hdc)
  Local $hBrush = _GDIPlus_LineBrushCreate(0, 20, $tData.right, 20, 0xFF606060, 0xFFFFFFFF)

  Local $hFormat = _GDIPlus_StringFormatCreate()
  _GDIPlus_StringFormatSetAlign($hFormat, 1)
  Local $hFamily = _GDIPlus_FontFamilyCreate("Arial")
  Local $hFont = _GDIPlus_FontCreate($hFamily, 28, 2)
  Local $tLayout = _GDIPlus_RectFCreate(0, Int(($tData.bottom - 40) / 2), $tData.right, 40)
  Local $aInfo = _GDIPlus_GraphicsMeasureString($hGraphic, "AutoIt Rulez !", $hFont, $tLayout, $hFormat)
  _GDIPlus_GraphicsClear($hGraphic, 0xFFFF0000)
  _GDIPlus_GraphicsDrawStringEx($hGraphic, "AutoIt Rulez !", $hFont, $aInfo[0], $hFormat, $hBrush)

  _GDIPlus_StringFormatDispose($hFormat)
  _GDIPlus_FontFamilyDispose($hFamily)
  _GDIPlus_FontDispose($hFont)
  _GDIPlus_BrushDispose($hBrush)
  _GDIPlus_GraphicsDispose($hGraphic)

  Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_DRAWITEM

 

Edited by Nine

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
  • Recently Browsing   0 members

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