Rich Edit Control 改变了DialogBox 返回值行为?
我有点困惑:我用编辑控件
创建了一个对话框,然后我注意到文本没有自动换行,所以我用谷歌搜索并发现我应该使用Rich Edit Control< /代码> 相反。所以我做到了。现在,只要我的对话框中存在
Rich Edit Control
,功能就会发生变化:如果没有 Rich Edit Control
,对话框将返回 IDOK
或IDCANCEL
,我在消息处理程序代码之外处理它。但是,如果对话框中的任何位置有 Rich Edit Control
,它总是返回 IDOK
以外的内容,甚至在我单击对话框中的任何按钮之前:对话框似乎甚至根本不被创造。
这是消息处理程序:
INT_PTR CALLBACK MyDialogBox(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam){
switch(message){
case WM_INITDIALOG: {
SetDlgItemText(hDlg, IDC_EDIT1, (LPCTSTR)some_string.c_str());
return (INT_PTR)TRUE;
}
case WM_COMMAND:
switch(LOWORD(wParam)){
case IDOK: case IDCANCEL: {
EndDialog(hDlg, LOWORD(wParam));
return (INT_PTR)TRUE;
}
}
break;
}
return (INT_PTR)FALSE;
}
这是我使用对话框的代码:
if(DialogBox(hInstance, MAKEINTRESOURCE(IDD_DIALOG1), hWnd, MyDialogBox) == IDOK){
// without rich edit control it goes here or below depending on the user choice.
}else{
// with rich edit it always goes here.
}
所以,这里的最终问题是:我如何让这个东西像正常的 Edit Control
一样工作?
编辑:失败时,值为:DialogBox() 为 -1,GetLastError() 为 0,如果有帮助的话?
编辑2: Antinome的链接:包含 afxwin.h
并调用窗口WM_CREATE
消息中的AfxInitRichEdit2()
。
I'm a bit puzzled: i created a dialogbox with Edit Control
, then i noticed the text isn't word wrapped, so i googled and found out that i should use Rich Edit Control
instead. So i did. Now, when ever there is a Rich Edit Control
in my dialog box, the functionality changes: without Rich Edit Control
the dialogbox returned either IDOK
or IDCANCEL
, which i handle outside of the message handler code. BUT, if there is a Rich Edit Control
anywhere in the dialogbox, it always returns something else than IDOK
, before i even click any buttons in the dialog box: the dialogbox seems to not even be created at all.
Here is the message handler:
INT_PTR CALLBACK MyDialogBox(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam){
switch(message){
case WM_INITDIALOG: {
SetDlgItemText(hDlg, IDC_EDIT1, (LPCTSTR)some_string.c_str());
return (INT_PTR)TRUE;
}
case WM_COMMAND:
switch(LOWORD(wParam)){
case IDOK: case IDCANCEL: {
EndDialog(hDlg, LOWORD(wParam));
return (INT_PTR)TRUE;
}
}
break;
}
return (INT_PTR)FALSE;
}
And here is the code where i use the dialogbox:
if(DialogBox(hInstance, MAKEINTRESOURCE(IDD_DIALOG1), hWnd, MyDialogBox) == IDOK){
// without rich edit control it goes here or below depending on the user choice.
}else{
// with rich edit it always goes here.
}
So, the ultimate question here is: how do i get this thing work like it works with normal Edit Control
?
Edit: when it fails, the values are: -1 for DialogBox(), and 0 for GetLastError(), if that helps ?
Edit2: Problem solved by antinome's link: include afxwin.h
and call AfxInitRichEdit2()
at the window WM_CREATE
message.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
此线程 有一些解决这个问题的好技巧。总结一下:
如果使用纯 WinAPI:
LoadLibrary("RichEd20.dll");
或LoadLibrary("Msftedit.dll");
。后者是该控件的较新版本。如果使用 MFC:
AfxInitRichEdit2()
,例如在InitInstance()
中This thread has some good tips for resolving this problem. To summarize:
If using pure WinAPI:
LoadLibrary("RichEd20.dll");
orLoadLibrary("Msftedit.dll");
. The latter is the newer version of the control.InitCommonControlsEx()
with the appropriate class constant (MSFTEDIT_CLASS
apparently) — but it's only needed if you want windows visual styles to work.If using MFC:
AfxInitRichEdit2()
at initialization stage, for example inInitInstance()