Jump to content
Sign in to follow this  
JohnOne

Set ctrl font colour winapi(Solved)

Recommended Posts

JohnOne

Looking for a way to change text colour of a label for instance via winapi.

This does not seem to work.

#include <WinAPI.au3>
#include <WindowsConstants.au3>

_Main()

Func _Main()
    Local $hwnd, $hDC
    $hwnd = GUICreate("test")
    $hlabel = GUICtrlCreateLabel("label", 10,10,50,25)
    $hlabel2 = GUICtrlGetHandle($hlabel)
    $hDC = _WinAPI_GetDC($hlabel2)
    If @error Then Exit MsgBox(0,"_WinAPI_GetDC", @error); no error
    _WinAPI_SetTextColor($hDC, 0x0000FF)
    If @error Then Exit MsgBox(0,"_WinAPI_SetTextColor", @error); no error
    GUISetState()
    While 1
        If GUIGetMsg() = -3 Then ExitLoop
    WEnd
    _WinAPI_ReleaseDC($hlabel2, $hDC)
EndFunc   ;==>_Main

Not sure why.

Appreciate any suggestions, bearing in mind I know I can do it with native functions but that is not what I'm after.

I cannot even make it work c++, and ideas about that would be just as sufficient.

Thanks for reading.

Edited by JohnOne

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Share this post


Link to post
Share on other sites
UEZ

This is working but I don't know whether it is what you are looking for.

#include <WindowsConstants.au3>
#include <WinAPI.au3>


Global $hwnd, $iCol = 0x0000FF ;BGR

$hwnd = GUICreate("test")
$iLabel = GUICtrlCreateLabel("label", 10,10,50,25)
$hLabel = GUICtrlGetHandle($iLabel)
GUIRegisterMsg($WM_CTLCOLORSTATIC, '_WM_CTLCOLORSTATIC')
GUISetState()

While 1
    If GUIGetMsg() = -3 Then ExitLoop
WEnd

GUIDelete()
Exit

Func _WM_CTLCOLORSTATIC($hWnd, $iMsg, $wParam, $iParam)
    #forceref $hWnd, $iMsg
    Switch _WinAPI_GetDlgCtrlID($iParam)
        Case $iLabel
            _WinAPI_SetTextColor($wParam, $iCol)
            _WinAPI_SetBkMode($wParam, $TRANSPARENT)
            Return _WinAPI_GetStockObject($NULL_BRUSH)
    EndSwitch
    Return "GUI_RUNDEFMSG"
EndFunc

Br,

UEZ

  • Like 1

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

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
Sign in to follow this  

×