1。如何响应用户按下回车以及 Ctrl+Enter?(要能够区分)
2。如何插入一个段字符串,且要求字符串有自己的字体和颜色。万分感谢~

解决方案 »

  1.   

    1:BOOL CTest6Dlg::PreTranslateMessage(MSG* pMsg) 
    {
    if( pMsg->message == WM_KEYDOWN )
    {   
    if(pMsg->hwnd == GetDlgItem(IDC_RICHEDIT1)->m_hWnd)
    {
    switch( pMsg->wParam )
    case VK_RETURN:
    if(::GetKeyState(VK_CONTROL) < 0)//control+enter
      {
    AfxMessageBox("ctrl+enter");
    }
    else
    AfxMessageBox("enter");
    return TRUE;
    case VK_ESCAPE:
    AfxMessageBox("esc");
    return TRUE;
    }
    }
    }
    return CDialog::PreTranslateMessage(pMsg);
    }
      

  2.   

    2.给选定区域着色
    CFont font;CHARFORMAT cf;
    cf.cbSize = sizeof(CHARFORMAT);
    cf.dwMask = CFM_BOLD | CFM_COLOR | CFM_FACE |CFM_ITALIC | CFM_SIZE | CFM_UNDERLINE;
    cf.dwEffects = CFM_BOLD | CFM_COLOR | CFM_FACE |CFM_ITALIC | CFM_SIZE | CFM_UNDERLINE;
            cf.yHeight = 100;//高度
    cf.crTextColor = RGB(200, 100, 255);//颜色
            strcpy(cf.szFaceName ,_T("宋体"));//字体m_richedit1.SetSel(1, 5);
    m_richedit1.SetSelectionCharFormat(cf);