如何让 CMFCRibbonEdit 自动将内容转换为大写?
我正在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我想您已经知道,CMFCRibbonEdit 内部有一个成员变量
CMFCRibbonRichEditCtrl* m_pWndEdit;
,该类型是 CRichEditCtrl 的后代。因此,正如 @Stanich 页面的评论所述,不支持 ES_UPPERCASE。我想你最好的选择是:在你的派生类中,你不要忘记将
ON_CONTROL_REFLECT(EN_CHANGE, OnChange)
放在消息映射中;并寻找基类原始代码:将 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:change strText in yours to be all caps letters after the GetWindowText line.