//--------------------------------------------------------------------------------------------------------------// BOOL CFrmMain::PreCreateWindow(CREATESTRUCT& cs) { if (FALSE == CFrameWnd::PreCreateWindow(cs)) return FALSE; cs.dwExStyle &= ~WS_EX_CLIENTEDGE; lstrcpyn(AfxGetThreadState()->m_szTempClassName, c_szSingleInstanceId, sizeof(AfxGetThreadState()->m_szTempClassName) / sizeof(TCHAR)); cs.lpszClass = AfxGetThreadState()->m_szTempClassName; WNDCLASS wndcls = {0}; HINSTANCE hInst = NULL; hInst = AfxGetInstanceHandle(); if (FALSE == ::GetClassInfo(hInst, cs.lpszClass, &wndcls)) { wndcls.style = 0; wndcls.lpfnWndProc = ::DefWindowProc; wndcls.cbClsExtra = wndcls.cbWndExtra = 0; wndcls.hInstance = hInst; wndcls.hIcon = NULL; wndcls.hCursor = NULL; wndcls.hbrBackground = NULL; wndcls.lpszMenuName = NULL; wndcls.lpszClassName = cs.lpszClass; if (!AfxRegisterClass(&wndcls)) AfxThrowResourceException(); } else { ASSERT(wndcls.style == 0); return TRUE; } return TRUE; }
//延时函数,测试环境是一个对话框程序 //如果超时中止,返回真,否则假。 bool zstringEx::z_wait_message_until_true(bool *Global_x_false,long ms) { //注意,本函数可能让程序无法退出,所以结束程序时,要先结束本函数 //在启动本等待函数时,第一个参数为假,当它为真时,等待就结束了 //ms=0,则上一个等待是永远,否则就是等待的毫秒值,值一到就不再等了,哪怕第一个参数还是假 bool *is_loop_user_stop=Global_x_false; long m_start=clock();long m_end; long kms=ms;bool timeout_flag=false; _AFX_THREAD_STATE *pState; //定义指针 while(true) //这是一个死循环 { pState= AfxGetThreadState(); //得到线程状态参数的指针 if(pState==NULL)break; if(::PeekMessage(&(pState->m_msgCur),NULL, 0, 0, PM_REMOVE)) { ::TranslateMessage(&(pState->m_msgCur)); //执行线程消息,如使按钮能响应 ::DispatchMessage(&(pState->m_msgCur)); } if(is_loop_user_stop!=NULL){if(*is_loop_user_stop==true)break;} //判断 用户是否要求停止,如果要,就断了死循环 if(kms!=0){m_end=clock();if(m_end-m_start>=kms){timeout_flag=true;break;}} //判断是否超时 Sleep(1); //减少CPU的占用,这个参数是消息响应速度,越大响应效果越差,越小CPU占用越大 } return timeout_flag; }
void AFXAPI AfxOleTerm(BOOL bJustRevoke) { // release clipboard ownership COleDataSource::FlushClipboard(); // revoke all class factories COleObjectFactory::RevokeAll(); #ifndef _AFX_NO_OCC_SUPPORT AfxOleUnlockAllControls(); #endif if (!bJustRevoke) { CWinThread* pThread = AfxGetThread(); if (pThread != NULL) { // destroy message filter (may be derived class) delete pThread->m_pMessageFilter; pThread->m_pMessageFilter = NULL; } // terminate OLE last _AFX_THREAD_STATE* pState = AfxGetThreadState(); // -1 is special case, so need to compare against TRUE if (pState->m_bNeedTerm == TRUE) { CoFreeUnusedLibraries(); ::OleUninitialize(); pState->m_bNeedTerm = FALSE; } } }
BOOL COFSNcDlg::OnNcActivate(BOOL bActive) { /// Обработка OnNcActivate и Запоминания состояния для перерисовки if (m_nFlags & WF_STAYACTIVE) bActive = TRUE; if (!IsWindowEnabled()) bActive = FALSE; if (bActive==m_bActive) return TRUE; CWnd* pActiveWnd = GetActiveWindow(); if (pActiveWnd&&pActiveWnd!=this) { pActiveWnd->SendMessage(WM_NCACTIVATE,bActive); pActiveWnd->SendMessage(WM_NCPAINT); } // Turn WS_VISIBLE off before calling DefWindowProc, // so DefWindowProc won't paint and thereby cause flicker. // DWORD dwStyle = GetStyle(); if (dwStyle & WS_VISIBLE) ::SetWindowLong(*this, GWL_STYLE, (dwStyle & ~ WS_VISIBLE)); MSG& msg = AfxGetThreadState()->m_lastSentMsg; msg.wParam = bActive; Default(); if (dwStyle & WS_VISIBLE) ::SetWindowLong(*this, GWL_STYLE, dwStyle); // At this point, nothing has happened (since WS_VISIBLE was off). // Now it's time to paint. // m_bActive = bActive; // update state SendMessage(WM_NCPAINT); // paint non-client area (frame too) return TRUE; // done OK }
int CWinThread::RunLoop() { bool bIdle = true; LONG lIdleCount = 0; _AFX_THREAD_STATE* pState = AfxGetThreadState(); while (true) { #if UCFG_GUI while (bIdle && !::PeekMessage(&(pState->m_msgCur), 0, 0, 0, PM_NOREMOVE)) bIdle = OnIdle(lIdleCount++); #endif do { //#ifndef NO_GUI //!!! if (!PumpMessage()) return ExitInstance(); //#endif if (IsIdleMessage(pState->m_msgCur)) { bIdle = true; lIdleCount = 0; } } while (::PeekMessage(&(pState->m_msgCur), NULL, NULL, NULL, PM_NOREMOVE)); } }
void COXImageListBox::PreSubclassWindow() { // TODO: Add your specialized code here and/or call the base class DWORD dwStyle=GetStyle(); // make sure LBS_OWNERDRAWFIXED and LBS_MULTICOLUMN styles are specified ASSERT(dwStyle&LBS_OWNERDRAWFIXED); ASSERT(dwStyle&LBS_MULTICOLUMN); // make sure LBS_OWNERDRAWVARIABLE and LBS_MULTIPLESEL styles are not specified ASSERT(!(dwStyle&(LBS_OWNERDRAWVARIABLE|LBS_MULTIPLESEL))); // make sure the control is empty ASSERT(GetCount()==0); _AFX_THREAD_STATE* pThreadState=AfxGetThreadState(); // hook not already in progress if(pThreadState->m_pWndInit==NULL) { if(!InitializeImageListBox()) { TRACE(_T("COXImageListBox::PreSubclassWindow: failed to initialize the control\n")); } } CListBox::PreSubclassWindow(); }
void COXHistoryCombo::PreSubclassWindow() { ASSERT_VALID(this); // ... Attached window must be valid ASSERT(m_hWnd != NULL); ASSERT(::IsWindow(m_hWnd)); _AFX_THREAD_STATE* pThreadState=AfxGetThreadState(); // hook not already in progress if(pThreadState->m_pWndInit==NULL) { if(GetParent() != NULL) { // Initialize this control InitCombo(); } } // If GetParent() == NULL, this control is being created through Create() // and it is still to ealy to initialize, this will be done in OnCreate CComboBox::PreSubclassWindow(); ASSERT_VALID(this); }
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); }
int PASCAL CSocket::ProcessAuxQueue() { AFX_THREAD_STATE* pThreadState = AfxGetThreadState(); if (pThreadState->m_listSocketNotifications.IsEmpty()) return 0; int nCount = 0; while(!pThreadState->m_listSocketNotifications.IsEmpty()) { nCount++; MSG* pMsg = (MSG*)pThreadState->m_listSocketNotifications.RemoveHead(); ASSERT(pMsg != NULL); if (pMsg->message == WM_SOCKET_NOTIFY) { CAsyncSocket::DoCallBack(pMsg->wParam, pMsg->lParam); } else { ASSERT(CAsyncSocket::LookupHandle((SOCKET)pMsg->wParam, TRUE) != NULL); CAsyncSocket::DetachHandle((SOCKET)pMsg->wParam, TRUE); } delete pMsg; } return nCount; }
////////////////// // DoModal override copied mostly from MFC, with modification to use // m_ofnEx instead of m_ofn. // int CFileDialogEx::DoModal() { ASSERT_VALID(this); ASSERT(m_ofn.Flags & OFN_ENABLEHOOK); ASSERT(m_ofn.lpfnHook != NULL); // can still be a user hook // zero out the file buffer for consistent parsing later ASSERT(AfxIsValidAddress(m_ofn.lpstrFile, m_ofn.nMaxFile)); DWORD nOffset = lstrlen(m_ofn.lpstrFile)+1; ASSERT(nOffset <= m_ofn.nMaxFile); memset(m_ofn.lpstrFile+nOffset, 0, (m_ofn.nMaxFile-nOffset)*sizeof(TCHAR)); // WINBUG: This is a special case for the file open/save dialog, // which sometimes pumps while it is coming up but before it has // disabled the main window. HWND hWndFocus = ::GetFocus(); BOOL bEnableParent = FALSE; m_ofn.hwndOwner = PreModal(); AfxUnhookWindowCreate(); if (m_ofn.hwndOwner != NULL && ::IsWindowEnabled(m_ofn.hwndOwner)) { bEnableParent = TRUE; ::EnableWindow(m_ofn.hwndOwner, FALSE); } _AFX_THREAD_STATE* pThreadState = AfxGetThreadState(); ASSERT(pThreadState->m_pAlternateWndInit == NULL); if (m_ofn.Flags & OFN_EXPLORER) pThreadState->m_pAlternateWndInit = this; else AfxHookWindowCreate(this); memset(&m_ofnEx, 0, sizeof(m_ofnEx)); memcpy(&m_ofnEx, &m_ofn, sizeof(m_ofn)); if (IsWin2000()) m_ofnEx.lStructSize = sizeof(m_ofnEx); int nResult; if (m_bOpenFileDialog) nResult = ::GetOpenFileName((OPENFILENAME*)&m_ofnEx); else nResult = ::GetSaveFileName((OPENFILENAME*)&m_ofnEx); memcpy(&m_ofn, &m_ofnEx, sizeof(m_ofn)); m_ofn.lStructSize = sizeof(m_ofn); if (nResult) ASSERT(pThreadState->m_pAlternateWndInit == NULL); pThreadState->m_pAlternateWndInit = NULL; // WINBUG: Second part of special case for file open/save dialog. if (bEnableParent) ::EnableWindow(m_ofnEx.hwndOwner, TRUE); if (::IsWindow(hWndFocus)) ::SetFocus(hWndFocus); PostModal(); return nResult ? nResult : IDCANCEL; }
void PASCAL CAsyncSocket::DetachHandle(SOCKET hSocket, BOOL bDead) { ASSERT(CAsyncSocket::LookupHandle(hSocket, bDead) != NULL); AFX_THREAD_STATE* pThreadState = AfxGetThreadState(); if (!bDead) { pThreadState->m_mapSocketHandle.RemoveKey((void*)hSocket); if (pThreadState->m_mapSocketHandle.IsEmpty()) { ASSERT(pThreadState->m_hSocketWindow != NULL); CWnd* pWnd = CWnd::FromHandlePermanent(pThreadState->m_hSocketWindow); ASSERT_VALID(pWnd); pWnd->DestroyWindow(); delete pWnd; pThreadState->m_hSocketWindow = NULL; pThreadState->m_mapDeadSockets.RemoveAll(); } } else { pThreadState->m_mapDeadSockets.RemoveKey((void*)hSocket); } }
void CMDITabs::OnPaint() { CPaintDC dc(this); if (GetItemCount() == 0) return; // do nothing int dcState = dc.SaveDC(); // windows should draw the control as usual _AFX_THREAD_STATE* pThreadState = AfxGetThreadState(); pThreadState->m_lastSentMsg.wParam = WPARAM(HDC(dc)); Default(); dc.RestoreDC(dcState); DWORD face = ::GetSysColor(COLOR_3DFACE); if (m_bTop) { CRect rect(0, m_height - 7, m_width, m_height); dc.FillSolidRect(&rect, face); } else { CRect rect(0, 0, m_width, 3); dc.FillSolidRect(&rect, face); } }
COleControlLock::COleControlLock(REFCLSID clsid) { // initialize the object m_pNextLock = NULL; m_clsid = clsid; m_pClassFactory = NULL; // initialize OLE, if necessary _AFX_THREAD_STATE* pState = AfxGetThreadState(); if (!pState->m_bNeedTerm && !AfxOleInit()) return; // attempt to lock the class factory of the control if (SUCCEEDED(::CoGetClassObject(clsid, CLSCTX_INPROC_SERVER | CLSCTX_INPROC_HANDLER, NULL, IID_IClassFactory, (void**)&m_pClassFactory))) { ASSERT(m_pClassFactory != NULL); if (FAILED(m_pClassFactory->LockServer(TRUE))) { m_pClassFactory->Release(); m_pClassFactory = NULL; } } }
static LRESULT CALLBACK _AfxMsgFilterHook(int code, WPARAM wParam, LPARAM lParam) { CWinThread* pThread; if (AfxGetModuleState()->m_bDLL || (code < 0 && code != MSGF_DDEMGR) || !(pThread = AfxGetThread())) return AfxGetThreadState()->m_hookMsg.CallNext(code, wParam, lParam); ASSERT(pThread != NULL); return (LRESULT)pThread->ProcessMessageFilter(code, (LPMSG)lParam); }
int AFX_CDECL AfxCriticalNewHandler(size_t nSize) // nSize is already rounded { // called during critical memory allocation // free up part of the app's safety cache TRACE0("Warning: Critical memory allocation failed!\n"); _AFX_THREAD_STATE* pThreadState = AfxGetThreadState(); if (pThreadState != NULL && pThreadState->m_pSafetyPoolBuffer != NULL) { size_t nOldBufferSize = _msize(pThreadState->m_pSafetyPoolBuffer); if (nOldBufferSize <= nSize + MIN_MALLOC_OVERHEAD) { // give it all up TRACE0("Warning: Freeing application's memory safety pool!\n"); free(pThreadState->m_pSafetyPoolBuffer); pThreadState->m_pSafetyPoolBuffer = NULL; } else { BOOL bEnable = AfxEnableMemoryTracking(FALSE); _expand(pThreadState->m_pSafetyPoolBuffer, nOldBufferSize - (nSize + MIN_MALLOC_OVERHEAD)); AfxEnableMemoryTracking(bEnable); TRACE3("Warning: Shrinking safety pool from %d to %d to satisfy request of %d bytes.\n", nOldBufferSize, _msize(pThreadState->m_pSafetyPoolBuffer), nSize); } return 1; // retry it } TRACE0("ERROR: Critical memory allocation from safety pool failed!\n"); AfxThrowMemoryException(); // oops return 0; }
////////////////// // Like calling base class WindowProc, but with no args, so individual // message handlers can do the default thing. Like CWnd::Default // LRESULT CSubclassWnd::Default() { // MFC stores current MSG in thread state MSG& curMsg = AfxGetThreadState()->m_lastSentMsg; // Note: must explicitly call CSubclassWnd::WindowProc to avoid infinte // recursion on virtual function return CSubclassWnd::WindowProc(curMsg.message, curMsg.wParam, curMsg.lParam); }
// ==> XP Style Menu [Xanatos] - Stulle void CStatisticsTree::OnMeasureItem(int nIDCtl, LPMEASUREITEMSTRUCT lpMeasureItemStruct) { HMENU hMenu = AfxGetThreadState()->m_hTrackingMenu; if(CMenu *pMenu = CMenu::FromHandle(hMenu)) pMenu->MeasureItem(lpMeasureItemStruct); CTreeCtrl::OnMeasureItem(nIDCtl, lpMeasureItemStruct); }
void CDownloadClientsCtrl::OnMeasureItem(int nIDCtl, LPMEASUREITEMSTRUCT lpMeasureItemStruct) { HMENU hMenu = AfxGetThreadState()->m_hTrackingMenu; CMenu *pMenu = CMenu::FromHandle(hMenu); pMenu->MeasureItem(lpMeasureItemStruct); CWnd::OnMeasureItem(nIDCtl, lpMeasureItemStruct); }
// ==> XP Style Menu [Xanatos] - Stulle void CPPgScheduler::OnMeasureItem(int nIDCtl, LPMEASUREITEMSTRUCT lpMeasureItemStruct) { HMENU hMenu = AfxGetThreadState()->m_hTrackingMenu; if(CMenu *pMenu = CMenu::FromHandle(hMenu)) pMenu->MeasureItem(lpMeasureItemStruct); CPropertyPage::OnMeasureItem(nIDCtl, lpMeasureItemStruct); }
INT_PTR CColorDialog::DoModal() /*****************************/ { _AFX_THREAD_STATE *pState = AfxGetThreadState(); ASSERT( pState != NULL ); ASSERT( pState->m_pAlternateWndInit == NULL ); pState->m_pAlternateWndInit = this; return( ::ChooseColor( &m_cc ) ? IDOK : IDCANCEL ); }
BOOL CSearchWnd::DoSizeDetails() { MSG* pMsg = &AfxGetThreadState()->m_msgCur; CRect rcClient; CPoint point; GetClientRect( &rcClient ); if ( m_bPanel ) rcClient.left += Settings.Skin.SidebarWidth; if ( ! ( m_bPaused || m_bWaitMore ) ) rcClient.top += STATUS_HEIGHT; rcClient.bottom -= Settings.Skin.ToolbarHeight; ClientToScreen( &rcClient ); ClipCursor( &rcClient ); SetCapture(); ScreenToClient( &rcClient ); int nOffset = 0xFFFF; while ( GetAsyncKeyState( VK_LBUTTON ) & 0x8000 ) { while ( ::PeekMessage( pMsg, NULL, WM_MOUSEFIRST, WM_MOUSELAST, PM_REMOVE ) ); if ( ! AfxGetThread()->PumpMessage() ) { AfxPostQuitMessage( 0 ); break; } GetCursorPos( &point ); ScreenToClient( &point ); int nSplit = rcClient.bottom - point.y; if ( nOffset == 0xFFFF ) nOffset = m_nDetails - nSplit; nSplit += nOffset; if ( nSplit < 8 ) nSplit = 0; if ( nSplit > rcClient.Height() - Settings.Skin.Splitter - 8 ) nSplit = rcClient.Height() - Settings.Skin.Splitter; if ( nSplit != m_nDetails ) { m_nDetails = nSplit; Settings.Search.DetailPanelSize = nSplit; OnSize( SIZE_INTERNAL, 0, 0 ); Invalidate(); } } ReleaseCapture(); ClipCursor( NULL ); return TRUE; }
//**************************************************************************************** void CBCGFontComboBox::PreSubclassWindow() { CComboBox::PreSubclassWindow(); _AFX_THREAD_STATE* pThreadState = AfxGetThreadState (); if (pThreadState->m_pWndInit == NULL) { Init (); } }
void PASCAL CSocket::AuxQueueAdd(UINT message, WPARAM wParam, LPARAM lParam) { AFX_THREAD_STATE* pThreadState = AfxGetThreadState(); MSG* pMsg = new MSG; pMsg->message = message; pMsg->wParam = wParam; pMsg->lParam = lParam; pThreadState->m_listSocketNotifications.AddTail(pMsg); }
BOOL CAsyncSocket::AsyncSelect(long lEvent) { ASSERT(m_hSocket != INVALID_SOCKET); AFX_THREAD_STATE* pThreadState = AfxGetThreadState(); ASSERT(pThreadState->m_hSocketWindow != NULL); return WSAAsyncSelect(m_hSocket, pThreadState->m_hSocketWindow, WM_SOCKET_NOTIFY, lEvent) != SOCKET_ERROR; }
BOOL CLibraryFrame::DoSizePanel() { MSG* pMsg = &AfxGetThreadState()->m_msgCur; CRect rcClient; CPoint point; GetClientRect( &rcClient ); rcClient.left += m_nTreeSize + Settings.Skin.Splitter; rcClient.top += Settings.Skin.ToolbarHeight + m_nHeaderSize; rcClient.bottom -= Settings.Skin.ToolbarHeight; ClientToScreen( &rcClient ); ClipCursor( &rcClient ); SetCapture(); ScreenToClient( &rcClient ); int nOffset = 0xFFFF; while ( GetAsyncKeyState( VK_LBUTTON ) & 0x8000 ) { while ( ::PeekMessage( pMsg, NULL, WM_MOUSEFIRST, WM_MOUSELAST, PM_REMOVE ) ); if ( ! AfxGetThread()->PumpMessage() ) { AfxPostQuitMessage( 0 ); break; } GetCursorPos( &point ); ScreenToClient( &point ); int nSplit = rcClient.bottom - point.y; if ( nOffset == 0xFFFF ) nOffset = m_nPanelSize - nSplit; nSplit += nOffset; if ( nSplit < 8 ) nSplit = 0; if ( nSplit > rcClient.Height() - Settings.Skin.Splitter - 8 ) nSplit = rcClient.Height() - Settings.Skin.Splitter; if ( nSplit != m_nPanelSize ) { m_nPanelSize = nSplit; OnSize( 1982, 0, 0 ); Invalidate(); } } ReleaseCapture(); ClipCursor( NULL ); return TRUE; }
int CPlayerMgr::Run() { // TODO: 在此添加专用代码和/或调用基类 ASSERT_VALID(this); #ifndef _AFXDLL #define _AFX_SOCK_THREAD_STATE AFX_MODULE_THREAD_STATE #define _afxSockThreadState AfxGetModuleThreadState() _AFX_SOCK_THREAD_STATE* pState = _afxSockThreadState; if (pState->m_pmapSocketHandle == NULL) pState->m_pmapSocketHandle = new CMapPtrToPtr; if (pState->m_pmapDeadSockets == NULL) pState->m_pmapDeadSockets = new CMapPtrToPtr; if (pState->m_plistSocketNotifications == NULL) pState->m_plistSocketNotifications = new CPtrList; #endif if (!m_skListen.Socket(SOCK_STREAM, FD_ACCEPT)) return false; srand(time(NULL)); WORD nListenPort; while(true) { #ifdef _DEBUG nListenPort = 8880; #else nListenPort = 3000 + rand() % 1200; #endif if(m_skListen.Bind(nListenPort)) break; else { TRACE("bind error: %d\n", WSAGetLastError()); } } m_nListenPort = nListenPort; m_skListen.Listen(5); _AFX_THREAD_STATE* pTState = AfxGetThreadState(); while(true) { Process(); if(::PeekMessage(&(pTState->m_msgCur), NULL, NULL, NULL, PM_NOREMOVE)) { if (!PumpMessage()) return ExitInstance(); } } return 0; }
BOOL CChatWnd::DoSizeView() { MSG* pMsg = &AfxGetThreadState()->m_msgCur; CRect rcClient; GetClientRect( &rcClient ); ClientToScreen( &rcClient ); ClipCursor( &rcClient ); SetCapture(); GetClientRect( &rcClient ); int nOffset = 0xFFFF; while ( GetAsyncKeyState( VK_LBUTTON ) & 0x8000 ) { while ( ::PeekMessage( pMsg, NULL, WM_MOUSEFIRST, WM_MOUSELAST, PM_REMOVE ) ); if ( ! AfxGetThread()->PumpMessage() ) { AfxPostQuitMessage( 0 ); break; } CPoint point; GetCursorPos( &point ); ScreenToClient( &point ); int nSplit = rcClient.right - point.x; if ( nOffset == 0xFFFF ) nOffset = m_nUsersSize - nSplit; nSplit += nOffset; nSplit = max( nSplit, 0 ); nSplit = min( nSplit, (int)rcClient.right - SPLIT_SIZE ); if ( nSplit < 8 ) nSplit = 0; if ( nSplit > rcClient.right - SPLIT_SIZE - 8 ) nSplit = rcClient.right - SPLIT_SIZE; if ( nSplit != m_nUsersSize ) { m_nUsersSize = nSplit; OnSize( 1982, 0, 0 ); Invalidate(); } } ReleaseCapture(); ClipCursor( NULL ); return TRUE; }
void AFXAPI AfxWinTerm(void) { #ifdef _MAC AERemoveEventHandler(kCoreEventClass, kAEOpenApplication, _afxPfnOpenApp, false); AERemoveEventHandler(kCoreEventClass, kAEOpenDocuments, _afxPfnOpenDoc, false); AERemoveEventHandler(kCoreEventClass, kAEPrintDocuments, _afxPfnPrintDoc, false); AERemoveEventHandler(kCoreEventClass, kAEQuitApplication, _afxPfnQuit, false); #endif // unregister Window classes AFX_MODULE_STATE* pModuleState = AfxGetModuleState(); AfxLockGlobals(CRIT_REGCLASSLIST); LPTSTR lpsz = pModuleState->m_szUnregisterList; while (*lpsz != 0) { LPTSTR lpszEnd = _tcschr(lpsz, '\n'); ASSERT(lpszEnd != NULL); *lpszEnd = 0; UnregisterClass(lpsz, AfxGetInstanceHandle()); lpsz = lpszEnd + 1; } pModuleState->m_szUnregisterList[0] = 0; AfxUnlockGlobals(CRIT_REGCLASSLIST); // cleanup OLE if required CWinApp* pApp = AfxGetApp(); if (pApp != NULL && pApp->m_lpfnOleTermOrFreeLib != NULL) (*pApp->m_lpfnOleTermOrFreeLib)(TRUE, FALSE); // cleanup thread local tooltip window _AFX_THREAD_STATE* pThreadState = AfxGetThreadState(); if (pThreadState->m_pToolTip != NULL) { if (pThreadState->m_pToolTip->DestroyToolTipCtrl()) pThreadState->m_pToolTip = NULL; } if (!afxContextIsDLL) { // unhook windows hooks if (pThreadState->m_hHookOldMsgFilter != NULL) { ::UnhookWindowsHookEx(pThreadState->m_hHookOldMsgFilter); pThreadState->m_hHookOldMsgFilter = NULL; } if (pThreadState->m_hHookOldCbtFilter != NULL) { ::UnhookWindowsHookEx(pThreadState->m_hHookOldCbtFilter); pThreadState->m_hHookOldCbtFilter = NULL; } } }
BOOL CMenu::TrackPopupMenuEx( UINT fuFlags, int x, int y, CWnd *pWnd, LPTPMPARAMS lptpm ) /***************************************************************************************/ { _AFX_THREAD_STATE *pState = AfxGetThreadState(); ASSERT( pState != NULL ); pState->m_hTrackingWindow = pWnd->GetSafeHwnd(); pState->m_hTrackingMenu = m_hMenu; BOOL bRet = ::TrackPopupMenuEx( m_hMenu, fuFlags, x, y, pWnd->GetSafeHwnd(), lptpm ); pState->m_hTrackingWindow = NULL; pState->m_hTrackingMenu = NULL; return( bRet ); }
void CProtectedWinThread::PumpMessages() { ASSERT_VALID(this); // for tracking the idle time state BOOL bIdle = TRUE; LONG lIdleCount = 0; #if _MFC_VER >= 0x0710 _AFX_THREAD_STATE* pState = AfxGetThreadState(); MSG &msgCur = pState->m_msgCur; #else MSG &msgCur = m_msgCur; #endif /* _MFC_VER_ */ // 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(&msgCur, NULL, NULL, NULL, PM_NOREMOVE)) { // call OnIdle while in bIdle state if (!OnIdle(lIdleCount++)) bIdle = FALSE; // assume "no idle" state } // phase2: pump messages while available do { // pump message, but quit on WM_QUIT if (!PumpMessage()) { #if defined(_DEBUG) # if _MFC_VER < 0x0710 m_nDisablePumpCount--; // application must NOT die # else pState->m_nDisablePumpCount--; // application must NOT die # endif #endif return; } // reset "no idle" state after pumping "normal" message if (IsIdleMessage(&msgCur)) { bIdle = TRUE; lIdleCount = 0; } } while (::PeekMessage(&msgCur, NULL, NULL, NULL, PM_NOREMOVE)); } ASSERT(FALSE); // not reachable }