dantay9 Posted August 11, 2009 Posted August 11, 2009 (edited) I saw a few yahtzee games on the forum, but I didn't see any that looked very good at all, so I decided to update them. It is looking good so far, but I am having a bit of trouble with Icons.au3. I narrowed down the problem lines to these lines in _Icons_SetImage: $hPrev = _SendMessage($hWnd, $__STM_SETIMAGE, $iType, 0) If $hPrev Then If $iType = $IMAGE_BITMAP Then _WinAPI_DeleteObject($hPrev) Else _WinAPI_DestroyIcon($hPrev) EndIf EndIf If I comment these lines out, I can update my GuiCtrlCreatePics with _SetImage. If I leave these lines in, the image that I am trying to update to doesn't appear and the previous image disappears. I think taking out these lines would cause a memory leak. I don't know if I made this very clear. Here is my script. Just take a look at it. You will have to comment out the lines that include pictures. There are too many to include here. The problem lines in my script are 58 and 60 unless I comment out the lines specified above.New AutoIt v3 Script.au3 Edited August 11, 2009 by dantay9
dantay9 Posted August 11, 2009 Author Posted August 11, 2009 I think I fixed it. It works for me. Can anyone confirm this? Here is the replacement function: Func _SetImage($hWnd, $sImage) $hWnd = _Icons_CheckHandle($hWnd) If $hWnd = 0 Then Return SetError(1, 0, 0) Local $Ret, $hImage, $hBitmap, $hFit _WinAPI_DeleteObject(_SendMessage($hWnd, $__STM_GETIMAGE, $IMAGE_BITMAP, 0)) _GDIPlus_Startup() $hImage = _GDIPlus_BitmapCreateFromFile($sImage) $hFit = _Icons_FitTo($hWnd, $hImage) $hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hFit) _GDIPlus_ImageDispose($hFit) _GDIPlus_Shutdown() $Ret = _Icons_SetImage($hWnd, $hBitmap, $IMAGE_BITMAP) If $Ret Then $hImage = _SendMessage($hWnd, $__STM_GETIMAGE, $IMAGE_BITMAP, 0) If (@error) Or ($hBitmap = $hImage) Then $hBitmap = 0 EndIf If $hBitmap Then _WinAPI_DeleteObject($hBitmap) Return SetError(1 - $Ret, 0, $Ret) EndFunc ;==>_SetImage
wolf9228 Posted August 12, 2009 Posted August 12, 2009 expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <StaticConstants.au3> #Include <GDIPlus.au3> Dim $msg , $SS_REALSIZEIMAGE = 0x00000800 GUICreate(" My GUI Bitmap", 200, 200) Local $Pic1 = GUICtrlCreateLabel("", 10, 75, 75, 75,$WS_BORDER + $SS_CENTERIMAGE + $SS_REALSIZEIMAGE) STATIC_SETBITMAP($Pic1,@ScriptDir & "\BMP_1.bmp") Local $Pic2 = GUICtrlCreateLabel("", 115, 75, 75, 75,$WS_BORDER + $SS_CENTERIMAGE + $SS_REALSIZEIMAGE) STATIC_SETBITMAP($Pic2,@ScriptDir & "\PNG_1.png") GUISetState() While 1 $msg = GUIGetMsg() If $msg = $GUI_EVENT_CLOSE Then ExitLoop WEnd GUIDelete() Exit Func STATIC_SETBITMAP($hWnd,$ImageFileName) Local $GWL_STYLE = (-16) , $SS_BITMAP = 0x0000000E , $SS_ICON = 0x00000003 ,$STM_SETIMAGE = 0x0172 _ If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd) if Not BitAND(_WinAPI_GetWindowLong($hWnd, $GWL_STYLE), $SS_BITMAP) = $SS_BITMAP Then _WinAPI_SetWindowLong($hWnd, $GWL_STYLE, _WinAPI_GetWindowLong($hWnd, $GWL_STYLE) + $SS_BITMAP ) ElseIf BitAND(_WinAPI_GetWindowLong($hWnd, $GWL_STYLE), $SS_ICON) = $SS_ICON Then _WinAPI_SetWindowLong($hWnd, $GWL_STYLE, _WinAPI_GetWindowLong($hWnd, $GWL_STYLE) - $SS_ICON) EndIf _GDIPlus_Startup () Local $hImage = _GDIPlus_ImageLoadFromFile ($ImageFileName) Local $Status = DllCall($ghGDIPDll, "int", "GdipCreateHBITMAPFromBitmap", "hwnd", $hImage, "int*", 0, "int", 0) $HandleImage = $Status[2] _GDIPlus_ShutDown () Return _SendMessage($hWnd, $STM_SETIMAGE, 0, $HandleImage) EndFunc صرح السماء كان هنا
Yashied Posted August 12, 2009 Posted August 12, 2009 (edited) I saw a few yahtzee games on the forum, but I didn't see any that looked very good at all, so I decided to update them. It is looking good so far, but I am having a bit of trouble with Icons.au3. I narrowed down the problem lines to these lines in _Icons_SetImage: $hPrev = _SendMessage($hWnd, $__STM_SETIMAGE, $iType, 0) If $hPrev Then If $iType = $IMAGE_BITMAP Then _WinAPI_DeleteObject($hPrev) Else _WinAPI_DestroyIcon($hPrev) EndIf EndIf If I comment these lines out, I can update my GuiCtrlCreatePics with _SetImage. If I leave these lines in, the image that I am trying to update to doesn't appear and the previous image disappears. I think taking out these lines would cause a memory leak. I don't know if I made this very clear. Here is my script. Just take a look at it. You will have to comment out the lines that include pictures. There are too many to include here. The problem lines in my script are 58 and 60 unless I comment out the lines specified above. If you put all the necessary images to run your code, I would look into the problem. EDIT: With random images it works perfectly for me. EDIT2: My version of autoit was different because i had altered the include files that came with autoit for my own needs. That is why some of the functions didn't work properly in the way you used them. It works now. I just had to restore the include files that came with the original download of autoit. dantay9, may be here a similar problem. >_< Edited August 12, 2009 by Yashied My UDFs: iKey | FTP Uploader | Battery Checker | Boot Manager | Font Viewer | UDF Keyword Manager | Run Dialog Replacement | USBProtect | 3D Axis | Calculator | Sleep | iSwitcher | TM | NetHelper | File Types Manager | Control Viewer | SynFolders | DLL Helper Animated Tray Icons UDF Library | Hotkeys UDF Library | Hotkeys Input Control UDF Library | Caret Shape UDF Library | Context Help UDF Library | Most Recently Used List UDF Library | Icons UDF Library | FTP UDF Library | Script Communications UDF Library | Color Chooser UDF Library | Color Picker Control UDF Library | IPHelper (Vista/7) UDF Library | WinAPI Extended UDF Library | WinAPIVhd UDF Library | Icon Chooser UDF Library | Copy UDF Library | Restart UDF Library | Event Log UDF Library | NotifyBox UDF Library | Pop-up Windows UDF Library | TVExplorer UDF Library | GuiHotKey UDF Library | GuiSysLink UDF Library | Package UDF Library | Skin UDF Library | AITray UDF Library | RDC UDF Library Appropriate path | Button text color | Gaussian random numbers | Header's styles (Vista/7) | ICON resource enumeration | Menu & INI | Tabbed string size | Tab's skin | Pop-up circular menu | Progress Bar without animation (Vista/7) | Registry export | Registry path jumping | Unique hardware ID | Windows alignment More...
Yashied Posted August 12, 2009 Posted August 12, 2009 expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <StaticConstants.au3> #Include <GDIPlus.au3> Dim $msg , $SS_REALSIZEIMAGE = 0x00000800 GUICreate(" My GUI Bitmap", 200, 200) Local $Pic1 = GUICtrlCreateLabel("", 10, 75, 75, 75,$WS_BORDER + $SS_CENTERIMAGE + $SS_REALSIZEIMAGE) STATIC_SETBITMAP($Pic1,@ScriptDir & "\BMP_1.bmp") Local $Pic2 = GUICtrlCreateLabel("", 115, 75, 75, 75,$WS_BORDER + $SS_CENTERIMAGE + $SS_REALSIZEIMAGE) STATIC_SETBITMAP($Pic2,@ScriptDir & "\PNG_1.png") GUISetState() While 1 $msg = GUIGetMsg() If $msg = $GUI_EVENT_CLOSE Then ExitLoop WEnd GUIDelete() Exit Func STATIC_SETBITMAP($hWnd,$ImageFileName) Local $GWL_STYLE = (-16) , $SS_BITMAP = 0x0000000E , $SS_ICON = 0x00000003 ,$STM_SETIMAGE = 0x0172 _ If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd) if Not BitAND(_WinAPI_GetWindowLong($hWnd, $GWL_STYLE), $SS_BITMAP) = $SS_BITMAP Then _WinAPI_SetWindowLong($hWnd, $GWL_STYLE, _WinAPI_GetWindowLong($hWnd, $GWL_STYLE) + $SS_BITMAP ) ElseIf BitAND(_WinAPI_GetWindowLong($hWnd, $GWL_STYLE), $SS_ICON) = $SS_ICON Then _WinAPI_SetWindowLong($hWnd, $GWL_STYLE, _WinAPI_GetWindowLong($hWnd, $GWL_STYLE) - $SS_ICON) EndIf _GDIPlus_Startup () Local $hImage = _GDIPlus_ImageLoadFromFile ($ImageFileName) Local $Status = DllCall($ghGDIPDll, "int", "GdipCreateHBITMAPFromBitmap", "hwnd", $hImage, "int*", 0, "int", 0) $HandleImage = $Status[2] _GDIPlus_ShutDown () Return _SendMessage($hWnd, $STM_SETIMAGE, 0, $HandleImage) EndFunc Read this very carefully, please. Important In version 6 of the Microsoft Win32 controls, a bitmap passed to a static control using the STM_SETIMAGE message was the same bitmap returned by a subsequent STM_SETIMAGE message. The client is responsible to delete any bitmap sent to a static control. With Microsoft Windows XP, if the bitmap passed in the STM_SETIMAGE message contains pixels with non-zero alpha, the static control takes a copy of the bitmap. This copied bitmap is returned by the next STM_SETIMAGE message. The client code may independently track the bitmaps passed to the static control, but if it does not check and release the bitmaps returned from STM_SETIMAGE messages, the bitmaps are leaked. My UDFs: iKey | FTP Uploader | Battery Checker | Boot Manager | Font Viewer | UDF Keyword Manager | Run Dialog Replacement | USBProtect | 3D Axis | Calculator | Sleep | iSwitcher | TM | NetHelper | File Types Manager | Control Viewer | SynFolders | DLL Helper Animated Tray Icons UDF Library | Hotkeys UDF Library | Hotkeys Input Control UDF Library | Caret Shape UDF Library | Context Help UDF Library | Most Recently Used List UDF Library | Icons UDF Library | FTP UDF Library | Script Communications UDF Library | Color Chooser UDF Library | Color Picker Control UDF Library | IPHelper (Vista/7) UDF Library | WinAPI Extended UDF Library | WinAPIVhd UDF Library | Icon Chooser UDF Library | Copy UDF Library | Restart UDF Library | Event Log UDF Library | NotifyBox UDF Library | Pop-up Windows UDF Library | TVExplorer UDF Library | GuiHotKey UDF Library | GuiSysLink UDF Library | Package UDF Library | Skin UDF Library | AITray UDF Library | RDC UDF Library Appropriate path | Button text color | Gaussian random numbers | Header's styles (Vista/7) | ICON resource enumeration | Menu & INI | Tabbed string size | Tab's skin | Pop-up circular menu | Progress Bar without animation (Vista/7) | Registry export | Registry path jumping | Unique hardware ID | Windows alignment More...
dantay9 Posted August 12, 2009 Author Posted August 12, 2009 @Yashied No, that isn't it. Since that post, I recovered my computer and reinstalled autoit. I didn't change any include files since the recovery. It works now. I think it had to do with the way my images were formatted (some of them were handles, others were loaded with GDI+). That was probably it.
wolf9228 Posted August 13, 2009 Posted August 13, 2009 Read this very carefully, please. $hPrev = _SendMessage($hWnd, $__STM_SETIMAGE, $iType, 0) If $hPrev Then If $iType = $IMAGE_BITMAP Then _WinAPI_DeleteObject($hPrev) Else _WinAPI_DestroyIcon($hPrev) EndIf EndIf hallo! Yashied We do not need this operation only we need in Global Variables Image Handle . صرح السماء كان هنا
Yashied Posted August 13, 2009 Posted August 13, 2009 (edited) We do not need this operation only we need in Global Variables Image Handle .???EDIT:You did not read carefully! >_< Edited August 13, 2009 by Yashied My UDFs: iKey | FTP Uploader | Battery Checker | Boot Manager | Font Viewer | UDF Keyword Manager | Run Dialog Replacement | USBProtect | 3D Axis | Calculator | Sleep | iSwitcher | TM | NetHelper | File Types Manager | Control Viewer | SynFolders | DLL Helper Animated Tray Icons UDF Library | Hotkeys UDF Library | Hotkeys Input Control UDF Library | Caret Shape UDF Library | Context Help UDF Library | Most Recently Used List UDF Library | Icons UDF Library | FTP UDF Library | Script Communications UDF Library | Color Chooser UDF Library | Color Picker Control UDF Library | IPHelper (Vista/7) UDF Library | WinAPI Extended UDF Library | WinAPIVhd UDF Library | Icon Chooser UDF Library | Copy UDF Library | Restart UDF Library | Event Log UDF Library | NotifyBox UDF Library | Pop-up Windows UDF Library | TVExplorer UDF Library | GuiHotKey UDF Library | GuiSysLink UDF Library | Package UDF Library | Skin UDF Library | AITray UDF Library | RDC UDF Library Appropriate path | Button text color | Gaussian random numbers | Header's styles (Vista/7) | ICON resource enumeration | Menu & INI | Tabbed string size | Tab's skin | Pop-up circular menu | Progress Bar without animation (Vista/7) | Registry export | Registry path jumping | Unique hardware ID | Windows alignment More...
wolf9228 Posted August 14, 2009 Posted August 14, 2009 ???EDIT:You did not read carefully! >_<Explain to me this information صرح السماء كان هنا
wolf9228 Posted August 14, 2009 Posted August 14, 2009 LinkHope it was translated correctly.Thank you, I understandBut what is meant by the word leakedis meant that ... the image will be leaked from the static Controlorremain in the memory of the program And should be deleted to provide part of the program memory صرح السماء كان هنا
Authenticity Posted August 14, 2009 Posted August 14, 2009 remain in the memory of the programAnd should be deleted to provide partof the program memory Yes, that one. It'll bite you if it occurs on a program that should run for a couple of hours and be stable. For example, screen capture program, etc...
wolf9228 Posted August 14, 2009 Posted August 14, 2009 remain in the memory of the programAnd should be deleted to provide partof the program memory Yes, that one. It'll bite you if it occurs on a program that should run for a couple of hours and be stable. For example, screen capture program, etc...OK another questionWhen we Call function to send this messageLike previous function And after the completionof the logic operations And then return the resultsThe questionare Not be Automatically deleted all Operations function from the memoryI think the message Returns a False Or True And I do not know it is Returns Handle to the imageThank you for this explanation صرح السماء كان هنا
Authenticity Posted August 14, 2009 Posted August 14, 2009 The message returned value is depended on the content of the control. If the control contain a bitmap object, it'll return a handle to this object when calling $STM_SETIMAGE or $STM_GETIMAGE. When you return from a function, what is promised to be cleaned is the function local variables that will be garbage collected, not kernel objects or anything, for that matter, called via DllCall(). It's your responsibility to release any allocated block of memory. For example, things that will be garbage collected include, DllStructs, strings, primitives, etc.. Hope I'm not too far from the truth. >_<
Yashied Posted August 14, 2009 Posted August 14, 2009 Authenticity, I think you're a good teacher for wolf9228. >_< My UDFs: iKey | FTP Uploader | Battery Checker | Boot Manager | Font Viewer | UDF Keyword Manager | Run Dialog Replacement | USBProtect | 3D Axis | Calculator | Sleep | iSwitcher | TM | NetHelper | File Types Manager | Control Viewer | SynFolders | DLL Helper Animated Tray Icons UDF Library | Hotkeys UDF Library | Hotkeys Input Control UDF Library | Caret Shape UDF Library | Context Help UDF Library | Most Recently Used List UDF Library | Icons UDF Library | FTP UDF Library | Script Communications UDF Library | Color Chooser UDF Library | Color Picker Control UDF Library | IPHelper (Vista/7) UDF Library | WinAPI Extended UDF Library | WinAPIVhd UDF Library | Icon Chooser UDF Library | Copy UDF Library | Restart UDF Library | Event Log UDF Library | NotifyBox UDF Library | Pop-up Windows UDF Library | TVExplorer UDF Library | GuiHotKey UDF Library | GuiSysLink UDF Library | Package UDF Library | Skin UDF Library | AITray UDF Library | RDC UDF Library Appropriate path | Button text color | Gaussian random numbers | Header's styles (Vista/7) | ICON resource enumeration | Menu & INI | Tabbed string size | Tab's skin | Pop-up circular menu | Progress Bar without animation (Vista/7) | Registry export | Registry path jumping | Unique hardware ID | Windows alignment More...
wolf9228 Posted August 14, 2009 Posted August 14, 2009 The message returned value is depended on the content of the control. If the control contain a bitmap object, it'll return a handle to this object when calling $STM_SETIMAGE or $STM_GETIMAGE.When you return from a function, what is promised to be cleaned is the function local variables that will be garbage collected, not kernel objects or anything, for that matter, called via DllCall(). It's your responsibility to release any allocated block of memory. For example, things that will be garbage collected include, DllStructs, strings, primitives, etc.. Hope I'm not too far from the truth. Thank you Mass Spammer! >_< صرح السماء كان هنا
wolf9228 Posted August 14, 2009 Posted August 14, 2009 Authenticity, I think you're a good teacher for wolf9228. >_<I am happy to communicate with you via this site Thank you صرح السماء كان هنا
Yashied Posted August 14, 2009 Posted August 14, 2009 (edited) Mass Spammer! >_< Finally, when you understand (thanks Authenticity), let me add. In accordance with the requirements of Microsoft, your code should look something like this. ... $hBitmap = _SendMessage($hWnd, $STM_SETIMAGE, $IMAGE_BITMAP, $hNewBitmap) _WinAPI_DeleteObject($hBitmap) $hBitmap = _SendMessage($hWnd, $STM_GETIMAGE, $IMAGE_BITMAP, 0) If $hBitmap <> $hNewBitmap Then _WinAPI_DeleteObject($hNewBitmap) EndIf ... Good luck. Edited August 14, 2009 by Yashied My UDFs: iKey | FTP Uploader | Battery Checker | Boot Manager | Font Viewer | UDF Keyword Manager | Run Dialog Replacement | USBProtect | 3D Axis | Calculator | Sleep | iSwitcher | TM | NetHelper | File Types Manager | Control Viewer | SynFolders | DLL Helper Animated Tray Icons UDF Library | Hotkeys UDF Library | Hotkeys Input Control UDF Library | Caret Shape UDF Library | Context Help UDF Library | Most Recently Used List UDF Library | Icons UDF Library | FTP UDF Library | Script Communications UDF Library | Color Chooser UDF Library | Color Picker Control UDF Library | IPHelper (Vista/7) UDF Library | WinAPI Extended UDF Library | WinAPIVhd UDF Library | Icon Chooser UDF Library | Copy UDF Library | Restart UDF Library | Event Log UDF Library | NotifyBox UDF Library | Pop-up Windows UDF Library | TVExplorer UDF Library | GuiHotKey UDF Library | GuiSysLink UDF Library | Package UDF Library | Skin UDF Library | AITray UDF Library | RDC UDF Library Appropriate path | Button text color | Gaussian random numbers | Header's styles (Vista/7) | ICON resource enumeration | Menu & INI | Tabbed string size | Tab's skin | Pop-up circular menu | Progress Bar without animation (Vista/7) | Registry export | Registry path jumping | Unique hardware ID | Windows alignment More...
dantay9 Posted August 15, 2009 Author Posted August 15, 2009 My internet was down yesterday so I couldn't reply. After reading where this topic went, I understand my mistake and how to fix it. Thank you Yashied and Authenticity.
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