#include <GDIPlus.au3>
#include <GuiMenu.au3>
#include <GuiConstantsEx.au3>
#include <WinAPI.au3>
#include <WinAPIEx.au3>
#include <WindowsConstants.au3>
#Include <Constants.au3>
#Include <GDIPlusEx.au3>
Global $iMemo
$file = FileOpenDialog("Select file", @ScriptDir, ("Icons from (*.ico; *.dll; *.exe)"))
If @error Then Exit
_GDIPlus_Startup()
$hIcon = _WinAPI_ShellExtractIcon($file,0,32,32);读取图标,创建图标句柄
$hImage=_GDIPlus_BitmapCreateFromHICON($hIcon);从图标句柄创建位图句柄
_WinAPI_DestroyIcon($hIcon)
;~ $iWidth = 32
;~ $iHeight = 32
;~ $hBitmap = _GDIPlus_BitmapCreateFromScan0($iWidth, $iHeight)
;~ $hContext = _GDIPlus_ImageGetGraphicsContext($hBitmap)
;~ _GDIPlus_GraphicsDrawImageRect($hContext, $hImage, 0, 0, $iWidth, $iHeight)
$hIcon = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage);从位图句柄创建位图
_Main()
_GDIPlus_ImageDispose ($hImage)
_WinAPI_DeleteObject($hIcon)
_GDIPlus_Shutdown()
Exit
Func _Main()
Local $hGUI, $hFile, $hEdit, $hHelp, $hMain
Local Enum $idNew = 1000, $idOpen, $idSave, $idExit, $idCut, $idCopy, $idPaste, $idAbout
; Create GUI
$hGUI = GUICreate("Menu", 400, 300)
; Create File menu
$hFile = _GUICtrlMenu_CreateMenu ()
_GUICtrlMenu_InsertMenuItem ($hFile, 0, "&New", $idNew)
_GUICtrlMenu_InsertMenuItem ($hFile, 1, "&Open", $idOpen)
_GUICtrlMenu_InsertMenuItem ($hFile, 2, "&Save", $idSave)
_GUICtrlMenu_InsertMenuItem ($hFile, 3, "", 0)
_GUICtrlMenu_InsertMenuItem ($hFile, 4, "E&xit", $idExit)
; Create Edit menu
$hEdit = _GUICtrlMenu_CreateMenu ()
_GUICtrlMenu_InsertMenuItem ($hEdit, 0, "&Cut", $idCut)
_GUICtrlMenu_InsertMenuItem ($hEdit, 1, "C&opy", $idCopy)
_GUICtrlMenu_InsertMenuItem ($hEdit, 2, "&Paste", $idPaste)
; Create Help menu
$hHelp = _GUICtrlMenu_CreateMenu ()
_GUICtrlMenu_InsertMenuItem ($hHelp, 0, "&About", $idAbout)
; Create Main menu
$hMain = _GUICtrlMenu_CreateMenu ()
_GUICtrlMenu_InsertMenuItem ($hMain, 0, "&File", 0, $hFile)
_GUICtrlMenu_InsertMenuItem ($hMain, 1, "&Edit", 0, $hEdit)
_GUICtrlMenu_InsertMenuItem ($hMain, 2, "&Help", 0, $hHelp)
; Set window menu
_GUICtrlMenu_SetMenu ($hGUI, $hMain)
; Create memo control
$iMemo = GUICtrlCreateEdit("", 2, 2, 396, 276, 0)
GUICtrlSetFont($iMemo, 9, 400, 0, "Courier New")
GUISetState()
; Set New menu item to have a bitmap
_GUICtrlMenu_SetItemBmp ($hFile, 0, $hIcon)
MemoWrite("Item bitmap handle: 0x" & Hex(_GUICtrlMenu_GetItemBmp ($hFile, 0)))
; Loop until user exits
Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE
EndFunc ;==>_Main
; Write message to memo
Func MemoWrite($sMessage)
GUICtrlSetData($iMemo, $sMessage & @CRLF, 1)
EndFunc ;==>MemoWrite
;~ Func _GDIPlus_BitmapCreateFromScan0($iWidth, $iHeight, $iStride = 0, $iPixelFormat = 0x0026200A, $pScan0 = 0)
;~ Local $aResult = DllCall($ghGDIPDll, "uint", "GdipCreateBitmapFromScan0", "int", $iWidth, "int", $iHeight, "int", $iStride, "int", $iPixelFormat, "ptr", $pScan0, "int*", 0)
;~ If @error Then Return SetError(@error, @extended, 0)
;~ $GDIP_STATUS = $aResult[0]
;~ Return $aResult[6]
;~ EndFunc ;==>_GDIPlus_BitmapCreateFromScan0
|