Re: Too many Post Messages causing app not to refresh
Hi Joe,
Thanks for the link and the code sample. Much appreciated.
If only I can get it to work....
There are a few problems with the code.
I tried to fix the errors, but I am lost in a sea of static.
Here is what I did to try to fix the code.
First, Close() is not defined in the header.
Second, Forward() return type is different.
Third, formal parameter msg is being redefined.
/* static */ BOOL MsgWrapper::Post(CWnd * wnd, UINT msg, WPARAM wParam, =
LPARAM lParam)
{
ASSERT(messagePort != NULL);
if(messagePort == NULL)
return FALSE;
ASSERT(wnd != NULL); // must not be NULL! Must be a real window!
/* MsgWrapper * msg = new MsgWrapper(wnd, msg, wParam, lParam); */
MsgWrapper * msgw = new MsgWrapper(wnd, msg, wParam, lParam);
return PostQueuedCompletionStatus(messagePort,
0, // bytes transferred
0,
/* msg); */
msgw);
}
Fourth, I am not sure, but I guess all the members should be static.
BOOL CMyApp::InitInstance()
{
MsgWrapper::Init(); /* should be static in MsgWrapper.h ?*/
}
int CMyApp::ExitInstance()
{
MsgWrapper::Close(); /* should be static in MsgWrapper.h ?*/
}
Fifth, msg needs to be a pointer
#define MAX_MESSAGE_QUANTUM 10
for(int i = 0; i < MAX_MESSAGE_QUANTUM; i++)
{ /* scan messages */
/* MsgWrapper msg = MsgWrapper::GetQueuedMessage(); */
MsgWrapper* msg = MsgWrapper::GetQueuedMessage();
if(msg == NULL)
break;
w->Forward();
} /* scan messages */
} /* dequeue pending log messages */
Sixth, wP and lP should be wParam andlParam, plus there is an extra ")"
also, I had to make wParam and lParam static.
BOOL MsgWrapper::Forward()
{
/* BOOL result = wnd->PostMessage(msg, wP, lP)); */
BOOL result = wnd->PostMessage(msg, wParam, lParam);
delete this;
return result;
}
Seventh, I changed "w".
#define MAX_MESSAGE_QUANTUM 10
for(int i = 0; i < MAX_MESSAGE_QUANTUM; i++)
{ /* scan messages */
/* MsgWrapper msg = MsgWrapper::GetQueuedMessage(); */
MsgWrapper* msg = MsgWrapper::GetQueuedMessage();
if(msg == NULL)
break;
/* w->Forward(); */
MsgWrapper::Forward();
} /* scan messages */
} /* dequeue pending log messages */
Eighth, there is an extra "}"
for(int i = 0; i < MAX_MESSAGE_QUANTUM; i++)
{ /* scan messages */
MsgWrapper msg = MsgWrapper::GetQueuedMessage();
if(msg == NULL)
break;
w->Forward();
} /* scan messages */
// } /* dequeue pending log messages */
Ninth, if MsgWrapper::Forward() is supposed to be static,
then it will complain about static members not having "this" pointer.
So, I commented that out.
It also complains about wnd, so I had to make CWnd* pWnd static.
BOOL MsgWrapper::Forward()
{
BOOL result = wnd->PostMessage(msg, wParam, lParam);
/* delete this; */
return result;
}
/* This is my redefined MsgWrapper Class */
class MsgWrapper : public _OVERLAPPED
{
public: // creation
MsgWrapper(CWnd * w, UINT m, WPARAM wP, LPARAM lP);
/* non-virtual */ ~MsgWrapper() {/* ...your code here... */}
static BOOL Init();
public: // methods
static void Close();
static BOOL Forward();
static MsgWrapper * GetQueuedMessage();
static BOOL Post(CWnd * wnd, UINT msg, WPARAM wParam = 0, =
LPARAM lParam = 0);
protected:
static HANDLE messagePort;
static CWnd * wnd;
static UINT msg;
static WPARAM wParam;
static LPARAM lParam;
};
Great. It builds.
But then, I get unresolved externals. CWnd*, msg, lParam and wParam.
I don't know if what I did was right or wrong.
I tried making and object out of MsgWrapper
But, I need to supply it with the parameters, which are not available in =
the OnIdle() handler.
I think that is what I really need to do. That would make "delete this" =
in foward meaningful.
But, if I do that, then Init() and Close() would not be needed?
BOOL CVacmonApp::OnIdle(LONG lCount)
{
MsgWrapper* pMsgWrapper = new MsgWrapper(); /* I need to supply it =
with pWnd, msg, wParam and lParam */
#define MAX_MESSAGE_QUANTUM 10
for(int i = 0; i < MAX_MESSAGE_QUANTUM; i++)
{ /* scan messages */
MsgWrapper msg = MsgWrapper::GetQueuedMessage();
if(msg == NULL)
break;
w->Forward();
} /* scan messages */
return CWinApp::OnIdle(lCount);
}
P.S, I don't know if the following should be uncommented or not?
/* static */ HANDLE MsgWrapper::messagePort = NULL;
Sorry, for not understanding, but I am lost.
Thanks,