Jump to content



Photo

Tray menu icons (without substitute GUI)


  • Please log in to reply
13 replies to this topic

#1 playlet

playlet

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 459 posts

Posted 22 April 2012 - 07:09 PM

Hi!

This is an example of how you can add icons to tray menu items. And I don't mean creating the GUI substitute for it...

I couldn't find any script that would display icons the correct way so I combined this method with another way of extracting icons and it finally worked.

The code:
AutoIt         
#include <WinAPI.au3> Opt("TrayMenuMode", 1) Global $__Ext = 0, $__RGB = 1 $TItemM = TrayCreateMenu("Menu") $TItem1 = TrayCreateItem("Option", $TItemM) TrayCreateItem("") $TItem2 = TrayCreateItem("Exit") Switch @OSVersion     Case "WIN_2003", "WIN_XP", "WIN_XPe"         $hIco = _CreateBitmapFromIcon(_WinAPI_GetSysColor(4), @SystemDir & '\shell32.dll', 165, 13, 13)         _TrayMenu_AddIcon($hIco, 0)         DllCall("user32.dll", "int", "DestroyIcon", "hwnd", DllStructGetPtr($hIco))         $hIco = _CreateBitmapFromIcon(_WinAPI_GetSysColor(4), @SystemDir & '\shell32.dll', 43, 13, 13)         _TrayMenu_AddIcon($hIco, 0, $TItemM)         DllCall("user32.dll", "int", "DestroyIcon", "hwnd", DllStructGetPtr($hIco))         $hIco = _CreateBitmapFromIcon(_WinAPI_GetSysColor(4), @SystemDir & '\shell32.dll', 27, 13, 13)         _TrayMenu_AddIcon($hIco, 2)         DllCall("user32.dll", "int", "DestroyIcon", "hwnd", DllStructGetPtr($hIco))     Case "WIN_2008R2", "WIN_7", "WIN_2008", "WIN_VISTA"         $hIcc = _WinAPI_Create32BitHBITMAP(_WinAPI_ShellExtractIcon(@SystemDir & '\shell32.dll', 165, 13, 13), 1, 1)         _TrayMenu_AddIcon($hIcc, 0)         $hIcc = _WinAPI_Create32BitHBITMAP(_WinAPI_ShellExtractIcon(@SystemDir & '\shell32.dll', 43, 13, 13), 1, 1)         _TrayMenu_AddIcon($hIcc, 0, $TItemM)         $hIcc = _WinAPI_Create32BitHBITMAP(_WinAPI_ShellExtractIcon(@SystemDir & '\shell32.dll', 27, 13, 13), 1, 1)         _TrayMenu_AddIcon($hIcc, 2) EndSwitch TraySetState() While 1     If TrayGetMsg() = $TItem2 Then Exit     If GUIGetMsg() = -3 Then Exit WEnd Func _CreateBitmapFromIcon($iBackground, $sIcon, $iIndex, $iWidth, $iHeight)     Local $hDC = _WinAPI_GetDC(0)     Local $hBackDC = _WinAPI_CreateCompatibleDC($hDC)     $iBackground = BitAND(BitShift($iBackground, -16) + BitAND($iBackground, 0xFF00) + BitShift($iBackground, 16), 0xFFFFFF)     Local $hBitmap = _WinAPI_CreateSolidBitmap(0, $iBackground, $iWidth, $iHeight)     Local $hBackSv = _WinAPI_SelectObject($hBackDC, $hBitmap)     Local $hIcon = _WinAPI_ShellExtractIcon($sIcon, $iIndex, $iWidth, $iHeight)     If Not @error Then         _WinAPI_DrawIconEx($hBackDC, 0, 0, $hIcon, 0, 0, 0, 0, 0x0003)         _WinAPI_DestroyIcon($hIcon)     EndIf     _WinAPI_SelectObject($hBackDC, $hBackSv)     _WinAPI_ReleaseDC(0, $hDC)     _WinAPI_DeleteDC($hBackDC)     Return $hBitmap EndFunc   ;==>_CreateBitmapFromIcon Func _TrayMenu_AddIcon(ByRef $hIcon, $TrayMenuNr, $ParentMenu = 0, $IndexType = 0x00000400)     Dim $pIcoInfo, $hBmp     If _IconGetInfo($hIcon, $pIcoInfo) <> 0 Then         $hBmp = DllStructGetData($pIcoInfo, 5)         _TrayMenu_AddImage($hBmp, $TrayMenuNr, $ParentMenu, $IndexType)         $pIcoInfo = 0     Else         _TrayMenu_AddImage($hIcon, $TrayMenuNr, $ParentMenu, $IndexType)     EndIf EndFunc   ;==>_TrayMenu_AddIcon Func _TrayMenu_AddImage(ByRef $hBmp, $MenuIndex, $ParentMenu = 0, $IndexType = 0x00000400)     Local $ret = DllCall("user32.dll", "int", "SetMenuItemBitmaps", "hwnd", TrayItemGetHandle($ParentMenu), "int",  $MenuIndex, "int",  $IndexType, "hwnd", $hBmp, "hwnd", $hBmp) EndFunc   ;==>_TrayMenu_AddImage Func _IconGetInfo(ByRef $hIcon, ByRef $structICONINFO)     $structICONINFO = DllStructCreate("int; dword; dword; ptr; ptr")     Local $ret = DllCall("user32.dll", "long", "GetIconInfo","ptr", $hIcon, "ptr", DllStructGetPtr($structICONINFO))     Return $ret[0] EndFunc   ;==> _IconGetInfo ; ############## WinAPIEx.au3 functions ################ Func _WinAPI_Create32BitHBITMAP($hIcon, $fDib = 0, $fDelete = 0)     Local $tBITMAP, $tICONINFO, $hDC, $hSv, $Ret, $hTemp, $hBitmap = 0     Local $DIB[2] = [0, 0]     $hTemp = _WinAPI_Create32BitHICON($hIcon)     If @error Then Return SetError(1, 0, 0)     Do         $tICONINFO = DllStructCreate($tagICONINFO)         $Ret = DllCall('user32.dll', 'int', 'GetIconInfo', 'ptr', $hTemp, 'ptr', DllStructGetPtr($tICONINFO))         If (@error) Or (Not $Ret[0]) Then ExitLoop         For $i = 0 To 1             $DIB[$i] = DllStructGetData($tICONINFO, $i + 4)         Next         $tBITMAP = DllStructCreate('long bmType;long bmWidth;long bmHeight;long bmWidthBytes;ushort bmPlanes;ushort bmBitsPixel;ptr bmBits;')         If Not _WinAPI_GetObject($DIB[0], DllStructGetSize($tBITMAP), DllStructGetPtr($tBITMAP)) Then ExitLoop         If $fDib Then             $hBitmap = _WinAPI_CreateDIB(DllStructGetData($tBITMAP, 'bmWidth'), DllStructGetData($tBITMAP, 'bmHeight'))             $hDC = _WinAPI_CreateCompatibleDC(0)             $hSv = _WinAPI_SelectObject($hDC, $hBitmap)             _WinAPI_DrawIconEx($hDC, 0, 0, $hTemp)             _WinAPI_SelectObject($hDC, $hSv)             _WinAPI_DeleteDC($hDC)         Else             $hBitmap = $DIB[1]             $DIB[1] = 0         EndIf     Until 1     For $i = 0 To 1         If $DIB[$i] Then _WinAPI_DeleteObject($DIB[$i])     Next     _WinAPI_DestroyIcon($hTemp)     If Not $hBitmap Then Return SetError(1, 0, 0)     If $fDelete Then _WinAPI_DestroyIcon($hIcon)     Return $hBitmap EndFunc Func _WinAPI_Create32BitHICON($hIcon, $fDelete = 0)     Local $tICONINFO, $tSIZE, $hBitmap[2], $Size[2], $Ret, $hSrcDC, $hSrcSv, $hDstDC, $hDstSv, $hResult = 0     Local $DIB[2][2] = [[0, 0], [0, 0]]     $tICONINFO = DllStructCreate($tagICONINFO)     $Ret = DllCall('user32.dll', 'int', 'GetIconInfo', 'ptr', $hIcon, 'ptr', DllStructGetPtr($tICONINFO))     If (@error) Or (Not $Ret[0]) Then Return SetError(1, 0, 0)     For $i = 0 To 1         $hBitmap[$i] = DllStructGetData($tICONINFO, $i + 4)     Next     If _WinAPI_IsAlphaBitmap($hBitmap[1]) Then         $DIB[0][0] = _WinAPI_CreateANDBitmap($hBitmap[1])         If Not @error Then $hResult = _WinAPI_CreateIconIndirect($hBitmap[1], $DIB[0][0])     Else         $tSIZE = _WinAPI_GetBitmapDimension($hBitmap[1])         For $i = 0 To 1             $Size[$i] = DllStructGetData($tSIZE, $i + 1)         Next         $hSrcDC = _WinAPI_CreateCompatibleDC(0)         $hDstDC = _WinAPI_CreateCompatibleDC(0)         For $i = 0 To 1             $DIB[$i][0] = _WinAPI_CreateDIB($Size[0], $Size[1])             $DIB[$i][1] = $__Ext             $hSrcSv = _WinAPI_SelectObject($hSrcDC, $hBitmap[$i])             $hDstSv = _WinAPI_SelectObject($hDstDC, $DIB[$i][0])             _WinAPI_BitBlt($hDstDC, 0, 0, $Size[0], $Size[1], $hSrcDC, 0, 0, 0x00C000CA)             _WinAPI_SelectObject($hSrcDC, $hSrcSv)             _WinAPI_SelectObject($hDstDC, $hDstSv)         Next         _WinAPI_DeleteDC($hSrcDC)         _WinAPI_DeleteDC($hDstDC)         $Ret = DllCall('user32.dll', 'int', 'CallWindowProc', 'ptr', __XORProc(), 'ptr', 0, 'uint', $Size[0] * $Size[1] * 4, 'ptr', $DIB[0][1], 'ptr', $DIB[1][1])         If (Not @error) And ($Ret[0]) Then $hResult = _WinAPI_CreateIconIndirect($DIB[1][0], $hBitmap[0])     EndIf     For $i = 0 To 1         _WinAPI_DeleteObject($hBitmap[$i])         If $DIB[$i][0] Then _WinAPI_DeleteObject($DIB[$i][0])     Next     If Not $hResult Then Return SetError(1, 0, 0)     If $fDelete Then _WinAPI_DestroyIcon($hIcon)     Return $hResult EndFunc Func _WinAPI_CreateDIB($iWidth, $iHeight, $iBitsPerPel = 32, $tColorTable = 0, $iColorCount = 0)     Local $tBITMAPINFO, $RGBQ[2], $hBitmap, $Colors     Switch $iBitsPerPel         Case 1             $Colors = 2         Case 4             $Colors = 16         Case 8             $Colors = 256         Case Else             $Colors = 0     EndSwitch     If $Colors Then         If Not IsDllStruct($tColorTable) Then             Switch $iBitsPerPel                 Case 1                     $RGBQ[0] = 0                     $RGBQ[1] = 0xFFFFFF                     $tColorTable = _WinAPI_CreateDIBColorTable($RGBQ)                 Case Else             EndSwitch         Else             If $Colors > $iColorCount Then $Colors = $iColorCount             If (Not $Colors) Or ((4 * $Colors) > DllStructGetSize($tColorTable)) Then Return SetError(1, 0, 0)         EndIf         $RGBQ = 'dword[' & $Colors & ']'     Else         $RGBQ = ''     EndIf     $tBITMAPINFO = DllStructCreate('dword biSize;long biWidth;long biHeight;ushort biPlanes;ushort biBitCount;dword biCompression;dword biSizeImage;long biXPelsPerMeter;long biYPelsPerMeter;dword biClrUsed;dword biClrImportant;' & $RGBQ)     If @error Then Return SetError(1, 0, 0)     DllStructSetData($tBITMAPINFO, 'biSize', 40)     DllStructSetData($tBITMAPINFO, 'biWidth', $iWidth)     DllStructSetData($tBITMAPINFO, 'biHeight', $iHeight)     DllStructSetData($tBITMAPINFO, 'biPlanes', 1)     DllStructSetData($tBITMAPINFO, 'biBitCount', $iBitsPerPel)     DllStructSetData($tBITMAPINFO, 'biCompression', 0)     DllStructSetData($tBITMAPINFO, 'biSizeImage', 0)     DllStructSetData($tBITMAPINFO, 'biXPelsPerMeter', 0)     DllStructSetData($tBITMAPINFO, 'biYPelsPerMeter', 0)     DllStructSetData($tBITMAPINFO, 'biClrUsed', $Colors)     DllStructSetData($tBITMAPINFO, 'biClrImportant', 0)     If $Colors Then         If IsDllStruct($tColorTable) Then             _WinAPI_MoveMemory(DllStructGetPtr($tBITMAPINFO) + 40, DllStructGetPtr($tColorTable), 4 * $Colors)         Else             _WinAPI_ZeroMemory(DllStructGetPtr($tBITMAPINFO) + 40, 4 * $Colors)         EndIf     EndIf     $hBitmap = _WinAPI_CreateDIBSection(0, $tBITMAPINFO, 0, $__Ext)     If @error Then Return SetError(1, 0, 0)     Return $hBitmap EndFunc Func _WinAPI_IsAlphaBitmap($hBitmap)     Local $tDIB, $Ret, $Error     $hBitmap = _WinAPI_CopyBitmap($hBitmap)     If @error Then Return SetError(1, 0, 0)     Do         $Error = 1         $tDIB = DllStructCreate('long bmType;long bmWidth;long bmHeight;long bmWidthBytes;ushort bmPlanes;ushort bmBitsPixel;ptr bmBits;' & 'dword biSize;long biWidth;long biHeight;ushort biPlanes;ushort biBitCount;dword biCompression;dword biSizeImage;long biXPelsPerMeter;long biYPelsPerMeter;dword biClrUsed;dword biClrImportant;' & 'dword dsBitfields[3];ptr dshSection;dword dsOffset;')         If (Not _WinAPI_GetObject($hBitmap, DllStructGetSize($tDIB), DllStructGetPtr($tDIB))) Or (DllStructGetData($tDIB, 'bmBitsPixel') <> 32) Or (DllStructGetData($tDIB, 'biCompression')) Then ExitLoop         $Ret = DllCall('user32.dll', 'int', 'CallWindowProc', 'ptr', __AlphaProc(), 'ptr', 0, 'uint', 0, 'ptr', DllStructGetPtr($tDIB), 'ptr', 0)         If (@error) Or ($Ret[0] = -1) Then ExitLoop         $Error = 0     Until 1     _WinAPI_DeleteObject($hBitmap)     If $Error Then Return SetError(1, 0, 0)     Return $Ret[0] EndFunc Func _WinAPI_CreateANDBitmap($hBitmap)     Local $tDIB[2], $Ret, $Error, $hDib = 0     $hBitmap = _WinAPI_CopyBitmap($hBitmap)     If @error Then Return SetError(1, 0, 0)     Do         $Error = 1         $tDIB[0] = DllStructCreate('long bmType;long bmWidth;long bmHeight;long bmWidthBytes;ushort bmPlanes;ushort bmBitsPixel;ptr bmBits;' & 'dword biSize;long biWidth;long biHeight;ushort biPlanes;ushort biBitCount;dword biCompression;dword biSizeImage;long biXPelsPerMeter;long biYPelsPerMeter;dword biClrUsed;dword biClrImportant;' & 'dword dsBitfields[3];ptr dshSection;dword dsOffset;')         If (Not _WinAPI_GetObject($hBitmap, DllStructGetSize($tDIB[0]), DllStructGetPtr($tDIB[0]))) Or (DllStructGetData($tDIB[0], 'bmBitsPixel') <> 32) Or (DllStructGetData($tDIB[0], 'biCompression')) Then ExitLoop         $tDIB[1] = DllStructCreate('long bmType;long bmWidth;long bmHeight;long bmWidthBytes;ushort bmPlanes;ushort bmBitsPixel;ptr bmBits;')         $hDib = _WinAPI_CreateDIB(DllStructGetData($tDIB[0], 'bmWidth'), DllStructGetData($tDIB[0], 'bmHeight'), 1)         If Not _WinAPI_GetObject($hDib, DllStructGetSize($tDIB[1]), DllStructGetPtr($tDIB[1])) Then ExitLoop         $Ret = DllCall('user32.dll', 'int', 'CallWindowProc', 'ptr', __ANDProc(), 'ptr', 0, 'uint', 0, 'ptr', DllStructGetPtr($tDIB[0]), 'ptr', DllStructGetPtr($tDIB[1]))         If (@error) Or (Not $Ret[0]) Then ExitLoop         $Error = 0     Until 1     _WinAPI_DeleteObject($hBitmap)     If $Error Then         If $hDib Then _WinAPI_DeleteObject($hDib)         $hDib = 0     EndIf     Return SetError($Error, 0, $hDib) EndFunc Func _WinAPI_CreateIconIndirect($hBitmap, $hMask, $XHotspot = 0, $YHotspot = 0, $fIcon = 1)     Local $tICONINFO = DllStructCreate($tagICONINFO)     DllStructSetData($tICONINFO, 1, $fIcon)     DllStructSetData($tICONINFO, 2, $XHotspot)     DllStructSetData($tICONINFO, 3, $YHotspot)     DllStructSetData($tICONINFO, 4, $hMask)     DllStructSetData($tICONINFO, 5, $hBitmap)     Local $Ret = DllCall('user32.dll', 'ptr', 'CreateIconIndirect', 'ptr', DllStructGetPtr($tICONINFO))     If (@error) Or (Not $Ret[0]) Then Return SetError(1, 0, 0)     Return $Ret[0] EndFunc Func _WinAPI_GetBitmapDimension($hBitmap)     Local $tObj = DllStructCreate('long bmType;long bmWidth;long bmHeight;long bmWidthBytes;ushort bmPlanes;ushort bmBitsPixel;ptr bmBits;')     Local $Ret = DllCall('gdi32.dll', 'int', 'GetObject', 'int', $hBitmap, 'int', DllStructGetSize($tObj), 'ptr', DllStructGetPtr($tObj))     If (@error) Or (Not $Ret[0]) Then Return SetError(1, 0, 0)     Local $tSIZE = DllStructCreate($tagSIZE)     DllStructSetData($tSIZE, 1, DllStructGetData($tObj, 'bmWidth'))     DllStructSetData($tSIZE, 2, DllStructGetData($tObj, 'bmHeight'))     Return $tSIZE EndFunc Func __XORProc()     Static $pProc = 0     If Not $pProc Then         If @AutoItX64 Then             $pProc = __Init(Binary( _             '0x48894C240848895424104C894424184C894C24205541574831C050504883EC28' & '48837C24600074054831C0EB0748C7C0010000004821C0751B48837C24680074' & _             '054831C0EB0748C7C0010000004821C07502EB0948C7C001000000EB034831C0' & '4821C074084831C04863C0EB7748C7442428000000004C637C24584983C7FC4C' & _             '3B7C24287C4F4C8B7C24604C037C24284C897C2430488B6C2430807D00007405' & '4831C0EB0748C7C0010000004821C0741C4C8B7C24684C037C24284983C7034C' & _             '897C2430488B6C2430C64500FF48834424280471A148C7C0010000004863C0EB' & '034831C04883C438415F5DC3'))         Else             $pProc = __Init(Binary( _             '0x555331C05050837C241C00740431C0EB05B80100000021C07516837C24200074' & '0431C0EB05B80100000021C07502EB07B801000000EB0231C021C0740431C0EB' & _             '5AC70424000000008B5C241883C3FC3B1C247C3E8B5C241C031C24895C24048B' & '6C2404807D0000740431C0EB05B80100000021C074168B5C2420031C2483C303' & _             '895C24048B6C2404C64500FF8304240471B6B801000000EB0231C083C4085B5D' & 'C21000'))         EndIf     EndIf     Return $pProc EndFunc Func _WinAPI_CreateDIBColorTable(Const ByRef $aColorTable, $iStart = 0, $iEnd = -1)     If Not IsArray($aColorTable) Then Return SetError(2, 0, 0)     Local $tColorTable, $Count = 1     If $iStart < 0 Then $iStart = 0     If ($iEnd < 0) Or ($iEnd > UBound($aColorTable) - 1) Then $iEnd = UBound($aColorTable) - 1     $tColorTable = DllStructCreate('dword[' & ($iEnd - $iStart + 1) & ']')     If @error Then Return SetError(1, 0, 0)     For $i = $iStart To $iEnd         DllStructSetData($tColorTable, 1, _WinAPI_SwitchColor(__RGB($aColorTable[$i])), $Count)         $Count += 1     Next     Return $tColorTable EndFunc Func _WinAPI_MoveMemory($pDestination, $pSource, $iLength)     DllCall('ntdll.dll', 'none', 'RtlMoveMemory', 'ptr', $pDestination, 'ptr', $pSource, 'ulong_ptr', $iLength)     If @error Then Return SetError(1, 0, 0)     Return 1 EndFunc Func _WinAPI_ZeroMemory($pMemory, $iLength)     DllCall('ntdll.dll', 'none', 'RtlZeroMemory', 'ptr', $pMemory, 'ulong_ptr', $iLength)     If @error Then Return SetError(1, 0, 0)     Return 1 EndFunc Func _WinAPI_CreateDIBSection($hDC, $tBITMAPINFO, $iUsage, ByRef $pBits, $hSection = 0, $iOffset = 0)     $pBits = 0     Local $Ret = DllCall('gdi32.dll', 'ptr', 'CreateDIBSection', 'hwnd', $hDC, 'ptr', DllStructGetPtr($tBITMAPINFO), 'uint', $iUsage, 'ptr*', 0, 'ptr', $hSection, 'dword', $iOffset)     If (@error) Or (Not $Ret[0]) Then Return SetError(1, 0, 0)     $pBits = $Ret[4]     Return $Ret[0] EndFunc Func _WinAPI_CopyBitmap($hBitmap)     $hBitmap = _WinAPI_CopyImage($hBitmap, 0, 0, 0, 0x2000)     If @error Then Return SetError(1, 0, $hBitmap)     Return $hBitmap EndFunc Func __AlphaProc()     Static $pProc = 0     If Not $pProc Then         If @AutoItX64 Then             $pProc = __Init(Binary( _             '0x48894C240848895424104C894424184C894C24205541574831C050504883EC28' & '48837C24600074054831C0EB0748C7C0010000004821C0751F488B6C24604883' & _             '7D180074054831C0EB0748C7C0010000004821C07502EB0948C7C001000000EB' & '034831C04821C0740C48C7C0FFFFFFFF4863C0EB6F48C744242800000000488B' & _             '6C24604C637D04488B6C2460486345084C0FAFF849C1E7024983C7FC4C3B7C24' & '287C36488B6C24604C8B7D184C037C24284983C7034C897C2430488B6C243080' & _             '7D0000740C48C7C0010000004863C0EB1348834424280471A54831C04863C0EB' & '034831C04883C438415F5DC3'))         Else             $pProc = __Init(Binary( _             '0x555331C05050837C241C00740431C0EB05B80100000021C075198B6C241C837D' & '1400740431C0EB05B80100000021C07502EB07B801000000EB0231C021C07407' & _             'B8FFFFFFFFEB4FC70424000000008B6C241C8B5D048B6C241C0FAF5D08C1E302' & '83C3FC3B1C247C288B6C241C8B5D14031C2483C303895C24048B6C2404807D00' & _             '007407B801000000EB0C8304240471BE31C0EB0231C083C4085B5DC21000'))         EndIf     EndIf     Return $pProc EndFunc Func __ANDProc()     Static $pProc = 0     If Not $pProc Then         If @AutoItX64 Then             $pProc = __Init(Binary( _             '0x48894C240848895424104C894424184C894C2420554157415648C7C009000000' & '4883EC0848C704240000000048FFC875EF4883EC284883BC24A0000000007405' & _             '4831C0EB0748C7C0010000004821C00F85840000004883BC24A8000000007405' & '4831C0EB0748C7C0010000004821C07555488BAC24A000000048837D18007405' & _             '4831C0EB0748C7C0010000004821C07522488BAC24A800000048837D18007405' & '4831C0EB0748C7C0010000004821C07502EB0948C7C001000000EB034831C048' & _             '21C07502EB0948C7C001000000EB034831C04821C07502EB0948C7C001000000' & 'EB034831C04821C0740B4831C04863C0E9D701000048C74424280000000048C7' & _             '44243000000000488BAC24A00000004C637D0849FFCF4C3B7C24300F8C9C0100' & '0048C74424380000000048C74424400000000048C744244800000000488BAC24' & _             'A00000004C637D0449FFCF4C3B7C24480F8CDB000000488BAC24A00000004C8B' & '7D184C037C24284983C7034C897C2450488B6C2450807D000074264C8B7C2440' & _             '4C8B74243849F7DE4983C61F4C89F148C7C00100000048D3E04909C74C897C24' & '4048FF4424384C8B7C24384983FF1F7E6F4C8B7C244049F7D74C897C244048C7' & _             '442458180000004831C0483B4424587F3D488BAC24A80000004C8B7D184C037C' & '24604C897C24504C8B7C2440488B4C245849D3FF4C89F850488B6C2458588845' & _             '0048FF4424604883442458F871B948C74424380000000048C744244000000000' & '48834424280448FF4424480F810BFFFFFF48837C24380074794C8B7C244049F7' & _             'D74C8B74243849F7DE4983C6204C89F148C7C0FFFFFFFF48D3E04921C74C897C' & '244048C7442458180000004831C0483B4424587F3D488BAC24A80000004C8B7D' & _             '184C037C24604C897C24504C8B7C2440488B4C245849D3FF4C89F850488B6C24' & '585888450048FF4424604883442458F871B948FF4424300F814AFEFFFF48C7C0' & _             '010000004863C0EB034831C04883C470415E415F5DC3'))         Else             $pProc = __Init(Binary( _             '0x555357BA0800000083EC04C70424000000004A75F3837C243800740431C0EB05' & 'B80100000021C07562837C243C00740431C0EB05B80100000021C0753F8B6C24' & _             '38837D1400740431C0EB05B80100000021C075198B6C243C837D1400740431C0' & 'EB05B80100000021C07502EB07B801000000EB0231C021C07502EB07B8010000' & _             '00EB0231C021C07502EB07B801000000EB0231C021C0740731C0E969010000C7' & '042400000000C7442404000000008B6C24388B5D084B3B5C24040F8C3F010000' & _             'C744240800000000C744240C00000000C7442410000000008B6C24388B5D044B' & '3B5C24100F8CA90000008B6C24388B5D14031C2483C303895C24148B6C241480' & _             '7D0000741C8B5C240C8B7C2408F7DF83C71F89F9B801000000D3E009C3895C24' & '0CFF4424088B5C240883FB1F7E578B5C240CF7D3895C240CC744241818000000' & _             '31C03B4424187F2D8B6C243C8B5D14035C241C895C24148B5C240C8B4C2418D3' & 'FB538B6C241858884500FF44241C83442418F871CBC744240800000000C74424' & _             '0C0000000083042404FF4424100F8145FFFFFF837C240800745B8B5C240CF7D3' & '8B7C2408F7DF83C72089F9B8FFFFFFFFD3E021C3895C240CC744241818000000' & _             '31C03B4424187F2D8B6C243C8B5D14035C241C895C24148B5C240C8B4C2418D3' & 'FB538B6C241858884500FF44241C83442418F871CBFF4424040F81AFFEFFFFB8' & _             '01000000EB0231C083C4205F5B5DC21000'))         EndIf     EndIf     Return $pProc EndFunc Func __Init($bData)     Local $tData, $Ret, $Length     $Length = BinaryLen($bData)     $Ret = DllCall('kernel32.dll', 'ptr', 'VirtualAlloc', 'ptr', 0, 'ulong_ptr', $Length, 'dword', 0x00001000, 'dword', 0x00000040)     If (@error) Or (Not $Ret[0]) Then __FatalExit(1, 'Error allocating memory.')     $tData = DllStructCreate('byte[' & $Length & "]", $Ret[0])     DllStructSetData($tData, 1, $bData)     Return $Ret[0] EndFunc Func __RGB($iColor)     If $__RGB Then $iColor = _WinAPI_SwitchColor($iColor)     Return $iColor EndFunc Func _WinAPI_SwitchColor($iColor)     Return BitOR(BitAND($iColor, 0x00FF00), BitShift(BitAND($iColor, 0x0000FF), -16), BitShift(BitAND($iColor, 0xFF0000), 16)) EndFunc Func _WinAPI_CopyImage($hImage, $iType = 0, $xDesired = 0, $yDesired = 0, $iFlags = 0)     Local $Ret = DllCall('user32.dll', 'ptr', 'CopyImage', 'ptr', $hImage, 'int', $iType, 'int', $xDesired, 'int', $yDesired, 'int', $iFlags)     If (@error) Or (Not $Ret[0]) Then Return SetError(1, 0, 0)     Return $Ret[0] EndFunc Func __FatalExit($iCode, $sText = '')     If $sText Then _WinAPI_MsgBox(0x00040010, 'AutoIt', $sText)     _WinAPI_FatalExit($iCode) EndFunc Func _WinAPI_FatalExit($iCode)     DllCall('kernel32.dll', 'none', 'FatalExit', 'int', $iCode) EndFunc Func _WinAPI_ShellExtractIcon($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 (Not $Ret[0]) Or (Not $Ret[5]) Then Return SetError(1, 0, 0)     Return $Ret[5] EndFunc Func _WinAPI_AssocQueryString($sAssoc, $iType, $iFlags = 0, $sExtra = '')     Local $TypeOfExtra = 'wstr'     If Not StringStripWS($sExtra, 3) Then         $TypeOfExtra = 'ptr'         $sExtra = 0     EndIf     Local $Ret = DllCall('shlwapi.dll', 'uint', 'AssocQueryStringW', 'dword', $iFlags, 'dword', $iType, 'wstr', $sAssoc, $TypeOfExtra, $sExtra, 'wstr', '', 'dword*', 4096)     If @error Then         Return SetError(1, 0, '')     Else         If $Ret[0] Then Return SetError(1, $Ret[0], '')     EndIf     Return $Ret[5] EndFunc Func _WinAPI_ShellGetSpecialFolderPath($CSIDL, $fCreate = 0)     Local $Ret = DllCall('shell32.dll', 'int', 'SHGetSpecialFolderPathW', 'hwnd', 0, 'wstr', '', 'int', $CSIDL, 'int', $fCreate)     If (@error) Or (Not $Ret[0]) Then Return SetError(1, 0, '')     Return $Ret[2] EndFunc Func _WinAPI_GetFontResourceInfo($sFont, $fForce = 0)     If $fForce Then         If Not _WinAPI_AddFontResourceEx($sFont, 0x20) Then Return SetError(1, 0, '')     EndIf     Local $Ret = DllCall('gdi32.dll', 'int', 'GetFontResourceInfoW', 'wstr', $sFont, 'dword*', 4096, 'wstr', '', 'dword', 0x01)     If (@error) Or (Not $Ret[0]) Then $Ret = 0     If $fForce Then _WinAPI_RemoveFontResourceEx($sFont, 0x20)     If Not IsArray($Ret) Then Return SetError(1, 0, '')     Return $Ret[3] EndFunc Func _WinAPI_AddFontResourceEx($sFont, $iFlag = 0, $fNotify = 0)     Local $Ret = DllCall('gdi32.dll', 'int', 'AddFontResourceExW', 'wstr', $sFont, 'dword', $iFlag, 'ptr', 0)     If (@error) Or (Not $Ret[0]) Then Return SetError(1, 0, 0)     If $fNotify Then DllCall('user32.dll', 'none', 'SendMessage', 'hwnd', 0xFFFF, 'uint', 0x001D, 'wparam', 0, 'lparam', 0)     Return $Ret[0] EndFunc Func _WinAPI_RemoveFontResourceEx($sFont, $iFlag = 0, $fNotify = 0)     Local $Ret = DllCall('gdi32.dll', 'int', 'RemoveFontResourceExW', 'wstr', $sFont, 'dword', $iFlag, 'ptr', 0)     If (@error) Or (Not $Ret[0]) Then Return SetError(1, 0, 0)     If $fNotify Then DllCall('user32.dll', 'none', 'SendMessage', 'hwnd', 0xFFFF, 'uint', 0x001D, 'wparam', 0, 'lparam', 0)     Return 1 EndFunc


Cheers! ;)

Edited by playlet, 27 April 2012 - 12:29 AM.






#2 playlet

playlet

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 459 posts

Posted 23 April 2012 - 04:43 PM

Does it work? Testers needed ;)

#3 Yashied

Yashied

    Happy in Moscow

  • MVPs
  • 2,512 posts

Posted 23 April 2012 - 04:55 PM

Unfortunately, icon is opaque. For Vista+ you can use just a DIB. For example see _WinAPI_Create32BitHBITMAP() from WinAPIEx.au3.

Edited by Yashied, 23 April 2012 - 04:56 PM.


#4 guinness

guinness

    guinness

  • MVPs
  • 10,347 posts

Posted 23 April 2012 - 04:58 PM

Plus use _WinAPI_PrivateExtractIcon instead of _WinAPI_PrivateExtractIcon >> http://www.autoitscript.com/forum/topic/98712-winapiex-udf/page__view__findpost__p__933664.

Example List: _AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_DesktopDimensions()_DisplayPassword()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUISetIcon()_Icon_Clear()/_Icon_Set()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringIsValid()_StringReplaceWholeWord()_StringStripChar()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()AutoIt SearchAutoIt3 PortableAutoItWinGetTitle()/AutoItWinSetTitle()CodingFileInstallrGeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIGetBkColor()LockFile()PasteBinSciTE JumpSignature CreatorWM_COPYDATAMore Examples...Updated: 11/04/2013


#5 playlet

playlet

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 459 posts

Posted 23 April 2012 - 08:42 PM

Could you change my script to make it work on Vista+ and post it here?

I have Windows XP installed so if I use your way, the icons are opaque. On XP, using my way, they appear nice... I can't test this because I don't have Vista+ installed...
I'd like to add it to the first script so that we can finally have icons in tray menu no matter the windows version we use ;)

#6 playlet

playlet

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 459 posts

Posted 25 April 2012 - 10:45 PM

Hi!

Can someone who is using Vista or any newer version of Windows test this script and tell me whether the tray menu icon displays ok (transparent; no black or any other colored background - just the icon) or not?

Thank you ;)


AutoIt         
#include <WinAPI.au3> Opt("TrayMenuMode", 1) Global Const $tagBITMAP = 'long bmType;long bmWidth;long bmHeight;long bmWidthBytes;ushort bmPlanes;ushort bmBitsPixel;ptr bmBits;' Global Const $tagBITMAPINFOHEADER = 'dword biSize;long biWidth;long biHeight;ushort biPlanes;ushort biBitCount;dword biCompression;dword biSizeImage;long biXPelsPerMeter;long biYPelsPerMeter;dword biClrUsed;dword biClrImportant;' Global Const $tagDIBSECTION = 'long bmType;long bmWidth;long bmHeight;long bmWidthBytes;ushort bmPlanes;ushort bmBitsPixel;ptr bmBits;' & 'dword biSize;long biWidth;long biHeight;ushort biPlanes;ushort biBitCount;dword biCompression;dword biSizeImage;long biXPelsPerMeter;long biYPelsPerMeter;dword biClrUsed;dword biClrImportant;' & 'dword dsBitfields[3];ptr dshSection;dword dsOffset;' Global $__Ext = 0, $__RGB = 1 Global $TItem[2] $TItem[0] = TrayCreateItem("Settings") TrayCreateItem("") $TItem[1] = TrayCreateItem("Exit") $hIco = _WinAPI_Create32BitHBITMAP(_WinAPI_ShellExtractIcon(@SystemDir & '\shell32.dll', 43, 13, 13), 1, 1) _TrayMenu_AddIcon($hIco, 0) TraySetState() While 1     If TrayGetMsg() = $TItem[1] Then Exit     If GUIGetMsg() = -3 Then Exit WEnd Func _TrayMenu_AddIcon(ByRef $hIcon, $TrayMenuNr, $ParentMenu = 0, $IndexType = 0x00000400)     Dim $pIcoInfo, $hBmp     If _IconGetInfo($hIcon, $pIcoInfo) <> 0 Then         $hBmp = DllStructGetData($pIcoInfo, 5)         _TrayMenu_AddImage($hBmp, $TrayMenuNr, $ParentMenu, $IndexType)         $pIcoInfo = 0     Else         _TrayMenu_AddImage($hIcon, $TrayMenuNr, $ParentMenu, $IndexType)     EndIf EndFunc   ;==>_TrayMenu_AddIcon Func _TrayMenu_AddImage(ByRef $hBmp, $MenuIndex, $ParentMenu = 0, $IndexType = 0x00000400)     Local $ret = DllCall("user32.dll", "int", "SetMenuItemBitmaps", "hwnd", TrayItemGetHandle($ParentMenu), "int",  $MenuIndex, "int",  $IndexType, "hwnd", $hBmp, "hwnd", $hBmp) EndFunc   ;==>_TrayMenu_AddImage Func _IconGetInfo(ByRef $hIcon, ByRef $structICONINFO)     $structICONINFO = DllStructCreate("int; dword; dword; ptr; ptr")     Local $ret = DllCall("user32.dll", "long", "GetIconInfo","ptr", $hIcon, "ptr", DllStructGetPtr($structICONINFO))     Return $ret[0] EndFunc   ;==> _IconGetInfo ; ########################## WinAPIEx.au3 functions ############################### Func _WinAPI_ShellExtractIcon($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 (Not $Ret[0]) Or (Not $Ret[5]) Then Return SetError(1, 0, 0)     Return $Ret[5] EndFunc Func _WinAPI_Create32BitHBITMAP($hIcon, $fDib = 0, $fDelete = 0)     Local $tBITMAP, $tICONINFO, $hDC, $hSv, $Ret, $hTemp, $hBitmap = 0     Local $DIB[2] = [0, 0]     $hTemp = _WinAPI_Create32BitHICON($hIcon)     If @error Then Return SetError(1, 0, 0)     Do         $tICONINFO = DllStructCreate($tagICONINFO)         $Ret = DllCall('user32.dll', 'int', 'GetIconInfo', 'ptr', $hTemp, 'ptr', DllStructGetPtr($tICONINFO))         If (@error) Or (Not $Ret[0]) Then ExitLoop         For $i = 0 To 1             $DIB[$i] = DllStructGetData($tICONINFO, $i + 4)         Next         $tBITMAP = DllStructCreate($tagBITMAP)         If Not _WinAPI_GetObject($DIB[0], DllStructGetSize($tBITMAP), DllStructGetPtr($tBITMAP)) Then ExitLoop         If $fDib Then             $hBitmap = _WinAPI_CreateDIB(DllStructGetData($tBITMAP, 'bmWidth'), DllStructGetData($tBITMAP, 'bmHeight'))             $hDC = _WinAPI_CreateCompatibleDC(0)             $hSv = _WinAPI_SelectObject($hDC, $hBitmap)             _WinAPI_DrawIconEx($hDC, 0, 0, $hTemp)             _WinAPI_SelectObject($hDC, $hSv)             _WinAPI_DeleteDC($hDC)         Else             $hBitmap = $DIB[1]             $DIB[1] = 0         EndIf     Until 1     For $i = 0 To 1         If $DIB[$i] Then _WinAPI_DeleteObject($DIB[$i])     Next     _WinAPI_DestroyIcon($hTemp)     If Not $hBitmap Then Return SetError(1, 0, 0)     If $fDelete Then _WinAPI_DestroyIcon($hIcon)     Return $hBitmap EndFunc   ;==>_WinAPI_Create32BitHBITMAP Func _WinAPI_Create32BitHICON($hIcon, $fDelete = 0)     Local $tICONINFO, $tSIZE, $hBitmap[2], $Size[2], $Ret, $hSrcDC, $hSrcSv, $hDstDC, $hDstSv, $hResult = 0     Local $DIB[2][2] = [[0, 0], [0, 0]]     $tICONINFO = DllStructCreate($tagICONINFO)     $Ret = DllCall('user32.dll', 'int', 'GetIconInfo', 'ptr', $hIcon, 'ptr', DllStructGetPtr($tICONINFO))     If (@error) Or (Not $Ret[0]) Then Return SetError(1, 0, 0)     For $i = 0 To 1         $hBitmap[$i] = DllStructGetData($tICONINFO, $i + 4)     Next     If _WinAPI_IsAlphaBitmap($hBitmap[1]) Then         $DIB[0][0] = _WinAPI_CreateANDBitmap($hBitmap[1])         If Not @error Then $hResult = _WinAPI_CreateIconIndirect($hBitmap[1], $DIB[0][0])     Else         $tSIZE = _WinAPI_GetBitmapDimension($hBitmap[1])         For $i = 0 To 1             $Size[$i] = DllStructGetData($tSIZE, $i + 1)         Next         $hSrcDC = _WinAPI_CreateCompatibleDC(0)         $hDstDC = _WinAPI_CreateCompatibleDC(0)         For $i = 0 To 1             $DIB[$i][0] = _WinAPI_CreateDIB($Size[0], $Size[1])             $DIB[$i][1] = $__Ext             $hSrcSv = _WinAPI_SelectObject($hSrcDC, $hBitmap[$i])             $hDstSv = _WinAPI_SelectObject($hDstDC, $DIB[$i][0])             _WinAPI_BitBlt($hDstDC, 0, 0, $Size[0], $Size[1], $hSrcDC, 0, 0, 0x00C000CA)             _WinAPI_SelectObject($hSrcDC, $hSrcSv)             _WinAPI_SelectObject($hDstDC, $hDstSv)         Next         _WinAPI_DeleteDC($hSrcDC)         _WinAPI_DeleteDC($hDstDC)         $Ret = DllCall('user32.dll', 'int', 'CallWindowProc', 'ptr', __XORProc(), 'ptr', 0, 'uint', $Size[0] * $Size[1] * 4, 'ptr', $DIB[0][1], 'ptr', $DIB[1][1])         If (Not @error) And ($Ret[0]) Then $hResult = _WinAPI_CreateIconIndirect($DIB[1][0], $hBitmap[0])     EndIf     For $i = 0 To 1         _WinAPI_DeleteObject($hBitmap[$i])         If $DIB[$i][0] Then _WinAPI_DeleteObject($DIB[$i][0])     Next     If Not $hResult Then Return SetError(1, 0, 0)     If $fDelete Then _WinAPI_DestroyIcon($hIcon)     Return $hResult EndFunc   ;==>_WinAPI_Create32BitHICON Func _WinAPI_CreateDIB($iWidth, $iHeight, $iBitsPerPel = 32, $tColorTable = 0, $iColorCount = 0)     Local $tBITMAPINFO, $RGBQ[2], $hBitmap, $Colors     Switch $iBitsPerPel         Case 1             $Colors = 2         Case 4             $Colors = 16         Case 8             $Colors = 256         Case Else             $Colors = 0     EndSwitch     If $Colors Then         If Not IsDllStruct($tColorTable) Then             Switch $iBitsPerPel                 Case 1                     $RGBQ[0] = 0                     $RGBQ[1] = 0xFFFFFF                     $tColorTable = _WinAPI_CreateDIBColorTable($RGBQ)                 Case Else             EndSwitch         Else             If $Colors > $iColorCount Then $Colors = $iColorCount             If (Not $Colors) Or ((4 * $Colors) > DllStructGetSize($tColorTable)) Then Return SetError(1, 0, 0)         EndIf         $RGBQ = 'dword[' & $Colors & ']'     Else         $RGBQ = ''     EndIf     $tBITMAPINFO = DllStructCreate($tagBITMAPINFOHEADER & $RGBQ)     If @error Then Return SetError(1, 0, 0)     DllStructSetData($tBITMAPINFO, 'biSize', 40)     DllStructSetData($tBITMAPINFO, 'biWidth', $iWidth)     DllStructSetData($tBITMAPINFO, 'biHeight', $iHeight)     DllStructSetData($tBITMAPINFO, 'biPlanes', 1)     DllStructSetData($tBITMAPINFO, 'biBitCount', $iBitsPerPel)     DllStructSetData($tBITMAPINFO, 'biCompression', 0)     DllStructSetData($tBITMAPINFO, 'biSizeImage', 0)     DllStructSetData($tBITMAPINFO, 'biXPelsPerMeter', 0)     DllStructSetData($tBITMAPINFO, 'biYPelsPerMeter', 0)     DllStructSetData($tBITMAPINFO, 'biClrUsed', $Colors)     DllStructSetData($tBITMAPINFO, 'biClrImportant', 0)     If $Colors Then         If IsDllStruct($tColorTable) Then             _WinAPI_MoveMemory(DllStructGetPtr($tBITMAPINFO) + 40, DllStructGetPtr($tColorTable), 4 * $Colors)         Else             _WinAPI_ZeroMemory(DllStructGetPtr($tBITMAPINFO) + 40, 4 * $Colors)         EndIf     EndIf     $hBitmap = _WinAPI_CreateDIBSection(0, $tBITMAPINFO, 0, $__Ext)     If @error Then Return SetError(1, 0, 0)     Return $hBitmap EndFunc   ;==>_WinAPI_CreateDIB Func _WinAPI_IsAlphaBitmap($hBitmap)     Local $tDIB, $Ret, $Error     $hBitmap = _WinAPI_CopyBitmap($hBitmap)     If @error Then Return SetError(1, 0, 0)     Do         $Error = 1         $tDIB = DllStructCreate($tagDIBSECTION)         If (Not _WinAPI_GetObject($hBitmap, DllStructGetSize($tDIB), DllStructGetPtr($tDIB))) Or (DllStructGetData($tDIB, 'bmBitsPixel') <> 32) Or (DllStructGetData($tDIB, 'biCompression')) Then ExitLoop         $Ret = DllCall('user32.dll', 'int', 'CallWindowProc', 'ptr', __AlphaProc(), 'ptr', 0, 'uint', 0, 'ptr', DllStructGetPtr($tDIB), 'ptr', 0)         If (@error) Or ($Ret[0] = -1) Then ExitLoop         $Error = 0     Until 1     _WinAPI_DeleteObject($hBitmap)     If $Error Then Return SetError(1, 0, 0)     Return $Ret[0] EndFunc   ;==>_WinAPI_IsAlphaBitmap Func _WinAPI_CreateANDBitmap($hBitmap)     Local $tDIB[2], $Ret, $Error, $hDib = 0     $hBitmap = _WinAPI_CopyBitmap($hBitmap)     If @error Then Return SetError(1, 0, 0)     Do         $Error = 1         $tDIB[0] = DllStructCreate($tagDIBSECTION)         If (Not _WinAPI_GetObject($hBitmap, DllStructGetSize($tDIB[0]), DllStructGetPtr($tDIB[0]))) Or (DllStructGetData($tDIB[0], 'bmBitsPixel') <> 32) Or (DllStructGetData($tDIB[0], 'biCompression')) Then ExitLoop         $tDIB[1] = DllStructCreate($tagBITMAP)         $hDib = _WinAPI_CreateDIB(DllStructGetData($tDIB[0], 'bmWidth'), DllStructGetData($tDIB[0], 'bmHeight'), 1)         If Not _WinAPI_GetObject($hDib, DllStructGetSize($tDIB[1]), DllStructGetPtr($tDIB[1])) Then ExitLoop         $Ret = DllCall('user32.dll', 'int', 'CallWindowProc', 'ptr', __ANDProc(), 'ptr', 0, 'uint', 0, 'ptr', DllStructGetPtr($tDIB[0]), 'ptr', DllStructGetPtr($tDIB[1]))         If (@error) Or (Not $Ret[0]) Then ExitLoop         $Error = 0     Until 1     _WinAPI_DeleteObject($hBitmap)     If $Error Then         If $hDib Then _WinAPI_DeleteObject($hDib)         $hDib = 0     EndIf     Return SetError($Error, 0, $hDib) EndFunc   ;==>_WinAPI_CreateANDBitmap Func _WinAPI_CreateIconIndirect($hBitmap, $hMask, $XHotspot = 0, $YHotspot = 0, $fIcon = 1)     Local $tICONINFO = DllStructCreate($tagICONINFO)     DllStructSetData($tICONINFO, 1, $fIcon)     DllStructSetData($tICONINFO, 2, $XHotspot)     DllStructSetData($tICONINFO, 3, $YHotspot)     DllStructSetData($tICONINFO, 4, $hMask)     DllStructSetData($tICONINFO, 5, $hBitmap)     Local $Ret = DllCall('user32.dll', 'ptr', 'CreateIconIndirect', 'ptr', DllStructGetPtr($tICONINFO))     If (@error) Or (Not $Ret[0]) Then Return SetError(1, 0, 0)     Return $Ret[0] EndFunc   ;==>_WinAPI_CreateIconIndirect Func _WinAPI_GetBitmapDimension($hBitmap)     Local $tObj = DllStructCreate($tagBITMAP)     Local $Ret = DllCall('gdi32.dll', 'int', 'GetObject', 'int', $hBitmap, 'int', DllStructGetSize($tObj), 'ptr', DllStructGetPtr($tObj))     If (@error) Or (Not $Ret[0]) Then Return SetError(1, 0, 0)     Local $tSIZE = DllStructCreate($tagSIZE)     DllStructSetData($tSIZE, 1, DllStructGetData($tObj, 'bmWidth'))     DllStructSetData($tSIZE, 2, DllStructGetData($tObj, 'bmHeight'))     Return $tSIZE EndFunc   ;==>_WinAPI_GetBitmapDimension Func __XORProc()     Static $pProc = 0     If Not $pProc Then         If @AutoItX64 Then             $pProc = __Init(Binary( _                       '0x48894C240848895424104C894424184C894C24205541574831C050504883EC28' & _                         '48837C24600074054831C0EB0748C7C0010000004821C0751B48837C24680074' & _                         '054831C0EB0748C7C0010000004821C07502EB0948C7C001000000EB034831C0' & _                         '4821C074084831C04863C0EB7748C7442428000000004C637C24584983C7FC4C' & _                         '3B7C24287C4F4C8B7C24604C037C24284C897C2430488B6C2430807D00007405' & _                         '4831C0EB0748C7C0010000004821C0741C4C8B7C24684C037C24284983C7034C' & _                         '897C2430488B6C2430C64500FF48834424280471A148C7C0010000004863C0EB' & _                         '034831C04883C438415F5DC3'))         Else             $pProc = __Init(Binary( _                       '0x555331C05050837C241C00740431C0EB05B80100000021C07516837C24200074' & _                         '0431C0EB05B80100000021C07502EB07B801000000EB0231C021C0740431C0EB' & _                         '5AC70424000000008B5C241883C3FC3B1C247C3E8B5C241C031C24895C24048B' & _                         '6C2404807D0000740431C0EB05B80100000021C074168B5C2420031C2483C303' & _                         '895C24048B6C2404C64500FF8304240471B6B801000000EB0231C083C4085B5D' & _                         'C21000'))         EndIf     EndIf     Return $pProc EndFunc   ;==>__XORProc Func _WinAPI_CreateDIBColorTable(Const ByRef $aColorTable, $iStart = 0, $iEnd = -1)     If Not IsArray($aColorTable) Then Return SetError(2, 0, 0)     Local $tColorTable, $Count = 1     If $iStart < 0 Then $iStart = 0     If ($iEnd < 0) Or ($iEnd > UBound($aColorTable) - 1) Then $iEnd = UBound($aColorTable) - 1     $tColorTable = DllStructCreate('dword[' & ($iEnd - $iStart + 1) & ']')     If @error Then Return SetError(1, 0, 0)     For $i = $iStart To $iEnd         DllStructSetData($tColorTable, 1, _WinAPI_SwitchColor(__RGB($aColorTable[$i])), $Count)         $Count += 1     Next     Return $tColorTable EndFunc   ;==>_WinAPI_CreateDIBColorTable Func _WinAPI_MoveMemory($pDestination, $pSource, $iLength)     DllCall('ntdll.dll', 'none', 'RtlMoveMemory', 'ptr', $pDestination, 'ptr', $pSource, 'ulong_ptr', $iLength)     If @error Then Return SetError(1, 0, 0)     Return 1 EndFunc   ;==>_WinAPI_MoveMemory Func _WinAPI_ZeroMemory($pMemory, $iLength)     DllCall('ntdll.dll', 'none', 'RtlZeroMemory', 'ptr', $pMemory, 'ulong_ptr', $iLength)     If @error Then Return SetError(1, 0, 0)     Return 1 EndFunc   ;==>_WinAPI_ZeroMemory Func _WinAPI_CreateDIBSection($hDC, $tBITMAPINFO, $iUsage, ByRef $pBits, $hSection = 0, $iOffset = 0)     $pBits = 0     Local $Ret = DllCall('gdi32.dll', 'ptr', 'CreateDIBSection', 'hwnd', $hDC, 'ptr', DllStructGetPtr($tBITMAPINFO), 'uint', $iUsage, 'ptr*', 0, 'ptr', $hSection, 'dword', $iOffset)     If (@error) Or (Not $Ret[0]) Then Return SetError(1, 0, 0)     $pBits = $Ret[4]     Return $Ret[0] EndFunc   ;==>_WinAPI_CreateDIBSection Func _WinAPI_CopyBitmap($hBitmap)     $hBitmap = _WinAPI_CopyImage($hBitmap, 0, 0, 0, 0x2000)     If @error Then Return SetError(1, 0, $hBitmap)     Return $hBitmap EndFunc   ;==>_WinAPI_CopyBitmap Func __AlphaProc()     Static $pProc = 0     If Not $pProc Then         If @AutoItX64 Then             $pProc = __Init(Binary( _                       '0x48894C240848895424104C894424184C894C24205541574831C050504883EC28' & _                         '48837C24600074054831C0EB0748C7C0010000004821C0751F488B6C24604883' & _                         '7D180074054831C0EB0748C7C0010000004821C07502EB0948C7C001000000EB' & _                         '034831C04821C0740C48C7C0FFFFFFFF4863C0EB6F48C744242800000000488B' & _                         '6C24604C637D04488B6C2460486345084C0FAFF849C1E7024983C7FC4C3B7C24' & _                         '287C36488B6C24604C8B7D184C037C24284983C7034C897C2430488B6C243080' & _                         '7D0000740C48C7C0010000004863C0EB1348834424280471A54831C04863C0EB' & _                         '034831C04883C438415F5DC3'))         Else             $pProc = __Init(Binary( _                       '0x555331C05050837C241C00740431C0EB05B80100000021C075198B6C241C837D' & _                         '1400740431C0EB05B80100000021C07502EB07B801000000EB0231C021C07407' & _                         'B8FFFFFFFFEB4FC70424000000008B6C241C8B5D048B6C241C0FAF5D08C1E302' & _                         '83C3FC3B1C247C288B6C241C8B5D14031C2483C303895C24048B6C2404807D00' & _                         '007407B801000000EB0C8304240471BE31C0EB0231C083C4085B5DC21000'))         EndIf     EndIf     Return $pProc EndFunc   ;==>__AlphaProc Func __ANDProc()     Static $pProc = 0     If Not $pProc Then         If @AutoItX64 Then             $pProc = __Init(Binary( _                       '0x48894C240848895424104C894424184C894C2420554157415648C7C009000000' & _                         '4883EC0848C704240000000048FFC875EF4883EC284883BC24A0000000007405' & _                         '4831C0EB0748C7C0010000004821C00F85840000004883BC24A8000000007405' & _                         '4831C0EB0748C7C0010000004821C07555488BAC24A000000048837D18007405' & _                         '4831C0EB0748C7C0010000004821C07522488BAC24A800000048837D18007405' & _                         '4831C0EB0748C7C0010000004821C07502EB0948C7C001000000EB034831C048' & _                         '21C07502EB0948C7C001000000EB034831C04821C07502EB0948C7C001000000' & _                         'EB034831C04821C0740B4831C04863C0E9D701000048C74424280000000048C7' & _                         '44243000000000488BAC24A00000004C637D0849FFCF4C3B7C24300F8C9C0100' & _                         '0048C74424380000000048C74424400000000048C744244800000000488BAC24' & _                         'A00000004C637D0449FFCF4C3B7C24480F8CDB000000488BAC24A00000004C8B' & _                         '7D184C037C24284983C7034C897C2450488B6C2450807D000074264C8B7C2440' & _                         '4C8B74243849F7DE4983C61F4C89F148C7C00100000048D3E04909C74C897C24' & _                         '4048FF4424384C8B7C24384983FF1F7E6F4C8B7C244049F7D74C897C244048C7' & _                         '442458180000004831C0483B4424587F3D488BAC24A80000004C8B7D184C037C' & _                         '24604C897C24504C8B7C2440488B4C245849D3FF4C89F850488B6C2458588845' & _                         '0048FF4424604883442458F871B948C74424380000000048C744244000000000' & _                         '48834424280448FF4424480F810BFFFFFF48837C24380074794C8B7C244049F7' & _                         'D74C8B74243849F7DE4983C6204C89F148C7C0FFFFFFFF48D3E04921C74C897C' & _                         '244048C7442458180000004831C0483B4424587F3D488BAC24A80000004C8B7D' & _                         '184C037C24604C897C24504C8B7C2440488B4C245849D3FF4C89F850488B6C24' & _                         '585888450048FF4424604883442458F871B948FF4424300F814AFEFFFF48C7C0' & _                         '010000004863C0EB034831C04883C470415E415F5DC3'))         Else             $pProc = __Init(Binary( _                       '0x555357BA0800000083EC04C70424000000004A75F3837C243800740431C0EB05' & _                         'B80100000021C07562837C243C00740431C0EB05B80100000021C0753F8B6C24' & _                         '38837D1400740431C0EB05B80100000021C075198B6C243C837D1400740431C0' & _                         'EB05B80100000021C07502EB07B801000000EB0231C021C07502EB07B8010000' & _                         '00EB0231C021C07502EB07B801000000EB0231C021C0740731C0E969010000C7' & _                         '042400000000C7442404000000008B6C24388B5D084B3B5C24040F8C3F010000' & _                         'C744240800000000C744240C00000000C7442410000000008B6C24388B5D044B' & _                         '3B5C24100F8CA90000008B6C24388B5D14031C2483C303895C24148B6C241480' & _                         '7D0000741C8B5C240C8B7C2408F7DF83C71F89F9B801000000D3E009C3895C24' & _                         '0CFF4424088B5C240883FB1F7E578B5C240CF7D3895C240CC744241818000000' & _                         '31C03B4424187F2D8B6C243C8B5D14035C241C895C24148B5C240C8B4C2418D3' & _                         'FB538B6C241858884500FF44241C83442418F871CBC744240800000000C74424' & _                         '0C0000000083042404FF4424100F8145FFFFFF837C240800745B8B5C240CF7D3' & _                         '8B7C2408F7DF83C72089F9B8FFFFFFFFD3E021C3895C240CC744241818000000' & _                         '31C03B4424187F2D8B6C243C8B5D14035C241C895C24148B5C240C8B4C2418D3' & _                         'FB538B6C241858884500FF44241C83442418F871CBFF4424040F81AFFEFFFFB8' & _                         '01000000EB0231C083C4205F5B5DC21000'))         EndIf     EndIf     Return $pProc EndFunc   ;==>__ANDProc Func __Init($bData)     Local $tData, $Ret, $Length     $Length = BinaryLen($bData)     $Ret = DllCall('kernel32.dll', 'ptr', 'VirtualAlloc', 'ptr', 0, 'ulong_ptr', $Length, 'dword', 0x00001000, 'dword', 0x00000040)     If (@error) Or (Not $Ret[0]) Then __FatalExit(1, 'Error allocating memory.')     $tData = DllStructCreate('byte[' & $Length & "]", $Ret[0])     DllStructSetData($tData, 1, $bData)     Return $Ret[0] EndFunc   ;==>__Init Func __RGB($iColor)     If $__RGB Then $iColor = _WinAPI_SwitchColor($iColor)     Return $iColor EndFunc   ;==>__RGB Func _WinAPI_SwitchColor($iColor)     Return BitOR(BitAND($iColor, 0x00FF00), BitShift(BitAND($iColor, 0x0000FF), -16), BitShift(BitAND($iColor, 0xFF0000), 16)) EndFunc   ;==>_WinAPI_SwitchColor Func _WinAPI_CopyImage($hImage, $iType = 0, $xDesired = 0, $yDesired = 0, $iFlags = 0)     Local $Ret = DllCall('user32.dll', 'ptr', 'CopyImage', 'ptr', $hImage, 'int', $iType, 'int', $xDesired, 'int', $yDesired, 'int', $iFlags)     If (@error) Or (Not $Ret[0]) Then Return SetError(1, 0, 0)     Return $Ret[0] EndFunc   ;==>_WinAPI_CopyImage Func __FatalExit($iCode, $sText = '')     If $sText Then _WinAPI_MsgBox(0x00040010, 'AutoIt', $sText)     _WinAPI_FatalExit($iCode) EndFunc   ;==>__FatalExit Func _WinAPI_FatalExit($iCode)     DllCall('kernel32.dll', 'none', 'FatalExit', 'int', $iCode) EndFunc   ;==>_WinAPI_FatalExit


#7 ripdad

ripdad

    Member

  • Active Members
  • PipPipPipPipPipPip
  • 537 posts

Posted 26 April 2012 - 03:52 AM

playlet,

Nice Script!

Here's a screenshot in Win7 with mouse hovering over "Settings"
menu.png
I'm pretty sure this script has "some flaws" (somewhere). Welcome to programming!

#8 supersonic

supersonic

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 448 posts

Posted 26 April 2012 - 11:15 AM

playlet,

thank you very much! ;)

#9 Mehomic

Mehomic

    Seeker

  • Active Members
  • 6 posts

Posted 26 April 2012 - 12:00 PM

Worked for me on Vista

Thanks for sharing.........

#10 guinness

guinness

    guinness

  • MVPs
  • 10,347 posts

Posted 26 April 2012 - 12:04 PM

Works on Windows 7 x64.

Example List: _AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_DesktopDimensions()_DisplayPassword()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUISetIcon()_Icon_Clear()/_Icon_Set()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringIsValid()_StringReplaceWholeWord()_StringStripChar()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()AutoIt SearchAutoIt3 PortableAutoItWinGetTitle()/AutoItWinSetTitle()CodingFileInstallrGeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIGetBkColor()LockFile()PasteBinSciTE JumpSignature CreatorWM_COPYDATAMore Examples...Updated: 11/04/2013


#11 playlet

playlet

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 459 posts

Posted 26 April 2012 - 08:23 PM

Cool! ;)

Thanks, guys! Now I know it works...

#12 supersonic

supersonic

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 448 posts

Posted 07 May 2012 - 08:58 AM

playlet,

thank you for sharing! ;)

Your code example works pretty well for Vista and 7.

Under XP the icons looks unattractive.

Do you know a way to implement better handling for XP?

Grees,
-supersonic.

#13 playlet

playlet

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 459 posts

Posted 07 May 2012 - 09:19 PM

@supersonic

I use windows XP also (Home, 32 bit) and they appear ok. Which version and service pack are you using? 32/64 bit?

#14 supersonic

supersonic

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 448 posts

Posted 08 May 2012 - 09:48 AM

@playlet

I'm using WXP-SP3-X86.

Please see screenshot.

The 2nd icon is disabled.

Attached Thumbnails

  • XP-SP3.JPG

Edited by supersonic, 08 May 2012 - 09:49 AM.





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users