00 取消用鼠标拖动或者用键盘在编辑框中选择的文本内容

Post date: 2012/4/24 上午 06:44:59

  1. // 0x0118这个消息是MS未文档化的消息WM_SYSTIMER (caret blink)
  2. BOOL CXXDlg::PreTranslateMessage(MSG* pMsg)
  3. {
  4. // TODO: Add your specialized code here and/or call the base class
  5. CEdit* pEdit = (CEdit*)GetDlgItem(IDC_EDIT1);
  6. ASSERT(pEdit);
  7. if((0x0118 == pMsg->message) && (pMsg->hwnd == pEdit->GetSafeHwnd()))
  8. {
  9. int start = 0;
  10. int end = 0;
  11. pEdit->GetSel(start, end);
  12. if(start != end)
  13. {
  14. CPoint pt;
  15. GetCursorPos(&pt);
  16. pEdit->ScreenToClient(&pt);
  17. int nSel = LOWORD(pEdit->CharFromPos(pt));
  18. pEdit->SetSel(nSel, nSel);
  19. }
  20. }
  21. return CDialog::PreTranslateMessage(pMsg);