在编程过程中,总是会遇见弹出题为server busy的对话框,特别是在程序中加入了com组件,这种情况就更加频繁。以下几句代码就能轻松解决。
AfxOleGetMessageFilter()->EnableBusyDialog(FALSE);
AfxOleGetMessageFilter()->SetBusyReply(SERVERCALL_RETRYLATER);
AfxOleGetMessageFilter()->EnableNotRespondingDialog(TRUE);
AfxOleGetMessageFilter()->SetMessagePendingDelay((DWORD)-1);
最好用在初始化了com组件之后就是用进行设置,如我在工程中加入excel组件了,以下是我的代码,顺利通过。
LO ret = E_ERR;
::CoInitialize(0);
if (pXL != NULL)
{
pXL = NULL;
}
HRESULT hr = pXL.CreateInstance("Excel.Application");
if (SUCCEEDED(hr))
{
//pXL->Visible[0] = VARIANT_TRUE;
pXL->Visible[0] = VARIANT_FALSE;
pXL->DisplayAlerts[0] = VARIANT_FALSE;
AfxOleGetMessageFilter()->EnableBusyDialog(FALSE);
AfxOleGetMessageFilter()->SetBusyReply(SERVERCALL_RETRYLATER);
AfxOleGetMessageFilter()->EnableNotRespondingDialog(TRUE);
AfxOleGetMessageFilter()->SetMessagePendingDelay((DWORD)-1);
ret = E_OK;
}
else
{
ret = E_ERR;
}
return ret;