Jump to content

GUICtrlCreatePic() transparency issues, transparency in .bmp disappears whole GUI


Recommended Posts

Hello. I am currently experimenting with a custom menu centered around the mouse. I'm at step 1, basic GUI design. I know there are probably UDFs out there that can do exactly what I need, but I'm doing this for the experience.

Anyway, I'm trying to use GUICtrlCreatePic() to display the background of the GUI, it mimics the dark mode context menu of windows 11. 

 

1279732360_Screenshot2022-11-30041351.png.2e1a107c5f25f38abe059f7cf46505ba.png

This is the GUI that the function creates, as you can see it does an atrocious job of making the soft edges transparent. I figured I could edit the .bmp image to achieve what I want but upon doing so, I'm met with straight failure and the script just doesn't generate any image. I've been trying to diagnose the problem on my own for a while now. I thought the origin ( 0, 0 ) of the image was going to be the transparency reference but I found it was not. I changed the background to off-white and it seemed to fix it to what is displayed above. It seems as though any attempt to make GUICtrlCreatePic() display an image that already contains transparency just breaks the function.

Am I missing something? I'd appreciate any help on the matter. Below is the .bmp image I was hoping to get the GUI to display (without the off-white corners of course).

Tray.bmp

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Misc.au3>
#include <WINAPI.au3>

$aMousePos = MouseGetPos ()

$hGUI = GUICreate ( "", 216, 190, $aMousePos[0], $aMousePos[1]-190, $WS_POPUP, $WS_EX_LAYERED )
GUISetBkColor( 0xABCDEF, $hGUI )

$TrayBackground = GUICtrlCreatePic ( "Tray.bmp", 0, 0, 0, 0, -1, $WS_EX_LAYERED )
GUICtrlSetState ( $TrayBackground, $GUI_DISABLE )

_WinAPI_SetLayeredWindowAttributes($hGUI, 0xABCDEF, 255)

GUISetState(@SW_SHOW)

While 1
    If ( _IsPressed ( 01 ) ) And ( WinActive ( $hGUI ) = 0 ) Then Exit
    Sleep (10)
WEnd

EDIT: Also, just attaching the version of the .bmp that the function will accept and process (The one without transparency).

Tray2.bmp

Edited by D3fr0s7
fixed wording
Link to post
Share on other sites

Sorry if the image isn’t that clear, the GUI generated was created on a white background. The Gradient for the soft corners fades from GUI color to white and the working image still has a little bit of white on these corners. I took the image and adjusted the gradient manually changing from a ‘fade to white’ to a ‘fade to translucent’ which would’ve fixed that issue, but the function no longer works after doing so. 

Edit: Here is the GUI that the function will work with, with ugly soft corners:

1397535637_Screenshot2022-11-30041351.png.111e59600bd4e1de536bd7d36a58dc19.png

And here is the GUI that I was hoping to achieve:

401465745_DarkmodeTrayblackbck.png.319382ee5c03942664f8d58878bdea21.png

Edited by D3fr0s7
Added pictures to show intention
Link to post
Share on other sites
  • D3fr0s7 changed the title to GUICtrlCreatePic() transparency issues, transparency in .bmp disappears whole GUI

is this better ?

 

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Misc.au3>
#include <WINAPI.au3>

$aMousePos = MouseGetPos ()

$hGUI = GUICreate ( "", 216, 190, $aMousePos[0], $aMousePos[1]-190, $WS_POPUP, $WS_EX_LAYERED )
GUISetBkColor( 0xABCDEF, $hGUI )

$TrayBackground = GUICtrlCreatePic ( "Test.bmp", 0, 0, -1, -1, -1, $WS_EX_LAYERED )
GUICtrlSetState ( $TrayBackground, $GUI_DISABLE )

_WinAPI_SetLayeredWindowAttributes($hGUI, 0xABCDEF, 255)

GUISetState(@SW_SHOW)

While 1
    If ( _IsPressed ( 01 ) ) And ( WinActive ( $hGUI ) = 0 ) Then Exit
    Sleep (10)
WEnd

 

test.bmp

Some of my script sourcecode

Link to post
Share on other sites

A little 😀 in that it is less of an eyesore, but I was hoping for a simple way to get a GUI image with transparency. I’ve found some ways to do it but they look very hard to understand, and even harder to use as a GUI. Such as UEZ’s method. I’m thinking of scrapping the idea, I wanted a custom tray menu GUI that mimicked that of the OS’s dark mode context menu, but it seems like more trouble than it’s worth.

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
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...