ovideo Posted October 13, 2011 Share Posted October 13, 2011 (edited) Hello. I'm having trouble with my script. It seems to work perfectly on both computers that i can access but it causes some problems on other computers. After padding it with trace lines i came to the conclusion that GUIDelete is deleting the wrong GUI, even though i'm using it with (the correct) handle and everything. Is this a known issue? Is it something i can fix or work around? I would post my entire code but it would take hours to make it work on another machine (uses a lot of stuff on my computer), and it would in no way guarantee that you can replicate it, so i'll just post the troubleing part and try to explain: expandcollapse popup#include <Array.au3> #include <GDIPlus.au3> #include <WindowsConstants.au3> #include <GuiConstantsEx.au3> #include <autoitobject.au3> #include <file.au3> #include <oneventfunc.au3> #requireAdmin global $_gui $_hotk1="{tab}" $_PngPath= ; path to a png here $_offset=4 HotKeySet($_hotk1, "_toggleon") while 1 wend Func _SetBitmap($hGUI, $hImage, $iOpacity, $n_width, $n_height) 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", $n_width) DllStructSetData($tSize, "Y", $n_height) $tSource = DllStructCreate($tagPOINT) $pSource = DllStructGetPtr($tSource) $tBlend = DllStructCreate($tagBLENDFUNCTION) $pBlend = DllStructGetPtr($tBlend) DllStructSetData($tBlend, "Alpha", $iOpacity) DllStructSetData($tBlend, "Format", 1) _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 ;==>_SetBitmap Func _toggleoff() $h = False GUIDelete($_gui) HotKeySet($_hotk1, "_Toggleon") EndFunc ;==>_toggleoff Func _toggleon() HotKeySet($_hotk1) $h = True GUIDelete($_gui) ;==================================>this deletes a DIFFERENT GUI _GDIPlus_Startup() $_Image = _GDIPlus_ImageLoadFromFile($_PngPath) $_Wimage = _GDIPlus_ImageGetWidth($_Image) $_Himage = _GDIPlus_ImageGetHeight($_Image) $_gui = GUICreate("gui", $_Wimage, $_Himage, @DesktopWidth - $_Wimage - $_offset, @DesktopHeight - $_Himage - $_offset, -1, BitOR($ws_ex_layered, $WS_EX_TOPMOST, $ws_ex_toolwindow)) GUISetState(@SW_SHOWNOACTIVATE, $_gui) _SetBitmap($_gui, $_Image, 255, $_Wimage, $_Himage) HotKeySet($_hotk1, "_Toggleoff") _GDIPlus_ImageDispose($_Image) _GDIPlus_Shutdown() EndFunc This part works ok, it overlays transparent png's as it should and also removes them as it should. The problem is, the GUIDelete with the huge comment arrow doesn't only delete $_gui, it also deletes another GUI that was created before in a totally unrelated way, using totally unrelated resources. If this problem seems as weird to you as it does to me, maybe you can help me work around it, maybe by showing me how to remove the image without deleting the GUI. The _setbitmap function was taken from somewhere on the forum (would love to give credit where credit is due, but i can't find the thread in my browser history) - and i sort of need it the way it is since it properly displays transparent .png's. Any ideas for _UNsetbitmap? And a totally unrelated question: How do i set SCiTe to build in x86? Seems to be using x64 by default and i can't find any settings for that. Edited October 13, 2011 by ovideo Link to comment Share on other sites More sharing options...
jaberwacky Posted October 13, 2011 Share Posted October 13, 2011 Is $h being declared somewhere else in your script? Also, try using IsHwnd() as a test before you delete your $_gui and then report. If IsHWnd($_gui) Then GUIDelete($_gui) Else ConsoleWrite("1: $_gui is not an HWND") EndIf Helpful Posts and Websites: AutoIt3 Variables and Function Parameters MHz | AutoIt Wiki | Using the GUIToolTip UDF BrewManNH | Can't find what you're looking for on the Forum? Link to comment Share on other sites More sharing options...
ovideo Posted October 13, 2011 Author Share Posted October 13, 2011 Thank you very much for your reply. Yes, $h is declared somewhere else, just forgot to add it in here. And yes, the problem was exactly what you suspected (finally got it sorted a few hours ago...), GUIDelete($_gui) was being called before $_gui was created, so the call was actually being made with parameter "", which defaulted to deleting my other gui. Solution was just like you posted, just without the bells and whistles: IF $_gui then GUIDelete($_gui) Thx for the help, problem solved Link to comment Share on other sites More sharing options...
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