回复 8# kk_lee69
找到了获取下拉框状态的函数了,不需要注册WM_COMMAND消息,但上滑或下划还是不是很灵敏、存在阻塞,代码如下:
#include <GUIComboBox.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3>
#include <WinAPIFiles.au3>;含RGB轉換BGR顏色UDF
Global $iColor = 0xffffff;0x114c93;選中顏色
Global $clrWindow = 0xffffff;底色
Global $hBrushNorm = _WinAPI_CreateSolidBrush($clrWindow)
Global $hBrushSel = _WinAPI_CreateSolidBrush(_WinAPI_SwitchColor($iColor))
Global $hPen = _WinAPI_CreatePen($PS_SOLID, 2, _WinAPI_SwitchColor($iColor))
GUIRegisterMsg($WM_MEASUREITEM, '_WM_MEASUREITEM')
GUIRegisterMsg($WM_DRAWITEM, '_WM_DRAWITEM')
$hGUI = GUICreate('Test', 220, 300)
$ComboBox = GUICtrlCreateCombo('', 10, 10, 200, 300, BitOR($WS_CHILD, $CBS_OWNERDRAWVARIABLE, $CBS_HASSTRINGS, $CBS_DROPDOWNLIST))
GUICtrlSetData($ComboBox, "實現這裡背景為白色|蘋果|香蕉|桔子|梨子|李子|西瓜|桔子|梨子|李子|西瓜|桔子|梨子|李子|西瓜", "實現這裡背景為白色")
;------------------------新增
Local $wProcNew2 = DllCallbackRegister("_comboScroll", "int", "hwnd;uint;wparam;lparam")
$wProcOld2 = _WinAPI_SetWindowLong(GUICtrlGetHandle($ComboBox), $GWL_WNDPROC, DllCallbackGetPtr($wProcNew2))
;------------------------新增
GUICtrlSetFont(-1, 10, 400, -1)
GUISetState()
Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE
_WinAPI_DeleteObject($hPen)
_WinAPI_DeleteObject($hBrushSel)
_WinAPI_DeleteObject($hBrushNorm)
GUIDelete()
;------------------------新增代?
Func _comboScroll($hWnd, $uiMsg, $wParam, $lParam)
If $uiMsg = $WM_MOUSEWHEEL Then
If _GUICtrlComboBox_GetDroppedState($ComboBox) = True Then
If BitShift($wParam, 16) > 0 Then ;Wheel up
ControlSend($hGUI,"",$ComboBox,"{UP}")
ConsoleWrite("UP" & @CRLF)
Else ;-----------------------------Wheel down
ControlSend($hGUI,"",$ComboBox,"{DOWN}")
ConsoleWrite("DOWN" & @CRLF)
EndIf
EndIf
EndIf
Return _WinAPI_CallWindowProc($wProcOld2, $hWnd, $uiMsg, $wParam, $lParam)
EndFunc ;==>_comboScroll
;------------------------新增代?
Func _WM_MEASUREITEM($hWnd, $iMsg, $iwParam, $ilParam)
Local $tagMEASUREITEMSTRUCT = 'uint CtlType;uint CtlID;uint itemID;uint itemWidth;uint itemHeight;ulong_ptr itemData;'
Local $tMIS = DllStructCreate($tagMEASUREITEMSTRUCT, $ilParam)
Local $iCtlType, $iCtlID, $iItemID, $iItemWidth, $iItemHeight
Local $hComboBox
Local $tSize
Local $sText
$iCtlType = DllStructGetData($tMIS, 'CtlType')
$iCtlID = DllStructGetData($tMIS, 'CtlID')
$iItemID = DllStructGetData($tMIS, 'itemID')
$iItemWidth = DllStructGetData($tMIS, 'itemWidth')
$iItemHeight = DllStructGetData($tMIS, 'itemHeight')
$hComboBox = GUICtrlGetHandle($iCtlID)
If $iCtlType = 3 Then DllStructSetData($tMIS, 'itemHeight', 30)
Return $GUI_RUNDEFMSG
EndFunc ;==>_WM_MEASUREITEM
Func _WM_DRAWITEM($hWnd, $iMsg, $iwParam, $ilParam)
Local $tagDRAWITEMSTRUCT = 'uint CtlType;uint CtlID;uint itemID;uint itemAction;uint itemState;hwnd hwndItem;hwnd hDC;' & $tagRECT & ';ulong_ptr itemData;'
Local $tDIS = DllStructCreate($tagDRAWITEMSTRUCT, $ilParam)
Local $iCtlType, $iCtlID, $iItemID, $iItemAction, $iItemState
Local $clrForeground, $clrBackground
Local $hWndItem, $hDC, $hOldPen, $hOldBrush
Local $tRect, $aRect[4]
Local $sText
$iCtlType = DllStructGetData($tDIS, 'CtlType')
$iCtlID = DllStructGetData($tDIS, 'CtlID')
$iItemID = DllStructGetData($tDIS, 'itemID')
$iItemAction = DllStructGetData($tDIS, 'itemAction')
$iItemState = DllStructGetData($tDIS, 'itemState')
$hWndItem = DllStructGetData($tDIS, 'hwndItem')
$hDC = DllStructGetData($tDIS, 'hDC')
$tRect = DllStructCreate($tagRECT)
If $iCtlType = 3 Then
Switch $iCtlID
Case $ComboBox
For $i = 1 To 4
DllStructSetData($tRect, $i, DllStructGetData($tDIS, $i + 7))
$aRect[$i - 1] = DllStructGetData($tRect, $i)
Next
_GUICtrlComboBox_GetLBText($hWndItem, $iItemID, $sText)
If GUICtrlRead($ComboBox) = "實現這裡背景為白色" Then
Global $iColor = 0xffffff;選中顏色
Global $clrWindow = 0xffffff;底色
Global $hBrushNorm = _WinAPI_CreateSolidBrush($clrWindow)
Global $hBrushSel = _WinAPI_CreateSolidBrush(_WinAPI_SwitchColor($iColor))
Global $hPen = _WinAPI_CreatePen($PS_SOLID, 2, _WinAPI_SwitchColor($iColor))
Else
Global $iColor = 0x114c93;選中顏色
Global $clrWindow = 0xffffff;底色
Global $hBrushNorm = _WinAPI_CreateSolidBrush($clrWindow)
Global $hBrushSel = _WinAPI_CreateSolidBrush(_WinAPI_SwitchColor($iColor))
Global $hPen = _WinAPI_CreatePen($PS_SOLID, 2, _WinAPI_SwitchColor($iColor))
EndIf
If BitAND($iItemState, 1) Then
$hOldBrush = _WinAPI_SelectObject($hDC, $hBrushSel)
$hOldPen = _WinAPI_SelectObject($hDC, $hPen)
_WinAPI_Rectangle($hDC, $aRect[0] + 1, $aRect[1] + 1, $aRect[2], $aRect[3])
_WinAPI_SelectObject($hDC, $hOldPen)
_WinAPI_SelectObject($hDC, $hOldBrush)
$clrBackground = _WinAPI_SetBkColor($hDC, _WinAPI_SwitchColor($iColor))
$clrBackground = _WinAPI_SetTextColor($hDC, 0x000000)
Else
$clrBackground = _WinAPI_SetBkColor($hDC, $clrWindow)
_WinAPI_FillRect($hDC, DllStructGetPtr($tRect), $hBrushNorm)
EndIf
DllStructSetData($tRect, "Left", $aRect[0] + 4)
DllStructSetData($tRect, "Top", $aRect[1] + 8)
DllStructSetData($tRect, "Bottom", $aRect[3] - 2)
_WinAPI_DrawText($hDC, $sText, $tRect, BitOR($DT_LEFT, $DT_VCENTER))
_WinAPI_SetTextColor($hDC, $clrForeground)
_WinAPI_SetBkColor($hDC, $clrBackground)
EndSwitch
EndIf
Return $GUI_RUNDEFMSG
EndFunc ;==>_WM_DRAWITEM
Func _WinAPI_Rectangle($hDC, $iLeft, $iTop, $iRight, $iBottom)
Local $aResult = DllCall("gdi32.dll", "int", "Rectangle", "hwnd", $hDC, "int", $iLeft, "int", $iTop, "int", $iRight, "int", $iBottom)
If @error Then Return SetError(@error, @extended, 0)
Return $aResult[0] <> 0
EndFunc ;==>_WinAPI_Rectangle
|