|
发表于 2012-12-1 01:12:02
|
显示全部楼层
本帖最后由 netegg 于 2012-12-1 02:02 编辑
[au3]#AutoIt3Wrapper_au3check_parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6
#include <GuiConstantsEx.au3>
#include <GuiListView.au3>
#include <GuiImageList.au3>
#include <WindowsConstants.au3>
#include <EditConstants.au3>
#include <SendMessage.au3>
Opt('MustDeclareVars', 1)
$Debug_LV = False ; 检查传递给函数的类名, 设置为真并使用另一控件句柄观察其工作
Global $hListView, $edit
_Main()
Func _Main()
Local $GUI, $hImage
$GUI = GUICreate("(UDF Created) ListView Create", 400, 540)
$edit = GUICtrlCreateEdit("", 2, 277, 394, 258, BitOR($WS_VSCROLL, $ES_AUTOVSCROLL))
$hListView = _GUICtrlListView_Create($GUI, "", 2, 2, 394, 268)
_GUICtrlListView_SetExtendedListViewStyle($hListView, BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT, $LVS_EX_SUBITEMIMAGES))
GUISetState()
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
; 加载图像
$hImage = _GUIImageList_Create()
_GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap($hListView, 0xFF0000, 16, 16))
_GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap($hListView, 0x00FF00, 16, 16))
_GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap($hListView, 0x0000FF, 16, 16))
_GUICtrlListView_SetImageList($hListView, $hImage, 1)
; 添加列
_GUICtrlListView_InsertColumn($hListView, 0, "Column 1", 100)
_GUICtrlListView_InsertColumn($hListView, 1, "Column 2", 100)
_GUICtrlListView_InsertColumn($hListView, 2, "Column 3", 100)
; 添加项
_GUICtrlListView_AddItem($hListView, "123445", 0)
_GUICtrlListView_AddSubItem($hListView, 0, "2344-5", 1)
_GUICtrlListView_AddSubItem($hListView, 0, "2945-86", 2)
_GUICtrlListView_AddItem($hListView, "21455-6", 1)
_GUICtrlListView_AddSubItem($hListView, 1, "213458-96", 1)
_GUICtrlListView_AddItem($hListView, "3445", 2)
; 循环至用户退出
Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE
GUIDelete()
EndFunc ;==>_Main
Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
#forceref $hWnd, $iMsg, $iwParam
Local $hWndFrom, $iCode, $tNMHDR, $hWndListView, $tInfo, $subitem
;~Local $tBuffer
$hWndListView = $hListView
If Not IsHWnd($hListView) Then $hWndListView = GUICtrlGetHandle($hListView)
$tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
$hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
;$iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
$iCode = DllStructGetData($tNMHDR, "Code")
Switch $hWndFrom
Case $hWndListView
Switch $iCode
Case $LVN_COLUMNCLICK ; 点击一列
$tInfo = DllStructCreate($tagNMLISTVIEW, $ilParam)
$subitem = DllStructGetData($tInfo, "SubItem")
ConsoleWrite($subitem)
For $i = 0 To _GUICtrlListView_GetItemCount($hListView)
Local $text = _GUICtrlListView_GetItemText($hListView, $i, $subitem)
Local $num = StringInStr($text, '-')
If $num Then
_GUICtrlListView_SetItemText($hListView, $i, _NumFormat(Number(StringLeft($text, $num - 1), 3)) & StringRight($text, StringLen($text) - $num+1), $subitem)
Else
_GUICtrlListView_SetItemText($hListView, $i, _NumFormat(Number($text), 3), $subitem)
EndIf
Next
; 无返回值
EndSwitch
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc ;==>WM_NOTIFY
Func MemoWrite($s_text)
GUICtrlSetData($edit, $s_text & @CRLF, 1)
EndFunc ;==>MemoWrite
;例子
;======================================================================================
; 说明: 将数字或字符串按指定间隔值插入半角逗号。(常用于数字按千位加逗号符)
; 语法: _NumFormat('数字(或非数字)字符串'[, '间隔位数'[, '识别数字中首位的+-符及有效的小数点']])
; 参数: 可选参数'间隔位数',为3即逢千位插入","(默认)如 1,234 、 12,345,678 等
; 参数: 可选参数'识别数字中首位的+-符及有效的小数点',为1即识别(默认)如 -1234.12 返回 -1,234.12
; 返回值:成功: 返回格式化后的字符串。
; 失败: 返回-1。如果间隔位数不是整型数则返回-1
; 作者: Afan -- http://www.autoitx.com
;===================================================================================start
Func _NumFormat($num, $Insert = 3, $flag = 1)
If Not StringIsInt($Insert) Then Return -1
Local $Numstrout_h, $Numstrout_q
If $flag Then
Local $tmp = StringRegExpReplace($num, '^(\+|-).+', '$1')
If @extended > 0 Then
$Numstrout_q = $tmp
$num = StringTrimLeft($num, 1)
EndIf
$Numstrout_h = StringRegExpReplace($num, '.+(\.\d+)$', '$1')
If @extended = 0 Then $Numstrout_h = ''
$num = StringRegExpReplace($num, '\.\d+$', '')
EndIf
Local $Numstrout = StringRegExpReplace($num, '(.+?)(?:.{' & $Insert & '})+$', '$1')
If @extended = 0 Then Return $Numstrout_q & $Numstrout & $Numstrout_h
Local $Numstrout1 = StringRegExpReplace($num, '^' & $Numstrout, '')
$Numstrout1 = StringRegExpReplace($Numstrout1, '(.{' & $Insert & '})', '$1,')
Return $Numstrout_q & $Numstrout & ',' & StringTrimRight($Numstrout1, 1) & $Numstrout_h
EndFunc ;==>_NumFormat[/au3]
需要点击下标题栏,sendmessage应该可以解决,懒得写了 |
|