效果一
#include <GUIConstantsEx.au3>
#include <MyErrFunc.au3>
;#include <BackQuietMail.au3>
#include <GuiToolbar.au3> ;TOOLBAR 與MENU 需要
#include <GuiMenu.au3> ;TOOLBAR 與MENU 需要
#include <GuiToolTip.au3> ;提示
#include <GDIPlus.au3>
#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
#include <GUIComboBox.au3>
#include <Constants.au3>
#include <GuiImageList.au3>
#include <WindowsConstants.au3>
#include <EditConstants.au3>
#include <FontConstants.au3>
#include <GuiEdit.au3>
#include <MacEncryptX.au3>
#include <Date.au3>
#include <array.au3>
#include <Excel.au3>
#include <File.au3>
#include <_GetMachineInfo.au3>
Example()
Func Example()
Local $msg
GUICreate("我的下拉?合框 GUI") ; ?建居中?示的 GUI 窗口
GUICtrlCreateCombo("?目 1", 10, 10,100,20,0x0003) ; ?建下拉?合框 BitOR($GUI_SS_DEFAULT_COMBO ,$CBS_DROPDOWNLIST)
GUICtrlSetData(-1, "?目 2|?目 3", "?目 3") ; 添加其它?目并?置默??目
GUISetState()
; ?行 GUI, 直到 GUI 被??
While 1
$msg = GUIGetMsg()
If $msg = $GUI_EVENT_CLOSE Then ExitLoop
WEnd
EndFunc ;==>Example
效果二 請點擊 LISTVIEW 原地編輯
; Script Start - Add your code below here
#include <GUIComboBox.au3>
#include <GUIConstantsEx.au3>
#include <GuiEdit.au3>
#include <WinAPI.au3>
#include <GUIEdit.au3>
#include <WinAPIEx.au3>
#include <GuiListView.au3>
#include <GuiImageList.au3>
#include <FontConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <FontConstants.au3>
#include <MsgBoxConstants.au3>
;#include <WinAPIFiles.au3>
#include <Array.au3>
Opt("GUIOnEventMode", 1)
Opt('GUIResizeMode', 802)
Local Const $sFilePath = 'ConfigAA.ini'
$var = IniReadSection(@ScriptDir & '\' & $sFilePath, '1')
Local $sRead = "張三|123456|V|空|123456789|空|按鈕刪除行"
If @error Then IniWrite(@ScriptDir & '\' & $sFilePath, "1", "1", "$sRead")
Global $SS_CENTER, $SS_CENTERIMAGE, $Edit, $zys, $WinMainSub1, $MyGui, $XEButton1, $TEButton2, $Button7 ;, $Label, $Combo, $Button1, $Button2, $Button3, $Button4
Global $iWidtha = @DesktopWidth
Global $iHeighta = @DesktopHeight
Global Const $gc_tempdir = @ScriptDir
Global $sPath=@ScriptDir
Global $ListView1, $hListView1, $Input1, $hEdit, $aHit, $aRect, $aPos, $Buttont1, $hFont, $GInputuk7, $ilParam, $Item, $aShowdata, $SubItem, $aHit[3]
Global $iHeight = 22
Local $sTitle = "Listview控制項", $sText = "右鍵按一下刪除行按鈕,可刪除子專案," & @CRLF & " 左鍵按兩下可修改單條子專案內容。", $sText1 = "右鍵按一下刪除行按鈕,可刪除子專案," & @CRLF & " 左鍵按兩下可修改單條子專案內容。"
GUI_INI()
While 1
Sleep(1000)
;GUICtrlSetData($LTIME, @HOUR & ":" & @MIN & ":" & @SEC)
WEnd
Func GUI_INI()
$MyGui = GUICreate("Listview控制項讀取INI", $iWidtha / 2 + 15, $iHeighta / 2 + 10, -1, -1);400, 460); $iWidtha - 18, $iHeighta - 60, -1, -1);
;GUISetBkColor(0xfbfcfd)
GUISetBkColor(0xA1BFAA - 0x440000)
GUISetOnEvent($GUI_EVENT_CLOSE, "GForm1Close")
$GInputuk7 = GUICtrlCreateLabel("", $iWidtha / 2 - 10, 430, 60, 20)
GUICtrlSetColor(-1, 0x009900);0xCBAC00)
GUICtrlSetFont(-1, 11, 400, 0, "微軟雅黑")
GUICtrlSetState($GInputuk7, $GUI_HIDE)
$Button5 = GUICtrlCreateButton("編輯Edit", 30, 430, 80, 22)
$XEButton1 = GUICtrlCreateButton("修改", 120, 430, 80, 22);, $SS_CENTER + $SS_CENTERIMAGE + $WS_BORDER, $WS_EX_DLGMODALFRAME)
$TEButton2 = GUICtrlCreateButton("列表修改", 210, 430, 80, 22);, $BS_BITMAP, $WS_EX_DLGMODALFRAME
GUICtrlSetState($XEButton1, 128)
;GUICtrlSetState($TEButton2, 128)
$Button6 = GUICtrlCreateButton("返回", 390, 430, 80, 22)
$Button7 = GUICtrlCreateButton("添加", 300, 430, 80, 22, 0)
GUICtrlSetOnEvent($Button6, "_Edit2")
DllCall("uxtheme.dll", "none", "SetThemeAppProperties", "int", 0)
;#cs
Dim $WinMainSub1 = GUICreate("", $iWidtha / 2, 388, 4, 4, $WS_POPUP, 0x00000040 + 0x00000300, $MyGui)
GUISetBkColor(0xA1BFAA - 0x440000)
GUISetState(@SW_SHOW, $WinMainSub1)
;GUIRegisterMsg($WM_COMMAND, 'WM_COMMAND')
GUISetState(@SW_SHOW, $MyGui)
_Edit2()
EndFunc ;==>GUI_INI
Func GForm1Close()
GUIDelete()
Exit
EndFunc ;==>GForm1Close
Func _Edit2()
WinSetTitle($MyGui, '', "AU3控制項------Listview控制項讀取INI")
GUICtrlSetState($XEButton1, 128)
GUICtrlSetState($TEButton2, 64)
GUICtrlSetState($Button7, 64)
GUISetState(@SW_HIDE, $WinMainSub1)
GUIDelete($WinMainSub1)
Dim $WinMainSub1 = GUICreate("", $iWidtha / 2, 388, 4, 4, $WS_POPUP, 0x00000040 + 0x00000300, $MyGui)
GUISetBkColor(0xA1BFAA - 0x440000);GUISetBkColor(0xFF9933);GUISetBkColor(0xA0E0E0)
;_GUICtrlListView_DeleteAllItems($ListView1)
$ListView1 = GUICtrlCreateListView("", 2, 2, $iWidtha / 2 - 3, 376, $LVS_REPORT, $WS_EX_CLIENTEDGE);, BitOR($LVS_EX_CHECKBOXES, $LVS_EX_FULLROWSELECT));BitOR($LVS_REPORT, $WS_BORDER));,
$hListView1 = GUICtrlGetHandle(-1)
;_GUICtrlListView_SetExtendedListViewStyle($hListview1, $LVS_EX_FULLROWSELECT)
GUICtrlSetFont(-1, 11, 400, 0, "微軟雅黑")
GUICtrlSetTip(-1, $sText, $sTitle, 0, 1)
;Sleep(5000)
;GUICtrlSetTip($ListView1, "右鍵按一下可刪除子項目,左鍵按兩下可修改單條子專案內容。")
GUICtrlSetBkColor($ListView1, 0xC0E0FF);0xECE9D8);
_GUICtrlListView_SetBkColor($hListView1, 14675183)
;_GUICtrlListView_AddColumn($hListView1, "編號", 0, 2);設置列屬性
_GUICtrlListView_AddColumn($hListView1, "編號", $iWidtha / 26, 2);設置列屬性
_GUICtrlListView_AddColumn($hListView1, "用戶名", $iWidtha / 18)
_GUICtrlListView_AddColumn($hListView1, "密碼", $iWidtha / 18)
_GUICtrlListView_AddColumn($hListView1, "姓別", $iWidtha / 28, 2)
;_GUICtrlListView_AddColumn($hListView1, "姓別女", $iWidtha / 26)
_GUICtrlListView_AddColumn($hListView1, "生份證號", $iWidtha / 12, 2)
_GUICtrlListView_AddColumn($hListView1, "手機號", $iWidtha / 14)
_GUICtrlListView_AddColumn($hListView1, "部門", $iWidtha / 22)
_GUICtrlListView_AddColumn($hListView1, "", 6)
_GUICtrlListView_AddColumn($hListView1, "刪除行按鈕", $iWidtha / 13)
_GUICtrlListView_SetColumnWidth($hListView1, 4, 155)
;#cs
; 載入圖像
$hImage1 = _GUIImageList_Create(20, 20, 5, 3, 3)
;;_GUIImageList_AddIcon($hImage, "shell32.dll", 15, True)
_GUIImageList_AddIcon($hImage1, "shell32.dll", 137, True)
_GUIImageList_AddIcon($hImage1, "imageres.dll", 93, True)
_GUICtrlListView_SetImageList($hListview1, $hImage1, 1)
;#ce
$hImage = _GUIImageList_Create(1, $iHeight)
$iStyle = BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_GRIDLINES, $WS_EX_CLIENTEDGE, $LVS_EX_INFOTIP, $LVS_EX_SUBITEMIMAGES)
_GUICtrlListView_SetExtendedListViewStyle($ListView1, $iStyle)
;$hFont = _WinAPI_CreateFont($iHeight, 0, 0, 0, 400, False, False, False, $DEFAULT_CHARSET, $OUT_DEFAULT_PRECIS, $CLIP_DEFAULT_PRECIS, $DEFAULT_QUALITY, 0, '微軟雅黑')
$Number = _GUICtrlListView_GetItemCount($hListView1)
$cont = _GUICtrlListView_GetItemCount($hListView1);取得陣列的行列數
$num1 = $cont + 1
_GUICtrlListView_AddItem($ListView1, $num1, 0)
;_IniListView3()
GUIRegisterMsg($WM_NOTIFY, 'WM_NOTIFYa')
GUISetState(@SW_SHOW, $WinMainSub1)
;GUISetState(@SW_SHOW, $MyGui)
;GUIRegisterMsg($WM_COMMAND, 'WM_COMMAND')
EndFunc ;==>_Edit3
Func WM_NOTIFYa($hWnd, $iMsg, $iwParam, $ilParam)
Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndListView, $tInfo
Local $hWndListView1 = $ListView1
If Not IsHWnd($ListView1) Then $hWndListView1 = GUICtrlGetHandle($ListView1)
$tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
$hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
$iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
$iCode = DllStructGetData($tNMHDR, "Code")
;Switch $hWndFrom
;Case $hWndListView1
Switch $iCode
Case $NM_DBLCLK ; 按兩下
$tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam)
$iIndex = DllStructGetData($tInfo, "Index")
$iSub = DllStructGetData($tInfo, "SubItem")
$x = DllStructGetData($tInfo, "X")
Global $aHit = _GUICtrlListView_SubItemHitTest($hListView1)
;If $aHit[0] <> -1 Then
If ($iIndex <> -1) And ($iSub >= 0) And ($x > 16) Then;點擊的x>16才回應原地編輯
$Item = $iIndex
$SubItem = $iSub
Local $ax = 1
Local $ay = 1
Local $aRect = _GUICtrlListView_GetSubItemRect($hListView1, $iIndex, $iSub)
;MsgBox($MB_SYSTEMMODAL, "消息", StringFormat("子項矩形 : [%d, %d, %d, %d]", $aRect[0], $aRect[1], $aRect[2], $aRect[3]))
Local $iEdit_X = $aRect[0] ;+ 4
Local $iEdit_Y = $aRect[1] +3;+ 3
Local $iEdit_Width = _GUICtrlListView_GetColumnWidth($hListView1, $iSub) + 3
Local $iEdit_Height = $aRect[3] - $aRect[1] + 3
;$hEdit = GUICtrlCreateInput($aShowdata[$iIndex][$iSub], $iEdit_X, $iEdit_Y, $iEdit_Width, $iEdit_Height, BitOR($WS_CHILD, $WS_VISIBLE, $ES_LEFT))
Local $sItem = _GUICtrlListView_GetItemText($hListView1, $iIndex, $iSub);取listview$iIndex行 $iSub列的文本
;$hEdit = GUICtrlCreateEdit($sItem, $iEdit_X, $iEdit_Y, $iEdit_Width, $iEdit_Height, BitOR($WS_CHILD, $WS_VISIBLE, $ES_LEFT))
;$hEdit = GUICtrlCreateInput($sItem, $iEdit_X, $iEdit_Y, $iEdit_Width, $iEdit_Height, BitOR($WS_CHILD, $WS_VISIBLE, $ES_LEFT))
ConsoleWrite( $iEdit_X&" "&$iEdit_Y&@CRLF)
$aPOS=WinGetPos($MyGui)
$hEditForm = GUICreate("", $iEdit_Width, $iEdit_Height, $iEdit_X+$aPOS[0]+10, $iEdit_Y+$aPOS[1]+30, $WS_POPUP, -1, $WinMainSub1);創建一個子視窗用於裝載input控製項
$hEdit = GUICtrlCreateCombo("", 0, 0, $iEdit_Width, $iEdit_Height,0x0003 );0x0003 樣式 可多個下拉 不可輸入 拿掉就可以輸入
GUICtrlSetData(-1, "張三|李四|王五|陳六", "張三")
GUISetState(@SW_SHOW, $hEditForm)
;$hEdit = GUICtrlCreateCombo($sItem, $iEdit_X, $iEdit_Y, $iEdit_Width, $iEdit_Height,0x0003 );, BitOR($WS_CHILD, $WS_VISIBLE, $ES_LEFT))
;GUICtrlSetData(-1, "張三|李四|王五|陳六", "張三")
;GUICtrlSetFont($hEdit, 12)
GUICtrlSetFont($hEdit, 10, 400, 0, "微軟雅黑")
GUICtrlSetColor($hEdit, 0x990000)
GUICtrlSetBkColor($hEdit, 0xfbfcfd);0x009900); 背景色
GUICtrlSetState($hEdit, $GUI_FOCUS)
$hEdit = GUICtrlGetHandle($hEdit)
$index = _GUICtrlListView_GetSelectedIndices($hListView1)
GUICtrlSetData($GInputuk7, $index)
GUICtrlSetColor($GInputuk7, 0x990000)
Else
MsgBox(0, "提示", "按一下了空白處", 1)
EndIf
Case $NM_CLICK ; 滑鼠左鍵按一下
$index = _GUICtrlListView_GetSelectedIndices($ListView1)
$Index1 = $index + 1
If $index <> "" Then
$tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam)
$iIndex = DllStructGetData($tInfo, "Index")
$iSub = DllStructGetData($tInfo, "SubItem")
Local $iSubItem = DllStructGetData($tInfo, "iSubItem")
;If $Index = 0 And $iSub = 7 Then
If $iSub = 4 Then
;ConsoleWrite("你點了+" & @CRLF)
;ElseIf $iIndex = 0 And $iSub = 4 Then
;MsgBox(0, "", "你點了搜尋")
;ElseIf $iIndex = 0 And $iSub = 5 Then
;MsgBox(0, "", "你點了停止")
EndIf
EndIf
Case $NM_RCLICK ; 滑鼠按右鍵
$index = _GUICtrlListView_GetSelectedIndices($ListView1)
$Index1 = $index + 1
If $index <> "" Then
$tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam)
$iIndex = DllStructGetData($tInfo, "Index")
$iSub = DllStructGetData($tInfo, "SubItem")
Local $iSubItem = DllStructGetData($tInfo, "iSubItem")
;If $Index = 0 And $iSub = 7 Then
If $iSub = 8 Then
;ConsoleWrite("你點了+" & @CRLF)
MsgBox(0, "", "你點了 第 " & $Index1 & " 行 按鈕刪除行")
;Del()
;ElseIf $iIndex = 0 And $iSub = 4 Then
;MsgBox(0, "", "你點了搜尋")
;ElseIf $iIndex = 0 And $iSub = 5 Then
;MsgBox(0, "", "你點了停止")
EndIf
EndIf
EndSwitch
#forceref $hWnd, $iMsg, $iwParam
Local $MyGuiFrom, $iIDFrom, $iCode, $tNMHDR, $tInfo
$tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
$MyGuiFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
$iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
$iCode = DllStructGetData($tNMHDR, "Code")
Switch $iIDFrom
Case $ListView1
Switch $iCode
Case $NM_CUSTOMDRAW
Local $tCustDraw = DllStructCreate($tagNMLVCUSTOMDRAW, $ilParam)
Local $iDrawStage = DllStructGetData($tCustDraw, "dwDrawStage")
If $iDrawStage = $CDDS_PREPAINT Then Return $CDRF_NOTIFYITEMDRAW
If $iDrawStage = $CDDS_ITEMPREPAINT Then Return $CDRF_NOTIFYSUBITEMDRAW
Local $iSubItem = DllStructGetData($tCustDraw, "iSubItem")
Local $iItem = DllStructGetData($tCustDraw, "dwItemSpec")
Local $iColor, $hDC, $Font1
If _GUICtrlListView_GetItemChecked($hListView1, $iItem) = True Then
DllStructSetData($tCustDraw, "clrTextBk", 0xFF901E);BGR格式顏色值 高亮背景色
DllStructSetData($tCustDraw, "clrText", 0xFFFFFF) ;高亮後文字改為白色
EndIf
Switch $iSubItem;$iItem
Case 7, 8;, 14, 19;條目行數
$hDC = DllStructGetData($tCustDraw, "hdc")
If $iSubItem = 8 Then ;設置首列, 即專案
$iColor = RGB2BGR(0xFF0000)
DllStructSetData($tCustDraw, "clrText", $iColor)
EndIf
EndSwitch
EndSwitch
EndSwitch
;EndSwitch
Return $GUI_RUNDEFMSG
EndFunc ;==>WM_NOTIFYa
Func RGB2BGR($iColor)
Return BitAND(BitShift(String(Binary($iColor)), 8), 0xFFFFFF)
EndFunc ;==>RGB2BGR
|