回复 网络小僧
只有afan那个方法了,重新看了看combo的结构,没别的方法,如果创建combo必然带着下拉按键
netegg 发表于 2011-12-2 16:45
守夜到现在了,斗了一晚上地主,现在太兴奋了,一点睡意都没有,现在上来看看论坛有没有有点意思的问题,结果看到了这个问题还不错,远比那些‘看起来’就象干坏事的(如:如何欺骗;读取别的程序内存……)好点。
楼主既然要这种效果,可以连那个Button都不需要,直接点鼠标,就出来象Combo那样的下拉菜单,看看下面的代码效果,是不是合乎楼主的“完美解决”
#include <WindowsConstants.au3>
#include <GuiConstantsEx.au3>
#include <GuiConstants.au3>
#include <EditConstants.au3>
#include <Constants.au3>
#include <WinAPI.au3>
Global $hGui, $hProcA, $hProcB, $cInput, $cMenu, $aItem[10], $cRevItem
VoidMain()
Func VoidMain()
Local $cDummy
Opt("GUIOnEventMode", 1)
$hGui = GUICreate("PseuCombo Test", 400, 300)
GUISetOnEvent($GUI_EVENT_CLOSE, "SysEvent")
$cInput = GUICtrlCreateInput("Hit me strongly", 100, 100, 200, 20, $ES_CENTER + $ES_READONLY)
$cDummy = GUICtrlCreateDummy()
$cMenu = GUICtrlCreateContextMenu($cDummy)
For $i = 0 To UBound($aItem) - 1
$aItem[$i] = GUICtrlCreateMenuItem("Value" & $i + 1, $cMenu)
Next
$hProcA = DllCallbackRegister("WindowProc", "ptr", "hwnd;uint;long;ptr")
$hProcB = _WinAPI_SetWindowLong(GUICtrlGetHandle($cInput), $GWL_WNDPROC, DllCallbackGetPtr($hProcA))
GUISetState(@SW_SHOW, $hGui)
While True
Sleep(10)
WEnd
EndFunc
Func ShowContextMenu($hWnd, $cCtrlID)
Local $WinPos[2], $hMenu, $Return
$WinPos = WinGetPos($hGui)
$hMenu = GUICtrlGetHandle($cCtrlID)
$Return = DllCall("user32.dll", "int", "TrackPopupMenuEx", "hwnd", $hMenu, "int", 0x0100, "int", $WinPos[0] + 200, "int", $WinPos[1] + 140, "hwnd", $hWnd, "ptr", 0)
Return $Return[0]
EndFunc
Func SysEvent()
Switch @GUI_CtrlId
Case $GUI_EVENT_CLOSE
GUIDelete($hGui)
Exit
EndSwitch
EndFunc
Func WindowProc($hWnd, $iMsg, $wParam, $lParam)
Switch $iMsg
Case $WM_RBUTTONDOWN, $WM_CONTEXTMENU
If $hWnd = GUICtrlGetHandle($cInput) Then
$cRevItem = ShowContextMenu($hGui, $cMenu)
For $i = 0 To UBound($aItem) - 1
If $cRevItem = $aItem[$i] Then
GUICtrlSetData($cInput, "Value" & $i + 1)
ExitLoop
EndIf
Next
Return 0
EndIf
Case $WM_LBUTTONDOWN
If $hWnd = GUICtrlGetHandle($cInput) Then
$cRevItem = ShowContextMenu($hGui, $cMenu)
For $i = 0 To UBound($aItem) - 1
If $cRevItem = $aItem[$i] Then
GUICtrlSetData($cInput, "Value" & $i + 1)
ExitLoop
EndIf
Next
EndIf
EndSwitch
Return _WinAPI_CallWindowProc($hProcB, $hWnd, $iMsg, $wParam, $lParam)
EndFunc
|