Jump to content

Recommended Posts

Posted

Hi all,

For some reason I'm unable to get 

    Local $hActions = GUICtrlCreateButton(" Action" & @CRLF & " Center", 100, 220, 80, 40, $BS_MULTILINE)
        GUICtrlSetImage(-1, "C:\Windows\System32\ActionCenter.dll", -1)

to work in Windows 10. This also affects ActionCenterCPL.dll. The code works fine on Windows 7 however...

Does anyone know a workaround?

Thanks!

My UDFs are generally for me. If they aren't updated for a while, it means I'm not using them myself. As soon as I start using them again, they'll get updated.

My Projects

WhyNotWin11, MSEdgeRedirect
Cisco FinesseGithubIRC UDFWindowEx UDF

 

Posted

I'm not sure either, but there's this....

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>

Global $State = 1

ActionCenter()

Func ActionCenter()
    GUICreate("AC")
    GUICtrlCreateButton("Action Center", 10, 20, 40, 40, $BS_ICON)
    GUICtrlSetImage(-1, "shell32.dll", 22)
    GUISetState(@SW_SHOW)
    While $State = 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop
        EndSwitch
    WEnd
EndFunc

 

Posted (edited)

Generally you must add style $BS_BITMAP to button to be able to show image on that button .

In your case BS_ICON style to show icon on button.

Here is related code snippet from my Resources UDF where it's applied:

Func _ResourceSetImageToCtrl($CtrlId, $ResName, $ResType = 10, $DLL = -1) ; $RT_RCDATA = 10
    Local $ResData, $nSize, $hData, $pData, $pStream, $pBitmap, $hBitmap
    
    $ResData = _ResourceGet($ResName, $ResType, 0, $DLL)
    If @error Then Return SetError(1, 0, 0)
    $nSize = @extended
    
    If $ResType = $RT_BITMAP Then
        _SetBitmapToCtrl($CtrlId, $ResData)
        If @error Then Return SetError(2, 0, 0)
    Else
        ; thanks ProgAndy
        ; for other types than BITMAP use GDI+ for converting to bitmap first
        $hData = _MemGlobalAlloc($nSize,2)
        $pData = _MemGlobalLock($hData)
        _MemMoveMemory($ResData,$pData,$nSize)
        _MemGlobalUnlock($hData)
        $pStream = DllCall( "ole32.dll","int","CreateStreamOnHGlobal", "ptr",$hData, "int",1, "ptr*",0)
        $pStream = $pStream[3]
        $pBitmap = DllCall($ghGDIPDll,"int","GdipCreateBitmapFromStream", "ptr",$pStream, "ptr*",0)
        $pBitmap = $pBitmap[2]
        $hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($pBitmap)
        _SetBitmapToCtrl($CtrlId, $hBitmap)
        If @error Then SetError(3, 0, 0)
        _GDIPlus_BitmapDispose($pBitmap)
        _WinAPI_DeleteObject($pStream)
        _MemGlobalFree($hData)
    EndIf

    Return 1
EndFunc

; internal helper function
; thanks for improvements Melba
Func _SetBitmapToCtrl($CtrlId, $hBitmap)
    Local Const $STM_SETIMAGE = 0x0172
    Local Const $STM_GETIMAGE = 0x0173
    Local Const $BM_SETIMAGE = 0xF7
    Local Const $BM_GETIMAGE = 0xF6
    Local Const $IMAGE_BITMAP = 0
    Local Const $SS_BITMAP = 0x0E
    Local Const $BS_BITMAP = 0x0080
    Local Const $GWL_STYLE = -16

    Local $hWnd, $hPrev, $Style, $iCtrl_SETIMAGE, $iCtrl_GETIMAGE, $iCtrl_BITMAP

    $hWnd = GUICtrlGetHandle($CtrlId)
    If $hWnd = 0 Then Return SetError(1, 0, 0)
    
    $CtrlId = _WinAPI_GetDlgCtrlID($hWnd) ; support for $CtrlId = -1
    If @error Then Return SetError(2, 0, 0)

    ; determine control class and adjust constants accordingly
    Switch _WinAPI_GetClassName($CtrlId)
        Case "Button" ; button,checkbox,radiobutton,groupbox
            $iCtrl_SETIMAGE = $BM_SETIMAGE
            $iCtrl_GETIMAGE = $BM_GETIMAGE
            $iCtrl_BITMAP = $BS_BITMAP
        Case "Static" ; picture,icon,label
            $iCtrl_SETIMAGE = $STM_SETIMAGE
            $iCtrl_GETIMAGE = $STM_GETIMAGE
            $iCtrl_BITMAP = $SS_BITMAP
        Case Else
            Return SetError(3, 0, 0)
    EndSwitch
    
    ; set SS_BITMAP/BS_BITMAP style to the control
    $Style = _WinAPI_GetWindowLong($hWnd, $GWL_STYLE)
    If @error Then Return SetError(4, 0, 0)
    _WinAPI_SetWindowLong($hWnd, $GWL_STYLE, BitOR($Style, $iCtrl_BITMAP))
    If @error Then Return SetError(5, 0, 0)
    
    ; set image to the control
    $hPrev  = _SendMessage($hWnd, $iCtrl_SETIMAGE, $IMAGE_BITMAP, $hBitmap)
    If @error Then Return SetError(6, 0, 0)
    If $hPrev Then _WinAPI_DeleteObject($hPrev)
    
    Return 1
EndFunc

 

Edited by Zedna

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
×
×
  • Create New...