UINT fnTimerThreadProc( zPVOID p ) { ZTimer *pZTimer = (ZTimer *) p; HWND hWnd = pZTimer->m_hWnd; zUSHORT uInterval = (zUSHORT) pZTimer->m_lInterval; // DWORD dwStart = GetTickCount( ); // Stop if this has taken too long // if( GetTickCount() - dwStart >= TIMELIMIT ) // Cancel(); #ifdef DEBUG_ALL TraceLineI( "Starting Thread: ", (zLONG) AfxGetThread( ) ); #endif while ( mIs_hWnd( hWnd ) && pZTimer->m_bEnabled ) { SysWait( uInterval ); if ( mIs_hWnd( hWnd ) ) ProcessImmediateEvent( pZTimer, 1, 0 ); } #ifdef DEBUG_ALL TraceLineI( "All Done!!! Exiting Thread: ", (zLONG) AfxGetThread( ) ); #endif if ( mIs_hWnd( hWnd ) ) pZTimer->m_pThread = 0; return( 0 ); } // fnTimerThreadProc
void DataSocket::SetTransferType(int nType, BOOL bWaitForAccept) { m_nTransferType = nType; if (bWaitForAccept && !m_bConnected) { m_bInitialized = FALSE; return; } if (m_bConnected && m_nTransferType != -1) m_pConnectSocket->SendResponse("150 Connection accepted"); m_bInitialized = TRUE; switch(m_nTransferType) { case 0: // List Directory m_nStatus = XFERMODE_LIST; OnSend(0); break; case 1: // Send File if (PrepareSendFile(m_strData)) { m_nStatus = XFERMODE_SEND; m_bConnected = TRUE; OnSend(0); } else { Close(); } break; case 2: // Receive File if (PrepareReceiveFile(m_strData)) { m_nStatus = XFERMODE_RECEIVE; m_bConnected = TRUE; OnSend(0); } else { Close(); m_pConnectSocket->SendResponse("450 Can't access file."); // destroy this socket AfxGetThread()->PostThreadMessage(WM_THREADMSG, 0, 0); // upload failed ((ConnectThread *)AfxGetThread())->UpdateStatistic(FTPSTAT_UPLOADFAILED); } break; default: m_bInitialized = FALSE; break; } }
void DataSocket::OnConnect(int nErrorCode) { if (nErrorCode) { m_nStatus = XFERMODE_ERROR; m_pConnectSocket->SendResponse("425 Can't open data connection."); // destroy this socket AfxGetThread()->PostThreadMessage(WM_THREADMSG, 0, 0); } else { switch (m_nTransferType) { case 0: // List Directory m_nStatus = XFERMODE_LIST; m_bConnected = TRUE; OnSend(0); break; case 1: // Send File if (PrepareSendFile(m_strData)) { m_nStatus = XFERMODE_SEND; m_bConnected = TRUE; } else { Close(); } break; case 2: // Receive File if (PrepareReceiveFile(m_strData)) { m_nStatus = XFERMODE_RECEIVE; m_bConnected = TRUE; } else { Close(); m_pConnectSocket->SendResponse("450 can't access file."); // destroy this socket AfxGetThread()->PostThreadMessage(WM_THREADMSG, 0, 0); // upload failed ((ConnectThread *)AfxGetThread())->UpdateStatistic(FTPSTAT_UPLOADFAILED); } break; } } CAsyncSocket::OnConnect(nErrorCode); }
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 DoInit() { HINSTANCE hInstance = g_Instance; int nReturnCode = -1; CWinThread* pThread = AfxGetThread(); CWinApp* pApp = AfxGetApp(); // AFX internal initialization if (!AfxWinInit(hInstance, NULL, TEXT(""), SW_SHOW)) return DoExit(); // App global initializations (rare) if (pApp != NULL && !pApp->InitApplication()) return DoExit(); // Perform specific initializations if (!pThread->InitInstance()) { if (pThread->m_pMainWnd != NULL) { TRACE(traceAppMsg, 0, "Warning: Destroying non-NULL m_pMainWnd\n"); pThread->m_pMainWnd->DestroyWindow(); } nReturnCode = pThread->ExitInstance(); return DoExit(); } return TRUE; }
/////////////////////////////////////////////////////////////////////////////// // Seite einrichten (PrintLayout-Dialog anzeigen und auswerten) void CTRiASPreviewView::OnPreviewConfig() { m_PD.m_hWndParent = m_pPrintView -> GetSafeHwnd(); m_PD.m_pLayout -> m_lHeadlineLen = sizeof(m_cbBuffer); CViewPrintPreview *pPreview = (CViewPrintPreview *)m_pOrigView; ASSERT_VALID(pPreview); ASSERT(pPreview -> IsKindOf(RUNTIME_CLASS(CViewPrintPreview))); if (DEX_ShowPrintLayoutDlg(m_PD)) { // Neuinitialisierung veranlassen m_PP.pRenderDb = NULL; DEX_EndPrintPreview (m_PP); m_dcPrint.Detach(); // print DC is deleted by CPrintInfo destructor DELETE_OBJ(m_pPreviewInfo); // get rid of preview info DELETE_OBJ(m_pPreviewDC); // Get rid of preview DC object SetPrintView (m_pPrintView); // fertig melden pPreview -> HasConfig(); } else if (!pPreview -> GetHasConfig()) { // Dialog abgebrochen --> Druckvorschau schließen CWnd* pMainWnd = AfxGetThread()->m_pMainWnd; ASSERT_VALID(pMainWnd); pMainWnd -> PostMessage (WM_COMMAND, AFX_ID_PREVIEW_CLOSE); // Zeichnen abbrechen } }
// OnEndPrintPreview is here for swap tuning reasons // (see viewprev.cpp for complete preview mode implementation) void CView::OnEndPrintPreview(CDC* pDC, CPrintInfo* pInfo, POINT, CPreviewView* pView) { ASSERT_VALID(pDC); ASSERT_VALID(pView); if (pView->m_pPrintView != NULL) pView->m_pPrintView->OnEndPrinting(pDC, pInfo); CFrameWnd* pParent = (CFrameWnd*)AfxGetThread()->m_pMainWnd; ASSERT_VALID(pParent); ASSERT(pParent->IsKindOf(RUNTIME_CLASS(CFrameWnd))); // restore the old main window pParent->OnSetPreviewMode(FALSE, pView->m_pPreviewState); // Force active view back to old one pParent->SetActiveView(pView->m_pPreviewState->pViewActiveOld); if (pParent != GetParentFrame()) OnActivateView(TRUE, this, this); // re-activate view in real frame pView->DestroyWindow(); // destroy preview view // C++ object will be deleted in PostNcDestroy // restore main frame layout and idle message pParent->RecalcLayout(); pParent->SendMessage(WM_SETMESSAGESTRING, (WPARAM)AFX_IDS_IDLEMESSAGE, 0L); pParent->UpdateWindow(); }
// Another example //CWinApp-derived class BOOL CCMFCAutomationApp::InitInstance() { CWinApp::InitInstance(); // Initialize OLE libraries if (!AfxOleInit()) { AfxMessageBox(IDP_OLE_INIT_FAILED); return FALSE; } CWinThread* pThread = AfxGetThread(); if (pThread != NULL) { // Destroy message filter, thereby unregistering it. delete pThread->m_pMessageFilter; pThread->m_pMessageFilter = NULL; // Create the new message filter object. //CMyMessageFilter is derived from COleMessageFilter pThread->m_pMessageFilter = new CMyMessageFilter; ASSERT(AfxOleGetMessageFilter() != NULL); // Register the new message filter object. AfxOleGetMessageFilter()->Register(); }
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); }
BOOL AfxInternalPreTranslateMessage(MSG* pMsg) { // ASSERT_VALID(this); CWinThread *pThread = AfxGetThread(); if( pThread ) { // if this is a thread-message, short-circuit this function if (pMsg->hwnd == NULL && pThread->DispatchThreadMessageEx(*pMsg)) return TRUE; } // walk from target to main window CWnd* pMainWnd = AfxGetMainWnd(); if (CWnd::WalkPreTranslateTree(pMainWnd->GetSafeHwnd(), pMsg)) return TRUE; // in case of modeless dialogs, last chance route through main // window's accelerator table if (pMainWnd != NULL) { CWnd* pWnd = CWnd::FromHandle(pMsg->hwnd); if (pWnd->GetTopLevelParent() != pMainWnd) return pMainWnd->PreTranslateMessage(pMsg); } return FALSE; // no special processing }
BOOL TChart::Create(CWnd* pParentWnd,const RECT& rect) { BOOL ret; void *x; CClientDC cdc(pParentWnd); ret=CWnd::Create(0, Name, WS_CHILD | WS_BORDER, rect, pParentWnd, ID_CHART, 0); font1.CreatePointFont(60,"MS Sans Serif"); font2.CreatePointFont(100,"Arial"); if((x=Series.GainAcsess(WRITE))!=NULL) { SeriesProtector guard(x); TSeriesArray& series(guard); series.Parent=this; series.Parent=this; series.SetRender(SERIES_RENDER); } SetFont(&font1); menu1.LoadMenu(IDR_MENU2); OnPaintTimer.Start(); pThrd=AfxGetThread(); pWND=this; BckgBrush.CreateSolidBrush(RGB(140,140,140)); InitBasicElements(); OnSeriesUpdate(0,0); return ret; }
// ============================================================================ CVisualMSThread* CVisualMSThread::GetRunningThread() { // Make sure this function is being called from within an executing // CVisualMSThread by runtime checking the class. CWinThread *pThread = AfxGetThread(); if(pThread && pThread->IsKindOf(RUNTIME_CLASS(CVisualMSThread))) return (CVisualMSThread*)pThread; return NULL; }
void AFXAPI AfxPostQuitMessage(int nExitCode) { // cleanup OLE libraries CWinThread* pThread = AfxGetThread(); if (pThread != NULL && pThread->m_lpfnOleTermOrFreeLib != NULL) (*pThread->m_lpfnOleTermOrFreeLib)(TRUE, TRUE); ::PostQuitMessage(nExitCode); }
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; }
static void syncThread() { static MSG dispatch; while (PeekMessage( &dispatch, NULL, 0, 0, PM_NOREMOVE)) { if (!AfxGetThread()->PumpMessage()) {} } }
int AFXAPI AfxWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow) { ASSERT(hPrevInstance == NULL); int nReturnCode = -1; __try { CWinThread* pThread = AfxGetThread(); CWinApp* pApp = AfxGetApp(); // AFX internal initialization if (!AfxWinInit(hInstance, hPrevInstance, lpCmdLine, nCmdShow)) goto InitFailure; // App global initializations (rare) if (pApp != NULL && !pApp->InitApplication()) goto InitFailure; // Perform specific initializations if (!pThread->InitInstance()) { if (pThread->m_pMainWnd != NULL) { TRACE(traceAppMsg, 0, "Warning: Destroying non-NULL m_pMainWnd\n"); pThread->m_pMainWnd->DestroyWindow(); } nReturnCode = pThread->ExitInstance(); goto InitFailure; } nReturnCode = pThread->Run(); InitFailure: #ifdef _DEBUG // Check for missing AfxLockTempMap calls if (AfxGetModuleThreadState()->m_nTempMapLock != 0) { TRACE(traceAppMsg, 0, "Warning: Temp map lock count non-zero (%ld).\n", AfxGetModuleThreadState()->m_nTempMapLock); } AfxLockTempMaps(); AfxUnlockTempMaps(-1); #else ; #endif } __except(RecordExceptionInfo(GetExceptionInformation())) { } // must call AfxWinTerm after handling exception or we'll crash // again trying to destroy the tooltip window AfxWinTerm(); return nReturnCode; }
void CPreviewView::OnPreviewPrint() { CView* pOrigView = m_pOrigView; OnPreviewClose(); // force close of Preview // cause print (can be overridden by catching the command) CWnd* pMainWnd = AfxGetThread()->m_pMainWnd; ASSERT_VALID(pMainWnd); pMainWnd->SendMessage(WM_COMMAND, ID_FILE_PRINT); }
/////////////////////////////////////////////////////////////////////////////// // Schließen mit anschließendem Drucken void CTRiASPreviewView::OnPreviewPrint() { OnPreviewClose(); // force close of Preview // cause print (can be overridden by catching the command) CWnd* pMainWnd = AfxGetThread()->m_pMainWnd; ASSERT_VALID(pMainWnd); pMainWnd -> PostMessage(WM_COMMAND, IDM_FILE_PRINT); // Drucken auslösen }
LIBELCBASEUI_API BOOL ElcBase_FilterDllMsg(MSG* pMsg) { AFX_MANAGE_STATE(AfxGetStaticModuleState()); TRY { return AfxGetThread()->PreTranslateMessage(pMsg); } END_TRY return FALSE; }
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; }
bool CProgressDlg::Abort() { // Allow any messages to be processed MSG msg; while (::PeekMessage(&msg, NULL, NULL, NULL, PM_NOREMOVE)) { AfxGetThread()->PumpMessage(); } return m_abort; }
LIBELCBASEUI_API void ElcBase_ProcessDllIdle() { AFX_MANAGE_STATE(AfxGetStaticModuleState()); TRY { long lCount = 0; while (AfxGetThread()->OnIdle(lCount)) lCount++; } END_TRY }
void AFXAPI AfxEndThread( UINT nExitCode, BOOL bDelete ) /******************************************************/ { if( bDelete ) { CWinThread *pThread = AfxGetThread(); if( pThread->m_bAutoDelete ) { delete pThread; } } ::ExitThread( nExitCode ); }
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; }
BOOL CALLBACK _AfxAbortProc(HDC, int) { _AFX_WIN_STATE* pWinState = _afxWinState; MSG msg; while (!pWinState->m_bUserAbort && ::PeekMessage(&msg, NULL, NULL, NULL, PM_NOREMOVE)) { if (!AfxGetThread()->PumpMessage()) return FALSE; // terminate if WM_QUIT received } return !pWinState->m_bUserAbort; }
void CMktStructureBaseDlg::DoEvents() { MSG msg; // Process existing messages in the application's message queue. // When the queue is empty, do clean up and return. while (::PeekMessage(&msg,NULL,0,0,PM_NOREMOVE) && !m_bCanceled) { if (!AfxGetThread()->PumpMessage()) return; } }
void MessageForWindow::DispatchMsg( void *t ) { ASSERT(Msg); ASSERT(Reciver.pThrd); ASSERT(Reciver.pWND); CWinThread *thrd=AfxGetThread(); if(thrd==Reciver.pThrd) { Reciver.pWND->PostMessage(Msg,wParam,(LPARAM)t); } else Reciver.pThrd->PostThreadMessage(UM_GENERIC_MESSAGE,wParam,(LPARAM)t); }
void CMonitorBarCtrl::OnLButtonDown(UINT nFlags, CPoint point) { if ( m_rcTrack.PtInRect( point ) ) { MSG* pMsg = &AfxGetThreadState()->m_msgCur; CRect rcTrack( &m_rcTrack ); ClientToScreen( &rcTrack ); ClipCursor( &rcTrack ); ScreenToClient( &rcTrack ); rcTrack.DeflateRect( m_rcTab.Width() / 2, 0 ); m_bTab = TRUE; Invalidate(); while ( GetAsyncKeyState( VK_LBUTTON ) & 0x8000 ) { while ( ::PeekMessage( pMsg, NULL, WM_MOUSEFIRST, WM_MOUSELAST, PM_REMOVE ) ); if ( ! AfxGetThread()->PumpMessage() ) { AfxPostQuitMessage( 0 ); break; } CPoint pt; GetCursorPos( &pt ); ScreenToClient( &pt ); int nPosition = (DWORD)( 110.0f * (float)( pt.x - rcTrack.left ) / (float)rcTrack.Width() ); if ( nPosition < 0 ) nPosition = 0; else if ( nPosition >= 105 ) nPosition = 101; else if ( nPosition >= 100 ) nPosition = 100; if ( nPosition != (int)Settings.Live.BandwidthScale ) { Settings.Live.BandwidthScale = (DWORD)nPosition; Invalidate(); } } m_bTab = FALSE; ReleaseCapture(); ClipCursor( NULL ); Invalidate(); } else { CControlBar::OnLButtonDown( nFlags, point ); } }
bool AfxDoIdle() { MSG msg; while (::PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE)) { if (!AfxGetThread()->PumpMessage()) return false; } LONG lIdle = 0; while (AfxGetApp()->OnIdle(lIdle++)) { Sleep(10); }; return true; };
bool EClientSocket::eConnect( const char *host, UINT port, int clientId, bool extraAuth) { // already connected? if( isConnected()) { getWrapper()->error( NO_VALID_ID, ALREADY_CONNECTED.code(), ALREADY_CONNECTED.msg()); return false; } // init sockets AfxSocketInit(); // close open connection if there was one eDisconnect(); // create socket m_pSocket.reset(new MySocket(this)); if( !m_pSocket->Create()) { eDisconnect(); getWrapper()->winError( "Failed to create socket", GetLastError() ); getWrapper()->error( NO_VALID_ID, FAIL_CREATE_SOCK.code(), FAIL_CREATE_SOCK.msg()); return false; } // use local machine if no host passed in if( !(host && *host)) { host = "127.0.0.1"; } // connect to server if( !m_pSocket->Connect(host, port)) { int lastError = GetLastError(); if( lastError != WSAEWOULDBLOCK && !handleSocketError(GetLastError())) { return false; } } setClientId( clientId); setExtraAuth( extraAuth); { // Wait till we are fully connected (or for an error) CWinThread* pThread = AfxGetThread(); while( m_pSocket.get() && !isConnected()) { if (!pThread->PumpMessage()) return false; } } return true; }