Renderer

creating a vertical label

6 posts in this topic

Hi Guys! How can i create a vertical label ? I'm waiting for your answers. Thanks in advance!

Share this post


Link to post
Share on other sites



#3 ·  Posted (edited)

Here a "real" vertical label:

;build 2015-08-03
#include <GDIPlus.au3>
#include <GUIConstantsEx.au3>

Global Const $STM_SETIMAGE = 0x0172
Global $aRet1 = _GDIPlus_BitmapCreateVerticalText("Vertical Label1", 40)
Global $aRet2 = _GDIPlus_BitmapCreateVerticalText("Vertical Label2", 40, "Arial", 0xFF000000, 0xFFF0F0F0, 1)
Global Const $hGUI = GUICreate("Vertical Label", 300, 400)
Global Const $iPic_Label1 = GUICtrlCreatePic("", 10, 0, $aRet1[1], $aRet1[2])
Global Const $iPic_Label2 = GUICtrlCreatePic("", 290 - $aRet1[1], 20, $aRet2[1], $aRet2[2])
_WinAPI_DeleteObject(GUICtrlSendMsg($iPic_Label1, $STM_SETIMAGE, $IMAGE_BITMAP, $aRet1[0]))
_WinAPI_DeleteObject(GUICtrlSendMsg($iPic_Label2, $STM_SETIMAGE, $IMAGE_BITMAP, $aRet2[0]))
GUISetState()

Do
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            _WinAPI_DeleteObject($aRet1[0])
            _WinAPI_DeleteObject($aRet2[0])
            GUIDelete()
            Exit
        Case $iPic_Label1, $iPic_Label2
            MsgBox(0, "Test", "Label was clicked")
    EndSwitch
Until False


Func _GDIPlus_BitmapCreateVerticalText($sString, $fFontSize = 10, $sFont = "Arial", $iColor_Text = 0xFF000000, $iColor_Bg = 0xFFF0F0F0, $iFlip = 3)
    $iFlip = $iFlip <> 3 Or $iFlip <> 1 ? 3 : $iFlip
    _GDIPlus_Startup()
    Local Const $hDC = _WinAPI_GetWindowDC(0)
    Local Const $hGraphic = _GDIPlus_GraphicsCreateFromHDC($hDC)
    Local Const $hBrush = _GDIPlus_BrushCreateSolid($iColor_Text)
    Local Const $hFormat = _GDIPlus_StringFormatCreate()
    Local Const $hFamily = _GDIPlus_FontFamilyCreate($sFont)
    Local Const $hFont = _GDIPlus_FontCreate($hFamily, $fFontSize)
    Local $tLayout = _GDIPlus_RectFCreate()
    Local Const $aInfo = _GDIPlus_GraphicsMeasureString($hGraphic, $sString, $hFont, $tLayout, $hFormat)
    Local $iError = 1
    If Not @error Then
        Local Const $iW = Ceiling($aInfo[0].Width), $iH = Ceiling($aInfo[0].Height)
        Local Const $hBitmap = _GDIPlus_BitmapCreateFromScan0($iW, $iH), $hCanvas = _GDIPlus_ImageGetGraphicsContext($hBitmap)
        _GDIPlus_GraphicsSetSmoothingMode($hCanvas, $GDIP_SMOOTHINGMODE_HIGHQUALITY)
        _GDIPlus_GraphicsSetTextRenderingHint($hCanvas, $GDIP_TEXTRENDERINGHINT_ANTIALIASGRIDFIT)
        $tLayout.X = 0
        $tLayout.Y = 0
        $tLayout.Width = $iW
        $tLayout.Height = $iH
        _GDIPlus_GraphicsDrawStringEx($hCanvas, $sString, $hFont, $tLayout, $hFormat, $hBrush)
        _GDIPlus_ImageRotateFlip($hBitmap, $iFlip)
        Local Const $hBitmap_GDI = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap)
        _GDIPlus_GraphicsDispose($hCanvas)
        _GDIPlus_BitmapDispose($hBitmap)
        $iError = 0
    EndIf
    _GDIPlus_FontDispose($hFont)
    _GDIPlus_FontFamilyDispose($hFamily)
    _GDIPlus_StringFormatDispose($hFormat)
    _GDIPlus_BrushDispose($hBrush)
    _GDIPlus_GraphicsDispose($hGraphic)
    _WinAPI_ReleaseDC(0, $hDC)
    _GDIPlus_Shutdown()
    If $iError Then Return SetError(1, 0, 0)
    Local $aResult[3] = [$hBitmap_GDI, $iH, $iW]
    Return $aResult
EndFunc

;)

Edited by UEZ
Added some checks but still not fully tested!

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites

Obviously it was a question for UEZ, the GDI+ local reference  :D

Share this post


Link to post
Share on other sites

Obviously it was a question for UEZ, the GDI+ local reference  :D

:sweating:

There is also a GDI version flying around made by BugFix...


Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites

thanks GUYS!

Share this post


Link to post
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