yykj 发表于 2009-5-18 22:56:05

请教关于guictrlcreatelistviewitem的美观问题

本帖最后由 yykj 于 2009-5-18 22:58 编辑

今天根据一份源码做了个小菜单.可是GUICtrlCreateListViewItem的创建过程会一闪一闪的
看了人家的菜单都没有这么闪的.请问如何改善AU3的这个问题.

源码是参照这个写的
#Region ;**** 参数创建于 ACNWrapper_GUI ****
#AutoIt3Wrapper_icon=e:\autoit3\Aut2Exe\Icons\windows.ico
#EndRegion ;**** 参数创建于 ACNWrapper_GUI ****
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <GuiListView.au3>;_GUICtrlListView_SetView
#include <WinAPI.au3>
#Include <Array.au3>


Global $Gui_width = 800, $Gui_height = 550
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
Global $Type = ;初始化分类变量
Global $button=
Global $current_type ;初始化当前分类判断
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("游戏菜单", $Gui_width, $Gui_height, -1, -1, $WS_CAPTION + $WS_SYSMENU + $WS_MAXIMIZEBOX + $WS_MINIMIZEBOX + $WS_SIZEBOX)
;~ $WS_SIZEBOX 可用鼠标调整窗口大小.
$button = GUICtrlCreateButton("分类一", 8, 8, 75, 25, 0)
GUICtrlSetResizing(-1, "802");2+32+256+512=802,表示(在窗口被调整大小时)控件位置将一直不变
$button = GUICtrlCreateButton("分类二", 88, 8, 75, 25, 0)
GUICtrlSetResizing(-1, "802")
$button = GUICtrlCreateButton("分类三", 168, 8, 75, 25, 0)
GUICtrlSetResizing(-1, "802")
$ListView1 = GUICtrlCreateListView("", 8, 40, $Gui_width - 20, $Gui_height - 80)
;~ GUICtrlSetResizing($ListView1, "32+64+2+4");不完美
GUICtrlSetResizing(-1, $GUI_DOCKLEFT + $GUI_DOCKRIGHT + $GUI_DOCKTOP + $GUI_DOCKBOTTOM);随窗体放大

_GUICtrlListView_SetView($ListView1, "1");排列图标: 0为详细情况排列 ;1为正常图标排列;$ 2为列表排列,; 3为小图标排列: 4为列表加文字排列
GUICtrlSetBkColor($ListView1, 0x396BA5)
$menu1 = GUICtrlCreateContextMenu($ListView1)
$menu_01 = GUICtrlCreateMenuItem("更新游戏", $menu1)
$menu_02 = GUICtrlCreateMenuItem("直接运行", $menu1)
$menu_03 = GUICtrlCreateMenuItem("打开目录", $menu1)
$Label1 = GUICtrlCreateLabel("欢迎光临", 8, 424, 90, 17)
GUICtrlSetResizing(-1, 512+64);随窗体放大
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

_SearechType(@ScriptDir & "\link\")
_filelist(@ScriptDir & "\link\" & $Type)
$current_type = @ScriptDir & "\link\" & $Type
While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit
                Case $button
                        _filelist(@ScriptDir & "\link\" & $Type)
                        $current_type = @ScriptDir & "\link\" & $Type
                Case $button
                        _filelist(@ScriptDir & "\link\" & $Type)
                        $current_type = @ScriptDir & "\link\" & $Type
                Case $button
                        _filelist(@ScriptDir & "\link\" & $Type)
                        $current_type = @ScriptDir & "\link\" & $Type
        EndSwitch
WEnd


Func _SearechType($dir);获取分类
        FileChangeDir($dir)
        $search_type = FileFindFirstFile("*.*")
        If $search_type = -1 Then
                MsgBox(0, "不存在链接文件", "不存在链接文件")
                Exit
        EndIf
        While 1
                $file = FileFindNextFile($search_type)
                If @error Then ExitLoop
                If FileGetAttrib($file) = "D" Then
                        $Type += 1
                        _ArrayAdd($Type, $file)
                        GUICtrlSetData ($button[$type], $file)
                        EndIf
                WEnd
        FileClose($search_type)
EndFunc   ;==>_SearechType

Func _filelist($DirSource);获取每个分类的链接文件
        _GUICtrlListView_DeleteAllItems($ListView1)
        If FileExists($DirSource) = 0 Then
                MsgBox(64, "提示", "【" & $DirSource & "】目录不存在!请重新指定有效目录.")
        Else
                Local $WorkingDir, $search, $file
                FileChangeDir($DirSource)
                $search = FileFindFirstFile("*.*")
                If $search = -1 Then
                        ;MsgBox(64, "完成提示", "在目录【" & $DirSource & "】下未找到任何文件和子目录!")
                Else
                        While 1
                                $file = FileFindNextFile($search)
                                If @error Then ExitLoop
                                If StringInStr(FileGetAttrib($DirSource & "\" & $file), "D") Then
                                        _filelist($DirSource & "\" & $file)
                                Else
                                        ;MsgBox(0, 000, $DirSource & "\" & $file)
                                        If StringRight($file, 3) = "lnk" Then
                                                GUICtrlCreateListViewItem($file, $ListView1)
                                                $links = FileGetShortcut($DirSource & "\" & $file);获取快捷方式的属性
                                                GUICtrlSetImage(-1, $links, 1, 1)
                                                GUICtrlSetColor(-1, 0xFFFFFF)
                                                GUICtrlSetResizing(-1, "32+64+2+4")
                                        EndIf

                                EndIf
                        WEnd
                EndIf
        EndIf
EndFunc   ;==>_filelist

Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam) ;检测鼠标动作事件内置函数
        Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndLV, $tInfo
        $hWndLV = GUICtrlGetHandle($ListView1)
        $hWndLV2 = _GUICtrlListView_GetSelectedIndices($ListView1)
        $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
        $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
        $iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
        $iCode = DllStructGetData($tNMHDR, "Code")
        Switch $hWndFrom
                Case $hWndLV
                        Switch $iCode
                                Case $NM_DBLCLK
                                        If Not $hWndLV2 <> "" Then
;~                                                 MsgBox(64, "系统提示", "请选择游戏.")
                                        Else
                                                $listicon = GUICtrlRead(GUICtrlRead($ListView1));读取选定的项目的文本
                                                ;MsgBox(0,"",$current_type & "\" & $listicon)
                                                ShellExecute($current_type & "\" & $listicon)
                                        EndIf
                                        ;Case $NM_RCLICK          ; 鼠标右键事件

                        EndSwitch
        EndSwitch
        Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY

Func _uplists()
        _GUICtrlListView_DeleteAllItems($ListView1)
        GUISetState(@SW_LOCK, $Form1)
        For $i = 1 To 20
                GUICtrlCreateListViewItem("qq" & $i, $ListView1)
                GUICtrlSetImage(-1, @ScriptDir & "\ico\qq.ico", "", 1)
                GUICtrlSetColor(-1, 0xFFFFFF)
                GUICtrlSetResizing(-1, "32+64+2+4")
        Next
        GUISetState(@SW_UNLOCK, $Form1)
;~         GUICtrlSetColor(-1, $Close2))
EndFunc   ;==>_uplists

yykj 发表于 2009-5-18 23:02:34

一个_GUICtrlListView_DeleteAllItems, 一个GUICtrlCreateListViewItem.当数量多的时候.菜单上将一闪一闪的,得花好些时间才能创建完...请版主来帮下忙吧
页: [1]
查看完整版本: 请教关于guictrlcreatelistviewitem的美观问题