本文整理汇总了C++中CWinApp::OnIdle方法的典型用法代码示例。如果您正苦于以下问题:C++ CWinApp::OnIdle方法的具体用法?C++ CWinApp::OnIdle怎么用?C++ CWinApp::OnIdle使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CWinApp
的用法示例。
在下文中一共展示了CWinApp::OnIdle方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ProcessGUIMessages
virtual void ProcessGUIMessages()
{
// Adapted from MFC's CWinThread::Run() (thrdcore.cpp).
_AFX_THREAD_STATE* pState = AfxGetThreadState();
CWinApp* pApp = AfxGetApp();
BOOL bIdle = TRUE;
LONG lIdleCount = 0;
// phase1: check to see if we can do idle work
while (bIdle &&
!::PeekMessage(&pState->m_msgCur, NULL, NULL, NULL, PM_NOREMOVE))
{
// call OnIdle while in bIdle state
if (!pApp->OnIdle(lIdleCount++))
bIdle = FALSE; // assume "no idle" state
}
// phase2: pump messages while available
while (::PeekMessage(&pState->m_msgCur, NULL, NULL, NULL, PM_NOREMOVE))
{
// pump message, but quit on WM_QUIT
if (!pApp->PumpMessage())
{
Terminate();
pApp->ExitInstance();
}
}
::Sleep(0);
}
示例2: OnContextHelp
void CFrameWnd::OnContextHelp()
{
// don't enter twice, and don't enter if initialization fails
if (m_bHelpMode == HELP_ACTIVE || !CanEnterHelpMode())
return;
// don't enter help mode with pending WM_EXITHELPMODE message
MSG msg;
if (PeekMessage(&msg, m_hWnd, WM_EXITHELPMODE, WM_EXITHELPMODE,
PM_REMOVE|PM_NOYIELD))
{
return;
}
BOOL bHelpMode = m_bHelpMode;
ASSERT(m_bHelpMode == HELP_INACTIVE || m_bHelpMode == HELP_ENTERING);
m_bHelpMode = HELP_ACTIVE;
#ifndef _AFX_NO_OLE_SUPPORT
// allow any in-place active servers to go into help mode
if (bHelpMode != HELP_ENTERING && m_pNotifyHook != NULL &&
!m_pNotifyHook->OnContextHelp(TRUE))
{
TRACE0("Error: an in-place server failed to enter context help mode.\n");
m_pNotifyHook->OnContextHelp(FALSE); // undo partial help mode
m_bHelpMode = HELP_INACTIVE;
return;
}
#endif
if (bHelpMode == HELP_INACTIVE)
{
// need to delay help startup until later
PostMessage(WM_COMMAND, ID_CONTEXT_HELP);
m_bHelpMode = HELP_ENTERING;
return;
}
ASSERT(m_bHelpMode == HELP_ACTIVE);
// display special help mode message on status bar
UINT nMsgSave = (UINT)SendMessage(WM_SETMESSAGESTRING,
(WPARAM)AFX_IDS_HELPMODEMESSAGE);
if (nMsgSave == 0)
nMsgSave = AFX_IDS_IDLEMESSAGE;
DWORD dwContext = 0;
POINT point;
GetCursorPos(&point);
SetHelpCapture(point, NULL);
LONG lIdleCount = 0;
CWinApp* pApp = AfxGetApp();
while (m_bHelpMode)
{
if (PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE))
{
if (!ProcessHelpMsg(msg, &dwContext))
break;
ASSERT(dwContext == 0);
}
else if (!pApp->OnIdle(lIdleCount++))
{
lIdleCount = 0;
WaitMessage();
}
}
m_bHelpMode = HELP_INACTIVE;
ReleaseCapture();
// make sure the cursor is set appropriately
SetCapture();
ReleaseCapture();
// restore original status bar text
SendMessage(WM_SETMESSAGESTRING, (WPARAM)nMsgSave);
#ifndef _AFX_NO_OLE_SUPPORT
// tell in-place servers to exit Shift+F1 help mode
if (m_pNotifyHook != NULL)
m_pNotifyHook->OnContextHelp(FALSE);
#endif
if (dwContext != 0)
{
if (dwContext == -1)
SendMessage(WM_COMMAND, ID_DEFAULT_HELP);
else
pApp->WinHelp(dwContext);
}
PostMessage(WM_KICKIDLE); // trigger idle update
}
示例3: OnContextHelp
void CFrameWnd::OnContextHelp()
/*****************************/
{
if( !m_bHelpMode && CanEnterHelpMode() ) {
m_bHelpMode = TRUE;
::SetCursor( _HelpCursor );
UINT nIDOld = (UINT)::SendMessage( m_hWnd, WM_SETMESSAGESTRING,
AFX_IDS_HELPMODEMESSAGE, 0L );
if( nIDOld == 0 ) {
nIDOld = AFX_IDS_IDLEMESSAGE;
}
CWinApp *pApp = AfxGetApp();
ASSERT( pApp != NULL );
MSG msg;
LONG lCount = 0L;
DWORD_PTR dwHelpId = 0L;
for( ;; ) {
while( !::PeekMessage( &msg, NULL, 0, 0, PM_NOREMOVE ) ) {
if( pApp->OnIdle( lCount ) ) {
lCount++;
} else {
::WaitMessage();
}
}
::GetMessage( &msg, NULL, 0, 0 );
if( msg.message == WM_EXITHELPMODE ) {
break;
} else if( msg.message == WM_KEYDOWN && msg.wParam == VK_ESCAPE ) {
break;
} else if( (msg.message >= WM_KEYFIRST && msg.message <= WM_KEYLAST) ||
msg.message == WM_SYSCOMMAND ) {
if( !pApp->PreTranslateMessage( &msg ) ) {
::TranslateMessage( &msg );
if( msg.message != WM_SYSKEYDOWN && msg.message != WM_SYSKEYUP &&
msg.message != WM_SYSCHAR && msg.message != WM_SYSDEADCHAR &&
msg.message != WM_SYSCOMMAND ) {
continue;
}
}
} else if( msg.message == WM_LBUTTONDOWN ||
msg.message == WM_NCLBUTTONDOWN ) {
int nHitTest = (int)::SendMessage( msg.hwnd, WM_NCHITTEST, 0,
MAKELPARAM( msg.pt.x, msg.pt.y ) );
if( nHitTest == HTCLIENT ) {
HWND hWnd = msg.hwnd;
while( hWnd != NULL && dwHelpId == 0L ) {
CPoint point( msg.pt );
::ScreenToClient( hWnd, &point );
dwHelpId = (DWORD_PTR)::SendMessage( hWnd, WM_HELPHITTEST, 0,
MAKELPARAM( point.x,
point.y ) );
hWnd = ::GetParent( hWnd );
}
break;
} else if( nHitTest >= 0 && nHitTest != HTMENU &&
nHitTest != HTSYSMENU ) {
dwHelpId = HID_BASE_NCAREAS + nHitTest;
break;
}
}
::DispatchMessage( &msg );
}
m_bHelpMode = FALSE;
::SendMessage( m_hWnd, WM_SETMESSAGESTRING, nIDOld, 0L );
POINT point;
::GetCursorPos( &point );
HWND hWndCursor = ::WindowFromPoint( point );
if( hWndCursor != NULL ) {
int nHitTest = (int)::SendMessage( hWndCursor, WM_NCHITTEST, 0,
MAKELPARAM( point.x, point.y ) );
::SendMessage( hWndCursor, WM_SETCURSOR, (WPARAM)hWndCursor,
MAKELPARAM( nHitTest, WM_MOUSEMOVE ) );
} else {
HCURSOR hCursor = ::LoadCursor( NULL, IDC_ARROW );
::SetCursor( hCursor );
}
if( dwHelpId != 0L ) {
pApp->WinHelpInternal( dwHelpId );
}
}
}