voldor Posted February 2, 2008 Posted February 2, 2008 Hello im trying to have the same effect like the one using this code ; EXAMPLE SHOWING Bitmap to Region function ( BMP2RGN() ) ; ; int BMP2RGN("str","path to BMP", ; "int",red value, ; "int",green value, ; "int",blue value) ; ; The red, green, blue values should be the color of the pixel ; in the BMP that you DON't want to see. ; #include <GUIConstants.au3> $gui = GUICreate("",100,100,-1,-1, $WS_POPUP) GUICtrlCreatePic("larry.bmp",0,0,100,100) GUICtrlSetState(-1, $GUI_DISABLE) $Button = GUICtrlCreateButton("button", 15, 40, 70, 20) $a = DLLCall("BMP2RGN.dll","int","BMP2RGN", _ "str","larry.bmp", _ "int",0, _ "int",0, _ "int",0) SetWindowRgn($gui, $a[0]) GUISetState(@SW_SHOW) While 1 $msg = GUIGetMsg() Select Case $msg = $Button Exit EndSelect WEnd Func SetWindowRgn($h_win, $rgn) DllCall("user32.dll", "long", "SetWindowRgn", "hwnd", $h_win, "long", $rgn, "int", 1) EndFunc but my problem is that the dll call work on a given Windows XP but not on other. Is it possible to do it another way ? Or do you have any idea why the black region is still visible in the above example ?
martin Posted February 2, 2008 Posted February 2, 2008 (edited) Hello im trying to have the same effect like the one using this code ; EXAMPLE SHOWING Bitmap to Region function ( BMP2RGN() ) ; ; int BMP2RGN("str","path to BMP", ; "int",red value, ; "int",green value, ; "int",blue value) ; ; The red, green, blue values should be the color of the pixel ; in the BMP that you DON't want to see. ; #include <GUIConstants.au3> $gui = GUICreate("",100,100,-1,-1, $WS_POPUP) GUICtrlCreatePic("larry.bmp",0,0,100,100) GUICtrlSetState(-1, $GUI_DISABLE) $Button = GUICtrlCreateButton("button", 15, 40, 70, 20) $a = DLLCall("BMP2RGN.dll","int","BMP2RGN", _ "str","larry.bmp", _ "int",0, _ "int",0, _ "int",0) SetWindowRgn($gui, $a[0]) GUISetState(@SW_SHOW) While 1 $msg = GUIGetMsg() Select Case $msg = $Button Exit EndSelect WEnd Func SetWindowRgn($h_win, $rgn) DllCall("user32.dll", "long", "SetWindowRgn", "hwnd", $h_win, "long", $rgn, "int", 1) EndFunc but my problem is that the dll call work on a given Windows XP but not on other. Is it possible to do it another way ? Or do you have any idea why the black region is still visible in the above example ? The dll probably uses the API SetWindowRegion. The example below makes the background disappear so that the text on the label and the button are all that you see. If you want to make a colour on your picture become transparent then just create the picture, set the test colour by choosing the point for PixelGetColor and it should work. The dll is probably a lot faster, and doesn't require the window or Pic to be shown before it is converted. I think the same thing could still be done without a dll but probably more slowly. expandcollapse popup#include <GuiConstants.au3> #include <windowsconstants.au3> HotKeySet("{ESC}", "QuitApp") Global $Startx, $Starty, $Endx, $Endy, $aM_Mask, $aMask, $nc Global $gw=300,$gh=220 $Main_Gui = GUICreate("", $gw, $gh, 100, 20, $WS_POPUP, $WS_EX_TOOLWINDOW + $WS_EX_TOPMOST) $Label1 = GUICtrlCreateLabel("Label1", 70, 70, 156, 60) GUICtrlSetFont(-1, 36, 800, 0, "Arial") GUICtrlSetColor(-1, 0xFF0000) $But1 = GUICtrlCreateButton(" remove background ", 100, 200, 120, 21) Opt("PixelCoordMode", 2) GUISetState() While 1 $Msg = GUIGetMsg() Switch $Msg Case $But1 setTrans() 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 The code is a bit rushed but it shows the idea. Edited February 2, 2008 by martin 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.
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