xlbcwn 发表于 2011-6-2 14:57:02

png图片替换

我自己做了一个插入png图片的源码,还有替换图片的,可替换的过程会闪,希望大家能改一改,或者给个udf。Func _GUICtrlCreatePic($filedir,$left = 0,$top = 0)
        Local Const $STM_SETIMAGE = 0x0172
        Local Const $STM_GETIMAGE = 0x0173

        Local $hForm,$Pic,$hPic,$hBitmap,$hObj,$hImage,$hStream,$bData,$hData,$pData,$tData,$Lenght,$open
        $open = FileOpen($filedir,16)
        $bData = FileRead($open)
        FileClose($open)
        $Lenght = BinaryLen($bData)
        $hData = _MemGlobalAlloc($Lenght,2)
        $pData = _MemGlobalLock($hData)
        $tData = DllStructCreate("byte[" & $Lenght & "]",$pData)
        DllStructSetData($tData,1,$bData)
        _MemGlobalUnlock($hData)
        $hStream = _WinAPI_CreateStreamOnHGlobal($hData)
        _GDIPlus_Startup()
        $hImage = _GDIPlus_BitmapCreateFromStream($hStream)
        $hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage)
        $Width = _GDIPlus_ImageGetWidth($hImage)
        $Height = _GDIPlus_ImageGetHeight($hImage)
        _GDIPlus_ImageDispose($hImage)
        _GDIPlus_Shutdown()
        $Pic = GUICtrlCreatePic("",$left,$top,$Width,$Height)
        $hPic = GUICtrlGetHandle($Pic)
        _SendMessage($hPic,$STM_SETIMAGE,0,$hBitmap)
        $hObj = _SendMessage($hPic,$STM_GETIMAGE)
        _WinAPI_DeleteObject($hBitmap)
        Return $Pic
EndFunc

Func _GUICtrlSetPic($id,$filedir)
        Local Const $STM_SETIMAGE = 0x0172
        Local Const $STM_GETIMAGE = 0x0173
        Local $hForm,$Pic,$hPic,$hBitmap,$hObj,$hImage,$hStream,$bData,$hData,$pData,$tData,$Width,$Height,$Lenght,$open
        $open = FileOpen($filedir,16)
        $bData = FileRead($open)
        FileClose($open)
        $Lenght = BinaryLen($bData)
        $hData = _MemGlobalAlloc($Lenght,2)
        $pData = _MemGlobalLock($hData)
        $tData = DllStructCreate("byte[" & $Lenght & "]",$pData)
        DllStructSetData($tData,1,$bData)
        _MemGlobalUnlock($hData)
        $hStream = _WinAPI_CreateStreamOnHGlobal($hData)
        _GDIPlus_Startup()
        $hImage = _GDIPlus_BitmapCreateFromStream($hStream)
        $hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage)
        _GDIPlus_ImageDispose($hImage)
        _GDIPlus_Shutdown()
        $hPic = GUICtrlGetHandle($id)
        _SendMessage($hPic,$STM_SETIMAGE)
        _SendMessage($hPic,$STM_SETIMAGE,0,$hBitmap)
        _SendMessage($hPic,$STM_GETIMAGE)
        _WinAPI_DeleteObject($hBitmap)
        Return 1
EndFunc

Func _GUICtrlDeletPic($id)
        GUICtrlDelete($id)
EndFunc

Func _chuxiancishu($string,Const $find)
        Local $return = 0
        Local $stringlen = StringLen($find)
        While StringInStr($string,$find)
                $string = StringTrimLeft($string,StringInStr($string,$find) + $stringlen - 1)
                $return += 1
        WEnd
        Return $return
EndFunc

Func _GDIPlus_BitmapCreateFromStream($hStream)

    Local $aResult = DllCall($ghGDIPDll,"uint","GdipCreateBitmapFromStream","ptr",$hStream,"ptr*",0)

    If @error Then
      Return SetError(@error,@extended,0)
    EndIf
    Return $aResult
EndFunc   ;==>_GDIPlus_BitmapCreateFromStream

wsfda 发表于 2011-6-2 21:34:01

占楼研究...

zysanjing1 发表于 2011-6-2 22:34:22

看不懂,帮顶

dalanmao 发表于 2011-6-12 09:52:39

我也版定一下
页: [1]
查看完整版本: png图片替换