Jump to content
Sign in to follow this  

Create GUI Controls without Autoit Functions

Recommended Posts


A while back I was working on some functions for autosized labels (both width and height given some parameters), and progress bars that changed from red to green from 0 to 100% over a gradient. It worked, but I think I can make it more efficient.

To autosize the label, I called GUICtrlCreateLabel() many times and obtained the size of the resulting label as part of the calculations. Does anyone know how to create labels and progress bars without calling the built in autoit functions? Maybe if I could look at the actual DLLs, I'll see another way to do this. I know msgbox() can be replaced with DLL calls, which is why I ask if these built in functions are simply calling DLLs with preset parameters.

I've looked at Melba's autosize UDF, but calling GUICtrlCreateLabel() and measuring that is accurate to a single pixel, where as the GDI functions sometimes differ compared to the way a label seems to display the same text. Any help is appreciated.

Share this post

Link to post
Share on other sites

; Johnmcloud - 2014
#include <FontConstants.au3>
#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>
#include <WinAPI.au3>

Global $hGUI, $g_tRECT, $g_hFont, $g_hOldFont, $g_hDC

$hGUI = GUICreate("Johnmcloud test code", 625, 120, -1, -1)

_GUICtrlCreateLabel("This label is made with WinAPI", 10, 5, 610, 45, 0x0000FF)
_GUICtrlCreateLabel("Is cool or useless?", 10, 60, 610, 100, 0xFF0000)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE

Func _GUICtrlCreateLabel($Text, $Left, $Top, $Right, $Buttom, $TextColor)
    $g_tRECT = DllStructCreate($tagRect)
    DllStructSetData($g_tRECT, "Left", $Left)
    DllStructSetData($g_tRECT, "Top", $Top)
    DllStructSetData($g_tRECT, "Right", $Right)
    DllStructSetData($g_tRECT, "Bottom", $Buttom)
    $g_hDC = _WinAPI_GetDC($hGUI)
    $g_hFont = _WinAPI_CreateFont(50, 0, 0, 0, 400, False, False, False, $DEFAULT_CHARSET, $OUT_DEFAULT_PRECIS, $CLIP_DEFAULT_PRECIS, $DEFAULT_QUALITY, 0, 'Arial')
    $g_hOldFont = _WinAPI_SelectObject($g_hDC, $g_hFont)
    _WinAPI_SetTextColor($g_hDC, $TextColor)
    _WinAPI_SetBkColor($g_hDC, 0x000000)
    _WinAPI_SetBkMode($g_hDC, $TRANSPARENT)
    _WinAPI_DrawText($g_hDC, $Text, $g_tRECT, $DT_CENTER)
EndFunc   ;==>_GUICtrlCreateLabel

Func _Exit()
    _WinAPI_SelectObject($g_hDC, $g_hOldFont)
    _WinAPI_ReleaseDC($hGUI, $g_hDC)
    _WinAPI_InvalidateRect($hGUI, 0)
    $g_tRECT = 0
EndFunc   ;==>_Exit

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  


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.