Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

WM_KICKIDLE and Modal Dialogs

Status
Not open for further replies.

billgower

Programmer
Oct 15, 2003
2
US
Has anyone gotten the WM_KICKIDLE working with dialogs.

In my header
#include <afxpriv.h>


afx_msg LRESULT OnKickIdle();

in cpp

ON_MESSAGE(WM_KICKIDLE, OnKickIdle)

LResult MyClass::OnKickIdle()
{
AfxMessageBox(&quot;made it&quot;);
return TRUE;
}


The message box never pops up. I ran Spy++ and left my dialog box up for 1 hour and the message was never received.
 
WM_KICKIDLE is used by MFC framework to do some idle work. It never be dispatched to window procedure and can only be processed in virtual function WinApp::OnIdle(long). You should override this virtual function to fulfill your own aim. You can find out this fact in the codes for message loop in MFC source file. Here are some pieces of it:


int CWinThread::Run()
{
BOOL bIdle = TRUE;
LONG lIdleCount = 0;
// acquire and dispatch messages until a WM_QUIT message is received.
for (;;)
{
// phase1: check to see if we can do idle work
while (bIdle &&
!::peekMessage(&m_msgCur, NULL, NULL, NULL, PM_NOREMOVE))
{
// call OnIdle while in bIdle state
if (!OnIdle(lIdleCount++))
bIdle = FALSE; // assume &quot;no idle&quot; state
}

// phase2: pump messages while available
do
{
// pump message, but quit on WM_QUIT
if (!PumpMessage())
return ExitInstance();

// reset &quot;no idle&quot; state after pumping &quot;normal&quot; message
if (IsIdleMessage(&m_msgCur))
{
bIdle = TRUE;
lIdleCount = 0;
}

} while :):peekMessage(&m_msgCur, NULL, NULL, NULL, PM_NOREMOVE));
}

}


BOOL CWinThread::pumpMessage()
{
if (!::GetMessage(&m_msgCur, NULL, NULL, NULL))
{
return FALSE;
}

// process this message

if (m_msgCur.message != WM_KICKIDLE && !PreTranslateMessage(&m_msgCur))
{
::TranslateMessage(&m_msgCur);
::DispatchMessage(&m_msgCur);
}
return TRUE;
}
 
I'm awfully sorry about my nonsense in reply 1,
because I've just find out what IsIdleMessage really mean.
I'll try to think about it thoughtfully and give a accurate
answer if possible.
 
after reading my second reply, you may think that I am also confused with this question, but this time I am sure that I'll give a absolutely right answer as following

firstly, notice this piece of codes in reply 1:

if (m_msgCur.message != WM_KICKIDLE && !PreTranslateMessage(&m_msgCur))
{
::TranslateMessage(&m_msgCur);
::DispatchMessage(&m_msgCur);
}
return TRUE;
}

it means WM_KICKIDLE never be dispatch to window procedure, that is why your message handler for this message never be called.

secondly, look at the MFC codes for IsIdleMessage(&m_msgCur) which make me confused in reply 2:

BOOL CWinThread::IsIdleMessage(MSG* pMsg)
{
/* Return FALSE if the message just dispatched should _not_ cause OnIdle to be run. Messages which do not usually affect the state of the user interface and happen very often are checked for.*/

// redundant WM_MOUSEMOVE and WM_NCMOUSEMOVE
if (pMsg->message == WM_MOUSEMOVE || pMsg->message == WM_NCMOUSEMOVE)
{
// mouse move at same position as last mouse move?
if (m_ptCursorLast == pMsg->pt && pMsg->message == m_nMsgLast)
return FALSE;

m_ptCursorLast = pMsg->pt; // remember for next time
m_nMsgLast = pMsg->message;
return TRUE;
}

// WM_PAINT and WM_SYSTIMER (caret blink)
return pMsg->message != WM_PAINT && pMsg->message != 0x0118;
}

this piece of code means that a last WM_MOUSEMOVE or WM_NCMOUSEMOVE posted when the cursor is remain at the same place does not cause OnIdle to be called even if it is the last message in the message queue. WM_PAINT and WM_SYSTIMER
has the same effect. All other messages, includding WM_KICKIDLE, can cause OnIdle to be called if there are no messages staying in the message queue after GetMessage gets one of these messages out of message queue.

In conclusion, your application can only reply to WM_KICKIDLE in your overriding of CWinApp::OnIdle.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top