找回密码
 加入
搜索
查看: 3760|回复: 10

[GUI管理] ListView加上皮肤问题[已解决]

  [复制链接]
发表于 2011-11-16 23:49:12 | 显示全部楼层 |阅读模式
本帖最后由 jackywjl 于 2011-11-23 20:12 编辑

小弟在官网找到ListView可显示图档缩图,但加了皮肤之后,却无法正常显示缩图,不知问题出在哪
档案都在附件里,请大大帮帮忙~~谢谢


本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?加入

×
 楼主| 发表于 2011-11-18 09:30:43 | 显示全部楼层
换了3.3.6.1也是一样无法显示,下面是加了皮肤的源码
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Include <File.au3>
#Include <EditConstants.au3>
#Include <Constants.au3>
#include <GuiListView.au3>
#include <GuiImageList.au3>
#include <GDIPlus.au3>
#include <WinAPI.au3>

Opt('MustDeclareVars', 1)
Opt("OnExitFunc","Quit")
FileInstall("SkinCrafterDll.dll", @TempDir&"\SkinCrafterDll.dll", 1)
FileInstall("vista.skf", @TempDir&"\vista.skf", 1)
Global $sExtFilter = "bmp|gif|jpeg|jpg|png|tif|tiff"
Global $hGui, $Path, $BRowse, $LV, $Pic, $Msg, $Dll
Global $hImageList, $sCur, $sLast, $iDX, $iPicState = 0, $DoubleClick = -1

$hGui = GUICreate("Image Viewer", 490, 620)
_SkinGUI(@TempDir&"\SkinCrafterDll.dll", @TempDir&"\vista.skf", $hGui)
$Path = GUICtrlCreateInput("", 10, 10, 400, 20, $ES_READONLY)
$BRowse = GUICtrlCreateButton("Browse", 420, 10, 60, 20)
$LV = GUICtrlCreateListView("",  5, 40, 480, 575, -1, BitOr($WS_EX_CLIENTEDGE, $LVS_EX_DOUBLEBUFFER))
_GUICtrlListView_SetView($LV, 1)
_GUICtrlListView_SetIconSpacing($LV, 75, 60)
$Pic = GUICtrlCreatePic("", 200, 80, 440, 440)
GUISetState(@SW_SHOW)

GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")

While 1
    $Msg = GUIGetMsg()
    Switch $Msg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Browse
            _Browse()
    EndSwitch
WEnd

Func _Browse()
    Local $FSF, $FL2A, $hBmp, $iCnt = 0
    $FSF = FileSelectFolder("Browse for folder containing pictures", "", "", $hGui)
    If Not @error And FileExists($FSF) Then
        If StringRight($FSF, 1) <> "" Then $FSF &= ""
        $FL2A = _FileListToArray($FSF, "*", 1)
        If Not @Error Then
            If IsPtr($hImageList) Then
                _GUICtrlListView_DeleteAllItems(GUICtrlGetHandle($LV))
                _GUiImageList_Destroy($hImageList)
                $hImageList = ""
                _hBmpToPicControl($Pic, $hBmp)
                GUICtrlSetImage($Pic, "")
                $iDX = -1
                $iPicState = 0
                $sCur = ""
                $sLast = ""
            EndIf
            $hImageList = _GUiImageList_Create(60, 60, 5, 3)
            _GUICtrlListView_SetImageList($LV, $hImageList, 0)
            For $i = 1 To $FL2A[0]
                If StringRegExp($FL2A[$i], "(?i)\.(" & $sExtFilter & ")", 0) Then
                    $hBmp = _GetImage($FSF & $FL2A[$i], 60)
                    _GUiImageList_Add($hImageList, $hBmp)
                    _WinAPI_DeleteObject($hBmp)
                    _GUICtrlListView_AddItem($LV, $FL2A[$i], $iCnt)
                    _GUICtrlListView_SetItemImage($LV, $iCnt, $iCnt)
                    $iCnt += 1
                EndIf
            Next
            GUICtrlSetData($Path, $FSF)
        EndIf
        WinSetTitle($hGui, "", "Images Found: " & $iCnt)
    EndIf
EndFunc

Func _GetImage($sFile, $iWH, $iBkClr = 0xFFFFFF)
    Local $hBmp1, $hBitmap, $hGraphic, $hImage, $iW, $iH, $aGS, $hBmp2
    _GDIPlus_Startup()
    $hBmp1 = _WinAPI_CreateBitmap($iWH, $iWH, 1, 32)
    $hBitmap = _GDIPlus_BitmapCreateFromHBITMAP($hBmp1)
    $hGraphic = _GDIPlus_ImageGetGraphicsContext($hBitmap)
    _WinAPI_DeleteObject($hBmp1)
    _GDIPlus_GraphicsClear($hGraphic, BitOR(0xFF000000, $iBkClr))
    $hImage = _GDIPlus_ImageLoadFromFile($sFile)
    $iW = _GDIPlus_ImageGetWidth($hImage)
    $iH = _GDIPlus_ImageGetHeight($hImage)
    $aGS = _GetScale($iW, $iH, $iWH)
    _GDIPlus_GraphicsDrawImageRect($hGraphic, $hImage, $aGS[0], $aGS[1], $aGS[2], $aGS[3])
    _GDIPlus_ImageDispose($hImage)
    _GDIPlus_GraphicsDispose($hGraphic)
    $hBmp2 = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap)
    _GDIPlus_BitmapDispose($hBitmap)
    _GDIPlus_Shutdown()
    Return $hBmp2
EndFunc

Func _GetScale($iW, $iH, $iWH)
    Local $aRet[4]
    If $iW <= $iWH And $iH <= $iWH Then
        $aRet[2] = $iW
        $aRet[3] = $iH
        $aRet[0] = ($iWH - $aRet[2])/2
        $aRet[1] = ($iWH - $aRet[3])/2
    ElseIf $iW > $iH Then
        $aRet[2] = $iWH
        $aRet[3] = $iH/($iW/$iWH)
        $aRet[0] = 0
        $aRet[1] = ($iWH - $aRet[3])/2
    ElseIf $iW < $iH Then
        $aRet[2] = $iW/($iH/$iWH)
        $aRet[3] = $iWH
        $aRet[0] = ($iWH - $aRet[2])/2
        $aRet[1] = 0
    ElseIf $iW = $iH Then
        $aRet[2] = $iWH
        $aRet[3] = $iWH
        $aRet[0] = 0
        $aRet[1] = 0
    EndIf
    Return $aRet
EndFunc

Func _hBmpToPicControl($iCID, ByRef $hBmp, $iFlag = 0)
    Local Const $STM_SETIMAGE = 0x0172
    Local Const $IMAGE_BITMAP = 0
    Local $hOldBmp
    $hOldBmp = GUICtrlSendMsg($iCID, $STM_SETIMAGE, $IMAGE_BITMAP, $hBmp)
    If $hOldBmp Then _WinAPI_DeleteObject($hOldBmp)
    If $iFlag Then _WinAPI_DeleteObject($hBmp)
EndFunc

Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
    Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndListView, $tInfo, $aIDX
    $hWndListView = GUICtrlGetHandle($LV)
    $tNMHDR = DllStructCreate('hwnd hWndFrom;int_ptr IDFrom;int Code', $ilParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
    $iCode = DllStructGetData($tNMHDR, "Code")
    Switch $hWndFrom
        Case $hWndListView
            Switch $iCode
                Case $NM_CLICK
                    $iDX = _GUICtrlListView_GetNextItem($hWndListView)
                Case $NM_DBLCLK
                    $DoubleClick = _GUICtrlListView_GetNextItem($hWndListView)
                Case $LVN_KEYDOWN
                    $tInfo = DllStructCreate('hwnd hWndFrom;int_ptr IDFrom;int Code;int_ptr VKey;int Flags', $ilParam)
                    Switch BitAnd(DllStructGetData($tInfo, "VKey"), 0xFFFF)
                        Case $VK_UP
                            $iDX = _GUICtrlListView_GetNextItem($hWndListView) -1
                            If $iDX < 0 Then $iDX = 0
                        Case $VK_DOWN
                            $iDX = _GUICtrlListView_GetNextItem($hWndListView) + 1
                            If $iDX >= _GUICtrlListView_GetItemCount($hWndListView) Then $iDX -= 1
                    EndSwitch
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc

Func _SkinGUI($SkincrafterDll, $SkincrafterSkin, $Handle)
   $Dll = DllOpen($SkincrafterDll) 
   DllCall($Dll, "int:cdecl", "InitLicenKeys", "wstr", "1", "wstr", "", "wstr", "1@1.com", "wstr", "1") 
   DllCall($Dll, "int:cdecl", "InitDecoration", "int", 1) 
   DllCall($Dll, "int:cdecl", "LoadSkinFromFile", "wstr", $SkincrafterSkin) 
   DllCall($Dll, "int:cdecl", "DecorateAs", "int", $Handle, "int", 25) 
   DllCall($Dll, "int:cdecl", "ApplySkin") 
EndFunc 
Func Quit()
    GUISetState(@SW_HIDE)
    DllCall($Dll, "int:cdecl", "DeInitDecoration")
    DllCall($Dll, "int:cdecl", "RemoveSkin")
    DllClose($Dll)
        FileDelete(@TempDir&"SkinCrafterDll.dll")
        FileDelete(@TempDir&"vista.skf") 
    Exit
EndFunc
发表于 2011-11-20 21:04:54 | 显示全部楼层
等答案中……..
 楼主| 发表于 2011-11-22 17:08:15 | 显示全部楼层
附件里是从官网抓的源码,未修改的可正常显示,4楼的源码是我加上皮肤的,不知哪出问题,加了皮肤就无法显示
等待高手帮忙~~谢谢
发表于 2011-11-23 10:04:53 | 显示全部楼层
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Include <File.au3>
#Include <EditConstants.au3>
#Include <Constants.au3>
#include <GuiListView.au3>
#include <GuiImageList.au3>
#include <GDIPlus.au3>
#include <WinAPI.au3>

Opt('MustDeclareVars', 1)
Opt("OnExitFunc","Quit")
FileInstall("SkinCrafterDll.dll", @TempDir&"\SkinCrafterDll.dll", 1)
FileInstall("vista.skf", @TempDir&"\vista.skf", 1)
Global $sExtFilter = "bmp|gif|jpeg|jpg|png|tif|tiff"
Global $hGui, $Path, $BRowse, $LV, $Pic, $Msg, $Dll
Global $hImageList, $sCur, $sLast, $iDX, $iPicState = 0, $DoubleClick = -1

$hGui = GUICreate("Image Viewer", 490, 620)

$Path = GUICtrlCreateInput("", 10, 10, 400, 20, $ES_READONLY)
$BRowse = GUICtrlCreateButton("Browse", 420, 10, 60, 20)
$LV = GUICtrlCreateListView("",  5, 40, 480, 575, -1, BitOr($WS_EX_CLIENTEDGE, $LVS_EX_DOUBLEBUFFER))
_GUICtrlListView_SetView($LV, 1)
_GUICtrlListView_SetIconSpacing($LV, 75, 60)
$Pic = GUICtrlCreatePic("", 200, 80, 440, 440)
_SkinGUI(@TempDir&"\SkinCrafterDll.dll", @TempDir&"\vista.skf", $hGui)
GUISetState(@SW_SHOW)

GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")

While 1
    $Msg = GUIGetMsg()
    Switch $Msg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Browse
            _Browse()
    EndSwitch
WEnd

Func _Browse()
    Local $FSF, $FL2A, $hBmp, $iCnt = 0
    $FSF = FileSelectFolder("Browse for folder containing pictures", "", "", $hGui)
    If Not @error And FileExists($FSF) Then
        If StringRight($FSF, 1) <> "\" Then $FSF &= "\"
        $FL2A = _FileListToArray($FSF, "*", 1)
        If Not @Error Then
            If IsPtr($hImageList) Then
                _GUICtrlListView_DeleteAllItems(GUICtrlGetHandle($LV))
                _GUiImageList_Destroy($hImageList)
                $hImageList = ""
                _hBmpToPicControl($Pic, $hBmp)
                GUICtrlSetImage($Pic, "")
                $iDX = -1
                $iPicState = 0
                $sCur = ""
                $sLast = ""
            EndIf
            $hImageList = _GUiImageList_Create(60, 60, 5, 3)
            _GUICtrlListView_SetImageList($LV, $hImageList, 0)
            For $i = 1 To $FL2A[0]
                If StringRegExp($FL2A[$i], "(?i)\.(" & $sExtFilter & ")", 0) Then
                    $hBmp = _GetImage($FSF & $FL2A[$i], 60)
                    _GUiImageList_Add($hImageList, $hBmp)
                    _WinAPI_DeleteObject($hBmp)
                    _GUICtrlListView_AddItem($LV, $FL2A[$i], $iCnt)
                    _GUICtrlListView_SetItemImage($LV, $iCnt, $iCnt)
                    $iCnt += 1
                EndIf
            Next
            GUICtrlSetData($Path, $FSF)
        EndIf
        WinSetTitle($hGui, "", "Images Found: " & $iCnt)
    EndIf
EndFunc

Func _GetImage($sFile, $iWH, $iBkClr = 0xFFFFFF)
    Local $hBmp1, $hBitmap, $hGraphic, $hImage, $iW, $iH, $aGS, $hBmp2
    _GDIPlus_Startup()
    $hBmp1 = _WinAPI_CreateBitmap($iWH, $iWH, 1, 32)
    $hBitmap = _GDIPlus_BitmapCreateFromHBITMAP($hBmp1)
    $hGraphic = _GDIPlus_ImageGetGraphicsContext($hBitmap)
    _WinAPI_DeleteObject($hBmp1)
    _GDIPlus_GraphicsClear($hGraphic, BitOR(0xFF000000, $iBkClr))
    $hImage = _GDIPlus_ImageLoadFromFile($sFile)
    $iW = _GDIPlus_ImageGetWidth($hImage)
    $iH = _GDIPlus_ImageGetHeight($hImage)
    $aGS = _GetScale($iW, $iH, $iWH)
    _GDIPlus_GraphicsDrawImageRect($hGraphic, $hImage, $aGS[0], $aGS[1], $aGS[2], $aGS[3])
    _GDIPlus_ImageDispose($hImage)
    _GDIPlus_GraphicsDispose($hGraphic)
    $hBmp2 = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap)
    _GDIPlus_BitmapDispose($hBitmap)
    _GDIPlus_Shutdown()
    Return $hBmp2
EndFunc

Func _GetScale($iW, $iH, $iWH)
    Local $aRet[4]
    If $iW <= $iWH And $iH <= $iWH Then
        $aRet[2] = $iW
        $aRet[3] = $iH
        $aRet[0] = ($iWH - $aRet[2])/2
        $aRet[1] = ($iWH - $aRet[3])/2
    ElseIf $iW > $iH Then
        $aRet[2] = $iWH
        $aRet[3] = $iH/($iW/$iWH)
        $aRet[0] = 0
        $aRet[1] = ($iWH - $aRet[3])/2
    ElseIf $iW < $iH Then
        $aRet[2] = $iW/($iH/$iWH)
        $aRet[3] = $iWH
        $aRet[0] = ($iWH - $aRet[2])/2
        $aRet[1] = 0
    ElseIf $iW = $iH Then
        $aRet[2] = $iWH
        $aRet[3] = $iWH
        $aRet[0] = 0
        $aRet[1] = 0
    EndIf
    Return $aRet
EndFunc

Func _hBmpToPicControl($iCID, ByRef $hBmp, $iFlag = 0)
    Local Const $STM_SETIMAGE = 0x0172
    Local Const $IMAGE_BITMAP = 0
    Local $hOldBmp
    $hOldBmp = GUICtrlSendMsg($iCID, $STM_SETIMAGE, $IMAGE_BITMAP, $hBmp)
    If $hOldBmp Then _WinAPI_DeleteObject($hOldBmp)
    If $iFlag Then _WinAPI_DeleteObject($hBmp)
EndFunc

Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
    Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndListView, $tInfo, $aIDX
    $hWndListView = GUICtrlGetHandle($LV)
    $tNMHDR = DllStructCreate('hwnd hWndFrom;int_ptr IDFrom;int Code', $ilParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
    $iCode = DllStructGetData($tNMHDR, "Code")
    Switch $hWndFrom
        Case $hWndListView
            Switch $iCode
                Case $NM_CLICK
                    $iDX = _GUICtrlListView_GetNextItem($hWndListView)
                Case $NM_DBLCLK
                    $DoubleClick = _GUICtrlListView_GetNextItem($hWndListView)
                Case $LVN_KEYDOWN
                    $tInfo = DllStructCreate('hwnd hWndFrom;int_ptr IDFrom;int Code;int_ptr VKey;int Flags', $ilParam)
                    Switch BitAnd(DllStructGetData($tInfo, "VKey"), 0xFFFF)
                        Case $VK_UP
                            $iDX = _GUICtrlListView_GetNextItem($hWndListView) -1
                            If $iDX < 0 Then $iDX = 0
                        Case $VK_DOWN
                            $iDX = _GUICtrlListView_GetNextItem($hWndListView) + 1
                            If $iDX >= _GUICtrlListView_GetItemCount($hWndListView) Then $iDX -= 1
                    EndSwitch
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc

Func _SkinGUI($SkincrafterDll, $SkincrafterSkin, $Handle)
   $Dll = DllOpen($SkincrafterDll) 
   DllCall($Dll, "int:cdecl", "InitLicenKeys", "wstr", "1", "wstr", "", "wstr", "1@1.com", "wstr", "1") 
   DllCall($Dll, "int:cdecl", "InitDecoration", "int", 1) 
   DllCall($Dll, "int:cdecl", "LoadSkinFromFile", "wstr", $SkincrafterSkin) 
   DllCall($Dll, "int:cdecl", "DecorateAs", "int", $Handle, "int", 25) 
   DllCall($Dll, "int:cdecl", "ApplySkin") 
EndFunc 
Func Quit()
    GUISetState(@SW_HIDE)
    DllCall($Dll, "int:cdecl", "DeInitDecoration")
    DllCall($Dll, "int:cdecl", "RemoveSkin")
    DllClose($Dll)
        FileDelete(@TempDir&"SkinCrafterDll.dll")
        FileDelete(@TempDir&"vista.skf") 
    Exit
EndFunc
发表于 2011-11-23 10:41:15 | 显示全部楼层
楼上正解哈。
 楼主| 发表于 2011-11-23 19:50:57 | 显示全部楼层
3mile大大~太感动了帮我解决了大问题,还以为这篇可能要沉入大海~~
话说_SkinGUI(@TempDir&"\SkinCrafterDll.dll", @TempDir&"\vista.skf", $hGui)这行换一个位置就可以显示
不知为啥会这样~~还是谢谢3mile大大帮忙
发表于 2011-11-23 20:40:29 | 显示全部楼层
改用SHE皮肤哈。。
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-6-3 02:00 , Processed in 0.082333 second(s), 25 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表