企业🤖AI Agent构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
### 复制粘贴 ***** [原文](http://www.voidcn.com/article/p-tutainvk-bht.html) 右键类向导 虚函数PreTranslateMessage ```c++ BOOL CCustomizedListCtrl::CListEditor::PreTranslateMessage(MSG* pMsg) { // 编辑框快捷键操作 if(WM_KEYDOWN == pMsg->message) { if(::GetFocus() == m_hWnd && (GetKeyState( VK_CONTROL) & 0xFF00 ) == 0xFF00) { // 全选 if( pMsg->wParam == 'A' || pMsg->wParam == 'a') { this->SetSel(0, -1); return true; } // 拷贝 if( pMsg->wParam == 'C' || pMsg->wParam == 'c') { this->Copy(); return true; } // 剪切 if( pMsg->wParam == 'X' || pMsg->wParam == 'x') { this->Cut(); return true; } // 粘贴 if( pMsg->wParam == 'V' || pMsg->wParam == 'v') { this->Paste(); return true; } // 粘贴 if( pMsg->wParam == 'Z' || pMsg->wParam == 'z') { this->Undo(); return true; } } } return CEdit::PreTranslateMessage(pMsg); } ``` ![](https://box.kancloud.cn/656fb66375ec7e9afc679bb5e8a911b8_784x390.png) 一开始实现时,编辑列表项不能捕捉焦点,后在google代码搜索中搜关键字PreTranslateMessage,才知道没加一个判断条件,::GetFocus() == m_hWnd。 ### 失去焦点 ***** 失去焦点的是WM_KILLFOCUS,重载OnKillFocus(CWnd* pNewWnd) 获取焦点的是WM_SETFOCUS,或者调用::SetFocus(HWND hwnd)把焦点设到某个控件上 ### 禁用标题拖动窗口 ***** ``` void CTestThreadDlg::OnNcLButtonDown(UINT nHitTest, CPoint point) { // TODO: Add your message handler code here and/or call default if (HTCAPTION == nHitTest) { return; } CDialog::OnNcLButtonDown(nHitTest, point); } ``` ### 进制拖拽窗口改变窗口大小 ***** 也可以用 OnNcHitest虚函数试试 可以查看 HTBORDER 这个宏(在没有大小边框的窗口的边框中) 可以根据不同的宏实现不同的意思,可以使用help library ```c++ void CSingleListDlg::OnNcLButtonDown(UINT nHitTest, CPoint point) { // TODO: 在此添加消息处理程序代码和/或调用默认值 if (HTCAPTION == nHitTest || HTBORDER == nHitTest) { return ; } __super::OnNcLButtonDown(nHitTest, point); } ``` ### 禁止输入中文 ***** **MFC禁止输入中文** ``` 1.stdafx.h 中 //禁止中文输入法 #include <imm.h> #pragma comment (lib ,"imm32.lib") //可以选择不引入库 2.InitInstance()中 在中上添加 也就是在注册其他东西前添加 //禁用中文输入法方法 ImmDisableIME(GetCurrentThreadId()); 3.获取控件焦点 SetFocus()中 HWND hwnd = this->m_hWnd; HIMC hi = ImmGetContext(hwnd); if (hi != NULL) { ImmAssociateContext(hwnd, nullptr);//禁用 ImmReleaseContext(hwnd, hi); } 4.释放 if (hi != NULL) { ImmDestroyContext(hi); hi = nullptr; } ``` **注意禁用跟启用是配合来用的** ``` HIMC hi = ImmAssociateContext(hwnd, nullptr);//禁用 ImmAssociateContext(OldHwnd, m_bHi);//启用 ```