Jump to content

Transparent pic + Window transparency


Nahuel
 Share

Recommended Posts

Here's the thing. I'd like you to see this example to know what I mean:

#include <WindowsConstants.au3>

$Form=GUICreate("test",192,110,-1,-1,$WS_POPUP,$WS_EX_LAYERED)
GUICtrlCreatePic("bitmap.bmp",0,0,192,110)
GUISetState()

Do
Until GUIGetMsg()=-3

Please save this pic: http://nahueljose.googlepages.com/bitmap.bmp in the same dir as the script.

You should see something like this:

Posted Image

But look what happens if I want some transparency.

Posted Image

Before you say anything, I know there's an example on how to use a PNG picture with a reeeally smooth effect and transparency, but I can't add text to it. I need to add text on the picture, preferably with a Label control. I tried creating a child GUI with the $WS_EX_MDICHILD ex-style, but I have many problems... I need it to be more efficient.

So, to the graphic genuises, is there a way I can fix this transparency issue or at least find an efficient way to add text to a transparent GUI created with a PNG picture?

I hope you understand :)

Link to comment
Share on other sites

This does what I think you want. I have added $GUI_WS_EX_PARENTDRAG to the pic so you can drag it around to see the effect.

It's a it slow so if you can trim the bmp it will help speed it up. It might not be the best way but it's the only way I can think of to do what you want.

CODE

#include <GuiConstants.au3>

#include <windowsconstants.au3>

HotKeySet("{ESC}", "QuitApp")

Global $Startx, $Starty, $Endx, $Endy, $aM_Mask, $aMask, $nc

Global $gw=192,$gh=110

$Main_Gui = GUICreate("nahuel", $gw, $gh, 100, 20, $WS_POPUP, $WS_EX_TOOLWINDOW + $WS_EX_TOPMOST)

GUICtrlCreatePic("bitmap.bmp",0,0,192,110,-1,$GUI_WS_EX_PARENTDRAG)

Opt("PixelCoordMode", 2)

GUISetState()

setTrans()

WinSetTrans("nahuel","",170)

While 1

$Msg = GUIGetMsg()

Switch $Msg

Case - 3

Exit

EndSwitch

WEnd

Func setTrans()

$aM_Mask = DllCall("gdi32.dll", "long", "CreateRectRgn", "long", 0, "long", 0, "long", 460, "long", 460)

$rct = DllStructCreate("int;int;int;inr", $aM_Mask[0])

$TestCol = PixelGetColor(1, 1);<----------------------------set coords for your test colour here

;anything on the window which is the same colour as $TestCol will become transparent

$Startx = -1

$Starty = -1

$Endx = 0

$Endy = 0

For $i = 0 To $gw;the window width

For $j = 0 To $gh;the window height

If PixelGetColor($i, $j) = $TestCol And $j < $gh Then

If $Startx = -1 Then;start a new region

$Startx = $i

$Starty = $j

$Endx = $i

$Endy = $j

Else;region already started so extend the end

$Endx = $i

$Endy = $j

EndIf

Else;not testcol or at end of line

If $Startx <> -1 Then addRegion()

$Startx = -1

$Starty = -1

EndIf

Next

Next

DllCall("user32.dll", "long", "SetWindowRgn", "hwnd", $Main_Gui, "long", $aM_Mask[0], "int", 1)

EndFunc ;==>setTrans

Func addRegion()

$aMask = DllCall("gdi32.dll", "long", "CreateRectRgn", "long", $Startx, "long", $Starty, "long", $Endx + 1, "long", $Endy + 1)

$nc += 1

ConsoleWrite($nc & ', ')

DllCall("gdi32.dll", "long", "CombineRgn", "long", $aM_Mask[0], "long", $aMask[0], "long", $aM_Mask[0], "int", 3)

EndFunc ;==>addRegion

Func QuitApp()

Exit

EndFunc ;==>QuitApp

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

-EDIT-

Martin, that's exactly the kind of answer I was looking for! That's genius, thank you! :)

*applause*

-ignore from this point on-

Thanks for the reply.

I tried many ways. I do not understand the _GDIPlus..() functions so I was hoping someone could give me a hand.

In the example that comes in the example folder in the autoit installation, there's a function called SetBitmap($hGUI, $hImage, $iOpacity). I'm guessing this is the kind of things that make the creation of text impossible.

This is what I did modifying the PaulIA's example:

#include <GDIPlus.au3>
#include <WinAPI.au3>
#include <WindowsConstants.au3>

Global Const $AC_SRC_ALPHA      = 1

_GDIPlus_Startup()
$hImage = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\bitmap.bmp")

$Form=GUICreate("test",192,110,-1,-1,$WS_POPUP,$WS_EX_LAYERED)
;~ GUICtrlCreatePic("bitmap.bmp",0,0,192,110)
SetBitmap($Form, $hImage, 170)
GUISetState()

Do
Until GUIGetMsg()=-3

_GDIPlus_ImageDispose($hImage)
_GDIPlus_Shutdown()


Func SetBitmap($hGUI, $hImage, $iOpacity)
  Local $hScrDC, $hMemDC, $hBitmap, $hOld, $pSize, $tSize, $pSource, $tSource, $pBlend, $tBlend

  $hScrDC  = _WinAPI_GetDC(0)
  $hMemDC  = _WinAPI_CreateCompatibleDC($hScrDC)
  $hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage)
  $hOld    = _WinAPI_SelectObject($hMemDC, $hBitmap)
  $tSize   = DllStructCreate($tagSIZE)
  $pSize   = DllStructGetPtr($tSize  )
  DllStructSetData($tSize, "X", _GDIPlus_ImageGetWidth ($hImage))
  DllStructSetData($tSize, "Y", _GDIPlus_ImageGetHeight($hImage))
  $tSource = DllStructCreate($tagPOINT)
  $pSource = DllStructGetPtr($tSource)
  $tBlend  = DllStructCreate($tagBLENDFUNCTION)
  $pBlend  = DllStructGetPtr($tBlend)
  DllStructSetData($tBlend, "Alpha" , $iOpacity    )
  DllStructSetData($tBlend, "Format", $AC_SRC_ALPHA)
  _WinAPI_UpdateLayeredWindow($hGUI, $hScrDC, 0, $pSize, $hMemDC, $pSource, 0, $pBlend, $ULW_ALPHA)
  _WinAPI_ReleaseDC   (0, $hScrDC)
  _WinAPI_SelectObject($hMemDC, $hOld)
  _WinAPI_DeleteObject($hBitmap)
  _WinAPI_DeleteDC    ($hMemDC)
EndFunc

EXACT same effect as using WinSetTrans(). But still, even if the transparency problem was solved, I still wouldn't be able to use labels.

I tried using PNG pictures with PaulIA's example and then creating a child GUI with floating text on top of the last one using the ex-style $WS_EX_MDICHILD, but I have problems when dragging. When the main GUI is dragged, the text stays where it was. It only moves with the parent GUI if I minimize and then restore the main GUI.

Hope it's clear >_<

Edited by Nahuel
Link to comment
Share on other sites

-EDIT-

Martin, that's exactly the kind of answer I was looking for!

That's good. I was quite pleased with the effect too. I'll use that myself somewhen.

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

  • 6 months later...

Hi

I was wondering if I could get some advice on this old post. I`m specifically interested in Martin`s script. I got the script working my Windows XP but couldn`t get it working on Vista. Is there any reason why this would be the case?

My other problem. When I have it working on XP. If my script deletes a guictrl icon and then redraws different icons the script doesn`t redraw the icons properly. Half of an icon ends up getting drawn? Perhaps it's hard to explain, I can provide pictures tomorrow if needed.

I`m wondering if there are other ways of using regions to turn one colour in the gui and all of the controls transparent or if anyone has advice on this one.

Thanks very much for any help.

[Edit]

I found this example, seems to be the best option yet.

http://www.autoitscript.com/forum/index.ph...indowAttributes

Edited by picea892
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...