• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ MsgWaitForMultipleObjects函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中MsgWaitForMultipleObjects函数的典型用法代码示例。如果您正苦于以下问题:C++ MsgWaitForMultipleObjects函数的具体用法?C++ MsgWaitForMultipleObjects怎么用?C++ MsgWaitForMultipleObjects使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了MsgWaitForMultipleObjects函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: IsVisible

int Win::DoModal()
{
	WinID lastParentFC = parent ? parent->lastFocusChild : 0; 
	bool visibled = IsVisible();
	bool enabled = IsEnabled();
	try {
		if (!visibled) Show();
		if (!enabled) Enable(true);

		if (parent && type != WT_POPUP) parent->RecalcLayouts();

		AppBlock(GetID());
		UnblockTree(GetID());

		ModalStruct modalStruct;
		modal = &modalStruct;

		MSG msg;
		
		while (!modalStruct.end) 
		{
			wth_DoEvents();
			if (modalStruct.end) break;

			if (!PeekMessage(&msg, NULL, 0, 0,PM_NOREMOVE))
			{
				unsigned waitTime = RunTimers();
				if (waitTime > 5000) waitTime = 5000;
				if (modalStruct.end) break;

				HANDLE thEvent = wthInternalEvent.SignalFD();
				DWORD res = MsgWaitForMultipleObjects(1,&thEvent,FALSE, waitTime, QS_ALLINPUT);

				if (res == WAIT_TIMEOUT) CheckMousePosition();

				continue;
			}

			if (!GetMessage(&msg, NULL, 0, 0)) 
				break;

			DispatchMessage(&msg);
		}

		modal = 0;
		AppUnblock(GetID());
		if (!visibled) Hide();

///
		if (type == WT_POPUP || type == WT_CHILD && parent) 
		{
			Win *w = GetWinByID(lastParentFC);
			if (w) w->SetFocus();
		}

		return modalStruct.id;
	} catch (...) {
		modal = 0;
		AppUnblock(GetID());
		if (!visibled) Hide(); 
		throw;
	}
}
开发者ID:carriercomm,项目名称:WalCommander,代码行数:63,代码来源:swl_wincoreMS.cpp


示例2: rpl_select


//.........这里部分代码省略.........
            }
          if (wbits.in[i / CHAR_BIT] & (1 << (i & (CHAR_BIT - 1))))
            {
              requested |= FD_WRITE | FD_CONNECT;
              FD_SET ((SOCKET) h, wfds);
              FD_SET ((SOCKET) h, &handle_wfds);
            }
          if (xbits.in[i / CHAR_BIT] & (1 << (i & (CHAR_BIT - 1))))
            {
              requested |= FD_OOB;
              FD_SET ((SOCKET) h, xfds);
              FD_SET ((SOCKET) h, &handle_xfds);
            }

          WSAEventSelect ((SOCKET) h, hEvent, requested);
          nsock++;
        }
      else
        {
          handle_array[nhandles++] = h;

          /* Poll now.  If we get an event, do not wait below.  */
          if (wait_timeout != 0
              && windows_poll_handle (h, i, &rbits, &wbits, &xbits))
            wait_timeout = 0;
        }
    }

  if (wait_timeout == 0 || nsock == 0)
    rc = 0;
  else
    {
      /* See if we need to wait in the loop below.  If any select is ready,
         do MsgWaitForMultipleObjects anyway to dispatch messages, but
         no need to call select again.  */
      rc = select (0, &handle_rfds, &handle_wfds, &handle_xfds, &tv0);
      if (rc == 0)
        {
          /* Restore the fd_sets for the other select we do below.  */
          memcpy (&handle_rfds, rfds, sizeof (fd_set));
          memcpy (&handle_wfds, wfds, sizeof (fd_set));
          memcpy (&handle_xfds, xfds, sizeof (fd_set));
        }
      else
        wait_timeout = 0;
    }

  for (;;)
    {
      ret = MsgWaitForMultipleObjects (nhandles, handle_array, FALSE,
                                       wait_timeout, QS_ALLINPUT);

      if (ret == WAIT_OBJECT_0 + nhandles)
        {
          /* new input of some other kind */
          BOOL bRet;
          while ((bRet = PeekMessage (&msg, NULL, 0, 0, PM_REMOVE)) != 0)
            {
              TranslateMessage (&msg);
              DispatchMessage (&msg);
            }
        }
      else
        break;
    }
开发者ID:encore-zhou,项目名称:DyVerifyUsingCrest,代码行数:66,代码来源:select.c


示例3: PeekMessage

DWORD Scheduler::SchedulerThreadProcPrivate()
{
    HRESULT hr = S_OK;
    MSG     msg;
    LONG    lWait = INFINITE;
    BOOL    bExitThread = FALSE;

    // Force the system to create a message queue for this thread.
    // (See MSDN documentation for PostThreadMessage.)
    PeekMessage(&msg, NULL, WM_USER, WM_USER, PM_NOREMOVE);

    // Signal to the scheduler that the thread is ready.
    SetEvent(m_hThreadReadyEvent);

    while( !bExitThread )
    {
        // Wait for a thread message OR until the wait time expires.
        DWORD dwResult = MsgWaitForMultipleObjects(0, NULL, FALSE, lWait, QS_POSTMESSAGE);

        if (dwResult == WAIT_TIMEOUT)
        {
            // If we timed out, then process the samples in the queue
            hr = ProcessSamplesInQueue(&lWait);
            if (FAILED(hr))
            {
                bExitThread = TRUE;
            }
        }

        while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
        {
            BOOL bProcessSamples = TRUE;

            switch (msg.message) 
            {
            case eTerminate:
                TRACE((L"eTerminate\n"));
                bExitThread = TRUE;
                break;

            case eFlush:
                // Flushing: Clear the sample queue and set the event.
                m_ScheduledSamples.Clear();
                lWait = INFINITE;
                SetEvent(m_hFlushEvent);
                break;

            case eSchedule:
                // Process as many samples as we can.
                if (bProcessSamples)
                {
                    hr = ProcessSamplesInQueue(&lWait);
                    if (FAILED(hr))
                    {
                        bExitThread = TRUE;
                    }
                    bProcessSamples = (lWait != INFINITE); 
                }
                break;
            } // switch  

        } // while PeekMessage
    
    }  // while (!bExitThread)

    TRACE((L"Exit scheduler thread.\n"));
    return (SUCCEEDED(hr) ? 0 : 1);
}
开发者ID:AbdoSalem95,项目名称:WindowsSDK7-Samples,代码行数:68,代码来源:scheduler.cpp


示例4: choose_destination_file_and_convert


//.........这里部分代码省略.........
  EnableWindow(hwnd, FALSE);
  ShowWindow(params->status_window, SW_SHOWNORMAL);
  UpdateWindow(params->status_window);
  SetWindowLong(params->status_window, GWL_USERDATA, (LONG)&play_pause_stop);
  thread = CreateThread(NULL, 0, prg2wav_thread, params, 0, &thread_id);
  is_to_sound = IsDlgButtonChecked(hwnd, IDC_TO_SOUND);
  if (is_to_sound) {
    HWND stop_button = GetDlgItem(params->status_window, IDCANCEL);
    RECT window_rect, play_pause_button_rect;
    stop_icon = LoadBitmap(instance, MAKEINTRESOURCE(IDB_STOP));
    play_pause_stop.play_icon = LoadBitmap(instance, MAKEINTRESOURCE(IDB_PLAY));
    play_pause_stop.pause_icon = LoadBitmap(instance, MAKEINTRESOURCE(IDB_PAUSE));
    /* make sure the pause button is visible and shows the pause icon*/
    SendDlgItemMessage(params->status_window, IDC_PLAYPAUSE, BM_SETIMAGE, (WPARAM)IMAGE_BITMAP, (LPARAM)play_pause_stop.pause_icon);
    ShowWindow(GetDlgItem(params->status_window, IDC_PLAYPAUSE), SW_SHOW);
    /* get width of window */
    GetClientRect(params->status_window, &window_rect);
    /* get absolute position of play-pause button */
    GetWindowRect(GetDlgItem(params->status_window, IDC_PLAYPAUSE), &play_pause_button_rect);
    /* get position of play-pause button within window */
    MapWindowPoints(NULL, params->status_window, (LPPOINT)&play_pause_button_rect, 2);
    /* make stop button as big as play-pause button, top-aligned and symmetrically placed */
    MoveWindow(stop_button,
      window_rect.right - play_pause_button_rect.right,
      play_pause_button_rect.top,
      play_pause_button_rect.right - play_pause_button_rect.left,
      play_pause_button_rect.bottom - play_pause_button_rect.top,
      TRUE);
    /* make sure the stop button shows the stop icon instead of the word Cancel*/
    SetWindowLongPtr(stop_button, GWL_STYLE, GetWindowLongPtr(stop_button, GWL_STYLE) | BS_BITMAP);
    SendDlgItemMessage(params->status_window, IDCANCEL, BM_SETIMAGE, (WPARAM)IMAGE_BITMAP, (LPARAM)stop_icon);
  }

  while (1) {
    DWORD retval;
    retval =
      MsgWaitForMultipleObjects(1, &thread, FALSE, INFINITE, QS_ALLINPUT);
    if (retval == WAIT_OBJECT_0)
      break;
    while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) {
      if (is_to_sound && msg.message == WM_KEYDOWN) {
        if (msg.wParam == VK_MEDIA_PLAY_PAUSE)
          PostMessage (params->status_window, WM_COMMAND, IDC_PLAYPAUSE, 0);
        else if (msg.wParam == VK_MEDIA_STOP)
          PostMessage (params->status_window, WM_COMMAND, IDCANCEL, 0);
      }
      TranslateMessage(&msg);
      DispatchMessage(&msg);
    }
  }

  EnableWindow(hwnd, TRUE);
  DestroyWindow(params->status_window);

  tap2audio_close(params->file);
  remove_all_simple_block_list_elements(&params->program);
  if (IsDlgButtonChecked(hwnd, IDC_TO_SOUND)) {
    DeleteObject(play_pause_stop.play_icon);
    DeleteObject(play_pause_stop.pause_icon);
    DeleteObject(stop_icon);
  }
}

static void choose_file(HWND hwnd){
  char name[1024] = "";
  OPENFILENAMEA ofn;
  struct prg2wav_params params;

  params.program = NULL;

  memset(&ofn, 0, sizeof(ofn));
  ofn.lStructSize = sizeof(ofn);
  ofn.hwndOwner = hwnd;
  ofn.hInstance = instance;
  ofn.lpstrFilter =
    "All supported types\0*.t64;*.prg;*.p00\0Tape image files (*.t64)\0*.t64\0Program files (*.prg)\0*.prg\0PC64 files (*.p00)\0*.p00\0All files\0*.*\0\0";
  ofn.lpstrCustomFilter = NULL;
  ofn.nMaxCustFilter = 0;
  ofn.nFilterIndex = 1;
  ofn.lpstrFile = name;
  ofn.nMaxFile = sizeof(name);
  ofn.lpstrFileTitle = NULL;
  ofn.nMaxFileTitle = 0;
  ofn.lpstrInitialDir = NULL;
  ofn.lpstrTitle = "Choose the PRG, P00 or T64 file";
  ofn.Flags = (OFN_EXPLORER
               | OFN_HIDEREADONLY
               | OFN_NOTESTFILECREATE
               | OFN_FILEMUSTEXIST
               | OFN_ENABLEHOOK | OFN_ENABLETEMPLATE | OFN_SHAREAWARE);
  ofn.lpfnHook = frompc_hook_proc;
  ofn.lpTemplateName = MAKEINTRESOURCEA(IDD_CONTENTS);
  ofn.nFileOffset = 0;
  ofn.nFileExtension = 0;
  ofn.lpstrDefExt = NULL;
  ofn.lCustData = (LPARAM)&params.program;

  if (GetOpenFileNameA(&ofn))
    choose_destination_file_and_convert(hwnd, &params);
}
开发者ID:bitfixer,项目名称:bitfixer,代码行数:101,代码来源:prg2wav_gui.c


示例5: ATLTRACE

STDMETHODIMP CXMLDOMDocument::loadXML(BSTR bstrXML, VARIANT_BOOL  *isSuccessful)
{
	ATLTRACE(_T("CXMLDOMDocument::loadXML\n"));

	if (NULL == isSuccessful)
		return E_POINTER;

	*isSuccessful = VARIANT_FALSE;

	// do not start another thread if there is another active
	if (NULL != m_hParseThread) {
		DWORD exitCode = 0;
		BOOL rc = ::GetExitCodeThread(m_hParseThread, &exitCode);
		if (!rc || STILL_ACTIVE == exitCode)
			return S_OK;
		
		::CloseHandle(m_hParseThread);
		m_hParseThread = NULL;
	}

	HRESULT hr = S_OK;
	m_bAbort = false;
	
	m_FileName = _T("");
	m_TmpDocument = 0;
	m_bThreadValidate = m_bValidate;
	
	m_xml = bstrXML;
	if (0 == m_xml.length())
		return E_INVALIDARG;

	UINT nthreadID = 0;
	m_hParseThread = reinterpret_cast<HANDLE> (_beginthreadex(NULL,
												 0,
											     CXMLDOMDocument::ParseThread,
												 (void *) this,
												 0,
												 &nthreadID));
	if (NULL == m_hParseThread)
		return S_OK;
	
	if (m_bAsync) {
		*isSuccessful = VARIANT_TRUE;
		return S_OK;
	}

	bool bWait = true;
	while (bWait) {
		DWORD dwEvt = MsgWaitForMultipleObjects(1,&m_hParseThread,FALSE,INFINITE,QS_ALLINPUT);
		switch(dwEvt) {
			case WAIT_OBJECT_0:
				bWait = false;
				break;
			case WAIT_OBJECT_0 + 1:
			{
				MSG msg;
				while(::PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE)) {
					if (WM_CLOSE == msg.message || WM_QUIT == msg.message) {
						 bWait = false;
						 m_bAbort = true;
						 break;
					}
					else {
						PeekMessage(&msg, NULL, 0, 0, PM_REMOVE);
						TranslateMessage(&msg);
						DispatchMessage(&msg);
					}
				}
				break;
			}
			default:
				m_bAbort = true;
				bWait = false;
				break;
		}
	}

	if (m_bAbort)
		return S_OK;

	if (m_bParseError)
		return hr;

    if(m_Document)
        delete m_Document;
	m_Document = m_TmpDocument;
	m_TmpDocument = 0;
	
	m_url = m_FileName;
	*isSuccessful = VARIANT_TRUE;
	
	return hr;
}
开发者ID:syoutetu,项目名称:ColladaViewer_VC8,代码行数:93,代码来源:XMLDOMDocument.cpp


示例6: ASSERT

//on thread can only call putSync once on the callstack.
DSRequest DSRequestQueue::putSync(DSRequest req, BOOL bKeepUIActive)
{	
	HANDLE hEvents[1]; 
	DWORD dwWaitResult;
	int iDebug=0;
	HRESULT hr = S_OK;

	ASSERT(m_pSetRequests);
	if(!m_pSetRequests || !m_dwThreadWorker)
	{
		DSRequest req;
		req.setHR(E_FAIL);
		return req;
	}

	m_pSetRequests->AddRef();
	DSTSSetOfRequests *pSetRequests = m_pSetRequests;

	//not important what this handle is.
	hEvents[0]=m_hThreadWorker;
	ASSERT(hEvents[0]);
	EnterCriticalSection(&m_critsec);
		DSRequest returnValue;		
		
		//put into queue.
		req.putSync(m_dwTotalRequests);		
		put(req);
		
	//leave the critical section so others can put stuff in.		
	LeaveCriticalSection(&m_critsec);	

	//Wait for message to come.
	MSG msg;
	BOOL bRet;
	BOOL bQuit=FALSE;
	
	//
	//Note that we have the possibility of this call stack:
	// putsync (A)
	//    wait for (A).
	//        putsync (B).
	//            wait for (B).
	//                 (A) appears.
	//                 (B) appears.

	CString strMsg = "PutSync threadID:"+str(::GetCurrentThreadId())+"\n";
	TRACE(strMsg);

	DSTSSetOfRequests::FindResult fr;
				
	while(!bQuit)
	{
		dwWaitResult = MsgWaitForMultipleObjects(1,hEvents,FALSE,1000,QS_ALLEVENTS);
	
		if(dwWaitResult==WAIT_TIMEOUT)
			TRACE("PutSync::MsgWait timed out: %i\n", iDebug++);
		else if((dwWaitResult>=WAIT_OBJECT_0) && (dwWaitResult<= (WAIT_OBJECT_0 + 2)))
			TRACE("PutSync::MsgWait got a signal: %i\n", iDebug++);
		else if((dwWaitResult>=WAIT_ABANDONED_0) && (dwWaitResult <= (WAIT_ABANDONED_0 + 2 - 1 )))
			TRACE("PutSync::MsgWait abandoned: %i\n", iDebug++);
		else if((dwWaitResult>=WAIT_IO_COMPLETION) && (dwWaitResult <= (WAIT_IO_COMPLETION + 2 - 1)))
			TRACE("PutSync::MsgWait IO_COMPLETION: %i\n", iDebug++);		
		else if(dwWaitResult==0xFFFFFFFF)
		{
			TRACE("MsgWait failed: %i\n", iDebug++);		
			DWORD dwError = GetLastError();	
			LPVOID lpMsgBuf;
			FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL,
			    dwError, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR) &lpMsgBuf,    0,    NULL );
			TRACE((LPTSTR)lpMsgBuf);
			LocalFree( lpMsgBuf );

			//This is caused by the invalid handle of the closed thread. It's okay.
		}
		else ASSERT(0);
		
		bRet = ::PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE);
		
		while(bRet && !bQuit)
		{
			bRet = ::GetMessage(&msg, NULL, 0, 0);
			
			ASSERT( (int)bRet != -1 );
			if (bRet)
			{
				if(msg.message==WM_SYNC_CALL_FINISHED)
				{				 			    
					ASSERT(msg.hwnd==NULL);

					DSRequest tempRetvalue;
					tempRetvalue.putSync(msg.wParam);

					//look for a response of ID tempRetValue. This will fill the rest of the struct out.
					fr = pSetRequests->find(tempRetvalue,tempRetvalue);
					if(fr == DSTSSetOfRequests::FR_TERMINATE)
					{
						TRACE("PutSync: The worker thread has terminated. Quiting without waiting for Signal\n.");
						bQuit=TRUE;					
					}
//.........这里部分代码省略.........
开发者ID:opensim4opencog,项目名称:PrologVirtualWorlds,代码行数:101,代码来源:dqueue.cpp


示例7: main

int
main(int argc, char *argv[])
{
    char pipe[2048];
    MSG msg;
    STARTUPINFO si = { 0, };
    PROCESS_INFORMATION pi = { 0, };
    gchar *program_path = get_program_path();
    gchar *command;
    int rv = 0;

    argv[0] = "gdb -ex run --args";
    command = g_strjoinv(" ", argv);

    snprintf(pipe, sizeof(pipe), "\\\\.\\pipe\\SpiceController-%lu", GetCurrentProcessId());

    SetEnvironmentVariable("SPICE_DEBUG", "1");
    SetEnvironmentVariable("G_MESSAGES_DEBUG", "all");
    SetEnvironmentVariable("SPICE_XPI_NAMEDPIPE", pipe);

    si.cb = sizeof(si);
    if (!CreateProcess(NULL,
                       command,
                       NULL,
                       NULL,
                       FALSE,
                       0,
                       NULL,
                       program_path,
                       &si,
                       &pi)) {
        printf("CreateProcess failed (%ld).\n", GetLastError());
        rv = 1;
        goto end;
    }


    while (1) {
        DWORD reason = MsgWaitForMultipleObjects(1, &pi.hProcess, FALSE,
                                                 INFINITE, QS_ALLINPUT);
        if (reason == WAIT_OBJECT_0)
            break;
        else {
            if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) {
                TranslateMessage(&msg);
                DispatchMessage(&msg);
            }
        }
    }

    // Close process and thread handles
    CloseHandle(pi.hProcess);
    CloseHandle(pi.hThread);

end:
    g_free(program_path);
    g_free(command);

    exit(rv);
    return rv;
}
开发者ID:Jactry,项目名称:virt-viewer,代码行数:61,代码来源:debug-helper.c


示例8: CaptureThread

DWORD WINAPI CaptureThread(HANDLE hDllMainThread)
{
    bool bSuccess = false;

    //wait for dll initialization to finish before executing any initialization code
    if(hDllMainThread)
    {
        WaitForSingleObject(hDllMainThread, INFINITE);
        CloseHandle(hDllMainThread);
    }

    TCHAR lpLogPath[MAX_PATH];
    SHGetFolderPath(NULL, CSIDL_APPDATA, NULL, SHGFP_TYPE_CURRENT, lpLogPath);
    wcscat_s(lpLogPath, MAX_PATH, TEXT("\\OBS\\pluginData\\captureHookLog.txt"));

    dummyEvent = CreateEvent(NULL, FALSE, FALSE, NULL);

    if(!logOutput.is_open())
        logOutput.open(lpLogPath, ios_base::in | ios_base::out | ios_base::trunc, _SH_DENYNO);

    wstringstream str;
    str << OBS_KEEPALIVE_EVENT << UINT(GetCurrentProcessId());
    strKeepAlive = str.str();

    logOutput << CurrentDateTimeString() << "we're booting up: " << endl;

    InitializeCriticalSection(&d3d9EndMutex);
    InitializeCriticalSection(&glMutex);

    WNDCLASS wc;
    ZeroMemory(&wc, sizeof(wc));
    wc.hInstance = hinstMain;
    wc.lpszClassName = SENDER_WINDOWCLASS;
    wc.lpfnWndProc = (WNDPROC)DefWindowProc;

    DWORD procID = GetCurrentProcessId();

    wstringstream strRestartEvent, strEndEvent, strReadyEvent, strExitEvent, strInfoMemory;
    strRestartEvent << RESTART_CAPTURE_EVENT << procID;
    strEndEvent     << END_CAPTURE_EVENT     << procID;
    strReadyEvent   << CAPTURE_READY_EVENT   << procID;
    strExitEvent    << APP_EXIT_EVENT        << procID;
    strInfoMemory   << INFO_MEMORY           << procID;

    hSignalRestart  = GetEvent(strRestartEvent.str().c_str());
    hSignalEnd      = GetEvent(strEndEvent.str().c_str());
    hSignalReady    = GetEvent(strReadyEvent.str().c_str());
    hSignalExit     = GetEvent(strExitEvent.str().c_str());

    hInfoFileMap = CreateFileMapping(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0, sizeof(CaptureInfo), strInfoMemory.str().c_str());
    if(!hInfoFileMap)
    {
        logOutput << CurrentTimeString() << "CaptureThread: could not info file mapping" << endl;
        return 0;
    }

    infoMem = (CaptureInfo*)MapViewOfFile(hInfoFileMap, FILE_MAP_ALL_ACCESS, 0, 0, sizeof(CaptureInfo));
    if(!infoMem)
    {
        logOutput << CurrentTimeString() << "CaptureThread: could not map view of info shared memory" << endl;
        CloseHandle(hInfoFileMap);
        hInfoFileMap = NULL;
        return 0;
    }

    hwndOBS = FindWindow(OBS_WINDOW_CLASS, NULL);
    if(!hwndOBS)
    {
        logOutput << CurrentTimeString() << "CaptureThread: could not find main application window?  wtf?  seriously?" << endl;
        return 0;
    }

    if (RegisterClass(&wc)) {
        hwndSender = CreateWindow(SENDER_WINDOWCLASS, NULL, 0, 0, 0, 0, 0, NULL, 0, hinstMain, 0);
        if (hwndSender) {
            textureMutexes[0] = OpenMutex(MUTEX_ALL_ACCESS, FALSE, TEXTURE_MUTEX1);
            if (textureMutexes[0]) {
                textureMutexes[1] = OpenMutex(MUTEX_ALL_ACCESS, FALSE, TEXTURE_MUTEX2);
                if (textureMutexes[1]) {
                    while(!AttemptToHookSomething())
                        Sleep(50);

                    logOutput << CurrentTimeString() << "(half life scientist) everything..  seems to be in order" << endl;

                    MSG msg;
                    while (MsgWaitForMultipleObjects(1, &dummyEvent, FALSE, 3000, QS_ALLPOSTMESSAGE) != WAIT_ABANDONED_0) {
                    //while (1) {
                        AttemptToHookSomething();

                        if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) {
                            TranslateMessage(&msg);
                            DispatchMessage(&msg);
                        }

                        //Sleep(50);
                    }

                    CloseHandle(textureMutexes[1]);
                    textureMutexes[1] = NULL;
                } else {
//.........这里部分代码省略.........
开发者ID:Crehl,项目名称:OBS,代码行数:101,代码来源:GraphicsCaptureHook.cpp


示例9: assert

void CPigEngine::ScriptDirMonitor(HANDLE hevtExit)
{
  assert(m_hDirChange && INVALID_HANDLE_VALUE != m_hDirChange);

  // Enter this thread into the MTA
  _SVERIFYE(CoInitializeEx(NULL, COINIT_MULTITHREADED));

  // Declare an enum and an array of objects on which to wait
  enum {e_DirChange = WAIT_OBJECT_0, e_Exit, e_Msg};
  HANDLE hObjs[] = {m_hDirChange, hevtExit};
  const int cObjs = sizeofArray(hObjs);

  // Process change notification until exit
  UINT idTimer = 0;
  DWORD dwWait = MsgWaitForMultipleObjects(cObjs, hObjs, false, INFINITE,
    QS_ALLINPUT);
  while (e_Exit != dwWait)
  {
    if (e_DirChange == dwWait)
    {
      // Reset the timer
      if (idTimer)
        KillTimer(NULL, idTimer);
      idTimer = SetTimer(NULL, 0, 2000, NULL);

      // Continue waiting for change notifications
      if (!FindNextChangeNotification(m_hDirChange))
      {
        #ifdef _DEBUG
          DWORD dwLastError = ::GetLastError();
          debugf("\nCPigEngine::ScriptDirMonitor(): "
            "FindNextChangeNotification Failed : "
            "GetLastError() = 0x%08X, m_hDirChange = 0x%08X\n",
            dwLastError, m_hDirChange);
        #endif // _DEBUG
        Sleep(1000);
      }
    }
    else // (e_Msg == dwWait)
    {
      MSG msg;
      while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
      {
        if (WM_TIMER == msg.message)
        {
          assert(msg.wParam == idTimer);

          // Kill the timer
          KillTimer(NULL, idTimer);
          idTimer = 0;

          // Process the files in the directory
          ProcessScriptDirChanges();
        }
        else if (WM_QUIT == msg.message)
        {
          dwWait = e_Exit;
          break;
        }
      }
    }

    // Continue waiting
    dwWait = MsgWaitForMultipleObjects(cObjs, hObjs, false, INFINITE,
      QS_ALLINPUT);
  }

  // Remove this thread from the MTA
  CoUninitialize();

  // Clear the thread pointer
  InterlockedExchange((long*)&m_pth, 0);
}
开发者ID:borgified,项目名称:Allegiance,代码行数:73,代码来源:PigEngine.cpp


示例10: ZeroMemory

/// <summary>
/// Creates the main window and begins processing
/// </summary>
/// <param name="hInstance">handle to the application instance</param>
/// <param name="nCmdShow">whether to display minimized, maximized, or normally</param>
int Direct2DWindow::Run(HINSTANCE hInstance, int nCmdShow)
{
    MSG       msg = {0};
    WNDCLASS  wc;

    // Dialog custom window class
    ZeroMemory(&wc, sizeof(wc));
    wc.style         = CS_HREDRAW | CS_VREDRAW;
    wc.cbWndExtra    = DLGWINDOWEXTRA;
    wc.hInstance     = hInstance;
    wc.hCursor       = LoadCursorW(NULL, IDC_ARROW);
    wc.hIcon         = LoadIconW(hInstance, MAKEINTRESOURCE(IDI_APP));
    wc.lpfnWndProc   = DefDlgProcW;
    wc.lpszClassName = L"DepthBasicsAppDlgWndClass";

    if (!RegisterClassW(&wc))
    {
        return 0;
    }

    // Create main application window
    HWND hWndApp = CreateDialogParamW(
        hInstance,
        MAKEINTRESOURCE(IDD_APP),
        NULL,
        (DLGPROC)Direct2DWindow::MessageRouter, 
        reinterpret_cast<LPARAM>(this));

    // Show window
    ShowWindow(hWndApp, nCmdShow);

    const int eventCount = 2;
    HANDLE hEvents[eventCount];

    // Main message loop
    while (WM_QUIT != msg.message)
    {
        hEvents[0] = m_cdmap->GetNextDepthFrameEvent();
        hEvents[1] = m_cdmap->GetNextColorFrameEvent();

        // Check to see if we have either a message (by passing in QS_ALLINPUT)
        // Or a Kinect event (hEvents)
        // Update() will check for Kinect events individually, in case more than one are signalled
        MsgWaitForMultipleObjects(eventCount, hEvents, FALSE, INFINITE, QS_ALLINPUT);

        // Explicitly check the Kinect frame event since MsgWaitForMultipleObjects
        // can return for other reasons even though it is signaled.
        Update();

        while (PeekMessageW(&msg, NULL, 0, 0, PM_REMOVE))
        {
            // If a dialog message will be taken care of by the dialog proc
            if ((hWndApp != NULL) && IsDialogMessageW(hWndApp, &msg))
            {
                continue;
            }

            TranslateMessage(&msg);
            DispatchMessageW(&msg);
        }
    }

    return static_cast<int>(msg.wParam);
}
开发者ID:vernonrj,项目名称:robotics-kinect,代码行数:69,代码来源:KinectNui.cpp


示例11: GetTickCount

inline DWORD CSplashScreen::PumpMsgWaitForMultipleObjects(HWND hWnd, DWORD nCount, LPHANDLE pHandles, DWORD dwMilliseconds)
{
	// useful variables
	const DWORD dwStartTickCount = ::GetTickCount();
	// loop until done
	for (;;)
	{
		// calculate timeout
		const DWORD dwElapsed = GetTickCount() - dwStartTickCount;
		const DWORD dwTimeout = dwMilliseconds == INFINITE ? INFINITE :dwElapsed < dwMilliseconds ? dwMilliseconds - dwElapsed : 0;

		// wait for a handle to be signaled or a message
		const DWORD dwWaitResult = MsgWaitForMultipleObjects(nCount, pHandles, FALSE, dwTimeout, QS_ALLINPUT);

		if (dwWaitResult == WAIT_OBJECT_0 + nCount)
		{
			// pump messages
			MSG msg;

			while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE) != FALSE)
			{
				// check for WM_QUIT
				if (msg.message == WM_QUIT)
				{
					// repost quit message and return
					PostQuitMessage((int) msg.wParam);
					return WAIT_OBJECT_0 + nCount;
				}

				// dispatch thread message
				TranslateMessage(&msg);
				DispatchMessage(&msg);
			}
		}
		else
		{
			// check fade event (pHandles[1]).  If the fade event is not set then we simply need to exit.  
			// if the fade event is set then we need to fade out  
			const DWORD dwWaitResult = MsgWaitForMultipleObjects(1, &pHandles[1], FALSE, 0, QS_ALLINPUT);
			if (dwWaitResult == WAIT_OBJECT_0) {
				MSG msg;
				// timeout on actual wait or any other object
				SetTimer(hWnd, 1, 30,NULL);
				m_nFadeoutEnd = GetTickCount()+m_nFadeoutTime;
				BOOL bRet;

				while( (bRet = GetMessage( &msg, hWnd, 0, 0 )) != 0)
				{ 
					if (bRet == -1)
					{
						// handle the error and possibly exit
					}
					else
					{
						if (msg.message==WM_TIMER) {
							if (FadeWindowOut(hWnd)) { // finished
								return dwWaitResult;
							}
						}
						TranslateMessage(&msg); 
						DispatchMessage(&msg); 
					}
				}
			}
			return dwWaitResult;
		}
	}
}
开发者ID:StackableRegiments,项目名称:metl2011,代码行数:68,代码来源:SplashScreen.cpp


示例12: hid_event_read_cancellable

int hid_event_read_cancellable(hid_event_monitor* monitor, hid_event* event, hid_cancel_token* cancel_token) {
	auto current_thread_id = GetCurrentThreadId();
	auto monitor_thread_id = GetWindowThreadProcessId(monitor->hwnd, NULL);

	if (current_thread_id != monitor_thread_id) {
		printf("hid_event_read_cancellable failed, monitor have to be created" \
			   " in the same thread which is calling this function.");

		return -1;
	}

	DWORD res = 0;

	DWORD handle_count = 0;
	HANDLE handle = NULL;

	if (cancel_token) {
		handle_count = 1;
		handle = cancel_token->event_handle;
	}

	while (true) {
		//will wait for cancel event and events send/posted to this thread
		res = MsgWaitForMultipleObjects(handle_count, &handle, FALSE, INFINITE, QS_ALLINPUT);

		if (cancel_token && res == WAIT_OBJECT_0) {
			return READ_CANCELLED;
		}

		if (res != WAIT_OBJECT_0 + handle_count) {
			if (res == WAIT_FAILED) {
				DWORD last_error = GetLastError();
				printf("hid_event_read_cancellable failed, WAIT_FAILED, last error: %ul", last_error);
				return -1;
			}

			//some other error with no last error set
			return -1;
		}

		MSG msg;
		//PeekMesssage will call WindowProc where monitor->event struct is set
		//Because device messages are send not posted to queue, PeekMessage
		// will return as if there wasn't any messages, so msg struct & return
		// value is useless
		PeekMessage(&msg, monitor->hwnd, 0, 0, PM_REMOVE);

		//There might be messages other than what we want, if message was what we
		// wanted we set proc_real_event to true in WindowProc, else false
		if (monitor->proc_real_event) {
			//monitors event is reused on every WindowProc so we have to copy all of its contents
			event->action = monitor->proc_event.action;
			event->device_info->path = monitor->proc_event.device_info->path;

			if (event->action == EVENT_ADD) {
				parse_info_from_path(event, monitor->proc_event.device_info->path);
			}

			//we don't free string allocated in WindowProc here, its now part
			// of event and therefore caller of this function has the
			// responsibility of freeing event & its stuff (path)
			monitor->proc_event.device_info->path = NULL;

			monitor->proc_real_event = false;
			break;
		}
	}

	return 0;
}
开发者ID:Finlod,项目名称:Lohi,代码行数:70,代码来源:hidapi_ext_win.cpp


示例13: WDML_SyncWaitTransactionReply

/******************************************************************
 *		WDML_SyncWaitTransactionReply
 *
 * waits until an answer for a sent request is received
 * time out is also handled. only used for synchronous transactions
 */
static HDDEDATA WDML_SyncWaitTransactionReply(HCONV hConv, DWORD dwTimeout, const WDML_XACT* pXAct, DWORD *ack)
{
    DWORD	start, elapsed;
    DWORD	err;
    WDML_CONV*	pConv;

    TRACE("Starting wait for a timeout of %d ms\n", dwTimeout);

    start = GetTickCount();
    while ((elapsed = GetTickCount() - start) < dwTimeout)
    {
	/* we cannot be in the crit sect all the time because when client and server run in a
	 * single process they need to share the access to the internal data
	 */
	if (MsgWaitForMultipleObjects(0, NULL, FALSE,
				      dwTimeout - elapsed, QS_POSTMESSAGE) == WAIT_OBJECT_0)
	{
	    MSG		msg;

	    while (PeekMessageW(&msg, 0, WM_DDE_FIRST, WM_DDE_LAST, PM_REMOVE))
	    {
                HDDEDATA hdd = NULL;

                pConv = WDML_GetConv(hConv, FALSE);
                if (pConv == NULL)
                {
                    /* conversation no longer available... return failure */
                    return 0;
                }
                if (msg.hwnd == pConv->hwndClient)
                {
                    /* check that either pXAct has been processed or no more xActions are pending */
                    BOOL ret = (pConv->transactions == pXAct);
                    if (WDML_HandleReply(pConv, &msg, &hdd, ack) == WDML_QS_HANDLED)
                    {
                        TRACE("WDML_HandleReply returned WDML_QS_HANDLED\n");
                        ret = TRUE;
                    }
                    else
                        ret = (pConv->transactions == NULL || ret);

                    if (ret)
                    {
                        pConv->instance->lastError = hdd ? DMLERR_NO_ERROR : DMLERR_NOTPROCESSED;
                        return hdd;
                    }
                }
                else
                {
                    DispatchMessageW(&msg);
                }
            }
	}
    }

    TRACE("Timeout !!\n");

    pConv = WDML_GetConv(hConv, FALSE);
    if (pConv != NULL)
    {
	if (pConv->transactions)
	{
	    switch (pConv->transactions->ddeMsg)
	    {
	    case WM_DDE_ADVISE:		err = DMLERR_ADVACKTIMEOUT;	break;
	    case WM_DDE_REQUEST:	err = DMLERR_DATAACKTIMEOUT; 	break;
	    case WM_DDE_EXECUTE:	err = DMLERR_EXECACKTIMEOUT;	break;
	    case WM_DDE_POKE:		err = DMLERR_POKEACKTIMEOUT;	break;
	    case WM_DDE_UNADVISE:	err = DMLERR_UNADVACKTIMEOUT;	break;
	    default:			err = DMLERR_INVALIDPARAMETER;	break;
	    }

	    pConv->instance->lastError = err;
	}
    }

    return 0;
}
开发者ID:Moteesh,项目名称:reactos,代码行数:84,代码来源:ddeclient.c


示例14: MsgWaitForMultipleObjects

void CGame::SleepUntilInput( int time )
{
	MsgWaitForMultipleObjects(1, &m_hEvent, FALSE, time, QS_KEY );
}
开发者ID:RaisingTheDerp,项目名称:raisingthebar,代码行数:4,代码来源:gamewndproc.cpp


示例15: wf_client_thread

DWORD WINAPI wf_client_thread(LPVOID lpParam)
{
	MSG msg;
	int width;
	int height;
	BOOL msg_ret;
	int quit_msg;
	DWORD nCount;
	HANDLE handles[64];
	wfContext* wfc;
	freerdp* instance;
	rdpContext* context;
	rdpChannels* channels;
	rdpSettings* settings;
	BOOL async_input;
	BOOL async_transport;
	HANDLE input_thread;

	instance = (freerdp*) lpParam;
	context = instance->context;
	wfc = (wfContext*) instance->context;

	if (!freerdp_connect(instance))
		return 0;

	channels = instance->context->channels;
	settings = instance->context->settings;

	async_input = settings->AsyncInput;
	async_transport = settings->AsyncTransport;

	if (async_input)
	{
		if (!(input_thread = CreateThread(NULL, 0,
				(LPTHREAD_START_ROUTINE) wf_input_thread,
				instance, 0, NULL)))
		{
			WLog_ERR(TAG, "Failed to create async input thread.");
			goto disconnect;
		}
	}

	while (1)
	{
		nCount = 0;

		if (freerdp_focus_required(instance))
		{
			wf_event_focus_in(wfc);
			wf_event_focus_in(wfc);
		}

		if (!async_transport)
		{
			DWORD tmp = freerdp_get_event_handles(context, &handles[nCount], 64 - nCount);

			if (tmp == 0)
			{
				WLog_ERR(TAG, "freerdp_get_event_handles failed");
				break;
			}

			nCount += tmp;
		}

		if (MsgWaitForMultipleObjects(nCount, handles, FALSE, 1000, QS_ALLINPUT) == WAIT_FAILED)
		{
			WLog_ERR(TAG, "wfreerdp_run: WaitForMultipleObjects failed: 0x%04X", GetLastError());
			break;
		}

		if (!async_transport)
		{
			if (!freerdp_check_event_handles(context))
			{
				if (wf_auto_reconnect(instance))
					continue;

				WLog_ERR(TAG, "Failed to check FreeRDP file descriptor");
				break;
			}
		}

		if (freerdp_shall_disconnect(instance))
			break;

		quit_msg = FALSE;

		while (PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE))
		{
			msg_ret = GetMessage(&msg, NULL, 0, 0);

			if (instance->settings->EmbeddedWindow)
			{
				if ((msg.message == WM_SETFOCUS) && (msg.lParam == 1))
				{
					PostMessage(wfc->hwnd, WM_SETFOCUS, 0, 0);
				}
				else if ((msg.message == WM_KILLFOCUS) && (msg.lParam == 1))
				{
//.........这里部分代码省略.........
开发者ID:Distrotech,项目名称:FreeRDP,代码行数:101,代码来源:wf_client.c


示例16: WinMain

int WINAPI WinMain(HINSTANCE instance, HINSTANCE prev_instance, char* command_line, int show_command) {
#else
int main(int argc, char*[] argv) {
#endif
	radish_state* radish;
	radish_window host_window;
	radish_init_for_states();
	radish = radish_create_state(L"main.lua");
	radish->main_fiber = ConvertThreadToFiber(NULL);
	radish->script_fiber = radish_create_script_fiber(radish);
	radish_init_host_window(radish, &host_window);

	if (radish_script_step(radish)) {
		radish_create_window(radish, &host_window);
		radish_update_first(radish);
		// script may have terminated during the create window phase
		while (radish_script_running(radish)) {
			DWORD timeout = radish_update_timeout(radish);
			DWORD result = MsgWaitForMultipleObjects(
				radish->wait_object_count,
				radish->wait_objects,
				FALSE,
				timeout,
				QS_ALLINPUT);
			if (result == WAIT_OBJECT_0 + radish->wait_object_count) {
				while (PeekMessage(&radish->msg, NULL, 0, 0, PM_REMOVE)) {
					UINT message = radish->msg.message;
					HWND hwnd = radish->msg.hwnd;
					WPARAM wparam = radish->msg.wParam;
					LPARAM lparam = radish->msg.lParam;
					if (hwnd == NULL) {
						radish_script_step(radish);
						// overridable default behaviours
						if (radish->msg.message != WMRADISH_HANDLED) {
							switch (message) {
								case WMRADISH_DIALOG_REQUEST:
									radish_do_dialog(radish, (radish_dialog*)lparam);
									if (wparam != 0) {
										PostThreadMessage((UINT)wparam, WMRADISH_DIALOG_RESPONSE, 0, lparam);
									}
									else {
										radish->msg.message = WMRADISH_DIALOG_RESPONSE;
										radish->msg.lParam = lparam;
										radish_script_step(radish);
										radish_free_dialog(radish, (radish_dialog*)lparam);
									}
									break;
							}
						}
						// non-overridable default behaviours
						switch (message) {
							case WMRADISH_THREAD_TERMINATED:
								// TODO: make sure all strings etc are freed too
								free((radish_state*)lparam);
								break;
							case WMRADISH_THREAD_SEND_DATA:
								radish_buffer_free((radish_buffer*)lparam);
								break;
						}
					}
					else {
		                if (radish->accelerator_table != NULL && TranslateAccelerator(
								radish->msg.hwnd, radish->accelerator_table, &radish->msg)) {
		                    // don't TranslateMessage
		                }
		                else {
							TranslateMessage(&radish->msg);
							DispatchMessageW(&radish->msg);
						}
					}

				}
			}
			else if (result >= WAIT_OBJECT_0 && result < (WAIT_OBJECT_0 + radish->wait_object_count)) {
				radish->msg.message = WMRADISH_WAIT_OBJECT_SIGNALLED;
				radish->msg.hwnd = NULL;
				radish->msg.lParam = (LPARAM)(result - WAIT_OBJECT_0);
				radish->msg.wParam = (WPARAM)radish->wait_objects[radish->msg.lParam];
				radish_script_step(radish);
				radish_update_maybe(radish);
			}
			else if (result >= WAIT_ABANDONED_0 && result < (WAIT_ABANDONED_0 + radish->wait_object_count)) {
				radish->msg.message = WMRADISH_MUTEX_ABANDONED;
				radish->msg.hwnd = NULL;
				radish->msg.lParam = (LPARAM)(result - WAIT_ABANDONED_0);
				radish->msg.wParam = (WPARAM)radish->wait_objects[radish->msg.lParam];
				radish_script_step(radish);
				radish_update_maybe(radish);
			}
			else if (result == WAIT_TIMEOUT) {
				radish_update_certain(radish);
				if (timeout == 0) Sleep(0);
			}
			else if (result == WAIT_FAILED) {
				radish->error = L"MsgWaitForMultipleObjects Error";
				goto finalize;
			}
			else {
				radish->error = L"Unknown result from MsgWaitForMultipleObjects";
				goto finalize;
//.........这里部分代码省略.........
开发者ID:taxler,项目名称:radish,代码行数:101,代码来源:radish-runner.c


示例17: Launch


//.........这里部分代码省略.........
    if (!GetModuleFileNameA(nullptr, path, MAX_PATH)) {
      Fail(false, L"GetModuleFileNameA errorno=%d", GetLastError());
      return FAILURE;
    }
    char* slash = strrchr(path, '\\');
    if (!slash)
      return FAILURE;
    *slash = '\0'; // no trailing slash
    testFilePath = path;
    testFilePath += "\\";
    sFirefoxPath = testFilePath;
    sFirefoxPath += kFirefoxExe;
    testFilePath += kMetroTestFile;
  }

  // Make sure the firefox bin exists
  if (GetFileAttributesW(sFirefoxPath) == INVALID_FILE_ATTRIBUTES) {
    Fail(false, L"Invalid bin path: '%s'", sFirefoxPath);
    return FAILURE;
  }

  Log(L"Using bin path: '%s'", sFirefoxPath);

  Log(L"Writing out tests.ini to: '%s'", CStringW(testFilePath));
  HANDLE hTestFile = CreateFileA(testFilePath, GENERIC_WRITE,
                                 0, nullptr, CREATE_ALWAYS,
                                 FILE_ATTRIBUTE_NORMAL,
                                 nullptr);
  if (hTestFile == INVALID_HANDLE_VALUE) {
    Fail(false, L"CreateFileA errorno=%d", GetLastError());
    return FAILURE;
  }

  DeleteTestFileHelper dtf(testFilePath);

  // nsAppRunner expects the first param to be the bin path, just like a
  // normal startup. So prepend our bin path to our param string we write.
  CStringA asciiParams = sFirefoxPath;
  asciiParams += " ";
  asciiParams += sAppParams;
  asciiParams.Trim();
  Log(L"Browser command line args: '%s'", CString(asciiParams));
  if (!WriteFile(hTestFile, asciiParams, asciiParams.GetLength(),
                 nullptr, 0)) {
    CloseHandle(hTestFile);
    Fail(false, L"WriteFile errorno=%d", GetLastError());
    return FAILURE;
  }
  FlushFileBuffers(hTestFile);
  CloseHandle(hTestFile);

  // Create a named stdout pipe for the browser
  if (!SetupTestOutputPipe()) {
    Fail(false, L"SetupTestOutputPipe failed (errno=%d)", GetLastError());
    return FAILURE;
  }

  // Launch firefox
  hr = activateMgr->ActivateApplication(appModelID, L"", AO_NOERRORUI, &processID);
  if (FAILED(hr)) {
    Fail(true, L"ActivateApplication result %X", hr);
    return RETRY;
  }

  Log(L"Activation succeeded.");

  // automation.py picks up on this, don't mess with it.
  Log(L"METRO_BROWSER_PROCESS=%d", proc 

鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ Msg_Get函数代码示例发布时间:2022-05-30
下一篇:
C++ MsgDev函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap