; ====================================================================================================================================================== ; = Add Icons To Tray Menu(s) = ; = Functions By Playlet = ; = http://www.autoitscript.com/forum/topic/139826-tray-menu-icons-without-substitute-gui/ = ; ====================================================================================================================================================== ; = _Tray_Get_Icon($_TGI_IconFile, $_TGI_IconIndex, $_TGI_IconSize, $_TGI_MenuItem, $_TGI_MenuParent = 0) = ; ====================================================================================================================================================== #Region ; Necessary Options ; ====================================================================================================================================================== Opt("TrayMenuMode", 1) ; Default tray menu items (Script Paused/Exit) will not be shown. ; ====================================================================================================================================================== #EndRegion ; Necessary Options ; ====================================================================================================================================================== #Region ; Necessary Includes ; ====================================================================================================================================================== #Include ; ====================================================================================================================================================== #EndRegion ; Necessary Includes ; ====================================================================================================================================================== #Region ; Necessary Variables ; ====================================================================================================================================================== Global $__Ext = 0, $__RGB = 1 ; ====================================================================================================================================================== #EndRegion ; Necessary Variables ; ====================================================================================================================================================== #Region ; Example ; ====================================================================================================================================================== #CS $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 #CE ; ====================================================================================================================================================== #EndRegion ; Example ; ====================================================================================================================================================== #Region ; My Wrapper For Simplicity ; ====================================================================================================================================================== Func _Tray_Get_Icon($_TGI_IconFile, $_TGI_IconIndex, $_TGI_IconSize, $_TGI_MenuItem, $_TGI_MenuParent = 0) If (@OSVersion = "WIN_2000" Or StringInStr(@OSVersion, "WIN_XP") Or StringInStr(@OSVersion, "WIN_2003")) Then $_TGI_Icon = _CreateBitmapFromIcon(_WinAPI_GetSysColor(4), $_TGI_IconFile, $_TGI_IconIndex, $_TGI_IconSize, $_TGI_IconSize) _TrayMenu_AddIcon($_TGI_Icon, $_TGI_MenuItem, $_TGI_MenuParent) DllCall("user32.dll", "int", "DestroyIcon", "hwnd", DllStructGetPtr($_TGI_Icon)) Else $_TGI_Icon = _WinAPI_Create32BitHBITMAP(_WinAPI_ShellExtractIcon($_TGI_IconFile, $_TGI_IconIndex, $_TGI_IconSize, $_TGI_IconSize), 1, 1) _TrayMenu_AddIcon($_TGI_Icon, $_TGI_MenuItem, $_TGI_MenuParent) EndIf EndFunc ; ====================================================================================================================================================== #EndRegion ; My Wrapper For Simplicity ; ====================================================================================================================================================== #Region ; Previous Version of Script ; ====================================================================================================================================================== #CS Func _Tray_Get_Icon($Icon_DLL_File, $Icon_DLL_Index, $Icon_DLL_Size, $Icon_DLL_Menu_Item, $Icon_DLL_Menu_Parent = 0) $hIco = _WinAPI_Create32BitHBITMAP(_WinAPI_ShellExtractIcon($Icon_DLL_File, $Icon_DLL_Index, $Icon_DLL_Size, $Icon_DLL_Size), 1, 1) Return _TrayMenu_AddIcon($hIco, $Icon_DLL_Menu_Item, $Icon_DLL_Menu_Parent) EndFunc #CE ; ====================================================================================================================================================== #EndRegion ; Previous Version of Script ; ====================================================================================================================================================== #Region ; Prior To Win7 Functions ; ====================================================================================================================================================== 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 ; ====================================================================================================================================================== #EndRegion ; Prior To Win7 Functions ; ====================================================================================================================================================== #CS ; 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 ; ====================================================================================================================================================== #CE ; WinAPIEx.au3 Functions ; ======================================================================================================================================================