G
Girish
I was wondering if anybody has the implementation of CWnd::RunModalLoop/
CWnd::EndModalLoop in C#
Mine is a single threaded application... what I want is, the application
to wait at one point (and continue processing the messages) until some
event sets a flag, which will let the waiting code to continue...
e.g.
someFun()
{
...
...
... (some code which will fire someEvent later)
flag = waiting
Wait and process other messages
if flag == continue process stmts bellow else continue waiting
(Above 3 stmts are processed in CWnd::RunModalLoop)
...
...
}
someEvent()
{
...
...
flag = continue
(Above stmt is processed in CWnd::EndModalLoop)
}
I tried implementing these functions without any luck, can somebody tell
me what am I doing wrong...
-------------------------------------------------------
public static int RunModalLoop()
{
m_nFlags |= (WF_MODALLOOP|WF_CONTINUEMODAL);
for(;
{
MSG msg = new MSG();
GetMessageA(ref msg, 0, 0, 0);
do
{
TranslateMessage(ref msg);
DispatchMessageA(ref msg);
if (!ContinueModal())
goto ExitModal;
}while(PeekMessageA(ref msg, 0, 0, 0, PM_NOREMOVE) != 0);
}
ExitModal:
m_nFlags &= ~(WF_MODALLOOP|WF_CONTINUEMODAL);
return m_nModalResult;
}
private static bool ContinueModal()
{
return (m_nFlags & WF_CONTINUEMODAL) == WF_CONTINUEMODAL;
}
public static void EndModalLoop(int nResult)
{
m_nModalResult = nResult;
// make sure a message goes through to exit the modal loop
if (ContinueModal())
{
MSG msg = new MSG();
msg.hwnd = IntPtr.Zero;
msg.lParam = 0;
msg.message = 0;
msg.time = 0;
msg.wParam = 0;
m_nFlags &= ~WF_CONTINUEMODAL;
PostMessageA(0, msg, 0, 0);
}
}
CWnd::EndModalLoop in C#
Mine is a single threaded application... what I want is, the application
to wait at one point (and continue processing the messages) until some
event sets a flag, which will let the waiting code to continue...
e.g.
someFun()
{
...
...
... (some code which will fire someEvent later)
flag = waiting
Wait and process other messages
if flag == continue process stmts bellow else continue waiting
(Above 3 stmts are processed in CWnd::RunModalLoop)
...
...
}
someEvent()
{
...
...
flag = continue
(Above stmt is processed in CWnd::EndModalLoop)
}
I tried implementing these functions without any luck, can somebody tell
me what am I doing wrong...
-------------------------------------------------------
public static int RunModalLoop()
{
m_nFlags |= (WF_MODALLOOP|WF_CONTINUEMODAL);
for(;
{
MSG msg = new MSG();
GetMessageA(ref msg, 0, 0, 0);
do
{
TranslateMessage(ref msg);
DispatchMessageA(ref msg);
if (!ContinueModal())
goto ExitModal;
}while(PeekMessageA(ref msg, 0, 0, 0, PM_NOREMOVE) != 0);
}
ExitModal:
m_nFlags &= ~(WF_MODALLOOP|WF_CONTINUEMODAL);
return m_nModalResult;
}
private static bool ContinueModal()
{
return (m_nFlags & WF_CONTINUEMODAL) == WF_CONTINUEMODAL;
}
public static void EndModalLoop(int nResult)
{
m_nModalResult = nResult;
// make sure a message goes through to exit the modal loop
if (ContinueModal())
{
MSG msg = new MSG();
msg.hwnd = IntPtr.Zero;
msg.lParam = 0;
msg.message = 0;
msg.time = 0;
msg.wParam = 0;
m_nFlags &= ~WF_CONTINUEMODAL;
PostMessageA(0, msg, 0, 0);
}
}