Jump to content
Sign in to follow this  

Notification Window Based on GDI+

Recommended Posts


I poked around on the forum, and asked Dr. Google his advice, but I'm coming up empty, and am not able to figure something out. So I was hoping someone here could shed some light for me.

I'm trying to use GDI+ to create a custom GUI that sort of mimics the borderless alert notification window that is seen on Windows 10 (see included pic). I can get some embedded images to show, but I can't seem to get embedded images + text + a close "X" button to all show/work at the same time. I know there's the Metro GUI UDF, but I'm wanting just the bare bones code, and don't need a full UDF. So does anyone happen to have an example, or can give me some advice?

(going back to digging into other examples I previously found)


Share this post

Link to post
Share on other sites

Try this:

#include <GDIPlus.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>

Global Const $hImage_Icon = _GDIPlus_ImageLoadFromFile("c:\Program Files (x86)\AutoIt3\Examples\GUI\merlin.gif")
Global Const $ahGUI = _GDIPlus_CreateW10TrayWin("Done with AutoIt", "This little example was created" & @CRLF & "using GDI+." & @CRLF & "Have fun. ;-)", _
                                                $hImage_Icon, @DesktopWidth - 370, @DesktopHeight - 150)
WinSetTrans($ahGUI[0], "", 0xF4)
GUISetState(@SW_SHOW, $ahGUI[0])

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE, $ahGUI[1]
Until False

;coded by UEZ build 2015-05-13
Func _GDIPlus_CreateW10TrayWin($sTitle, $sText, $hBmp_Icon = 0, $iGUIPosX = -1, $iGUIPosY = -1, $iW = 360, $iH = 100, $sFontName = "Palatino Linotype", $fFontSize = 11.5, $iBgColor = 0xFF1F1F1F, $iTitleColor = 0xFFF8F8F8, $iTextColor = 0xFFA0A0A0)
    Local Const $STM_SETIMAGE = 0x0172
    Local Const $hGUI_W10TW = GUICreate($sTitle, $iW, $iH, $iGUIPosX, $iGUIPosY, $WS_POPUP)
    Local Const $iLable_Drag = GUICtrlCreateLabel("", 0, 0, $iW, 11, -1, $GUI_WS_EX_PARENTDRAG)
    Local Const $iPicBg_W10TW = GUICtrlCreatePic("", 0, 0, $iW, $iH)
    GUICtrlSetState(-1, $GUI_DISABLE)
    Local Const $iPicIcon_W10TW = GUICtrlCreatePic("", 12, 12, 32, 32)
    GUICtrlSetState(-1, $GUI_DISABLE)
    Local Const $iBtn_W10TW = GUICtrlCreateLabel("X", $iW - 25, 14, 10, 10, BitOR($SS_CENTER, $SS_SIMPLE))
    GUICtrlSetFont(-1, 8, 200, 0, "Arial")
    GUICtrlSetBkColor(-1, BitAND($iBgColor, 0x00FFFFFF))
    GUICtrlSetColor(-1, 0xF0F0F0)
    Local Const $hBitmap = _GDIPlus_BitmapCreateFromScan0($iW, $iH)
    Local Const $hGfx = _GDIPlus_ImageGetGraphicsContext($hBitmap)
    _GDIPlus_GraphicsSetSmoothingMode($hGfx, 4)
    _GDIPlus_GraphicsSetPixelOffsetMode($hGfx, 2)
    _GDIPlus_GraphicsSetTextRenderingHint($hGfx, 5)
    _GDIPlus_GraphicsClear($hGfx, $iBgColor)
    Local $hBmp_GDI
    Local $hPen_Border = _GDIPlus_PenCreate(0xFF484848)
    Local Const $hBrush_TextTitle = _GDIPlus_BrushCreateSolid($iTitleColor), $hBrush_Text = _GDIPlus_BrushCreateSolid($iTextColor)
    _GDIPlus_GraphicsDrawRect($hGfx, 0, 0, $iW - 1, $iH - 1, $hPen_Border)

    Local $tLayout_Title = _GDIPlus_RectFCreate(56, 13, $iW - 80, 16)
    Local Const $hFormat_Title = _GDIPlus_StringFormatCreate()
    Local Const $hFamily_Title = _GDIPlus_FontFamilyCreate($sFontName)
    Local Const $hFont_Title = _GDIPlus_FontCreate($hFamily_Title, $fFontSize, 1)
    _GDIPlus_GraphicsDrawStringEx($hGfx, $sTitle, $hFont_Title, $tLayout_Title, $hFormat_Title, $hBrush_TextTitle)

    Local $tLayout_Text = _GDIPlus_RectFCreate(56, 33, $iW - 80, $iH - 35)
    Local Const $hFormat_Text = _GDIPlus_StringFormatCreate()
    Local Const $hFamily_Text = _GDIPlus_FontFamilyCreate($sFontName)
    Local Const $hFont_Text = _GDIPlus_FontCreate($hFamily_Title, $fFontSize - 1)
    _GDIPlus_GraphicsDrawStringEx($hGfx, $sText, $hFont_Text, $tLayout_Text, $hFormat_Text, $hBrush_Text)

    $hBmp_GDI = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap)
    _WinAPI_DeleteObject(GUICtrlSendMsg($iPicBg_W10TW, $STM_SETIMAGE, $IMAGE_BITMAP, $hBmp_GDI))
    If $hBmp_Icon Then
        Local $aDim = _GDIPlus_ImageGetDimension($hBmp_Icon), $fScaleX, $fScaleY
        If $aDim[0] >= $aDim[1] Then
            $fScaleX = 32 / $aDim[0]
            $fScaleY = $fScaleX
        ElseIf $aDim[0] < $aDim[1] Then
            $fScaleY = 32 / $aDim[1]
            $fScaleX = $fScaleY
        Local Const $hBmp_tmp = _GDIPlus_ImageScale($hBmp_Icon, $fScaleX, $fScaleY)
        $hBmp_GDI = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBmp_tmp)
        _WinAPI_DeleteObject(GUICtrlSendMsg($iPicIcon_W10TW, $STM_SETIMAGE, $IMAGE_BITMAP, $hBmp_GDI))
    Local $aGUI_W10TW[2] = [$hGUI_W10TW, $iBtn_W10TW]
    Return $aGUI_W10TW
EndFunc   ;==>_GDIPlus_CreateW10TrayWin


Edited by UEZ

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