|
发表于 2012-5-18 10:10:58
|
显示全部楼层
本帖最后由 netegg 于 2012-5-22 11:19 编辑
[au3]#include <Constants.au3>
#include <GUIConstantsEx.au3>
#include <GUIComboBox.au3>
#include <GUIListView.au3>
#include <WindowsConstants.au3>
Opt('GUIOnEventMode', 1)
Dim $hGUI = GUICreate('Test', 300, 200)
Dim $ListView = GUICtrlCreateListView('A|B|C', 0, 0, 300, 200, $LVS_NOSORTHEADER)
Dim $hListView = GUICtrlGetHandle($ListView)
Dim $hHeader = _GUICtrlListView_GetHeader($hListView)
Dim $hComboBox = _GUICtrlComboBox_Create($hListView, 'A|B|C|D', 0, 0)
Dim $hProc = DllCallbackRegister('_ListViewHandler', 'lresult', 'hwnd;uint;wparam;lparam')
Dim $pProc = DllCallbackGetPtr($hProc)
Dim $hListViewProc = _WinAPI_SetWindowLong($hListView, $GWL_WNDPROC, $pProc)
Dim $iItem = -1, $iSubitem = -1
_WinAPI_ShowWindow($hComboBox, @SW_HIDE)
_GUICtrlListView_SetExtendedListViewStyle($hListView, BitOR($LVS_EX_DOUBLEBUFFER, $LVS_EX_GRIDLINES))
_GUICtrlListView_SetColumnWidth($hListView, 0, 100)
_GUICtrlListView_SetColumnWidth($hListView, 1, 100)
_GUICtrlListView_SetColumnWidth($hListView, 2, 100)
_GUICtrlListView_BeginUpdate($hListView)
For $i = 1 To 10
Local $iItem = _GUICtrlListView_AddItem($hListView, $i)
_GUICtrlListView_AddSubItem($hListView, $iItem, '', 1)
_GUICtrlListView_AddSubItem($hListView, $iItem, '', 2)
Next
_GUICtrlListView_EndUpdate($hListView)
GUISetOnEvent($GUI_EVENT_CLOSE, '_Close')
GUIRegisterMsg($WM_NOTIFY, 'WM_NOTIFY')
GUISetState()
While 1
Sleep(10)
WEnd
Func _Close()
GUIDelete()
DllCallbackFree($hProc)
Exit
EndFunc
Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
Local $tNM = DllStructCreate($tagNMHDR, $ilParam)
Local $aSubHitTest
Local $aRect
Switch DllStructGetData($tNM, 'hWndFrom')
Case $hListView
If DllStructGetData($tNM, 'Code') = $LVN_HOTTRACK Then
$aSubHitTest = _GUICtrlListView_SubItemHitTest($hListView)
If $aSubHitTest[1] > 0 Then
$aRect = _GUICtrlListView_GetSubItemRect($hListView, $aSubHitTest[0], $aSubHitTest[1])
_GUICtrlListView_SetItemText($hListView, $iItem, _GUICtrlComboBox_GetEditText($hComboBox), $iSubitem)
_WinAPI_ShowWindow($hComboBox, @SW_HIDE)
_WinAPI_MoveWindow($hComboBox, $aRect[0], $aRect[1], 100, 120)
_GUICtrlComboBox_SetCurSel($hComboBox, _GUICtrlComboBox_FindString($hComboBox, _GUICtrlListView_getItemText($hListView, $aSubHitTest[0], $aSubHitTest[1])))
_WinAPI_ShowWindow($hComboBox)
$iItem = $aSubHitTest[0]
$iSubitem = $aSubHitTest[1]
Else
_WinAPI_ShowWindow($hComboBox, @SW_HIDE)
EndIf
EndIf
Case $hHeader
Switch DllStructGetData($tNM, 'Code')
Case $HDN_BEGINTRACK, $HDN_BEGINTRACKW
Return 1
EndSwitch
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc
Func _ListViewHandler($hWnd, $iMsg, $iwParam, $ilParam)
Local $aRect
Switch $iMsg
Case $WM_HSCROLL, $WS_VSCROLL
If BitAND(_WinAPI_GetWindowLong($hComboBox, $GWL_STYLE), $WS_VISIBLE) Then
$aRect = _GUICtrlListView_GetSubItemRect($hListView, $iItem, $iSubitem)
_WinAPI_MoveWindow($hComboBox, $aRect[0], $aRect[1], 100, 120)
EndIf
EndSwitch
Return _WinAPI_CallWindowProc($hListViewProc, $hWnd, $iMsg, $iwParam, $ilParam)
EndFunc[/au3]
嗯,改成$LVN_HOTTRACK比$nm_click好多了 |
|