本文整理匯總了C++中AfxGetThreadState函數的典型用法代碼示例。如果您正苦於以下問題:C++ AfxGetThreadState函數的具體用法?C++ AfxGetThreadState怎麽用?C++ AfxGetThreadState使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了AfxGetThreadState函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C++代碼示例。
示例1: lstrcpyn
//--------------------------------------------------------------------------------------------------------------//
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;
}
示例2: while
//延時函數,測試環境是一個對話框程序
//如果超時中止,返回真,否則假。
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;
}
示例3: AfxOleTerm
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;
}
}
}
示例4: GetActiveWindow
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
}
示例5: AfxGetThreadState
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));
}
}
示例6: ASSERT
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();
}
示例7: ASSERT_VALID
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);
}
示例8: 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);
}
示例9: AfxGetThreadState
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;
}
示例10: ASSERT_VALID
//////////////////
// 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;
}
示例11: ASSERT
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);
}
}
示例12: dc
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);
}
}
示例13: AfxGetThreadState
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;
}
}
}
示例14: _AfxMsgFilterHook
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);
}
示例15: AfxCriticalNewHandler
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;
}