大家都知道弹出模式对话框(CDialog), 有谁知道如何产生 弹出模式CFrameWnd(他是个CFrameWnd, 不过弹出后, 会锁定母CFrameWnd) 多多UP

code_cold 2002-07-03 02:34:42
大家都知道弹出模式对话框(CDialog), 有谁知道如何产生 弹出模式CFrameWnd(他是个CFrameWnd, 不过弹出后, 会锁定母CFrameWnd)
...全文
131 28 打赏 收藏 转发到动态 举报
写回复
用AI写文章
28 条回复
切换为时间正序
请发表友善的回复…
发表回复
code_cold 2002-07-08
  • 打赏
  • 举报
回复
// 感谢各位, 谢谢redfire提供的代码, 下面是经测试没问题的代码

void CModalView::OnLButtonDblClk(UINT nFlags, CPoint point)
{
TRACE(_T("Create the populate wnd\n"));

CCreateContext context;
context.m_pNewViewClass = RUNTIME_CLASS(CMyView);
context.m_pCurrentDoc = NULL;

CModalFrame* pFrame = new CModalFrame;
pFrame->Create(NULL, _T("Modal frame"), WS_OVERLAPPEDWINDOW | WS_VISIBLE, CFrameWnd::rectDefault,
AfxGetMainWnd(), NULL, 0, &context);
pFrame->InitialUpdateFrame(NULL, TRUE); // Make to call CView::OnInitialUpdate()

// pFrame->ShowWindow(SW_SHOW);
// pFrame->UpdateWindow();

AfxGetMainWnd()->EnableWindow(FALSE);
pFrame->RunModalLoop(MLF_SHOWONIDLE);

pFrame->PostMessage(WM_DESTROY);

AfxGetMainWnd()->EnableWindow();
AfxGetMainWnd()->SetActiveWindow();

// CView::OnLButtonDblClk(nFlags, point);
}
code_cold 2002-07-08
  • 打赏
  • 举报
回复
// 感谢各位, 谢谢redfire提供的代码, 下面是经测试没问题的代码

void CModalView::OnLButtonDblClk(UINT nFlags, CPoint point)
{
TRACE(_T("Create the populate wnd\n"));

CCreateContext context;
context.m_pNewViewClass = RUNTIME_CLASS(CMyView);
context.m_pCurrentDoc = NULL;

CModalFrame* pFrame = new CModalFrame;
pFrame->Create(NULL, _T("Modal frame"), WS_OVERLAPPEDWINDOW | WS_VISIBLE, CFrameWnd::rectDefault,
AfxGetMainWnd(), NULL, 0, &context);
pFrame->InitialUpdateFrame(NULL, TRUE); // Make to call CView::OnInitialUpdate()

// pFrame->ShowWindow(SW_SHOW);
// pFrame->UpdateWindow();

AfxGetMainWnd()->EnableWindow(FALSE);
pFrame->RunModalLoop(MLF_SHOWONIDLE);

pFrame->PostMessage(WM_DESTROY);

AfxGetMainWnd()->EnableWindow();
AfxGetMainWnd()->SetActiveWindow();

// CView::OnLButtonDblClk(nFlags, point);
}
zhangdaqiang 2002-07-05
  • 打赏
  • 举报
回复
这个例子行
CReportErrorDlg::OnSend()
{
CWhatWereYouDoingDlg dlg1(this);
dlg1.m_strString = m_strWhatWereYouDoing;
if(dlg1.DoModal() == IDOK)
{
m_strWhatWereYouDoing = dlg1.m_strString;
HINSTANCE hMail = NULL;
hMail = ::LoadLibraryA("MAPI32.DLL");
if (hMail == NULL)
{
AfxMessageBox(AFX_IDP_FAILED_MAPI_LOAD); return;
}
ASSERT(hMail != NULL);

ULONG (PASCAL *lpfnSendMail)(ULONG, ULONG, MapiMessage*, FLAGS, ULONG);
(FARPROC&)lpfnSendMail = GetProcAddress(hMail, "MAPISendMail");
if(lpfnSendMail == NULL)
{
AfxMessageBox(AFX_IDP_INVALID_MAPI_DLL); return;
}
ASSERT(lpfnSendMail != NULL);

// make a recipient
MapiRecipDesc rec;

char szRName[] = "Clever Programmer";
char szRAddress[] = "SMTP:sendyourerrorsto@yourcompanynotmine.com";
memset(&rec, 0, sizeof(rec));
rec.ulRecipClass = MAPI_TO;
rec.lpszName = szRName;
rec.lpszAddress = szRAddress;

char szSubject[] = "An exception has occurred";

// prepare the message
------------------------

MapiMessage message;
memset(&message, 0, sizeof(message));

message.nRecipCount = 1;
message.lpRecips = &rec;
message.lpszSubject = szSubject;

CString s =m_strWhatWereYouDoing;
s +="\n";
PrepareErrorMessage(s);

message.lpszNoteText = s.GetBuffer(s.GetLength());

// prepare for modal dialog box
AfxGetApp()->EnableModeless(FALSE);
HWND hWndTop;
CWnd* pParentWnd= CWnd::GetSafeOwner(NULL, &hWndTop);

// some extra precautions are required to use
//MAPISendMail as it tends to enable the parent
// window in between dialogs (after the login
// dialog, but before the send not dialog).
pParentWnd->SetCapture();
::SetFocus(NULL);
pParentWnd->m_nFlags |= WF_STAYDISABLED;



int nError =lpfnSendMail(0, (ULONG)pParentWnd->GetSafeHwnd(),
&message, MAPI_LOGON_UI|MAPI_DIALOG, 0);
s.ReleaseBuffer();

// after returning from the MAPISendMail call,
// the window must be re-enabled and focus
// returned to the frame to undo the workaround
// done before the MAPI call.
::ReleaseCapture();
pParentWnd->m_nFlags &= ~WF_STAYDISABLED;

pParentWnd->EnableWindow(TRUE);
::SetActiveWindow(NULL);
pParentWnd->SetActiveWindow();
pParentWnd->SetFocus();
if (hWndTop != NULL)
::EnableWindow(hWndTop, TRUE);
AfxGetApp()->EnableModeless(TRUE);

if (nError != SUCCESS_SUCCESS && nError !=MAPI_USER_ABORT && nError !=MAPI_E_LOGIN_FAILURE)
{
AfxMessageBox(AFX_IDP_FAILED_MAPI_SEND);
}
::FreeLibrary(hMail);
}
}

RedFire 2002-07-05
  • 打赏
  • 举报
回复
我做好了,怎么给你?
蒋晟 2002-07-04
  • 打赏
  • 举报
回复
注意这些
开始模态
// prepare for modal dialog box
AfxGetApp()->EnableModeless(FALSE);
HWND hWndTop;
CWnd* pParentWnd= CWnd::GetSafeOwner(NULL, &hWndTop);

// some extra precautions are required to use
//MAPISendMail as it tends to enable the parent
// window in between dialogs (after the login
// dialog, but before the send not dialog).
pParentWnd->SetCapture();
::SetFocus(NULL);
pParentWnd->m_nFlags |= WF_STAYDISABLED;

结束模态
// after returning from the MAPISendMail call,
// the window must be re-enabled and focus
// returned to the frame to undo the workaround
// done before the MAPI call.
::ReleaseCapture();
pParentWnd->m_nFlags &= ~WF_STAYDISABLED;

pParentWnd->EnableWindow(TRUE);
::SetActiveWindow(NULL);
pParentWnd->SetActiveWindow();
pParentWnd->SetFocus();
if (hWndTop != NULL)
::EnableWindow(hWndTop, TRUE);
AfxGetApp()->EnableModeless(TRUE);
systree 2002-07-04
  • 打赏
  • 举报
回复
模仿CDialog的Domodel写一段消息循环
RedFire 2002-07-04
  • 打赏
  • 举报
回复
还没有搞定呀!其实很简单,就是两个函数,RunModalLoop和EndModalLoop,而且这两个函数是CWnd的成员。也就是说,模式窗口的能力是CWnd与身俱来的。
code_cold 2002-07-04
  • 打赏
  • 举报
回复
push
code_cold 2002-07-04
  • 打赏
  • 举报
回复
2: jiangsheng(蒋晟.Net)
没看明白

push
mi13chael 2002-07-04
  • 打赏
  • 举报
回复
我这有一段代码可以在一个主窗口的情况下,在开游离主窗口的副窗口。
CFrameWnd m_wndsource ;

if(!m_wndsource.CreatEx(WS_EX_TOPMOST,NULL,"Source",WS_CAPTION,CRect(100,100,150,180),NULL,0))
return -1;


flyingjust 2002-07-04
  • 打赏
  • 举报
回复
up
flyingjust 2002-07-04
  • 打赏
  • 举报
回复
up
code_cold 2002-07-04
  • 打赏
  • 举报
回复
难度在于:
一个SDI Application 如何能有两个CFrameWnd
code_cold 2002-07-04
  • 打赏
  • 举报
回复
搞定后我贴出来
Lemon_2000 2002-07-03
  • 打赏
  • 举报
回复
up
Panr 2002-07-03
  • 打赏
  • 举报
回复
CWhatWereYouDoingDlg::DopModal (); 当然不是模态CFrameWnd


我不知lpfnSendMail 指向的是什么,但我看CWinApp::EnableModeless 的两次调用是为lpfnSendMail 服务的,好象这与CFrameWnd 也无关吧?
Panr 2002-07-03
  • 打赏
  • 举报
回复
CWhatWereYouDoingDlg::DopModal (); 当然不是模态CFrameWnd


我不知lpfnSendMail 指向的是什么,但我看EnableModeless(false) / EnableModeless(false) 是为lpfnSendMail 服务的,好象这与CFrameWnd 也无关吧?
蒋晟 2002-07-03
  • 打赏
  • 举报
回复
CReportErrorDlg::OnSend()
{
CWhatWereYouDoingDlg dlg1(this);
dlg1.m_strString = m_strWhatWereYouDoing;
if(dlg1.DoModal() == IDOK)
{
m_strWhatWereYouDoing = dlg1.m_strString;
HINSTANCE hMail = NULL;
hMail = ::LoadLibraryA("MAPI32.DLL");
if (hMail == NULL)
{
AfxMessageBox(AFX_IDP_FAILED_MAPI_LOAD); return;
}
ASSERT(hMail != NULL);

ULONG (PASCAL *lpfnSendMail)(ULONG, ULONG, MapiMessage*, FLAGS, ULONG);
(FARPROC&)lpfnSendMail = GetProcAddress(hMail, "MAPISendMail");
if(lpfnSendMail == NULL)
{
AfxMessageBox(AFX_IDP_INVALID_MAPI_DLL); return;
}
ASSERT(lpfnSendMail != NULL);

// make a recipient
MapiRecipDesc rec;

char szRName[] = "Clever Programmer";
char szRAddress[] = "SMTP:sendyourerrorsto@yourcompanynotmine.com";
memset(&rec, 0, sizeof(rec));
rec.ulRecipClass = MAPI_TO;
rec.lpszName = szRName;
rec.lpszAddress = szRAddress;

char szSubject[] = "An exception has occurred";

// prepare the message
------------------------

MapiMessage message;
memset(&message, 0, sizeof(message));

message.nRecipCount = 1;
message.lpRecips = &rec;
message.lpszSubject = szSubject;

CString s =m_strWhatWereYouDoing;
s +="\n";
PrepareErrorMessage(s);

message.lpszNoteText = s.GetBuffer(s.GetLength());

// prepare for modal dialog box
AfxGetApp()->EnableModeless(FALSE);
HWND hWndTop;
CWnd* pParentWnd= CWnd::GetSafeOwner(NULL, &hWndTop);

// some extra precautions are required to use
//MAPISendMail as it tends to enable the parent
// window in between dialogs (after the login
// dialog, but before the send not dialog).
pParentWnd->SetCapture();
::SetFocus(NULL);
pParentWnd->m_nFlags |= WF_STAYDISABLED;



int nError =lpfnSendMail(0, (ULONG)pParentWnd->GetSafeHwnd(),
&message, MAPI_LOGON_UI|MAPI_DIALOG, 0);
s.ReleaseBuffer();

// after returning from the MAPISendMail call,
// the window must be re-enabled and focus
// returned to the frame to undo the workaround
// done before the MAPI call.
::ReleaseCapture();
pParentWnd->m_nFlags &= ~WF_STAYDISABLED;

pParentWnd->EnableWindow(TRUE);
::SetActiveWindow(NULL);
pParentWnd->SetActiveWindow();
pParentWnd->SetFocus();
if (hWndTop != NULL)
::EnableWindow(hWndTop, TRUE);
AfxGetApp()->EnableModeless(TRUE);

if (nError != SUCCESS_SUCCESS && nError !=MAPI_USER_ABORT && nError !=MAPI_E_LOGIN_FAILURE)
{
AfxMessageBox(AFX_IDP_FAILED_MAPI_SEND);
}
::FreeLibrary(hMail);
}
}
Panr 2002-07-03
  • 打赏
  • 举报
回复
不可能! (按我现在对MFC 的理解)
CDialog 的锁定是依靠其成员函数DoModal 中有一个消息循环,而CFrameWnd 根本没有这种机制


我建议你仍然用CDialog,具体做法是:在对话上创建视图类
视图类的创建时有一个创建上下文,你需要把父窗体的指针指向对话框就可以了

code_cold 2002-07-03
  • 打赏
  • 举报
回复
push
加载更多回复(8)

16,471

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧