ListView加上皮肤问题[已解决]
本帖最后由 jackywjl 于 2011-11-23 20:12 编辑小弟在官网找到ListView可显示图档缩图,但加了皮肤之后,却无法正常显示缩图,不知问题出在哪
档案都在附件里,请大大帮帮忙~~谢谢
换了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
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, $aGS, $aGS, $aGS)
_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
If $iW <= $iWH And $iH <= $iWH Then
$aRet = $iW
$aRet = $iH
$aRet = ($iWH - $aRet)/2
$aRet = ($iWH - $aRet)/2
ElseIf $iW > $iH Then
$aRet = $iWH
$aRet = $iH/($iW/$iWH)
$aRet = 0
$aRet = ($iWH - $aRet)/2
ElseIf $iW < $iH Then
$aRet = $iW/($iH/$iWH)
$aRet = $iWH
$aRet = ($iWH - $aRet)/2
$aRet = 0
ElseIf $iW = $iH Then
$aRet = $iWH
$aRet = $iWH
$aRet = 0
$aRet = 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 等答案中…….. 附件里是从官网抓的源码,未修改的可正常显示,4楼的源码是我加上皮肤的,不知哪出问题,加了皮肤就无法显示
等待高手帮忙~~谢谢 #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
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, $aGS, $aGS, $aGS)
_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
If $iW <= $iWH And $iH <= $iWH Then
$aRet = $iW
$aRet = $iH
$aRet = ($iWH - $aRet)/2
$aRet = ($iWH - $aRet)/2
ElseIf $iW > $iH Then
$aRet = $iWH
$aRet = $iH/($iW/$iWH)
$aRet = 0
$aRet = ($iWH - $aRet)/2
ElseIf $iW < $iH Then
$aRet = $iW/($iH/$iWH)
$aRet = $iWH
$aRet = ($iWH - $aRet)/2
$aRet = 0
ElseIf $iW = $iH Then
$aRet = $iWH
$aRet = $iWH
$aRet = 0
$aRet = 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 楼上正解哈。 3mile大大~太感动了帮我解决了大问题,还以为这篇可能要沉入大海~~{:face (239):}
话说_SkinGUI(@TempDir&"\SkinCrafterDll.dll", @TempDir&"\vista.skf", $hGui)这行换一个位置就可以显示
不知为啥会这样~~还是谢谢3mile大大帮忙 改用SHE皮肤哈。。
页:
[1]