一、枚举进程和其ID时:
Combo1.AddItem 进程名称
Combo1.ItemData(Combo1.NewIndex) = 进程ID
二、选择Combo1中的进程名称的时候,另外一个控件取得该进程所对应的PID:
Private Sub Combo1_Click()
Form2.label1.Caption = Combo1.ItemData(Combo1.ListIndex)
End Sub
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Const CB_SHOWDROPDOWN = &H14F
Private Sub Combo1_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = 40 And Shift = 0 Then
SendMessage Combo1.hwnd, CB_SHOWDROPDOWN, True, 0&
End If
End Sub
Private Sub Combo1_GotFocus()
SendKeys "%{Down}"
End Sub
zx001z回答的好啊,简单又实用。