玩技术的,熟悉Windows编程的来看,帮帮我!
如何向TextBox控件用SendMessage发送Ctrl+Left消息?
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 WM_KEYDOWN = &H100
Private Const WM_KEYUP = &H101
Private Const VK_CONTROL = &H11
Private Const VK_LEFT = &H25
Private Sub Command1_Click()
Dim t As Long
SendMessage Me.Text1.hwnd, WM_KEYDOWN, VK_CONTROL, 0
t = t And &H40000001
SendMessage Me.Text1.hwnd, WM_KEYDOWN, VK_LEFT, t
End Sub
Private Sub Text1_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyLeft Then
If Shift = 2 Then
MsgBox "Ctrl+Left"
End If
End If
End Sub
以前不好用.
MSDN中的消息说明:
The WM_KEYDOWN message is posted to the window with the keyboard focus when a nonsystem key is pressed. A nonsystem key is a key that is pressed when the alt key is not pressed.
WM_KEYDOWN
nVirtKey = (int) wParam; // virtual-key code
lKeyData = lParam; // key data
Parameters
nVirtKey
Value of wParam. Specifies the virtual-key code of the nonsystem key.
lKeyData
Value of lParam. Specifies the repeat count, scan code, extended-key flag, context code, previous key-state flag, and transition-state flag, as shown in the following table. Value Description
0–15 Specifies the repeat count for the current message. The value is the number of times the keystroke is auto-repeated as a result of the user holding down the key. If the keystroke is held long enough, multiple messages are sent. However, the repeat count is not cumulative.
16–23 Specifies the scan code. The value depends on the original equipment manufacturer (OEM).
24 Specifies whether the key is an extended key, such as the right-hand alt and ctrl keys that appear on an enhanced 101- or 102-key keyboard. The value is 1 if it is an extended key; otherwise, it is 0.
25–28 Reserved; do not use.
29 Specifies the context code. The value is always 0 for a WM_KEYDOWN message.
30 Specifies the previous key state. The value is 1 if the key is down before the message is sent, or it is 0 if the key is up.
31 Specifies the transition state. The value is always 0 for a WM_KEYDOWN message.
我想到的lParam的值为:
01000000 00000000 00000000 00000001
即&H40000001
不过好像不对,哪位大侠帮忙一下!!~~~~谢谢啦!