Func _ResourceSetImageToCtrl($CtrlId, $ResName, $ResType = 10, $DLL = -1) ; $RT_RCDATA = 10
Local $ResData, $nSize, $hData, $pData, $pStream, $pBitmap, $hBitmap
$ResData = _ResourceGet($ResName, $ResType, 0, $DLL)
If @error Then Return SetError(1, 0, 0)
$nSize = @extended
If $ResType = $RT_BITMAP Then
_SetBitmapToCtrl($CtrlId, $ResData)
If @error Then Return SetError(2, 0, 0)
Else
; thanks ProgAndy
; for other types than BITMAP use GDI+ for converting to bitmap first
$hData = _MemGlobalAlloc($nSize,2)
$pData = _MemGlobalLock($hData)
_MemMoveMemory($ResData,$pData,$nSize)
_MemGlobalUnlock($hData)
$pStream = DllCall( "ole32.dll","int","CreateStreamOnHGlobal", "int",$hData, "long",1, "Int*",0)
$pStream = $pStream[3]
$pBitmap = DllCall($ghGDIPDll,"int","GdipCreateBitmapFromStream", "ptr",$pStream, "int*",0)
$pBitmap = $pBitmap[2]
$hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($pBitmap)
_SetBitmapToCtrl($CtrlId, $hBitmap)
If @error Then SetError(3, 0, 0)
_GDIPlus_BitmapDispose($pBitmap)
_WinAPI_DeleteObject($pStream)
_MemGlobalFree($hData)
EndIf
Return 1
EndFunc
注意这句:_MemGlobalFree($hData),不是已经释放全局内存对象了吗? |