【已解决】combo如何隐藏垂直滚动条且鼠标滚动有效
本帖最后由 chamlien 于 2017-7-18 10:07 编辑这个帖子贴出了实现combo下拉背景色的变化,很强大。
帖子地址:http://www.autoitx.com/forum.php?mod=viewthread&tid=55417&extra=&highlight=combo&page=1
帖子代码:
#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, "實現這裡背景為白色|蘋果|香蕉|桔子|梨子|李子|西瓜|桔子|梨子|李子|西瓜|桔子|梨子|李子|西瓜", "實現這裡背景為白色")
GUICtrlSetFont(-1, 10, 400, -1)
GUISetState()
Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE
_WinAPI_DeleteObject($hPen)
_WinAPI_DeleteObject($hBrushSel)
_WinAPI_DeleteObject($hBrushNorm)
GUIDelete()
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
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 + 1, $aRect + 1, $aRect, $aRect)
_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 + 4)
DllStructSetData($tRect, "Top", $aRect + 8)
DllStructSetData($tRect, "Bottom", $aRect - 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
EndFunc ;==>_WinAPI_Rectangle
该代码没添加$WS_VSCROLL 样式,所以没有出现垂直滚动条。但是添加了该样式后,出现的滚动条又与背景颜色格格不入。
因此我的问题如下:
如何隐藏combo里的滚动条,且还能在下拉框里使用鼠标滑轮滚动?
本人也在帖子里回复了 kk_lee69 大侠,但尚未得到正解。希望大家提供一下思路,谢谢 回复 1# chamlien
原本的構想 好像加了COMBO 後 滑鼠滾輪的消息會被攔截
所以這條路行不通
_GUIScrollBars_ShowScrollBar
顯示或隱藏指定的捲軸.
這個 好像可以 但是重點是 要找的到 COMBO 下拉的捲軸 句柄 回复 2# kk_lee69
是的,我也找到了使用_WinAPI_SetWindowLong来获取鼠标滚动事件,但是无法判断COMBO的下拉框是否是展开状态。 回复 3# chamlien
_WinAPI_SetWindowLong 這個有反應嗎?? 下拉 可以找到時機點
_WinAPI_SetWindowLong 這個的用法有資料嗎 回复 4# kk_lee69
_WinAPI_SetWindowLong 是WinAPI上的一个函数,可以捕捉所有消息。
抛砖引玉一下。使用_WinAPI_SetWindowLong 可以获取鼠标放在COMBO上时滑动滑轮的事件,但在下拉框上滑动滑轮无法捕捉。
新增几行代码如下:
#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_MOUSEWHEELThen
MsgBox(0,0,"你在combo控件上滑动了鼠标滑轮")
Return 0
EndIf
Return _WinAPI_CallWindowProc($wProcOld2, $hWnd, $uiMsg, $wParam, $lParam)
EndFunc
;------------------------新增代码
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
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 + 1, $aRect + 1, $aRect, $aRect)
_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 + 4)
DllStructSetData($tRect, "Top", $aRect + 8)
DllStructSetData($tRect, "Bottom", $aRect - 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
EndFunc ;==>_WinAPI_Rectangle
回复 5# chamlien
基本上實現了你是看看 滾輪有用了
缺點是 在任何地方滾輪一樣會有作用 會發送 UPDOWN
要在細部修改 才能鎖住在COMOBO 的事件上
#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_MOUSEWHEELThen
If BitShift($wParam, 16) > 0 Then ;Wheel up
Send("{UP}")
Else ;-----------------------------Wheel down
Send("{DOWN}")
EndIf
EndIf
Return _WinAPI_CallWindowProc($wProcOld2, $hWnd, $uiMsg, $wParam, $lParam)
EndFunc
;------------------------新增代?
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
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 + 1, $aRect + 1, $aRect, $aRect)
_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 + 4)
DllStructSetData($tRect, "Top", $aRect + 8)
DllStructSetData($tRect, "Bottom", $aRect - 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
EndFunc ;==>_WinAPI_Rectangle 本帖最后由 chamlien 于 2017-7-18 01:27 编辑
回复 6# kk_lee69
答主可能漏了一层意思,我最终想实现的效果是在弹出的下拉框中,可以使用滑轮上下滚动,且这个滚动不能出现滚动条。
下面简图可能会容易理解些。(先睡了,明天再研究研究)
回复 5# chamlien
多加了一段控制應該比較完善了
#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))
Global $COMOBOCHECK=0
GUIRegisterMsg($WM_MEASUREITEM, '_WM_MEASUREITEM')
GUIRegisterMsg($WM_DRAWITEM, '_WM_DRAWITEM')
GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")
$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_MOUSEWHEELThen
IF $COMOBOCHECK=1 Then
If BitShift($wParam, 16) > 0 Then ;Wheel up
Send("{UP}")
ConsoleWrite("UP"&@CRLF)
Else ;-----------------------------Wheel down
Send("{DOWN}")
ConsoleWrite("DOWN"&@CRLF)
EndIf
EndIf
EndIf
Return _WinAPI_CallWindowProc($wProcOld2, $hWnd, $uiMsg, $wParam, $lParam)
EndFunc
;------------------------新增代?
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
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 + 1, $aRect + 1, $aRect, $aRect)
_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 + 4)
DllStructSetData($tRect, "Top", $aRect + 8)
DllStructSetData($tRect, "Bottom", $aRect - 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
EndFunc ;==>_WinAPI_Rectangle
Func WM_COMMAND($hWnd, $iMsg, $iwParam, $ilParam)
#forceref $hWnd, $iMsg
Local $hWndFrom, $iIDFrom, $iCode
$hWndFrom = $ilParam
$iIDFrom = BitAND($iwParam, 0xFFFF) ; Low Word
$iCode = BitShift($iwParam, 16) ; Hi Word
Switch $iIDFrom
Case $ComboBox
Switch $iCode
Case $CBN_DROPDOWN
$COMOBOCHECK=1
Case $CBN_CLOSEUP
$COMOBOCHECK=0
EndSwitch
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc ;==>WM_COMMAND 回复 7# chamlien
回复 9# kk_lee69
基本上实现了,感谢!原来漏了个 $COMOBOCHECK 的状态,一直想不出来,感谢帮忙! 回复 10# chamlien
其實我覺得這個還不是最佳解
最佳解應該是 加入 卷軸風格然後隱藏卷軸
畢竟拉動效果不同
不過是基本上 可以達到要求 回复 11# kk_lee69
是的,应该像你上面说的_GUIScrollBars_ShowScrollBar,找到卷轴的句柄,然后隐藏 回复 10# chamlien
放棄隱藏卷軸想法吧
剛剛測試了 EDIT 控件的隱藏卷軸
卷軸隱藏了 滾輪就沒作用了
此路不通......... 回复 13# kk_lee69
实际上8楼的代码确实有点小问题,不知道是不是这两个消息有冲突。
GUIRegisterMsg($WM_DRAWITEM, '_WM_DRAWITEM')
GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")
在GUIRegisterMsg($WM_DRAWITEM, '_WM_DRAWITEM')里也对下拉框做了判断,不知道能不能也在这个消息里加上对滑轮消息的判断? 回复 14# chamlien
概念不太一樣吧
WM_COMMAND是 下拉觸發一次關閉 觸發一次
WM_DRAWITEM應該是 一直在畫圖 上色吧 難道 你的那個檢核碼 要一直 切來切去的
页:
[1]
2