SYRAU3 Posted March 14, 2011 Posted March 14, 2011 I was using this: expandcollapse popup#include <GDIPlus.au3> #include <GuiMenu.au3> #include <GuiConstantsEx.au3> _Main() Exit Func _GUICtrlMenu_CreateBitmap($file, $iIndex = 0, $iX = 18, $iY = 18) If FileExists($file) Then Local $iStride = 0, $iPixelFormat = $GDIP_PXF32ARGB, $pScan0 = 0 Local $GDIp = 1, $aRet, $hIcon, $hImage, $hBitmap, $hContext, $hIcon $aRet = DllCall("shell32", "long", "ExtractAssociatedIcon", "int", 0, "str", $file, "int*", $iIndex) If @error Then Return SetError(@error, @extended, 0) $hIcon = $aRet[0] If Not $ghGDIPDll Then $GDIp = 0 _GDIPlus_Startup() EndIf $aRet = DllCall($ghGDIPDll, "int", "GdipCreateBitmapFromHICON", "ptr", $hIcon, "int*", 0) If @error Then Return SetError(@error, @extended, 0) $hImage = $aRet[2] _WinAPI_DestroyIcon($hIcon) $aRet = DllCall($ghGDIPDll, "uint", "GdipCreateBitmapFromScan0", "int", $iX, "int", $iY, "int", $iStride, "int", $iPixelFormat, "ptr", $pScan0, "int*", 0) If @error Then Return SetError(@error, @extended, 0) $hBitmap = $aRet[6] $hContext = _GDIPlus_ImageGetGraphicsContext($hBitmap) _GDIPlus_GraphicsDrawImageRect($hContext, $hImage, 0, 0, $iX, $iY) $hIcon = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap, 0xFF000000) _GDIPlus_GraphicsDispose($hContext) _GDIPlus_BitmapDispose($hBitmap) _GDIPlus_BitmapDispose($hImage) If Not $GDIp Then _GDIPlus_Shutdown() Return SetError(0, 0, $hIcon) Else Return SetError(1, 0, 0) EndIf EndFunc ;==>_GUICtrlMenu_CreateBitmap Func _Main() Local $hGUI, $hFile, $hEdit, $hHelp, $hMain Local Enum $idNew = 1000, $idOpen, $idSave, $idExit, $idCut, $idCopy, $idPaste, $idAbout $hGUI = GUICreate("Menu", 400, 300) $hFile = _GUICtrlMenu_CreateMenu() _GUICtrlMenu_InsertMenuItem($hFile, 0, "&New", $idNew) $hMain = _GUICtrlMenu_CreateMenu() _GUICtrlMenu_InsertMenuItem($hMain, 0, "&File", 0, $hFile) _GUICtrlMenu_SetMenu($hGUI, $hMain) GUISetState() Local $hBMP_File_New = _GUICtrlMenu_CreateBitmap(@systemdir & "\shell32.dll", 10) _GUICtrlMenu_SetItemBmp($hFile, 0, $hBMP_File_New) Do Until GUIGetMsg() = $GUI_EVENT_CLOSE Exit EndFunc ;==>_Main but it's really not as good as i want.. because the icon quality is sooooooo bad...! is there any other way...?
Yashied Posted March 14, 2011 Posted March 14, 2011 (edited) Because _GDIPlus_BitmapCreateHBITMAPFromBitmap() creates a DDB bitmap, but you need a DIB. You can use _WinAPI_Create32BitHBITMAP() from (only under Windows Vista/7). Edited March 14, 2011 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...
GEOSoft Posted March 18, 2011 Posted March 18, 2011 I usually use Holgers owner-drawn menus to accomplish this easily. I would look for the link but for some reason I seem to recall modifying his ModernMenuRaw.au3 file and probably so it would work with current versions of AutoIt. If you are still interested in this you can PM me and I'll send you the file with an example of how to use it with a context menu. Actually I can send you a bit of the code from one of my current projects and that will demonstrate it as well. George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!"
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