So, I want to show the user CDialog:
void CMeetingScheduleAssistantDlg::OnOptionsOutlookCalendarOptions()
{
COutlookCalendarSettingsDlg dlgSettings(this);
dlgSettings.DoModal();
}
Now the popup dialog (in OnInitDialog) launches the console application backstage. This console application interacts with Microsoft graphics .
As a result, it may take several seconds to display the dialog box.
I am launching a console application using this method:
bool CMeetingScheduleAssistantApp::ExecuteProgram(CString strCommand, DWORD& rExitCode)
{
PROCESS_INFORMATION processInformation = { nullptr };
STARTUPINFO startupInfo = { 0 };
int nStrBuffer;
BOOL bProcessResult, bExitCodeProcess;
bool bOK = false;
CWaitCursor wait;
SetProgramExecuting(true);
rExitCode = -1;
startupInfo.cb = sizeof(startupInfo);
nStrBuffer = strCommand.GetLength() + 50;
bProcessResult = CreateProcess(nullptr, strCommand.GetBuffer(nStrBuffer),
nullptr, nullptr, FALSE,
NORMAL_PRIORITY_CLASS | CREATE_NO_WINDOW,
nullptr, nullptr, &startupInfo, &processInformation);
strCommand.ReleaseBuffer();
if (!bProcessResult)
{
LPVOID lpMsgBuf;
DWORD dw = GetLastError();
FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
nullptr, dw, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR)&lpMsgBuf, 0, nullptr);
CString strError = (LPTSTR)lpMsgBuf;
TRACE(_T("Authenticate failed at CreateProcess()\nCommand=%s\nMessage=%s\n\n"), strCommand, strError);
LocalFree(lpMsgBuf);
SetProgramExecuting(false);
return false;
}
else
{
DWORD WaitResult;
do
{
WaitResult = MsgWaitForMultipleObjects(1,
&processInformation.hProcess,
FALSE,
INFINITE,
QS_ALLINPUT);
if (WaitResult == WAIT_OBJECT_0 + 1)
{
MSG Msg;
while (PeekMessage(&Msg, nullptr, 0, (UINT)-1, PM_REMOVE))
{
TRACE3("%d %d %d\n", Msg.message, Msg.wParam, Msg.lParam);
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
}
} while (WaitResult != WAIT_OBJECT_0);
ASSERT(WaitResult == WAIT_OBJECT_0);
bExitCodeProcess = GetExitCodeProcess(processInformation.hProcess, &rExitCode);
CloseHandle(processInformation.hProcess);
CloseHandle(processInformation.hThread);
if (!bExitCodeProcess)
{
TRACE(_T("Executed command but couldn't get exit code.\nCommand=%s\n"), strCommand);
SetProgramExecuting(false);
return false;
}
SetProgramExecuting(false);
return true;
}
}
Inside OnInitDialog, just before the call, ExecuteProgramI tried to use:
CWaitCursor wait;
But it does not matter. So, how can I show the wait cursor from the moment I call the popup dialog until the dialog is visible to the user?