Yashied Posted February 10, 2009 Share Posted February 10, 2009 (edited) There is a need to merge the two icons. I wrote a function that combines two icons into one, and draws them to the specified background. For my purposes the function works fine for all types of icons (1-bit, 4-bit, etc. and any combinations of them), but would like to see a combined icon had a transparent background.If you have any ideas on this, please reply. expandcollapse popup#include <Constants.au3> #include <GDIPlus.au3> #include <WinAPI.au3> #include <WindowsConstants.au3> func _DrawCombineBkIcon($iBackground, $sIconBack, $iIndexBack, $sIconFront, $iIndexFront, $iLeft, $iTop, $iWidth, $iHeight, $iStyle = -1, $iExStyle = -1) ; const $DI_NORMAL = 3 const $STM_SETIMAGE = 0x0172 local $iIcon, $tIcon, $tID, $hDC, $hBackDC, $hBackSv, $hBitmap, $hImage, $hBackIcon, $hFrontIcon, $aCombineIcon local $bError = false $tIcon = DllStructCreate('hwnd') $tID = DllStructCreate('hwnd') DllCall('user32.dll', 'int', 'PrivateExtractIcons', 'str', $sIconFront, 'int', $iIndexFront, 'int', $iWidth, 'int', $iHeight, 'ptr', DllStructGetPtr($tIcon), 'ptr', DllStructGetPtr($tID), 'int', 1, 'int', 0) if @error then $bError = 1 endif $hFrontIcon = DllStructGetData($tIcon, 1) DllCall('user32.dll', 'int', 'PrivateExtractIcons', 'str', $sIconBack, 'int', $iIndexBack, 'int', $iWidth, 'int', $iHeight, 'ptr', DllStructGetPtr($tIcon), 'ptr', DllStructGetPtr($tID), 'int', 1, 'int', 0) if @error then $bError = 1 endif $hBackIcon = DllStructGetData($tIcon, 1) $tIcon = 0 $tID = 0 if ($bError) or (not IsPtr($hFrontIcon)) or (not IsPtr($hBackIcon)) then return SetError(1, 0, 0) endif $hDC = _WinAPI_GetDC(0) $hBackDC = _WinAPI_CreateCompatibleDC($hDC) $hBitmap = _WinAPI_CreateSolidBitmap(0, $iBackground, $iWidth, $iHeight) $hBackSv = _WinAPI_SelectObject($hBackDC, $hBitmap) _WinAPI_DrawIconEx($hBackDC, 0, 0, $hBackIcon, 0, 0, 0, 0, $DI_NORMAL) _WinAPI_DrawIconEx($hBackDC, 0, 0, $hFrontIcon, 0, 0, 0, 0, $DI_NORMAL) _GDIPlus_Startup() $hImage = _GDIPlus_BitmapCreateFromHBITMAP($hBitmap) $aCombineIcon = DllCall($ghGDIPDll, 'int', 'GdipCreateHICONFromBitmap', 'hWnd', $hImage, 'int*', 0) _GDIPlus_ImageDispose($hImage) $iIcon = GUICtrlCreateIcon('', 0, $iLeft, $iTop, $iWidth, $iHeight, $iStyle, $iExStyle) if $iIcon > 0 then GUICtrlSendMsg($iIcon, $STM_SETIMAGE, $IMAGE_ICON, _WinAPI_CopyIcon($aCombineIcon[2])) endif _GDIPlus_Shutdown() _WinAPI_SelectObject($hBackDC, $hBackSv) _WinAPI_DeleteDC($hBackDC) _WinAPI_ReleaseDC(0, $hDC) _WinAPI_DeleteObject($aCombineIcon[2]) _WinAPI_DeleteObject($hBitmap) _WinAPI_DeleteObject($hFrontIcon) _WinAPI_DeleteObject($hBackIcon) return SetError(0, 0, $iIcon) endfunc; _DrawCombineBkIconDrawCombineBkIcon.au3 Edited May 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... Link to comment Share on other sites More sharing options...
Yashied Posted February 10, 2009 Author Share Posted February 10, 2009 (edited) If you are interested, here is a simple example for _DrawCombineBkIcon function. #include <GUIConstantsEx.au3> #include <DrawCombineBkIcon.au3> local $Form $Form = GUICreate('Test', 128, 128) GUISetState() _DrawCombineBkIcon(_GUIGetBkColor($Form), 'shell32.dll', 0, 'shell32.dll', 28, 48, 48, 32, 32) do Sleep(10) until GUIGetMsg() = $GUI_EVENT_CLOSE func _GUIGetBkColor($hWnd) local $hDC, $BkClr $hDC = _WinAPI_GetDC($hWnd) $BkClr = _WinAPI_SetBkColor($hDC, 0) _WinAPI_ReleaseDC($hWnd, $hDC) return $BkClr endfunc; _GUIGetBkColor Edited February 10, 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... Link to comment Share on other sites More sharing options...
ResNullius Posted February 10, 2009 Share Posted February 10, 2009 Very nice Yashied! Looks like you're contributing some great scripts. Welcome to the community. 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