INT_PTR XX::DoModal( LPCWSTR lpszXmlId, HWND hParent /*=NULL*/ , bool bShadow /*=false*/ , DM::CRect rect /* = NULL*/ )
{
BOOL bEnableParent = FALSE;
if (NULL == hParent)
{
hParent = GetActiveWnd();
}
if (hParent && hParent != ::GetDesktopWindow() && ::IsWindowEnabled(hParent))
{
::EnableWindow(hParent, FALSE);
bEnableParent = TRUE;
}
if (!DM_CreateWindow(lpszXmlId, rect.left,rect.top,rect.Width(),rect.Height(), hParent, bShadow))
{
::EnableWindow(hParent, TRUE);
return 0; // 此处失败了
}
GetClientRect(rect);
if (!rect.IsRectEmpty())
{
CenterWindow();
}
SendMessage(WM_INITDIALOG); //发送init消息
if (GetExStyle()&WS_EX_TOOLWINDOW)
{
::ShowWindow(m_hWnd,SW_SHOWNOACTIVATE);
}
else
{
::ShowWindow(m_hWnd,SW_SHOWNORMAL);
}
::SetWindowPos(m_hWnd, /*HWND_TOP*/ HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | SWP_SHOWWINDOW);
Run(m_hWnd, true ); // 消息循环
if (bEnableParent)
{
::EnableWindow(hParent, TRUE);
}
return m_nRetCode;
}
void XX::EndDialog( INT_PTR nResult )
{
m_nRetCode = nResult;
PostMessage(WM_QUIT);
}
|