我的问题主要是希望能通过敲击键盘的ENTER键实现:在对话框中,光标从一个编辑框跳到另一个编辑框,并且把刚跳至的那个编辑框里的内容用蓝色的高亮矩形盖住,以方便全部修改。这个效果我们都见过很多的,可是我不知道该如何去做。请指教,谁给出关键代码,必重酬!!!

解决方案 »

  1.   

    响应第一个编辑框的WM_CHAR判断是否为enter
    若是SetFocus第二个编辑框
    然后发EM_SETSEL到第二个编辑框
      

  2.   

    EM_SETSEL
    The EM_SETSEL message selects a range of characters in an edit control. You can send this message to either an edit control or a rich edit control.To send this message, call the SendMessage function with the following parameters. SendMessage( 
      (HWND) hWnd,              // handle to destination window 
      EM_SETSEL,                // message to send
      (WPARAM) wParam,          // starting position
      (LPARAM) lParam          // ending position
    );
    Parameters
    wParam 
    Specifies the starting character position of the selection. 
    lParam 
    Specifies the ending character position of the selection. 
    Return Values
    This message does not return a value. Res
    The start value can be greater than the end value. The lower of the two values specifies the character position of the first character in the selection. The higher value specifies the position of the first character beyond the selection. The start value is the anchor point of the selection, and the end value is the active end. If the user uses the SHIFT key to adjust the size of the selection, the active end can move but the anchor point remains the same.If the start is 0 and the end is –1, all the text in the edit control is selected. If the start is –1, any current selection is deselected. Edit controls: The control displays a flashing caret at the end position regardless of the relative values of start and end.
      

  3.   

    不好意思,我还是看不懂。我试过了,编辑框好像没有WM_CHAR和EM_SETSEL啊。
    而且我对对话框设定了ON_KEYDOWN ,连加速键都加上去了,但我在编辑框输入完后按回车仍是毫无反应,该如何是好呢,我急死了,请快救救我吧。
      

  4.   

    假设你的对话框为CDLG1,第一个EDIT框 ID为ID_EDIT1,第二个ID为ID_EDIT2:
    BOOL CDlg1::PreTranslateMessage(MSG* pMsg) 
    {
      if(pMsg->message == WM_KEYDOWN)
        if(int(pMsg->wParam) == VK_RETURN)
        {
          ((CEdit*)GetDlgItem(ID_EDIT2))->SetFocus();
          ((CEdit*)GetDlgItem(ID_EDIT2))->SetSel(0,-1);
          return TRUE;
        } 
      return CDialog::PreTranslateMessage(pMsg);
    }这里实现的是只要你回车就选种EDIT2的全部文本,你可以对其进行
    适当修改。
      

  5.   

    可是为什么在 class wizard 中对话框中有 keydown 事件,可是等我连上代码对话框又根本不响应呢。至于编辑框,事件本就少得可怜,我也不敢指望它能不通过对话框直接响应太多的键盘事件。对吗。