daywalkereg Posted September 28, 2008 Posted September 28, 2008 How I Can Save The $hIcon To File as .ico #include <WindowsConstants.au3> Global $GCL_HICONSM = -34 Global $GCL_HICON = -14 Run("Notepad.exe") $hNotepad = WinGetHandle("[Class:Notepad]") $hIcon = DllCall("user32.dll", "int", "GetClassLong", "hwnd", $hNotepad, "int", $GCL_HICON) $hIcon = $hIcon[0] If $hIcon = 0 Then $hIcon = DllCall("user32.dll", "int", "GetClassLong", "hwnd", $hNotepad, "int", $GCL_HICONSM) $hIcon = $hIcon[0] EndIf DllCall("user32.dll", "int", "SendMessage", "hwnd", $hGUI, "int", $WM_SETICON, "int", 1, "int", $hIcon) DllCall("User32.dll", "int", "DestroyIcon", "hwnd", $hIcon) 1 £0\\/3 |-|3® $0 |\\/|µ(|-|
daywalkereg Posted September 28, 2008 Author Posted September 28, 2008 It Is Just Too >_< Complicated To WriteIt MySelf Please Help 1 £0\\/3 |-|3® $0 |\\/|µ(|-|
daywalkereg Posted September 29, 2008 Author Posted September 29, 2008 bump 1 £0\\/3 |-|3® $0 |\\/|µ(|-|
daywalkereg Posted September 29, 2008 Author Posted September 29, 2008 (edited) Thanx rasim But This Didn't Work Simply Because $hIcon = 27919261 What I Don't Understand What Is This Number Or How To Extract It To Icon File I am Sure It Is Not Icon ID In The Exe File Edited September 29, 2008 by daywalkereg 1 £0\\/3 |-|3® $0 |\\/|µ(|-|
rasim Posted September 29, 2008 Posted September 29, 2008 Thanx rasim But This Didn't Work Simply Because $hIcon = 27919261 What I Don't Understand What Is This Number Or How To Extract It To Icon File I am Sure It Is Not Icon ID In The Exe File Please don't send message to PM, post your answers on forum. Example: expandcollapse popup#include <GDIPlus.au3> #include <WindowsConstants.au3> Run("Notepad.exe") WinWait("[Class:Notepad]") $hNotepad = WinGetHandle("[Class:Notepad]") $hIcon = _ExtractIconFromWindow($hNotepad) If $hIcon = 0 Then Exit _SaveIconAsFile($hIcon, @ScriptDir & "\new_Icon.bmp") Func _ExtractIconFromWindow($hWnd) If Not WinExists($hWnd) Then Return SetError(1, 0, 0) Local $GCL_HICONSM = -34 Local $GCL_HICON = -14 Local $hIcon = DllCall("user32.dll", "int", "GetClassLong", "hwnd", $hWnd, "int", $GCL_HICON) If $hIcon[0] = 0 Then $hIcon = DllCall("user32.dll", "int", "GetClassLong", "hwnd", $hWnd, "int", $GCL_HICONSM) EndIf Return $hIcon[0] EndFunc ;==>_ExtractIconFromWindow Func _SaveIconAsFile($hIcon, $sPath) _GDIPlus_Startup() $pBITMAP = DllStructCreate("hwnd") DllCall($ghGDIPDll, "int", "GdipCreateBitmapFromHICON", "hwnd", $hIcon, "ptr", DllStructGetPtr($pBITMAP)) $hSourceIMG = DllStructGetData($pBITMAP, 1) $hBitmap = _CreateBMP(32, 32) $hImage = _GDIPlus_BitmapCreateFromHBITMAP($hBitmap) $hGraphic = _GDIPlus_ImageGetGraphicsContext($hImage) _GDIPlus_GraphicsDrawImageRectRect($hGraphic, $hSourceIMG, 0, 0, 32, 32, 0, 0, 32, 32) _GDIPlus_ImageSaveToFile($hImage, $sPath) _WinAPI_DeleteObject($hBitmap) _WinAPI_DeleteObject($hImage) _GDIPlus_GraphicsDispose($hGraphic) _WinAPI_DestroyIcon($hIcon) _GDIPlus_Shutdown() EndFunc ;==>_SaveIconAsFile Func _CreateBMP($sWidth, $sHeight) Local $hWnd, $hDC, $hBMP $hWnd = _WinAPI_GetDesktopWindow() $hDC = _WinAPI_GetDC($hWnd) $hBMP = _WinAPI_CreateCompatibleBitmap($hDC, $sWidth, $sHeight) _WinAPI_ReleaseDC($hWnd, $hDC) Return $hBMP EndFunc ;==>_CreateBMP And please, don't ask me how to convert bmp image to ico.
daywalkereg Posted September 29, 2008 Author Posted September 29, 2008 Thanx rasim For Your Fast Reply I Owe You One Thanx Again 1 £0\\/3 |-|3® $0 |\\/|µ(|-|
Dolemite50 Posted April 29, 2009 Posted April 29, 2009 This is pretty slick. Nice work, lads! Is there a way to save as either png or gif and maintain transparency?
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