回复 39# qsy666888
#Include <GuiListView.au3>
#include <SQLite.au3>
#include <SQLite.dll.au3>
#Include <GuiListView.au3>
#Include <GuiTreeView.au3>
#include <GuiConstantsEx.au3>
#include <GuiImageList.au3>
#include <WindowsConstants.au3>
Global $hQuery
_SQLite_Startup ()
$SQLite_Data_Path =@ScriptDir&"\SQLite.db"
$Tablekj = "kaojuan"
#Region ### START Koda GUI section ### Form=
Global $Form1 = GUICreate("從資料庫裡獲取姓名示例", 478, 412, 481, 210)
GUISetFont(11, 400, 0, "宋體")
Global $ListView1 = GUICtrlCreateListView("序號|姓名|語文||", 8, 8, 458, 358)
GUICtrlSetBkColor($ListView1,0xC0C0A5)
_GUICtrlListView_SetBkColor($ListView1, $CLR_MONEYGREEN)
_GUICtrlListView_SetExtendedListViewStyle($ListView1, BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT, $LVS_EX_SUBITEMIMAGES,$LVS_NOSCROLL ))
$hImage = _GUIImageList_Create(20, 20, 5, 3)
KC_lvdraw()
_GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll",1);50
; _GUIImageList_AddIcon($hImage, @ScriptDir & "\icon\101.ico")
_GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll",13)
_GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll",24);50
_GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll",34)
_GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll",44)
_GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll",54)
_GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll",64)
_GUICtrlListView_SetImageList($ListView1, $hImage, 1)
_GUICtrlListView_AddSubItem($ListView1, 0, "", 3, 1)
_GUICtrlListView_AddSubItem($ListView1, 1, "", 3, 2)
_GUICtrlListView_AddSubItem($ListView1, 2, "", 3, 3)
_GUICtrlListView_AddSubItem($ListView1, 3, "", 3, 4)
_GUICtrlListView_AddSubItem($ListView1, 4, "", 3, 5)
_GUICtrlListView_AddSubItem($ListView1, 5, "", 3, 6)
Global $Button1 = GUICtrlCreateButton("查看分數", 293, 376, 75, 25)
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case -3
Exit
; Case $Button1
; msgbox(0,"70多分者", _get_N(7, 1))
; msgbox(0,"分數個位數是5者", _get_N(5, 0))
EndSwitch
WEnd
Func _get_N($iNum, $iCode = 1)
Local $aRow, $hQuery, $sMsg = ''
Local $sQuery
If $iCode Then
$sQuery = "'" & $iNum & "%'"
Else
$sQuery = "'%" & $iNum & "'"
EndIf
_SQLite_Open ($SQLite_Data_Path)
_SQLite_Query(-1, "SELECT * FROM kaojuan WHERE 分數 LIKE " & $sQuery & ";", $hQuery)
While _SQLite_FetchData($hQuery, $aRow) = $sqlite_ok
$sMsg &= $aRow[0] & @TAB & $aRow[1] & @CRLF
WEnd
Return $sMsg
EndFunc
Func KC_lvdraw()
_GUICtrlListView_DeleteAllItems(GUICtrlGetHandle($ListView1))
Global $Irval, $Aresult, $Irows, $Icolumns,$sQuery,$aRowa,$a = '',$b = '',$c = ''
$Irval = _SQLite_GetTable2d( _SQLite_Open ($SQLite_Data_Path), "select rowid,* from kaojuan;", $Aresult, $Irows, $Icolumns)
;GUICtrlSetColor($ListView1, 0x000000)
_ArrayDelete($aresult, 0)
_GUICtrlListView_AddArray($ListView1, $Aresult)
_SQLite_QueryFinalize($hQuery)
_GUICtrlListView_SetItemImage($ListView1,0,55)
_GUICtrlListView_SetItemImage($ListView1,1,55)
_GUICtrlListView_SetItemImage($ListView1,2,55)
_GUICtrlListView_SetItemImage($ListView1,3,55)
_GUICtrlListView_SetItemImage($ListView1,4,55)
_GUICtrlListView_SetItemImage($ListView1,5,55)
EndFunc
Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
#forceref $hWnd, $iMsg, $iwParam
Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndListView, $tInfo
;~ Local $tBuffer
$hWndListView = $ListView1
If Not IsHWnd($ListView1) Then $hWndListView = GUICtrlGetHandle($ListView1)
$tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
$hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
$iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
$iCode = DllStructGetData($tNMHDR, "Code")
Switch $hWndFrom
Case $hWndListView
Switch $iCode
Case $NM_CUSTOMDRAW ;顏色的處理部份 需搭配 上面繪圖的處理
Local $iDrawStage, $iIndex, $iSub,$iColor, $hDC
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
If Not BitAND($iDrawStage, $CDDS_SUBITEM) Then Return $CDRF_DODEFAULT
Local $iIndex = DllStructGetData($tCustDraw, "dwItemSpec")
Local $iSub = DllStructGetData($tCustDraw, "iSubItem")
;$CHKIDSerch=$iIndex
;$VLSIDSerch=_GUICtrlListView_GetSelectedIndices($VListViewSerch,True)
;這一段處理變色 跟判斷
IF _GUICtrlListView_GetItemText($hWndListView,$iIndex,2) <60 Then
DllStructSetData($tCustDraw, "clrText", 0x55FF55)
DllStructSetData($tCustDraw, "clrTextBk", 0x80FFFF)
Else
EndIf
Return $CDRF_NEWFONT
EndSwitch
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc ;==>WM_NOTIFY
|