我正在开发一个Notepad ++插件。
我有一个简单的对话框,使用CreateDialogParam()
创建。它最初是隐藏的。
点击菜单后,我会在其句柄上调用ShowWindow()
SW_SHOW
,这会导致此异常:
c000041d
调试后,我发现这两条消息在崩溃之前就被发送到了我的对话框
WM_SHOWWINDOW
WM_WINDOWPOSCHANGING
他们两个,我没有处理。这是我的dlgproc代码。知道为什么会这样吗?
BOOL CALLBACK StaticDialog::dlgProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_INITDIALOG :
{
// Get the additional init data
StaticDialog *pStaticDlg = (StaticDialog *)(lParam);
// Store the handle in the object
pStaticDlg->_hSelf = hwnd;
::SetWindowLongPtr(hwnd, GWL_USERDATA, (long)lParam);
// Store the co-ordinates in the object
::GetWindowRect(hwnd, &(pStaticDlg->_rc));
// Forward the message for further processing
pStaticDlg->run_dlgProc(message, wParam, lParam);
// TRUE if it processed the message
return TRUE;
}
default :
{
// Retrieve the user data
StaticDialog *pStaticDlg = (StaticDialog *)(::GetWindowLongPtr(hwnd, GWL_USERDATA));
if (!pStaticDlg)
return FALSE;
// Send the message for further processing
return pStaticDlg->run_dlgProc(message, wParam, lParam);
// return FALSE if it processed the message
}
}
}
BOOL CALLBACK MarkDownViewDialog::run_dlgProc( UINT Message, WPARAM wParam, LPARAM lParam)
{
switch (Message)
{
case WM_INITDIALOG:
{
EmbedBrowserObject(this->_hSelf);
DisplayHTMLPage(this->_hSelf,L"http://www.microsoft.com");
DisplayHTMLStr(this->_hSelf, L"<H2><CENTER>HTML string test</CENTER></H2><P><FONT COLOR=RED>This is a <U>HTML string</U> in memory.</FONT>");
break;
}
default:
break;
}
return FALSE;
}
该对话框是通过Notpead ++的插件机制创建的。我从其文件StaticDialog.cpp中提取源代码。该控件在下面的代码中经过else
块。
void StaticDialog::create(int dialogID, bool isRTL, bool isModeles)
{
if (isRTL)
{
DLGTEMPLATE *pMyDlgTemplate = NULL;
HGLOBAL hMyDlgTemplate = makeRTLResource(dialogID, &pMyDlgTemplate);
_hSelf = ::CreateDialogIndirectParam(_hInst, pMyDlgTemplate, _hParent, (DLGPROC)dlgProc, (LPARAM)this);
::GlobalFree(hMyDlgTemplate);
}
else
_hSelf = ::CreateDialogParam(_hInst, MAKEINTRESOURCE(dialogID), _hParent, (DLGPROC)dlgProc, (LPARAM)this);
//int i=GetLastError();
if (!_hSelf)
{
//systemMessage(_T("StaticDialog"));
return;
}
if (isModeles) {
_isModeles = isModeles;
::SendMessage(_hParent, NPPM_MODELESSDIALOG, MODELESSDIALOGADD, (WPARAM)_hSelf);
}
}
我的整个解决方案源代码都在这里托管: https://github.com/madhur/Npp-Markdown-Viewer
以下是我为解决问题所做的工作:
创建了一个Win32项目,在其中我创建了一个对话框,并将完全相同的源代码嵌入到WM_INITDIALOG中的浏览器控件中,并且它可以正常工作。此Win32项目链接到原始源代码链接的相同静态库。这是示例项目邮件文件的来源:
https://github.com/madhur/Npp-Markdown-Viewer/blob/master/dll/example/example.c
我在上面引用的静态库只不过是它包含在HWND中嵌入浏览器控件并呈现URL或字符串的函数。我从这里采取了来源:http://www.codeguru.com/Cpp/I-N/ieprogram/article.php/c4379
这是静态库主文件的来源:
https://github.com/madhur/Npp-Markdown-Viewer/blob/master/dll/dll.c
如果我评论这一行,该插件可以正常工作,基本上它会加载没有浏览器控件的对话框:
EmbedBrowserObject(这 - &GT; _hSelf);
此行引发了Visual Studio中的实际异常:
返回pStaticDlg-&gt; run_dlgProc(message,wParam,lParam);