如何让 CMFCRibbonEdit 自动将内容转换为大写?

发布于 2024-09-19 11:01:39 字数 1071 浏览 4 评论 0原文

我正在 Visual Studio 2008 中使用 MFC 功能包。我在功能区中有一个编辑框 (CMFCRibbonEdit),我只想包含大写字母。我知道我可以将 ES_UPPERCASE 传递给“Create”方法,但是“Create”是从功能区本身调用的,而不是由我的代码显式调用的。

要将编辑框添加到我的功能区,我称之为:

CMFCRibbonPanel* pPanel = pCategoryViewer->AddPanel("Panel Title");
CMFCRibbonEdit *cEdit = new CMFCRibbonPanel( ID_MYEDITBOX, 60, "Edit Title" );
pPanel->Add( cEdit );

根据我在 MSDN 上阅读的内容,我发现我可以重载 CMFCRibbonEdit 的“CreateEdit”函数。我尝试过,但没有成功。

class UpperCaseRibbonEdit : public CMFCRibbonEdit
{
public:
  UpperCaseRibbonEdit( UINT nID, int nWidth, LPCTSTR lpszLabel )
    :CMFCRibbonEdit( nID, nWidth, lpszLabel )
  {}

  CMFCRibbonRichEditCtrl* CreateEdit( CWnd* pWndParent, DWORD dwEditStyle )
  {
    return CMFCRibbonEdit::CreateEdit( pWndParent, dwEditStyle | ES_UPPERCASE );
  }
};

我还尝试在初始化功能区及其控件后进行此调用。这也行不通。

HWND editHwnd = GetDlgItem( ID_MYEDITBOX )->GetSafeHwnd();
SetWindowLong(editHwnd, GWL_STYLE, (LONG)GetWindowLong(editHwnd, GWL_STYLE) | ES_UPPERCASE);

有谁知道我怎样才能做到这一点?

I am using the MFC Feature pack in Visual Studio 2008. I have an edit box (CMFCRibbonEdit) in a ribbon that I would like only to contain uppercase letters. I know that I can pass ES_UPPERCASE to the "Create" method, however "Create" is called from the Ribbon itself, and not explicitly by my code.

To add the edit box to my ribbon, I call this:

CMFCRibbonPanel* pPanel = pCategoryViewer->AddPanel("Panel Title");
CMFCRibbonEdit *cEdit = new CMFCRibbonPanel( ID_MYEDITBOX, 60, "Edit Title" );
pPanel->Add( cEdit );

Based on what I read on MSDN I saw I could overload the "CreateEdit" function of CMFCRibbonEdit. I tried that, but it didn't work.

class UpperCaseRibbonEdit : public CMFCRibbonEdit
{
public:
  UpperCaseRibbonEdit( UINT nID, int nWidth, LPCTSTR lpszLabel )
    :CMFCRibbonEdit( nID, nWidth, lpszLabel )
  {}

  CMFCRibbonRichEditCtrl* CreateEdit( CWnd* pWndParent, DWORD dwEditStyle )
  {
    return CMFCRibbonEdit::CreateEdit( pWndParent, dwEditStyle | ES_UPPERCASE );
  }
};

I also tried making this call after initializing my ribbon and its controls. This didn't work either.

HWND editHwnd = GetDlgItem( ID_MYEDITBOX )->GetSafeHwnd();
SetWindowLong(editHwnd, GWL_STYLE, (LONG)GetWindowLong(editHwnd, GWL_STYLE) | ES_UPPERCASE);

Does anyone know how I could accomplish this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

天冷不及心凉 2024-09-26 11:01:39

我想您已经知道,CMFCRibbonEdit 内部有一个成员变量 CMFCRibbonRichEditCtrl* m_pWndEdit;,该类型是 CRichEditCtrl 的后代。因此,正如 @Stanich 页面的评论所述,不支持 ES_UPPERCASE。

我想你最好的选择是:在你的派生类中,你不要忘记将 ON_CONTROL_REFLECT(EN_CHANGE, OnChange) 放在消息映射中;并寻找基类原始代码:

void CMFCRibbonRichEditCtrl::OnChange()
{
    CString strText;
    GetWindowText(strText);

    m_edit.m_strEdit = strText;
    m_edit.SetEditText(strText);
}

将 GetWindowText 行之后的 strText 更改为全部大写字母。

As I think you already know, CMFCRibbonEdit has inside a member variable CMFCRibbonRichEditCtrl* m_pWndEdit; which type that is descendant of CRichEditCtrl. So, as the page @Stanich's comment states ES_UPPERCASE is not supported for it.

I guess your best option is: in your derived class you do not forget to put ON_CONTROL_REFLECT(EN_CHANGE, OnChange) in the message map; and looking for the base class original code:

void CMFCRibbonRichEditCtrl::OnChange()
{
    CString strText;
    GetWindowText(strText);

    m_edit.m_strEdit = strText;
    m_edit.SetEditText(strText);
}

change strText in yours to be all caps letters after the GetWindowText line.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文