How to make a picture's transparent background not visible when layered on a parent window?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
necomerx
Posts: 57
Joined: 01 Jan 2021, 09:09

How to make a picture's transparent background not visible when layered on a parent window?

Post by necomerx » 26 May 2021, 14:32

Hi everyone,
i'm stuck with this problem were i put a png picture on top of a parent window but the white background is always displayed no matter how i write the code. How to get rid of the background and only have the sun image please? Here is an example.

Code: Select all

SetWorkingDir,%A_WorkingDir%
gui, color, white
gui, add, picture, w100 h-1 , Sun.png
winget, ID, ID, Trees0 ahk_class Photo_Lightweight_Viewer
gui, -Caption -border parent%ID%
winset, TransColor, white
gui, show

Thanks for your help.
Attachments
Trees0.jpg
Trees0.jpg (90.37 KiB) Viewed 548 times
Sun.png
Sun.png (91.98 KiB) Viewed 548 times

User avatar
boiler
Posts: 17384
Joined: 21 Dec 2014, 02:44

Re: How to make a picture's transparent background not visible when layered on a parent window?

Post by boiler » 26 May 2021, 14:45

Code: Select all

Gui, Add, Picture, x0 y0, Trees0.jpg
Gui, Add, Picture, x0 y0 w-1 h300 BackgroundTrans, Sun.png
Gui, Show
return

GuiClose:
ExitApp

necomerx
Posts: 57
Joined: 01 Jan 2021, 09:09

Re: How to make a picture's transparent background not visible when layered on a parent window?

Post by necomerx » 26 May 2021, 14:55

Thanks you very much boiler, your solution work like a charm in that case of 2 pictures, i'm going to test it in the case of a window and a added picture because that's the case that's causing me problems.

necomerx
Posts: 57
Joined: 01 Jan 2021, 09:09

Re: How to make a picture's transparent background not visible when layered on a parent window?

Post by necomerx » 26 May 2021, 15:08

boiler wrote:
26 May 2021, 14:45

Code: Select all

Gui, Add, Picture, x0 y0, Trees0.jpg
Gui, Add, Picture, x0 y0 w-1 h300 BackgroundTrans, Sun.png
Gui, Show
return

GuiClose:
ExitApp
So with 2 pictures it works very well, but is it possible for this to work in a case were for exemple you open the Trees pictures on an image viewer window and want to add the sun on it? Because i tried it that way but it don't seems to work.

User avatar
boiler
Posts: 17384
Joined: 21 Dec 2014, 02:44

Re: How to make a picture's transparent background not visible when layered on a parent window?

Post by boiler » 26 May 2021, 15:11

This worked for me with it displayed in MS Paint. It should work with any window.

Code: Select all

gui, color, white
gui, add, picture, h-1 BackgroundTrans, Sun.png
winget, ID, ID, Trees0
gui, -Caption -border parent%ID% hwndGuiID
winset, TransColor, white, ahk_id %GuiID%
gui, show
return

Esc::ExitApp

necomerx
Posts: 57
Joined: 01 Jan 2021, 09:09

Re: How to make a picture's transparent background not visible when layered on a parent window?

Post by necomerx » 26 May 2021, 15:37

boiler wrote:
26 May 2021, 15:11
This worked for me with it displayed in MS Paint. It should work with any window.

Code: Select all

gui, color, white
gui, add, picture, h-1 BackgroundTrans, Sun.png
winget, ID, ID, Trees0
gui, -Caption -border parent%ID% hwndGuiID
winset, TransColor, white, ahk_id %GuiID%
gui, show
return

Esc::ExitApp
Ok thanks, So that's strange for me because this is what i got with windows seven photos viewer. I got some glitches also as you can see. I Will investigate to understand what's wrong in my case.
Attachments
Pic 3.PNG
Pic 3.PNG (638.58 KiB) Viewed 505 times
Pic 2.PNG
Pic 2.PNG (97.06 KiB) Viewed 505 times
Pic 1.PNG
Pic 1.PNG (87.48 KiB) Viewed 505 times

User avatar
boiler
Posts: 17384
Joined: 21 Dec 2014, 02:44

Re: How to make a picture's transparent background not visible when layered on a parent window?

Post by boiler » 26 May 2021, 17:05

I'm not sure why, but it doesn't work with the standard photo viewer in Win10 for me, but it works with other windows I've tried so far in addition to MS Paint, including Notepad, Notepad++, and Chrome.

WatsonEnterprises
Posts: 19
Joined: 25 May 2020, 23:04

Re: How to make a picture's transparent background not visible when layered on a parent window?

Post by WatsonEnterprises » 27 May 2021, 00:09

What happens if you switch the order around like this? (show gui -> set transparency -> attach to parent)

Code: Select all

gui, color, white
gui, add, picture, h-1 BackgroundTrans, Sun.png
winget, ID, ID, Trees0
gui, -Caption -border +hwndGuiID
gui, show
winset, TransColor, white, ahk_id %GuiID%
gui, +parent%ID%
return

Esc::ExitApp
When I run the above, Sun is transparent and is attached to Trees, but Sun doesn't move when Trees moves. If I don't set transparency (comment out the single line [winset, TransColor, white, ahk_id %GuiID%"]), then Sun DOES move along with Trees. So transparency seems to be messing something up with the child GUI.

This post by lexicos seems to suggest transparent child GUIs aren't possible. This post seems to sneak around that by manually moving the child GUIs, to make them move along with the parent.

necomerx
Posts: 57
Joined: 01 Jan 2021, 09:09

Re: How to make a picture's transparent background not visible when layered on a parent window?

Post by necomerx » 27 May 2021, 04:00

Yes boiler, it seems like this doesn't work with all windows, but i'm gonna take a look at the "sneak around" posted by WatsonEnterprises. Thanks also for your help WatsonEnterprises, your code doesn't work unfortunately, i will take a look at the post you provided.

Post Reply

Return to “Ask for Help (v1)”