WildByDesign Posted 4 hours ago Posted 4 hours ago Microsoft has updated the documentation for DwmSetWindowAttribute to include a new option for Windows 11 builds 26100 and higher. Therefore, if you are running Windows 11 24H2/25H2, this should be available now. I cannot see Microsoft adding this unless they somehow benefit from it directly. But I am very unfamiliar with working with bitmaps and therefore I don't even understand what all is possible and what can be achieved with this new option. From the docs: Quote Use with DwmSetWindowAttribute . Enables or disables the use of the alpha channel in the window's redirection bitmap. If this attribute is set to true, the window must contain premultiplied alpha values in each pixel. If it is false, the alpha is ignored and the redirection bitmap is treated as fully opaque. This attribute defaults to false. For anyone who is more familiar working with bitmaps, would you please be willing to put together one or two small examples so that I can gain some understanding from it? Whether that is examples with an image, text, or whatever just to show what is possible. Thank you. Also, I have expanded the _WinAPI_DwmSetWindowAttribute() function to include the constant values for the two new options: Global Const $DWMWA_REDIRECTIONBITMAP_ALPHA = 39 Global Const $DWMWA_BORDER_MARGINS = 40 Func _WinAPI_DwmSetWindowAttributeEx($hWnd, $iAttribute, $iData) Switch $iAttribute Case 2, 3, 4, 6, 7, 8, 10, 11, 12, 13, 14, 15, 16, $DWMWA_USE_IMMERSIVE_DARK_MODE, 33, 34, 35, 36, 37, 38, 39, 40 Case Else Return SetError(1, 0, 0) EndSwitch Local $aCall = DllCall('dwmapi.dll', 'long', 'DwmSetWindowAttribute', 'hwnd', $hWnd, 'dword', $iAttribute, _ 'dword*', $iData, 'dword', 4) If @error Then Return SetError(@error + 10, @extended, 0) If $aCall[0] Then Return SetError(10, $aCall[0], 0) Return 1 EndFunc ;==>_WinAPI_DwmSetWindowAttributeEx
UEZ Posted 3 hours ago Posted 3 hours ago (edited) Seem that it can display GUI with 32bit image with transparency without using WS_EX_LAYERED: expandcollapse popup;Coded by UEZ #include <GUIConstantsEx.au3> #include <GDIPlus.au3> #include <WinAPI.au3> #include <WindowsConstants.au3> AutoItSetOption("GuiOnEventMode", 1) Global Const $DWMWA_REDIRECTIONBITMAP_ALPHA = 39 _GDIPlus_Startup() Global $hImage = _GDIPlus_ImageLoadFromFile("c:\Program Files (x86)\AutoIt3\Examples\GUI\Torus.png") Global $iW = _GDIPlus_ImageGetWidth($hImage) Global $iH = _GDIPlus_ImageGetHeight($hImage) Global $hGUI = GUICreate(" DWMWA_REDIRECTIONBITMAP_ALPHA Test", $iW, $iH, -1, -1, $WS_POPUP) Global $aCall = DllCall("dwmapi.dll", "long", "DwmSetWindowAttribute", _ "hwnd", $hGUI, _ "dword", $DWMWA_REDIRECTIONBITMAP_ALPHA, _ "bool*", True, _ "dword", 4) GUISetState() GUIRegisterMsg($WM_PAINT, "_WM_PAINT") GUISetOnEvent($GUI_EVENT_CLOSE, "_Quit") _WinAPI_InvalidateRect($hGUI, 0, True) Do Until Not Sleep(100) Func _WM_PAINT($hWnd, $iMsg, $wParam, $lParam) If $hWnd <> $hGUI Then Return $GUI_RUNDEFMSG Local $tPS = DllStructCreate($tagPAINTSTRUCT) Local $hDC = _WinAPI_BeginPaint($hWnd, $tPS) Local $hGfx = _GDIPlus_GraphicsCreateFromHDC($hDC) _GDIPlus_GraphicsSetCompositingMode($hGfx, $GDIP_COMPOSITINGMODESOURCECOPY) _GDIPlus_GraphicsSetSmoothingMode($hGfx, $GDIP_SMOOTHINGMODE_HIGHQUALITY) _GDIPlus_GraphicsDrawImageRect($hGfx, $hImage, 0, 0, $iW, $iH) _GDIPlus_GraphicsDispose($hGfx) _WinAPI_EndPaint($hWnd, $tPS) Return 0 EndFunc Func _Quit() GUIRegisterMsg($WM_PAINT, "") _GDIPlus_BitmapDispose($hImage) _GDIPlus_Shutdown() GUIDelete($hGUI) Exit EndFunc Edited 1 hour ago by UEZ WildByDesign 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!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ
WildByDesign Posted 2 hours ago Author Posted 2 hours ago 36 minutes ago, UEZ said: Seem that it can display GUI with 32bit image with transparency without using WS_EX_LAYERED: This is a really nice example for me to learn from. I appreciate your help. Could this be used for child GUI windows as well? Could this also be used for text (eg. Alpha blending text)?
Solution UEZ Posted 1 hour ago Solution Posted 1 hour ago (edited) It seems to work also for child windows: expandcollapse popup;Coded by UEZ #include <GUIConstantsEx.au3> #include <GDIPlus.au3> #include <WinAPI.au3> #include <WindowsConstants.au3> AutoItSetOption("GuiOnEventMode", 1) Global Const $DWMWA_REDIRECTIONBITMAP_ALPHA = 39 _GDIPlus_Startup() Global $hImage = _GDIPlus_ImageLoadFromFile("c:\Program Files (x86)\AutoIt3\Examples\GUI\Torus.png") Global $iW = _GDIPlus_ImageGetWidth($hImage) Global $iH = _GDIPlus_ImageGetHeight($hImage) Global $hGfx = _GDIPlus_ImageGetGraphicsContext($hImage) _GDIPlus_GraphicsSetSmoothingMode($hGfx, $GDIP_SMOOTHINGMODE_HIGHQUALITY) _GDIPlus_GraphicsSetTextRenderingHint($hGfx, $GDIP_TEXTRENDERINGHINTANTIALIAS) Global $hBrush = _GDIPlus_BrushCreateSolid(0xA0FFFFFF) Global $hFormat = _GDIPlus_StringFormatCreate() Global $hFamily = _GDIPlus_FontFamilyCreate("Arial") Global $hFont = _GDIPlus_FontCreate($hFamily, 30) Global $tLayout = _GDIPlus_RectFCreate(0, $iH - 100, $iW, 32) _GDIPlus_StringFormatSetAlign($hFormat, 1) _GDIPlus_GraphicsDrawStringEx($hGfx, "Hello world", $hFont, $tLayout, $hFormat, $hBrush) _GDIPlus_FontDispose($hFont) _GDIPlus_FontFamilyDispose($hFamily) _GDIPlus_StringFormatDispose($hFormat) _GDIPlus_GraphicsDispose($hGfx) Global $hGUI = GUICreate("Parent", 200, 150, 300, 200) Global $hChild = GUICreate("Child", $iW, $iH, -1, -1, $WS_POPUP, $WS_EX_TOOLWINDOW, $hGUI) Global $aCall = DllCall("dwmapi.dll", "long", "DwmSetWindowAttribute", _ "hwnd", $hChild, _ "dword", $DWMWA_REDIRECTIONBITMAP_ALPHA, _ "bool*", True, _ "dword", 4) GUIRegisterMsg($WM_PAINT, "_WM_PAINT") GUISetState(@SW_SHOW, $hGUI) GUISetState(@SW_SHOW, $hChild) GUISetOnEvent($GUI_EVENT_CLOSE, "_Quit") Do Until Not Sleep(100) Func _WM_PAINT($hWnd, $iMsg, $wParam, $lParam) If $hWnd <> $hChild Then Return $GUI_RUNDEFMSG Local $tPS = DllStructCreate($tagPAINTSTRUCT) Local $hDC = _WinAPI_BeginPaint($hWnd, $tPS) Local $hGfx = _GDIPlus_GraphicsCreateFromHDC($hDC) _GDIPlus_GraphicsSetCompositingMode($hGfx, $GDIP_COMPOSITINGMODESOURCECOPY) _GDIPlus_GraphicsSetSmoothingMode($hGfx, $GDIP_SMOOTHINGMODE_HIGHQUALITY) _GDIPlus_GraphicsDrawImageRect($hGfx, $hImage, 0, 0, $iW, $iH) _GDIPlus_GraphicsDispose($hGfx) _WinAPI_EndPaint($hWnd, $tPS) Return 0 EndFunc Func _Quit() GUIRegisterMsg($WM_PAINT, "") _GDIPlus_BitmapDispose($hImage) _GDIPlus_Shutdown() GUIDelete($hGUI) GUIDelete($hChild) Exit EndFunc Edited 1 hour ago by UEZ WildByDesign 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!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now