Click here to Skip to main content
15,889,315 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: question regarging callback functions Pin
Cedric Moonen7-Jun-06 23:06
Cedric Moonen7-Jun-06 23:06 
QuestionSet the msflexgrid col width and row height according client rect [modified] Pin
zeus_master7-Jun-06 22:40
zeus_master7-Jun-06 22:40 
AnswerRe: Set the msflexgrid col width and row height according client rect [modified] Pin
Viorel.7-Jun-06 22:58
Viorel.7-Jun-06 22:58 
QuestionHow to make DoModal() in CFrameWnd Pin
huynhnb7-Jun-06 22:30
huynhnb7-Jun-06 22:30 
AnswerRe: How to make DoModal() in CFrameWnd Pin
Cedric Moonen7-Jun-06 22:34
Cedric Moonen7-Jun-06 22:34 
GeneralRe: How to make DoModal() in CFrameWnd Pin
huynhnb7-Jun-06 23:07
huynhnb7-Jun-06 23:07 
GeneralRe: How to make DoModal() in CFrameWnd Pin
Cedric Moonen7-Jun-06 23:12
Cedric Moonen7-Jun-06 23:12 
GeneralRe: How to make DoModal() in CFrameWnd Pin
huynhnb7-Jun-06 23:37
huynhnb7-Jun-06 23:37 
Source code :
// Child Frame .H
class CSDIChildFrame : public CFrameWnd
{
DECLARE_DYNCREATE(CSDIChildFrame)


// Attributes
public:
CSDIChildFrame(); // protected constructor used by dynamic creation
// Operations
public:
BOOL m_bClose;
BOOL m_bModal;
int RunModalLoop(DWORD dwFlags);
int DoModal(CWnd *pParentWnd);

// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CSDIChildFrame)
//}}AFX_VIRTUAL

// Implementation
protected:
virtual ~CSDIChildFrame();

// Generated message map functions
//{{AFX_MSG(CSDIChildFrame)
// NOTE - the ClassWizard will add and remove member functions here.
afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
afx_msg void OnExit();

//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
// Child frame .cpp
// SDIChildFrame.cpp : implementation file
//

#include "stdafx.h"
#include "SDIChildFrame.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CSDIChildFrame

IMPLEMENT_DYNCREATE(CSDIChildFrame, CFrameWnd)

CSDIChildFrame::CSDIChildFrame() : m_bClose(FALSE)
{
}

CSDIChildFrame::~CSDIChildFrame()
{
}


BEGIN_MESSAGE_MAP(CSDIChildFrame, CFrameWnd)
//{{AFX_MSG_MAP(CSDIChildFrame)
// NOTE - the ClassWizard will add and remove mapping macros here.

ON_COMMAND(ID_MENUITEM32772, OnExit)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CSDIChildFrame message handlers
int CSDIChildFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
return -1;

// TODO: Add your specialized creation code here
CCreateContext pContext;
return 0;

}

int CSDIChildFrame::DoModal(CWnd *pParentWnd)
{

BOOL bEnableParent, bResult;
HWND hWndParent, hWndTop;

m_bModal = TRUE;

hWndParent = CWnd::GetSafeOwner_(NULL, &hWndTop);
AfxHookWindowCreate(this);

bEnableParent = FALSE;
if (hWndParent != NULL && ::IsWindowEnabled(hWndParent))
{
::EnableWindow(hWndParent, FALSE);
bEnableParent = TRUE;
}

bResult = CFrameWnd::LoadFrame(
IDR_MENU1,
WS_OVERLAPPEDWINDOW | FWS_ADDTOTITLE | WS_VISIBLE,
pParentWnd,
NULL);



if (bResult)
{
DWORD dwFlags = MLF_SHOWONIDLE;

m_nFlags = m_nFlags & WF_CONTINUEMODAL;

if (GetStyle() & DS_NOIDLEMSG)
{
dwFlags |= MLF_NOIDLEMSG;
}

VERIFY(RunModalLoop(dwFlags) == m_nModalResult);
}


if (bEnableParent)
::EnableWindow(hWndParent, TRUE);
if (hWndParent != NULL)
::SetActiveWindow(hWndParent);


AfxUnhookWindowCreate(); // just in case
Detach(); // just in case

// re-enable windows
if (::IsWindow(hWndTop))
::EnableWindow(hWndTop, TRUE);
hWndTop = NULL;
CWinApp* pApp = AfxGetApp();
if (pApp != NULL)
pApp->EnableModeless(TRUE);

return m_nModalResult;

}

int CSDIChildFrame::RunModalLoop(DWORD dwFlags)
{
ASSERT(::IsWindow(m_hWnd)); // window must be created
ASSERT(!(m_nFlags & WF_MODALLOOP)); // window must not already be in modal state

// for tracking the idle time state
BOOL bIdle = TRUE;
LONG lIdleCount = 0;
BOOL bShowIdle = (dwFlags & MLF_SHOWONIDLE) && !(GetStyle() & WS_VISIBLE);
HWND hWndParent = ::GetParent(m_hWnd);
m_nFlags |= (WF_MODALLOOP|WF_CONTINUEMODAL);
// In VC 6.0
MSG* pMsg = &AfxGetThread()->m_msgCur;
// In VC 7.0
// MSG* pMsg = AfxGetCurrentMessage();

// acquire and dispatch messages until the modal state is done
for (;;)
{

/*
ASSERT(ContinueModal());
*/

if (m_bClose)
{
goto ExitModal;
}

// phase1: check to see if we can do idle work
while (bIdle &&
!::PeekMessage(pMsg, NULL, NULL, NULL, PM_NOREMOVE))
{

/*
ASSERT(ContinueModal());
*/

if (m_bClose)
{
goto ExitModal;
}

// show the dialog when the message queue goes idle
if (bShowIdle)
{
ShowWindow(SW_SHOWNORMAL);
UpdateWindow();
bShowIdle = FALSE;
}

// call OnIdle while in bIdle state
if (!(dwFlags & MLF_NOIDLEMSG) && hWndParent != NULL && lIdleCount == 0)
{
// send WM_ENTERIDLE to the parent
::SendMessage(hWndParent, WM_ENTERIDLE, MSGF_DIALOGBOX, (LPARAM)m_hWnd);
}

if (m_bClose)
{
goto ExitModal;
}

if ((dwFlags & MLF_NOKICKIDLE) ||
!SendMessage(WM_KICKIDLE, MSGF_DIALOGBOX, lIdleCount++))
{
// stop idle processing next time
bIdle = FALSE;
}
}

// phase2: pump messages while available
do
{
/*
ASSERT(ContinueModal());
*/

if (m_bClose)
{
goto ExitModal;
}

// pump message, but quit on WM_QUIT
if (!AfxGetThread()->PumpMessage())
{
AfxPostQuitMessage(0);
return -1;
}


// show the window when certain special messages rec'd
if (bShowIdle &&
(pMsg->message == 0x118 || pMsg->message == WM_SYSKEYDOWN))
{
ShowWindow(SW_SHOWNORMAL);
UpdateWindow();
bShowIdle = FALSE;
}

/*
if (!ContinueModal())
goto ExitModal;
*/


if (m_bClose)
{
goto ExitModal;
}
// reset "no idle" state after pumping "normal" message
if (AfxGetThread()->IsIdleMessage(pMsg))
{
bIdle = TRUE;
lIdleCount = 0;
}

if (m_bClose)
{
goto ExitModal;
}


} while (::PeekMessage(pMsg, NULL, NULL, NULL, PM_NOREMOVE));

}

ExitModal:
m_nFlags &= ~(WF_MODALLOOP|WF_CONTINUEMODAL);
return m_nModalResult;
}

void CSDIChildFrame::OnExit()
{
// TODO: Add your command handler code here
m_bClose = TRUE;

}
// include in Stdafx.h
#include <afxpriv.h>

// Use

void CMainFrame::OnLoadDoModalFrame()
{
CSDIChildFrame *pChildFrame = new CSDIChildFrame();
pChildFrame ->DoModal(this);
}
Questionneed sample code Pin
vasusree7-Jun-06 22:25
vasusree7-Jun-06 22:25 
AnswerRe: need sample code Pin
Cedric Moonen7-Jun-06 22:31
Cedric Moonen7-Jun-06 22:31 
AnswerRe: need sample code Pin
Hamid_RT7-Jun-06 22:36
Hamid_RT7-Jun-06 22:36 
AnswerRe: need sample code Pin
Viorel.7-Jun-06 22:46
Viorel.7-Jun-06 22:46 
NewsRe: need sample code Pin
vasusree7-Jun-06 22:48
vasusree7-Jun-06 22:48 
GeneralRe: need sample code Pin
Viorel.7-Jun-06 23:34
Viorel.7-Jun-06 23:34 
GeneralRe: need sample code Pin
vasusree8-Jun-06 3:41
vasusree8-Jun-06 3:41 
AnswerRe: need sample code Pin
Amar Sutar8-Jun-06 19:01
Amar Sutar8-Jun-06 19:01 
QuestionArray Pointer Pin
knoxplusplus7-Jun-06 22:19
knoxplusplus7-Jun-06 22:19 
AnswerRe: Array Pointer Pin
Hamid_RT7-Jun-06 22:27
Hamid_RT7-Jun-06 22:27 
QuestionVisitor Design Pattern Pin
knoxplusplus7-Jun-06 22:15
knoxplusplus7-Jun-06 22:15 
AnswerRe: Visitor Design Pattern Pin
Viorel.7-Jun-06 23:43
Viorel.7-Jun-06 23:43 
QuestionCWinThread in VC 7.0 ! Help me Pin
huynhnb7-Jun-06 21:41
huynhnb7-Jun-06 21:41 
AnswerRe: CWinThread in VC 7.0 ! Help me Pin
_AnsHUMAN_ 7-Jun-06 21:53
_AnsHUMAN_ 7-Jun-06 21:53 
GeneralRe: CWinThread in VC 7.0 ! Help me Pin
huynhnb7-Jun-06 22:01
huynhnb7-Jun-06 22:01 
GeneralRe: CWinThread in VC 7.0 ! Help me Pin
_AnsHUMAN_ 7-Jun-06 22:06
_AnsHUMAN_ 7-Jun-06 22:06 
GeneralRe: CWinThread in VC 7.0 ! Help me Pin
Cedric Moonen7-Jun-06 22:08
Cedric Moonen7-Jun-06 22:08 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.