简单问题!如何在SendMessage中发送一个有关于按下回车的WM_CHAR消息?

Alexander 2003-03-27 07:37:42
这个程序要在程序中控制另一个对话框。现在想想另一个对话框发送一个消息,消息内容是假设按下了enter键,但是我不知道这个enter键的虚拟码&HD应该怎么加到这个sendmessage里面,WM_CLOSE可以,但是WM_CHAR需要一个按键的参数阿,请大家救命

Private Sub Command2_Click()
Dim lpClassName As String
Dim lpCaption As String
Dim Handle As Long

Const NILL = 0&
Const WM_SYSCOMMAND = &H112
Const SC_CLOSE = &HF060&
Const BM_CLICK = &HD&
lpClassName = "#32770"
lpCaption = "NetMeeting - 没有进行呼叫"
lpCaption = "关于 Windows NetMeeting"
lpClassName = "Button"
lpCaption = "浏览(&R)..."
Determine the handle to the Calculator window.
Handle = FindWindow(lpClassName$, lpCaption$)
Handle = SendMessage(Handle, WM_SYSCOMMAND, SC_CLOSE, NILL)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

End Sub
...全文
493 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
用户 昵称 2003-03-27
  • 打赏
  • 举报
回复
发送回车可以直接
sendmessage hwnd, WM_CHAR, 10, 0

关闭程序参考
Private Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Long, lpdwProcessId As Long) As Long
Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
Private Declare Function TerminateProcess Lib "kernel32" (ByVal hProcess As Long, ByVal uExitCode As Long) As Long
Private Const PROCESS_TERMINATE = &H1

''用于结束外部进程,hCloseWnd 是要结束的程序的主窗口的 HWND
Public Function TernamiteProcessByHWND(ByVal hCloseWnd As Long) As Boolean
Dim hProcessID As Long
Dim hProcess As Long
On Error GoTo PROC_EXIT
If hCloseWnd = 0 Then GoTo PROC_EXIT
If GetWindowThreadProcessId(hCloseWnd, hProcessID) = 0 Then GoTo PROC_EXIT
hProcess = OpenProcess(PROCESS_TERMINATE, False, hProcessID)
If hProcess = 0 Then GoTo PROC_EXIT
If TerminateProcess(hProcess, 0&) = 0 Then GoTo PROC_EXIT
TernamiteProcessByHWND = True
PROC_EXIT:
If Err.Number <> 0 Then
Debug.Print Err.Description
Err.Clear
End If
End Function
gang75 2003-03-27
  • 打赏
  • 举报
回复
gz
Alexander 2003-03-27
  • 打赏
  • 举报
回复
改成

Private Sub Command2_Click()
Dim lpClassName As String
Dim lpCaption As String
Dim Handle As Long

Const NILL = 0&
Const WM_SYSCOMMAND = &H112
Const SC_CLOSE = &HF060&
Const VK_RETURN = &HD&
Const WM_CHAR = &H102


lpClassName = "#32770"
lpCaption = "关于 Windows NetMeeting"


Handle = FindWindow(lpClassName$, lpCaption$)

Handle = SendMessage(Handle, WM_CHAR, VK_RETURN, NILL)
End Sub

以后不行阿,没有效果
急,请大家帮忙!
Alexander 2003-03-27
  • 打赏
  • 举报
回复
老大,看看我的函数
Handle = SendMessage(Handle, WM_SYSCOMMAND, SC_CLOSE, NILL)
我还需要一个WM_SYSCOMMAND的位置呀,这个去掉了还能行吗?
用户 昵称 2003-03-27
  • 打赏
  • 举报
回复
sendmessage hwnd, WM_CHAR, key_ascii, 0
用户 昵称 2003-03-27
  • 打赏
  • 举报
回复
是WM_CHAR
Alexander 2003-03-27
  • 打赏
  • 举报
回复
我是向对话矿窗体发送消息,不是向按钮发送消息。所以需要发送键消息。
再问一下,是WM_CHAR还是WM_KEYDOWN
FUNDGIRL 2003-03-27
  • 打赏
  • 举报
回复
直接向按钮送送点击消息即可,不必发送键盘消息
模拟键盘鼠标操作飞信界面发送短信 private void SendSMS() { #if DEBUG string[] addr = new string[] { "闻佃来"}; #else string[] addr = new string[] { "张三", "李四"}; #endif string message = " "; if (message == "") return; Rectangle rect = new Rectangle(); Windows wins = new Windows(); IntPtr hwin = IntPtr.Zero; foreach (Window w in wins) { if (w.Title.IndexOf("发短信") >= 0) { hwin = w.hWnd; break; } } //未找到发送窗口,点击主窗口下的短信发送按钮 if (hwin == IntPtr.Zero) { wins = new Windows(); foreach (Window w in wins) { if (w.Title.IndexOf("飞信2013") >= 0) { //唤醒屏保 Win32.SetCursorPos(10,10); Win32.mouse_event(Win32.MOUSEEVENTF_MOVE, 50, 50, 0, 0); Thread.Sleep(1500); Win32.ShowWindow(w.hWnd, Win32.SW_SHOWNORMAL); Win32.SetForegroundWindow(hwin); Win32.GetWindowRect(w.hWnd, ref rect); IntPtr hDesk = Win32.GetDesktopWindow(); Rectangle rdesk = new Rectangle(); Win32.GetWindowRect(hDesk,ref rdesk); if (rect.Y < 0) { //上 Win32.SetCursorPos(rect.X +(rect.Width-rect.X)/2,0); Win32.mouse_event(Win32.MOUSEEVENTF_MOVE, 0, 1, 0, 0); Thread.Sleep(1500); Win32.GetWindowRect(w.hWnd, ref rect); } else if (rect.Y >= rdesk.Height - 3) { //下 Win32.SetCursorPos(rect.X + (rect.Width - rect.X) / 2,rdesk.Height); Win32.mouse_event(Win32.MOUSEEVENTF_MOVE, 0, -1, 0, 0); Thread.Sleep(1500); Win32.GetWindowRect(w.hWnd, ref rect); } else if (rect.X <= 0) { //左边 Win32.SetCursorPos(0, rect.Y + (rect.Height - rect.Y) / 2); Thread.Sleep(2000); Win32.mouse_event(Win32.MOUSEEVENTF_MOVE, 1, 0, 0, 0); Thread.Sleep(1500); Win32.GetWindowRect(w.hWnd, ref rect); } else if (rect.X >= rdesk.Width - 3) { //右边 Win32.SetCursorPos(rdesk.Width, rect.Y + (rect.Height - rect.Y) / 2); Thread.Sleep(2000); Win32.mouse_event(Win32.MOUSEEVENTF_MOVE, -1, 0, 0, 0); Thread.Sleep(1500); Win32.GetWindowRect(w.hWnd, ref rect); }else { Win32.MoveWindow(w.hWnd, rect.Left, 0, rect.Width - rect.Left, rect.Height - rect.Top, true); Win32.GetWindowRect(w.hWnd, ref rect); Thread.Sleep(300); } Win32.SetCursorPos(rect.X+70,rect.Height-50); Win32.mouse_event(Win32.MOUSEEVENTF_LEFTDOWN | Win32.MOUSEEVENTF_LEFTUP, 0, 0, 0, 0); Thread.Sleep(2000); break; } } //再次查找发送窗口 wins = new Windows(); foreach (Window w in wins) { if (w.Title.IndexOf("发短信") >= 0) { hwin = w.hWnd; break; } } } //查询发送窗口成功 if (hwin != IntPtr.Zero) { Win32.ShowWindow(hwin, Win32.SW_SHOWNORMAL); Win32.SetForegroundWindow(hwin); Win32.GetWindowRect(hwin, ref rect); IntPtr hwndtel = Win32.WindowFromPoint(rect.Left + 120, rect.Top + 45); IntPtr hwndsend = Win32.WindowFromPoint(rect.Left + 50, rect.Height - 60); //单击地址栏 Win32.SetCursorPos(rect.Left + 120, rect.Top + 45); Win32.mouse_event(Win32.MOUSEEVENTF_LEFTDOWN | Win32.MOUSEEVENTF_LEFTUP, 0, 0, 0, 0); Thread.Sleep(1000); //加入地址 for (int i = 0; i < addr.Length; i++) { Clipboard.SetText(addr[i]); Thread.Sleep(200); Win32.SendMessage(hwndtel, Win32.WM_PASTE, 0, 0); Thread.Sleep(300); Win32.SendMessage(hwndtel, Win32.WM_KEYDOWN, 0X0D, 0);//发 Win32.SendMessage(hwndtel, Win32.WM_KEYUP, 0X0D, 0); //送 Win32.SendMessage(hwndtel, Win32.WM_CHAR, 0X0D, 0); //回车 Thread.Sleep(300); } //加入消息文本 Clipboard.SetText(message); Thread.Sleep(200); Win32.SendMessage(hwndsend, Win32.WM_PASTE, 0, 0); Thread.Sleep(200); #if DEBUG #else if (!_TestMode) { Win32.SendMessage(hwndsend, Win32.WM_KEYDOWN, 0X0D, 0); Win32.SendMessage(hwndsend, Win32.WM_KEYUP, 0X0D, 0); Win32.SendMessage(hwndsend, Win32.WM_CHAR, 0X0D, 0); } #endif textBox1.AppendText("---------------------------------------- \n"); textBox1.AppendText(DateTime.Now + ":"+ message + "\n"); } else { textBox1.AppendText("无法打开飞信短信发送窗口\n"); } _LastSend = DateTime.Now; LastSendTime = _LastSend; }

7,763

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧