dantay9 Posted September 9, 2009 Share Posted September 9, 2009 (edited) I am trying to make an icon that looks like its floating. I am using Yashied's Icons.au3. The idea is to retrieve the image from a file (always an icon, at least the way I am doing it). I am currently combining the icons into a single icon so I don't have as many controls to handle. The icons that are extracted from the file have a white background, not a transparent one. Is there a way to make this background transparent, even after combining the icons?Floating Icon.au3 Edited September 10, 2009 by dantay9 Link to comment Share on other sites More sharing options...
Yashied Posted September 10, 2009 Share Posted September 10, 2009 If the both icons that you want to combine have an alpha channel, you can do the following trick. expandcollapse popup#Include <WinAPI.au3> #Include <WindowsConstants.au3> Global Const $AC_SRC_ALPHA = 1 $hForm = GUICreate('', 48, 48, -1, -1, $WS_POPUP, BitOR($WS_EX_TOPMOST, $WS_EX_TOOLWINDOW, $WS_EX_LAYERED, $WS_EX_ACCEPTFILES)) $hBitmap = _GetCombineIconAlpha(@SystemDir & '\shell32.dll', 130, @SystemDir & '\shell32.dll', 29, 48, 48) _SetBitmap($hForm, $hBitmap, 255) GUIRegisterMsg($WM_NCHITTEST, "WM_NCHITTEST") GUISetState() Do Until GUIGetMsg() = -3 Func _GetCombineIconAlpha($sIcon1, $iIndex1, $sIcon2, $iIndex2, $iWidth, $iHeight) Local $hIcon1 = _WinAPI_ShellExtractIcons($sIcon1, $iIndex1, $iWidth, $iHeight) Local $hIcon2 = _WinAPI_ShellExtractIcons($sIcon2, $iIndex2, $iWidth, $iHeight) If (Not $hIcon1) Or (Not $hIcon1) Then Return SetError(1, 0, 0) EndIf Local $hBitmap, $hDC, $hMem, $hSv $hDC = _WinAPI_GetDC(0) $hMem = _WinAPI_CreateCompatibleDC($hDC) $hBitmap = _WinAPI_CreateCompatibleBitmap($hDC, $iWidth, $iHeight) $hSv = _WinAPI_SelectObject($hMem, $hBitmap) _WinAPI_DrawIconEx($hMem, 0, 0, $hIcon1, $iWidth, $iHeight, 0, 0, 3) _WinAPI_DrawIconEx($hMem, 0, 0, $hIcon2, $iWidth, $iHeight, 0, 0, 3) _WinAPI_ReleaseDC(0, $hDC) _WinAPI_SelectObject($hMem, $hSv) _WinAPI_DeleteDC($hMem) _WinAPI_DestroyIcon($hIcon1) _WinAPI_DestroyIcon($hIcon2) Return $hBitmap EndFunc ;==>_GetCombineIconAlpha Func _SetBitmap($hWnd, $hBitmap, $iOpacity) Local $hScrDC, $hMemDC, $hOld, $tObj, $pSize, $tSize, $pSource, $tSource, $pBlend, $tBlend $hScrDC = _WinAPI_GetDC(0) $hMemDC = _WinAPI_CreateCompatibleDC($hScrDC) $hOld = _WinAPI_SelectObject($hMemDC, $hBitmap) $tObj = DllStructCreate($tagBITMAPINFO) DllCall('gdi32.dll', 'int', 'GetObject', 'int', $hBitmap, 'int', DllStructGetSize($tObj), 'ptr', DllStructGetPtr($tObj)) $tSize = DllStructCreate($tagSIZE) $pSize = DllStructGetPtr($tSize) DllStructSetData($tSize, "X", DllStructGetData($tObj, 'Width')) DllStructSetData($tSize, "Y", DllStructGetData($tObj, 'Height')) $tSource = DllStructCreate($tagPOINT) $pSource = DllStructGetPtr($tSource) $tBlend = DllStructCreate($tagBLENDFUNCTION) $pBlend = DllStructGetPtr($tBlend) DllStructSetData($tBlend, "Alpha", $iOpacity) DllStructSetData($tBlend, "Format", $AC_SRC_ALPHA) _WinAPI_UpdateLayeredWindow($hWnd, $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 _WinAPI_ShellExtractIcons($sIcon, $iIndex, $iWidth, $iHeight) Local $Ret = DllCall('shell32.dll', 'int', 'SHExtractIconsW', 'wstr', $sIcon, 'int', $iIndex, 'int', $iWidth, 'int', $iHeight, 'ptr*', 0, 'ptr*', 0, 'int', 1, 'int', 0) If (@error) Or ($Ret[0] = 0) Or ($Ret[5] = Ptr(0)) Then Return SetError(1, 0, 0) EndIf Return $Ret[5] EndFunc ;==>_WinAPI_ShellExtractIcons Func WM_NCHITTEST($hWnd, $iMsg, $iwParam, $ilParam) If ($hWnd = $hForm) And ($iMsg = $WM_NCHITTEST) Then Return $HTCAPTION EndIf EndFunc ;==>WM_NCHITTEST 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...
dantay9 Posted September 10, 2009 Author Share Posted September 10, 2009 Thank you Yashied. That works great. 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