The source is in File dlgcore.cpp (You must have MFC - libraries installed to have this file).
Original function DoModal() from dlgcore.cpp:
int CDialog:

oModal()
{
// can be constructed with a resource template or InitModalIndirect
ASSERT(m_lpszTemplateName != NULL || m_hDialogTemplate != NULL ||
m_lpDialogTemplate != NULL);
// load resource as necessary
LPCDLGTEMPLATE lpDialogTemplate = m_lpDialogTemplate;
HGLOBAL hDialogTemplate = m_hDialogTemplate;
HINSTANCE hInst = AfxGetResourceHandle();
if (m_lpszTemplateName != NULL)
{
hInst = AfxFindResourceHandle(m_lpszTemplateName, RT_DIALOG);
HRSRC hResource = ::FindResource(hInst, m_lpszTemplateName, RT_DIALOG);
hDialogTemplate = LoadResource(hInst, hResource);
}
if (hDialogTemplate != NULL)
lpDialogTemplate = (LPCDLGTEMPLATE)LockResource(hDialogTemplate);
// return -1 in case of failure to load the dialog template resource
if (lpDialogTemplate == NULL)
return -1;
// disable parent (before creating dialog)
HWND hWndParent = PreModal();
AfxUnhookWindowCreate();
BOOL bEnableParent = FALSE;
if (hWndParent != NULL && ::IsWindowEnabled(hWndParent))
{
::EnableWindow(hWndParent, FALSE);
bEnableParent = TRUE;
}
TRY
{
// create modeless dialog
AfxHookWindowCreate(this);
if (CreateDlgIndirect(lpDialogTemplate,
CWnd::FromHandle(hWndParent), hInst))
{
if (m_nFlags & WF_CONTINUEMODAL)
{
// enter modal loop
DWORD dwFlags = MLF_SHOWONIDLE;
if (GetStyle() & DS_NOIDLEMSG)
dwFlags |= MLF_NOIDLEMSG;
VERIFY(RunModalLoop(dwFlags) == m_nModalResult);
}
// hide the window before enabling the parent, etc.
if (m_hWnd != NULL)
SetWindowPos(NULL, 0, 0, 0, 0, SWP_HIDEWINDOW|
SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOZORDER);
}
}
CATCH_ALL(e)
{
DELETE_EXCEPTION(e);
m_nModalResult = -1;
}
END_CATCH_ALL
if (bEnableParent)
::EnableWindow(hWndParent, TRUE);
if (hWndParent != NULL && ::GetActiveWindow() == m_hWnd)
::SetActiveWindow(hWndParent);
// destroy modal window
DestroyWindow();
PostModal();
// unlock/free resources as necessary
if (m_lpszTemplateName != NULL || m_hDialogTemplate != NULL)
UnlockResource(hDialogTemplate);
if (m_lpszTemplateName != NULL)
FreeResource(hDialogTemplate);
return m_nModalResult;
}
bEnableParent was in original source code. You can use it for disabling/enabling Your windows or comment it out.
AfxUnhookWindowCreate() You can try to comment out, if You can't use it on Your plattform.
It is not too easy at all. I have used it for an application, but I'm afraid, if I send You code I used, You will have more Questions. Please, You can see it:
int CShowDlg:

oModal()
{
// can be constructed with a resource template or InitModalIndirect
ASSERT(m_lpszTemplateName != NULL || m_hDialogTemplate != NULL ||
m_lpDialogTemplate != NULL);
// load resource as necessary
LPCDLGTEMPLATE lpDialogTemplate = m_lpDialogTemplate;
HGLOBAL hDialogTemplate = m_hDialogTemplate;
HINSTANCE hInstSave = afxCurrentInstanceHandle;
// HINSTANCE hInst = AfxGetResourceHandle();
AfxSetResourceHandle(m_Hinst);
HINSTANCE hInst = AfxGetResourceHandle();
if (m_lpszTemplateName != NULL)
{
hInst = AfxFindResourceHandle(m_lpszTemplateName, RT_DIALOG);
HRSRC hResource = ::FindResource(hInst, m_lpszTemplateName, RT_DIALOG);
hDialogTemplate = LoadResource(hInst, hResource);
}
if (hDialogTemplate != NULL)
lpDialogTemplate = (LPCDLGTEMPLATE)LockResource(hDialogTemplate);
// return -1 in case of failure to load the dialog template resource
if (lpDialogTemplate == NULL) {
afxCurrentInstanceHandle=hInstSave;
AfxSetResourceHandle(hInstSave);
return -1;
}
HWND hWndParent = PreModal();
AfxUnhookWindowCreate();
CWnd* pParentWnd = CWnd::FromHandle(hWndParent);
// BOOL bEnableParent = FALSE;
//Disable only main Window
if(AfxGetMainWnd()) {
if

:IsWindowEnabled( AfxGetMainWnd()->m_hWnd)) {
//Disable Main Window
::EnableWindow( AfxGetMainWnd()->m_hWnd, FALSE);
}
}
//Enable Parent
if (hWndParent != NULL /*&& ::IsWindowEnabled(hWndParent)*/)
{
::EnableWindow(hWndParent, TRUE);
// bEnableParent = TRUE;
}
TRY
{
// create modeless dialog
AfxHookWindowCreate(this);
m_pDialog = this;
if(AfxGetMainWnd())
((CMainFrame*)AfxGetMainWnd())->m_pShowDlg = m_pDialog;
if ( CreateDlgIndirect(lpDialogTemplate, CWnd::FromHandle(hWndParent), m_Hinst)
|| CreateDlgIndirect(lpDialogTemplate, CWnd::FromHandle(hWndParent), hInst)
|| CreateDlgIndirect(lpDialogTemplate, CWnd::FromHandle(hWndParent), hInstSave))
{
if (m_nFlags & WF_CONTINUEMODAL)
{
// enter modal loop
DWORD dwFlags = MLF_SHOWONIDLE;
if (GetStyle() & DS_NOIDLEMSG)
dwFlags |= MLF_NOIDLEMSG;
// ModifyStyle( WS_CHILDWINDOW | WS_DISABLED |WS_DLGFRAME ,0);
ModifyStyle( WS_CHILD | WS_CHILDWINDOW | WS_DISABLED |WS_DLGFRAME ,
WS_POPUPWINDOW|WS_CAPTION | WS_OVERLAPPED | DS_NOFAILCREATE|DS_NOIDLEMSG, SWP_NOSIZE );
ModifyStyleEx(WS_EX_TOOLWINDOW | WS_EX_MDICHILD |WS_EX_DLGMODALFRAME, WS_EX_NOPARENTNOTIFY , 0);
ShowWindow( SW_SHOWNORMAL);
ShowWindow( SW_HIDE);
if(AfxGetMainWnd()) {
RECT Rect;
AfxGetMainWnd()->GetUpdateRect( &Rect, FALSE );
AfxGetMainWnd()->RedrawWindow(&Rect);
}
ShowWindow( SW_SHOWNORMAL);
ShowOwnedPopups(TRUE );
EnableWindow( TRUE );
SetActiveWindow( );
//Restore Instance Handle
afxCurrentInstanceHandle=hInstSave;
AfxSetResourceHandle(hInstSave);
VERIFY(RunModalLoop(dwFlags) == m_nModalResult);
}
// hide the window before enabling the parent, etc.
if (m_hWnd != NULL) {
SetWindowPos(NULL, 0, 0, 0, 0, SWP_HIDEWINDOW|
SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOZORDER);
}
}
else {
m_nModalResult = -1;
}
}
CATCH_ALL(e)
{
delete e;
// DELETE_EXCEPTION(e);
m_nModalResult = -1;
}
END_CATCH_ALL
//Restore Instance Handle
afxCurrentInstanceHandle=hInstSave;
AfxSetResourceHandle(hInstSave);
// if (bEnableParent)
::EnableWindow(hWndParent, TRUE);
if (hWndParent != NULL && ::GetActiveWindow() == m_hWnd)
::SetActiveWindow(hWndParent);
// destroy window
DestroyWindow();
PostModal();
// unlock/free resources as necessary
if (m_lpszTemplateName != NULL || m_hDialogTemplate != NULL)
UnlockResource(hDialogTemplate);
if (m_lpszTemplateName != NULL)
FreeResource(hDialogTemplate);
if(m_pDialog == this) {
m_pDialog = NULL;
if(AfxGetMainWnd())
((CMainFrame*)AfxGetMainWnd())->m_pShowDlg = NULL;
}
return m_nModalResult;
}