Пример #1
0
static void waitonbutton()
{
	int key = GetSystemMetrics(SM_SWAPBUTTON) ? VK_RBUTTON : VK_LBUTTON;
	if (GetAsyncKeyState(key) & 0x8000)
	{ // double clicked
		MSG msg;
		while (GetAsyncKeyState(key) & 0x8000)
			PeekMessageA(&msg, NULL, WM_MOUSEFIRST, WM_MOUSELAST, PM_REMOVE);
		// pull extra mouseUp out of queue
		while (PeekMessageA(&msg, NULL, WM_MOUSEFIRST, WM_MOUSELAST, PM_REMOVE))
			;
	}
	// SMR 1880 clear shift/control state
	MCmodifierstate = MCscreen->querymods();
}
Пример #2
0
static int Win32_GetEvent(SST_DisplayTarget target, SST_WMEvent* eventReturn)
{
	MSG msg;
	SST_DisplayTarget_Win32* displayTarget = (SST_DisplayTarget_Win32*)target;
	SST_Window_Win32* win;
	int found = 0;

	/* First, get Win32 messages and dispatch to winproc. We
	do this immediately, otherwise the OS thinks we've hung. */
	while(PeekMessageA(&msg, NULL, 0, 0, PM_REMOVE))
	{
		TranslateMessage(&msg);
		DispatchMessageA(&msg);	
	}

	/* Check for user events */
	if(RemoveFromEQ(&displayTarget->userEventQueue, eventReturn))
		return 1;

	/* Now check each window's event queue */
	win = displayTarget->firstWindow;
	while(win)
	{
		if(RemoveFromEQ(&win->eventQueue, eventReturn))
		{
			found = 1;
			break;
		}

		win = win->next;
	}

	return found;
}
int OGLTest::Run()
{
    bool fFirst = true;
    MSG msg;
    do
    {
        BOOL fGotMessage;
        if (miRenderStep)
        {
            fGotMessage = GetMessageA(&msg, 0, 0, 0);
        }
        else
        {
            fGotMessage = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
        }

        if (fGotMessage)
        {
            TranslateMessage(&msg);
            DispatchMessageA(&msg);
        }

        float dt = 0.0f; /* Time in seconds since last render step. @todo Measure. */

        BOOL fDoRender = FALSE;
        if (miRenderStep)
        {
            if (msg.message == WM_CHAR)
            {
                if (msg.wParam == ' ')
                {
                    fDoRender = TRUE;
                    dt = fFirst ? 0.0f : 0.1f; /* 0.1 second increment per step. */
                }
            }
        }
        else
        {
             fDoRender = TRUE;
        }

        if (fDoRender)
        {
            if (mpRender)
            {
                setCurrentGLCtx(mhGLRC);

                mpRender->TimeAdvance(dt);
                mpRender->DoRender();

                setCurrentGLCtx(NULL);

                fFirst = false;
            }
        }
    } while (msg.message != WM_QUIT);

    return msg.wParam;
}
Пример #4
0
/* process any pending messages */
static void do_events(void)
{
    MSG msg;

    while (PeekMessageA(&msg, NULL, 0, 0, PM_REMOVE))
    {
        TranslateMessage(&msg);
        DispatchMessageA(&msg);
    }
}
Пример #5
0
int CALLBACK 
WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
	HINSTANCE Module = hInstance;
	WNDCLASSEX WindowClass = {};
	WindowClass.cbSize = sizeof(WindowClass);
	WindowClass.style = CS_HREDRAW | CS_VREDRAW;
	WindowClass.lpfnWndProc = MainWindowProc;
	WindowClass.hInstance = Module;
	WindowClass.hIcon = LoadIcon(0, IDI_APPLICATION);
	WindowClass.hCursor = LoadCursorA(0, IDC_ARROW);
	WindowClass.lpszClassName = WINDOW_CLASS_NAME;
	RegisterClassExA(&WindowClass);

	DWORD WindowExStyle = WS_EX_APPWINDOW;
	DWORD WindowStyle = WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_OVERLAPPEDWINDOW & ~(WS_THICKFRAME | WS_MAXIMIZEBOX);
	HWND MainWindow = CreateWindowEx(
		WindowExStyle,
		WINDOW_CLASS_NAME,
		"FSWindow",
		WindowStyle,
		CW_USEDEFAULT, CW_USEDEFAULT,
		CW_USEDEFAULT, CW_USEDEFAULT,
		0, 0,
		Module,
		0);

	RECT AdjustRect = {};
	AdjustRect.right = MAIN_WINDOW_WIDTH;
	AdjustRect.bottom = MAIN_WINDOW_HEIGHT;
	AdjustWindowRectEx(&AdjustRect, WindowStyle, FALSE, WindowExStyle);
	SetWindowPos(MainWindow, 0, 
		0, 0, 
		AdjustRect.right - AdjustRect.left, AdjustRect.bottom - AdjustRect.top, 
		SWP_NOMOVE | SWP_NOCOPYBITS | SWP_SHOWWINDOW);

	BOOL Running = TRUE;
	while(Running) {
		MSG Message;
		while(PeekMessageA(&Message, 0, 0, 0, PM_REMOVE)) {
			if(Message.message == WM_QUIT) {
				Running = FALSE;
				break;
			}
			else {
				TranslateMessage(&Message);
				DispatchMessageA(&Message);
			}
		}

		Sleep(10);
	}

	return 0;
}
Пример #6
0
static void test_notification_dbg(HWND hwnd, const char* command, WPARAM type, int line)
{   /* Use type 0 as meaning no message */
    MSG msg;
    BOOL seen;
    do { seen = PeekMessageA(&msg, hwnd, 0, 0, PM_REMOVE); }
    while(seen && spurious_message(&msg));
    if(type && !seen) {
      /* We observe transient delayed notification, mostly on native.
       * Notification is not always present right when mciSend returns. */
      trace_(__FILE__,line)("Waiting for delayed notification from %s\n", command);
      MsgWaitForMultipleObjects(0, NULL, FALSE, 3000, QS_POSTMESSAGE);
      seen = PeekMessageA(&msg, hwnd, MM_MCINOTIFY, MM_MCINOTIFY, PM_REMOVE);
    }
    if(!seen)
      ok_(__FILE__,line)(type==0, "Expect message %04lx from %s\n", type, command);
    else if(msg.hwnd != hwnd)
        ok_(__FILE__,line)(msg.hwnd == hwnd, "Didn't get the handle to our test window\n");
    else if(msg.message != MM_MCINOTIFY)
        ok_(__FILE__,line)(msg.message == MM_MCINOTIFY, "got %04x instead of MM_MCINOTIFY from command %s\n", msg.message, command);
    else ok_(__FILE__,line)(msg.wParam == type, "got %04lx instead of MCI_NOTIFY_xyz %04lx from command %s\n", msg.wParam, type, command);
}
Пример #7
0
/* try to make sure pending X events have been processed before continuing */
static void flush_events(int waitTime)
{
    MSG msg;
    int diff = waitTime;
    DWORD time = GetTickCount() + waitTime;

    while (diff > 0)
    {
        if (MsgWaitForMultipleObjects( 0, NULL, FALSE, min(100,diff), QS_ALLEVENTS) == WAIT_TIMEOUT) break;
        while (PeekMessageA( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessageA( &msg );
        diff = time - GetTickCount();
    }
}
Пример #8
0
static void test_notification_dbg(HWND hwnd, const char* command, UINT m1, DWORD_PTR p2, int line)
{   /* Use message type 0 as meaning no message */
    MSG msg;
    if (hwnd) {
        /* msg.wParam is hmidiout, msg.lParam is the mhdr (or 0) */
        BOOL seen;
        do { seen = PeekMessageA(&msg, hwnd, 0, 0, PM_REMOVE); }
        while(seen && spurious_message(&msg));
        if (m1 && !seen) {
          /* We observe transient delayed notification, mostly on native.
           * Perhaps the OS preempts the player thread after setting MHDR_DONE
           * or clearing MHDR_INQUEUE, before calling DriverCallback. */
          DWORD rc;
          trace_(__FILE__,line)("Waiting for delayed message %x from %s\n", m1, command);
          SetLastError(0xDEADBEEF);
          rc = MsgWaitForMultipleObjects(0, NULL, FALSE, 3000, QS_POSTMESSAGE);
          ok_(__FILE__,line)(rc==WAIT_OBJECT_0, "Wait failed: %04x %d\n", rc, GetLastError());
          seen = PeekMessageA(&msg, hwnd, 0, 0, PM_REMOVE);
        }
        if (seen) {
            trace_(__FILE__,line)("Message %x, wParam=%lx, lParam=%lx from %s\n",
                  msg.message, msg.wParam, msg.lParam, command);
            ok_(__FILE__,line)(msg.hwnd==hwnd, "Didn't get the handle to our test window\n");
            ok_(__FILE__,line)(msg.message==m1 && msg.lParam==p2, "bad message %x/%lx from %s, expect %x/%lx\n", msg.message, msg.lParam, command, m1, p2);
        }
        else ok_(__FILE__,line)(m1==0, "Expect message %x from %s\n", m1, command);
    }
    else {
        /* FIXME: MOM_POSITIONCB and MOM_DONE are so close that a queue is needed. */
        if (cbmsg) {
            ok_(__FILE__,line)(cbmsg==m1 && cbval1==p2 && cbval2==0, "bad callback %x/%lx/%lx from %s, expect %x/%lx\n", cbmsg, cbval1, cbval2, command, m1, p2);
            cbmsg = 0; /* Mark as read */
            cbval1 = cbval2 = WHATEVER;
            ok_(__FILE__,line)(cbinst==MYCBINST, "callback dwInstance changed to %lx\n", cbinst);
        }
        else ok_(__FILE__,line)(m1==0, "Expect callback %x from %s\n", m1, command);
    }
}
Пример #9
0
/* try to make sure pending X events have been processed before continuing */
static void flush_events(void)
{
    MSG msg;
    int diff = 200;
    int min_timeout = 100;
    DWORD time = GetTickCount() + diff;

    while (diff > 0)
    {
        if (MsgWaitForMultipleObjects( 0, NULL, FALSE, min_timeout, QS_ALLINPUT ) == WAIT_TIMEOUT) break;
        while (PeekMessageA( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessageA( &msg );
        diff = time - GetTickCount();
    }
}
Пример #10
0
// ITextHost2 Interface
//@cmember Is a double click in the message queue?
BOOL tomEdit::TxIsDoubleClickPending() 
{
    MSG msg;

    HWND host = GetCenter()->GetHost() ;
    if( PeekMessageA(&msg, host, WM_LBUTTONDBLCLK, WM_LBUTTONDBLCLK,
        PM_NOREMOVE | PM_NOYIELD) )
    {
        return TRUE;
    }
    else
    {
        return FALSE;
    }
}
Пример #11
0
static void test_nopage(void)
{
    HPROPSHEETPAGE hpsp[1];
    PROPSHEETPAGEA psp;
    PROPSHEETHEADERA psh;
    HWND hdlg, hpage;
    MSG msg;

    memset(&psp, 0, sizeof(psp));
    psp.dwSize = sizeof(psp);
    psp.dwFlags = 0;
    psp.hInstance = GetModuleHandleA(NULL);
    U(psp).pszTemplate = "prop_page1";
    U2(psp).pszIcon = NULL;
    psp.pfnDlgProc = page_dlg_proc;
    psp.lParam = 0;

    hpsp[0] = CreatePropertySheetPageA(&psp);

    memset(&psh, 0, sizeof(psh));
    psh.dwSize = PROPSHEETHEADERA_V1_SIZE;
    psh.dwFlags = PSH_MODELESS | PSH_USECALLBACK;
    psh.pszCaption = "test caption";
    psh.nPages = 1;
    psh.hwndParent = GetDesktopWindow();
    U3(psh).phpage = hpsp;
    psh.pfnCallback = sheet_callback;

    hdlg = (HWND)PropertySheetA(&psh);
    ok(hdlg != INVALID_HANDLE_VALUE, "got invalid handle value %p\n", hdlg);

    ShowWindow(hdlg,SW_NORMAL);
    SendMessageA(hdlg, PSM_REMOVEPAGE, 0, 0);
    hpage = /* PropSheet_GetCurrentPageHwnd(hdlg); */
        (HWND)SendMessageA(hdlg, PSM_GETCURRENTPAGEHWND, 0, 0);
    active_page = /* PropSheet_HwndToIndex(hdlg, hpage)); */
        (int)SendMessageA(hdlg, PSM_HWNDTOINDEX, (WPARAM)hpage, 0);
    ok(hpage == NULL, "expected no current page, got %p, index=%d\n", hpage, active_page);
    flush_events();
    RedrawWindow(hdlg,NULL,NULL,RDW_UPDATENOW|RDW_ERASENOW);

    /* Check that the property sheet was fully redrawn */
    ok(!PeekMessageA(&msg, 0, WM_PAINT, WM_PAINT, PM_NOREMOVE),
       "expected no pending WM_PAINT messages\n");
    DestroyWindow(hdlg);
}
Пример #12
0
void WindowMessageLoop(gl_window_t *win) {
	BOOL isMessagePumpActive;
	MSG msg;
	if (PeekMessageA (&msg, win->hWnd, 0, 0, PM_REMOVE) != 0) {
		//printf("WindowMessageLoop\n");
		if (msg.message != WM_QUIT) {
			TranslateMessage(&msg); // needed for what? NeHe didn't call this
			DispatchMessageA (&msg);
		} else {
			WindowClose(win);
		}
	} else {
		if ( ! win->isVisible) {
			//WaitMessage();
		}
	}
}
Пример #13
0
void __fastcall TMainForm::ToolButton3Click(TObject *Sender)
{
	String FileName = "ExpMtr\\mtr.xml";
	TSendThread *Client;
	int mr, r, cnt;
	String err;
	MSG msg;

	if ((err = cVerifData()) != "")	{
		ShowMessage(err);
		return;
	}

	LoginForm->UserEdit->Text = /*"sc910001" + */"sc" + IntToStr(School.SchoolCode);
	LoginForm->PasswordEdit->Text = "jXCHJQQo";

	Client = new TSendThread(true);
	if (LoginForm->ShowModal() != mrOk)
		return;

	Client->idVisor = idVisor;
	Client->User = LoginForm->UserEdit->Text;
	Client->Password = LoginForm->PasswordEdit->Text;
	Client->ms = new TMemoryStream;
	SaveXMLToStream(Client->ms);
	Client->CommandID = "3";
	Client->srv = GetServerIP();
	Client->FreeOnTerminate = true;

	SendForm->Show();
	SendForm->Memo1->Lines->Append("Соединение с сервером.");

	while (PeekMessage(&msg, this->Handle, WM_USER, THRD_END, PM_REMOVE)); //инициализация и отчистка очереди
	Client->Resume();
	GetMessageA(&msg, 0, THRD_READY, THRD_READY);
	while (!PeekMessageA(&msg, 0, THRD_END, THRD_END, PM_NOREMOVE))	{
		Application->ProcessMessages();
		WaitMessage();
	}
	PostThreadMessageA(0, MAIN_READY, 0, 0);
	ShowMessage(ThreadMsg);
}
Пример #14
0
int entrypoint(void)
{
  //if (ChangeDisplaySettings(&screenSettings, CDS_FULLSCREEN) != DISP_CHANGE_SUCCESSFUL) return -1;
  ShowCursor(0);
  HDC hDC = GetDC(CreateWindowExA(WS_EX_APPWINDOW, "static", 0, WINDOWFLAGS, 0, 0, XRES, YRES, 0, 0, 0, 0));
  SetPixelFormat(hDC, ChoosePixelFormat(hDC, &pfd), &pfd);
  wglMakeCurrent(hDC, wglCreateContext(hDC));

  const int t = ((PFNGLCREATESHADERPROGRAMEXTPROC)wglGetProcAddress("glCreateShaderProgramEXT"))(GL_FRAGMENT_SHADER, fragmentShader);
  ((PFNGLUSEPROGRAMPROC)wglGetProcAddress("glUseProgram"))(t);
  do
  {
    static MSG dummyMessage;
    PeekMessageA(&dummyMessage, 0, 0, 0, 1); // Remove all Windows messages to prevent "Program not responding" dialog.
    glColor3us((unsigned short)GetTickCount(), 0, 0);
    glRects(-1, -1, 1, 1);
    SwapBuffers(hDC); //wglSwapLayerBuffers( hDC, WGL_SWAP_MAIN_PLANE );
  } while (!GetAsyncKeyState(VK_ESCAPE));
  ExitProcess(0);
  return 1;
}
Пример #15
0
int AppDelegate::mainloop()
{
	Director* director = Director::getInstance();
	MSG msg = { 0 };
	_timerSystem->init();
	while (msg.message != WM_QUIT)
	{
		if (PeekMessageA(&msg, nullptr, 0, 0, PM_REMOVE))
		{
			TranslateMessage(&msg);
			DispatchMessageA(&msg);
		}
		else if (director->getDelta() >= director->getDelay())
		{
			director->mainloop();
			director->getLoopTimer().reset();
		}
		else
			Sleep(1);
		_timerSystem->refresh();
	}
	return msg.wParam;
}
Пример #16
0
// Win32 entry point
int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd )
{
	LoadInvaders();

	CGameWindow window( hInstance, WndProc, "Space Invaders", ScrW(), ScrH(), WINDOWED );

	if ( render.Init( window.GetHandle(), WINDOWED, ScrW(), ScrH() ) )
	{
		LoadResources();

		bool quit = false;

		while ( !quit && !gameover )
		{
			MSG msg;

			while ( PeekMessageA( &msg, NULL, 0, 0, PM_REMOVE ) )
			{
				TranslateMessage( &msg );
				DispatchMessage( &msg );

				if ( msg.message == WM_QUIT )
				{
					quit = true;

					break;
				}
			}

			RenderFrame();
		}
	}

	render.Shutdown();

	return 0;
}
Пример #17
0
/* process pending messages until a condition is true or 3 seconds pass */
static void do_events_until(boolean_function test)
{
    MSG msg;
    UINT_PTR timerid;
    BOOL timedout=FALSE;

    timerid = SetTimer(0, 0, 3000, NULL);

    while (1)
    {
        while (PeekMessageA(&msg, NULL, 0, 0, PM_REMOVE))
        {
            if (msg.hwnd == 0 && msg.message == WM_TIMER && msg.wParam == timerid)
                timedout = TRUE;
            TranslateMessage(&msg);
            DispatchMessageA(&msg);
        }
        if (timedout || test())
            break;
        WaitMessage();
    }

    KillTimer(0, timerid);
}
Пример #18
0
void CCustomIOCPBaseList::ProcessMsgEvent()
{
	MSG Msg;

	while (PeekMessage(&Msg, 0, 0, 0, PM_NOREMOVE)) {
		BOOL Unicode;
		BOOL MsgExists;

		Unicode = (Msg.hwnd == 0) || IsWindowUnicode(Msg.hwnd);
		if (Unicode) {
			MsgExists = PeekMessageW(&Msg, 0, 0, 0, PM_REMOVE);
		} else {
			MsgExists = PeekMessageA(&Msg, 0, 0, 0, PM_REMOVE);
		}
		if (MsgExists) {
			TranslateMessage(&Msg);
			if (Unicode) {
				DispatchMessageW(&Msg);
			} else {
				DispatchMessageA(&Msg);
			}
		}
	}
}
Пример #19
0
int CALLBACK WinMain( HINSTANCE hInstance, HINSTANCE, LPSTR, int ) {
	LARGE_INTEGER performanceFrequencyResult;
	QueryPerformanceFrequency( &performanceFrequencyResult );
	performanceFrequency = performanceFrequencyResult.QuadPart;

	win32State_t *state = &win32State;
	Win32GetExeFileName( state );
	char gameDllFullPath[ 256 ];
	Win32BuildExePathFileName( state, "tiny.dll", sizeof( gameDllFullPath ), gameDllFullPath );
	char tempGameDllFullPath[ 256 ];
	Win32BuildExePathFileName( state, "tiny_temp.dll", sizeof( tempGameDllFullPath ), tempGameDllFullPath );

	UINT desiredSchedulerMs = 1;
	b32 sleepIsGranular = ( timeBeginPeriod( desiredSchedulerMs ) == TIMERR_NOERROR );

	WNDCLASSA wndClass = { 0 };
	wndClass.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
	wndClass.lpfnWndProc = WindowProc;
	wndClass.hInstance = hInstance;
	wndClass.lpszClassName = "tinyrenderer";

	if ( !RegisterClassA( &wndClass ) ) {
		printf( "Failed RegisterClass()\n" );
		return 1;
	}

	HWND hWnd = CreateWindow(
		wndClass.lpszClassName, "Tiny Renderer",
		WS_OVERLAPPEDWINDOW | WS_VISIBLE,
		CW_USEDEFAULT, CW_USEDEFAULT,
		WINDOW_WIDTH, WINDOW_HEIGHT,
		0, 0, 0, 0 );
	if ( !hWnd ) {
		printf( "Failed CreateWindowA()\n" );
		return 1;
	}

	Win32_ResizeDibSection( &backBuffer, RENDER_WIDTH, RENDER_HEIGHT );

	int monitorRefreshHz = 60;
	HDC refreshDC = GetDC( hWnd );
	int win32RefreshRate = GetDeviceCaps( refreshDC, VREFRESH );
	if ( win32RefreshRate > 1 ) {
		monitorRefreshHz = win32RefreshRate;
	}
	float gameUpdateHz = ( monitorRefreshHz / 2.0f );
	float targetMsPerFrame = 1000.0f * ( 1.0f / ( float ) gameUpdateHz );

	LARGE_INTEGER lastCounter = Win32GetWallClock( );
	LARGE_INTEGER flipWallClock = Win32GetWallClock( );

	win32GameCode_t game = Win32LoadGameCode( gameDllFullPath, tempGameDllFullPath );

	//uint64_t lastCycleCount = __rdtsc();
	running = true;
	while ( running ) {
		FILETIME dllWriteTime = Win32GetLastWriteTime( gameDllFullPath );
		if ( CompareFileTime( &dllWriteTime, &game.lastWriteTime ) != 0 ) {
			Win32UnloadGameCode( &game );
			game = Win32LoadGameCode( gameDllFullPath, tempGameDllFullPath );
		}

		MSG msg = { 0 };
		while ( PeekMessageA( &msg, hWnd, 0, 0, PM_REMOVE ) ) {
			TranslateMessage( &msg );
			DispatchMessageA( &msg );
		}
		if ( running ) {

			gameBackBuffer_t gameBuffer = {};
			gameBuffer.memory = backBuffer.memory;
			gameBuffer.width = backBuffer.width;
			gameBuffer.height = backBuffer.height;
			gameBuffer.pitch = backBuffer.pitch;

			// Render the things
			if ( game.updateAndRender ) {
				game.updateAndRender( &gameBuffer );
			}

			LARGE_INTEGER workCounter = Win32GetWallClock( );
			float workMsElapsed = Win32GetMsElapsed( lastCounter, workCounter );
			float msElapsedForFrame = workMsElapsed;
			if ( msElapsedForFrame < targetMsPerFrame ) {
				if ( sleepIsGranular ) {
					DWORD sleepMs = ( DWORD ) ( targetMsPerFrame - msElapsedForFrame );
					if ( sleepMs > 0 ) {
						Sleep( sleepMs );
					}
				}

				while ( msElapsedForFrame < targetMsPerFrame ) {
					msElapsedForFrame = Win32GetMsElapsed( lastCounter, Win32GetWallClock( ) );
				}
			}

			LARGE_INTEGER endCounter = Win32GetWallClock( );
			float msPerFrame = Win32GetMsElapsed( lastCounter, endCounter );
			lastCounter = endCounter;

			char title[ 256 ];
			sprintf_s( title, "%.2fms/f", msPerFrame );
			SetWindowTextA( hWnd, title );

			// Put the things on the screen
			HDC dc = GetDC( hWnd );
			RECT rect;
			GetClientRect( hWnd, &rect );
			int width = rect.right - rect.left;
			int height = rect.bottom - rect.top;
			Win32_AspectBlt( dc, &backBuffer, width, height );
			ReleaseDC( hWnd, dc );

			flipWallClock = Win32GetWallClock( );
		}
	}

	return 0;
}
Пример #20
0
Boolean MCScreenDC::handle(real8 sleep, Boolean dispatch, Boolean anyevent,
                           Boolean &abort, Boolean &reset)
{
	MSG msg, tmsg;
	stateinfo oldinfo = *curinfo;
	curinfo->abort = curinfo->reset = False;
	curinfo->dispatch = dispatch;
	curinfo->handled = False;
	curinfo->keysym = 0;
	curinfo->live = True;
	if (mousewheel == 0)
		mousewheel = RegisterWindowMessageA(MSH_MOUSEWHEEL);
	if (dispatch && pendingevents != NULL
	        || PeekMessageA(&msg, NULL, 0, 0, PM_REMOVE)
	        || sleep != 0
	        && MsgWaitForMultipleObjects(1, &g_notify_wakeup, False,
	                                     (DWORD)(sleep * 1000.0), QS_ALLINPUT)
	        != WAIT_TIMEOUT && PeekMessageA(&msg, NULL, 0, 0, PM_REMOVE))
	{
		if (dispatch && pendingevents != NULL)
		{
			curinfo->live = False;
			MCEventnode *tptr = (MCEventnode *)pendingevents->remove
			                    (pendingevents);
			MCmodifierstate = tptr->modifier;
			MCeventtime = tptr->time;
			curinfo->keysym = tptr->keysym;
			MCWindowProc(tptr->hwnd, tptr->msg, tptr->wParam, tptr->lParam);
			delete tptr;
		}
		else
		{
			Boolean dodispatch = True;
			if (dodispatch)
			{
				curinfo->live = True;
				MCeventtime = msg.time;
				if (msg.message == WM_KEYDOWN || msg.message == WM_SYSKEYDOWN
				        || msg.message == WM_KEYUP || msg.message == WM_SYSKEYUP)
					curinfo->keysym = getkeysym(msg.wParam, msg.lParam);
				TranslateMessage(&msg);

				bool t_char_found;
				if ((MCruntimebehaviour & RTB_ACCURATE_UNICODE_INPUT) != 0)
					t_char_found = PeekMessageW(&tmsg, NULL, WM_CHAR, WM_CHAR, PM_REMOVE) ||
				                 PeekMessageW(&tmsg, NULL, WM_SYSCHAR, WM_SYSCHAR, PM_REMOVE);
				else
					t_char_found = PeekMessageA(&tmsg, NULL, WM_CHAR, WM_CHAR, PM_REMOVE) ||
				                 PeekMessageA(&tmsg, NULL, WM_SYSCHAR, WM_SYSCHAR, PM_REMOVE);
				if (t_char_found)
				{
					_Drawable _dw;
					Drawable dw = &_dw;
					dw->type = DC_WINDOW;
					dw->handle.window = (MCSysWindowHandle)msg.hwnd;
					if (MCdispatcher->findstackd(dw) == NULL)
					{
						if ((MCruntimebehaviour & RTB_ACCURATE_UNICODE_INPUT) != 0)
							DispatchMessageW(&msg);
						else
							DispatchMessageA(&msg);
					}
					memcpy(&msg, &tmsg, sizeof(MSG));
				}
				if ((MCruntimebehaviour & RTB_ACCURATE_UNICODE_INPUT) != 0)
					DispatchMessageW(&msg);
				else
					DispatchMessageA(&msg);
			}
		}
	}
	if (MCrecording)
		MCtemplateplayer->handlerecord();

	abort = curinfo->abort;
	reset = curinfo->reset;
	Boolean handled = curinfo->handled;
	*curinfo = oldinfo;
	return handled;
}
Пример #21
0
static void test_acquire(IDirectInputA *pDI, HWND hwnd)
{
    HRESULT hr;
    IDirectInputDeviceA *pMouse = NULL;
    DIMOUSESTATE m_state;
    HWND hwnd2;
    DIPROPDWORD di_op;
    DIDEVICEOBJECTDATA mouse_state;
    DWORD cnt;
    MSG msg;
    int i;

    if (! SetForegroundWindow(hwnd))
    {
        skip("Not running as foreground app, skipping acquire tests\n");
        return;
    }

    hr = IDirectInput_CreateDevice(pDI, &GUID_SysMouse, &pMouse, NULL);
    ok(SUCCEEDED(hr), "IDirectInput_CreateDevice() failed: %08x\n", hr);
    if (FAILED(hr)) return;

    hr = IDirectInputDevice_SetCooperativeLevel(pMouse, hwnd, DISCL_NONEXCLUSIVE | DISCL_FOREGROUND);
    ok(hr == S_OK, "SetCooperativeLevel: %08x\n", hr);

    memset(&di_op, 0, sizeof(di_op));
    di_op.dwData = 5;
    di_op.diph.dwHow = DIPH_DEVICE;
    di_op.diph.dwSize = sizeof(DIPROPDWORD);
    di_op.diph.dwHeaderSize = sizeof(DIPROPHEADER);
    hr = IDirectInputDevice_SetProperty(pMouse, DIPROP_BUFFERSIZE, (LPCDIPROPHEADER)&di_op);
    ok(hr == S_OK, "SetProperty() failed: %08x\n", hr);

    hr = IDirectInputDevice_SetDataFormat(pMouse, &c_dfDIMouse);
    ok(SUCCEEDED(hr), "IDirectInputDevice_SetDataFormat() failed: %08x\n", hr);
    hr = IDirectInputDevice_Unacquire(pMouse);
    ok(hr == S_FALSE, "IDirectInputDevice_Unacquire() should have failed: %08x\n", hr);
    hr = IDirectInputDevice_Acquire(pMouse);
    ok(SUCCEEDED(hr), "IDirectInputDevice_Acquire() failed: %08x\n", hr);
    hr = IDirectInputDevice_Acquire(pMouse);
    ok(hr == S_FALSE, "IDirectInputDevice_Acquire() should have failed: %08x\n", hr);

    /* Foreground coop level requires window to have focus */
    /* Create a temporary window, this should make dinput
     * loose mouse input */
    hwnd2 = CreateWindowA("static", "Temporary", WS_VISIBLE, 10, 210, 200, 200, NULL, NULL, NULL,
                          NULL);
    ok(hwnd2 != NULL, "CreateWindowA failed with %u\n", GetLastError());
    while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessageA(&msg);

    hr = IDirectInputDevice_GetDeviceState(pMouse, sizeof(m_state), &m_state);
    ok(hr == DIERR_NOTACQUIRED, "GetDeviceState() should have failed: %08x\n", hr);
    /* Workaround so we can test other things. Remove when Wine is fixed */
    IDirectInputDevice_Unacquire(pMouse);

    hr = IDirectInputDevice_Acquire(pMouse);
    ok(hr == DIERR_OTHERAPPHASPRIO, "Acquire() should have failed: %08x\n", hr);

    SetActiveWindow( hwnd );
    hr = IDirectInputDevice_Acquire(pMouse);
    ok(hr == S_OK, "Acquire() failed: %08x\n", hr);

    mouse_event(MOUSEEVENTF_MOVE, 10, 10, 0, 0);
    cnt = 1;
    hr = IDirectInputDevice_GetDeviceData(pMouse, sizeof(mouse_state), &mouse_state, &cnt, 0);
    ok(hr == S_OK && cnt > 0, "GetDeviceData() failed: %08x cnt:%d\n", hr, cnt);

    mouse_event(MOUSEEVENTF_MOVE, 10, 10, 0, 0);
    IDirectInputDevice_Unacquire(pMouse);
    cnt = 1;
    hr = IDirectInputDevice_GetDeviceData(pMouse, sizeof(mouse_state), &mouse_state, &cnt, 0);
    ok(hr == S_OK && cnt > 0, "GetDeviceData() failed: %08x cnt:%d\n", hr, cnt);

    IDirectInputDevice_Acquire(pMouse);
    mouse_event(MOUSEEVENTF_MOVE, 10, 10, 0, 0);
    IDirectInputDevice_Unacquire(pMouse);
    IDirectInputDevice_Acquire(pMouse);
    cnt = 1;
    hr = IDirectInputDevice_GetDeviceData(pMouse, sizeof(mouse_state), &mouse_state, &cnt, 0);
    ok(hr == S_OK && cnt > 0, "GetDeviceData() failed: %08x cnt:%d\n", hr, cnt);

    /* Check for buffer owerflow */
    for (i = 0; i < 6; i++)
        mouse_event(MOUSEEVENTF_MOVE, 10 + i, 10 + i, 0, 0);

    cnt = 1;
    hr = IDirectInputDevice_GetDeviceData(pMouse, sizeof(mouse_state), &mouse_state, &cnt, 0);
    ok(hr == DI_OK, "GetDeviceData() failed: %08x cnt:%d\n", hr, cnt);
    cnt = 1;
    hr = IDirectInputDevice_GetDeviceData(pMouse, sizeof(mouse_state), &mouse_state, &cnt, 0);
    ok(hr == DI_OK && cnt == 1, "GetDeviceData() failed: %08x cnt:%d\n", hr, cnt);

    if (pMouse) IUnknown_Release(pMouse);

    DestroyWindow( hwnd2 );
}
Пример #22
0
static void test_button_messages(void)
{
    static const struct
    {
        DWORD style;
        DWORD dlg_code;
        const struct message *setfocus;
        const struct message *killfocus;
        const struct message *setstyle;
        const struct message *setstate;
        const struct message *clearstate;
        const struct message *setcheck;
    } button[] = {
        {   BS_PUSHBUTTON, DLGC_BUTTON | DLGC_UNDEFPUSHBUTTON,
            setfocus_seq, killfocus_seq, setstyle_seq,
            setstate_seq, setstate_seq, setcheck_ignored_seq
        },
        {   BS_DEFPUSHBUTTON, DLGC_BUTTON | DLGC_DEFPUSHBUTTON,
            setfocus_seq, killfocus_seq, setstyle_seq,
            setstate_seq, setstate_seq, setcheck_ignored_seq
        },
        {   BS_CHECKBOX, DLGC_BUTTON,
            setfocus_static_seq, killfocus_static_seq, setstyle_static_seq,
            setstate_static_seq, setstate_static_seq, setcheck_static_seq
        },
        {   BS_AUTOCHECKBOX, DLGC_BUTTON,
            setfocus_static_seq, killfocus_static_seq, setstyle_static_seq,
            setstate_static_seq, setstate_static_seq, setcheck_static_seq
        },
        {   BS_RADIOBUTTON, DLGC_BUTTON | DLGC_RADIOBUTTON,
            setfocus_static_seq, killfocus_static_seq, setstyle_static_seq,
            setstate_static_seq, setstate_static_seq, setcheck_radio_redraw_seq
        },
        {   BS_3STATE, DLGC_BUTTON,
            setfocus_static_seq, killfocus_static_seq, setstyle_static_seq,
            setstate_static_seq, setstate_static_seq, setcheck_static_seq
        },
        {   BS_AUTO3STATE, DLGC_BUTTON,
            setfocus_static_seq, killfocus_static_seq, setstyle_static_seq,
            setstate_static_seq, setstate_static_seq, setcheck_static_seq
        },
        {   BS_GROUPBOX, DLGC_STATIC,
            setfocus_groupbox_seq, killfocus_static_seq, setstyle_static_seq,
            setstate_static_seq, setstate_static_seq, setcheck_ignored_seq
        },
        {   BS_USERBUTTON, DLGC_BUTTON | DLGC_UNDEFPUSHBUTTON,
            setfocus_seq, killfocus_seq, setstyle_user_seq,
            setstate_user_seq, clearstate_seq, setcheck_ignored_seq
        },
        {   BS_AUTORADIOBUTTON, DLGC_BUTTON | DLGC_RADIOBUTTON,
            setfocus_static_seq, killfocus_static_seq, setstyle_static_seq,
            setstate_static_seq, setstate_static_seq, setcheck_radio_redraw_seq
        },
        {   BS_OWNERDRAW, DLGC_BUTTON,
            setfocus_ownerdraw_seq, killfocus_ownerdraw_seq, setstyle_ownerdraw_seq,
            setstate_ownerdraw_seq, clearstate_ownerdraw_seq, setcheck_ignored_seq
        },
    };
    const struct message *seq;
    unsigned int i;
    HWND hwnd, parent;
    DWORD dlg_code;
    HFONT zfont;
    BOOL todo;

    /* selection with VK_SPACE should capture button window */
    hwnd = create_button(BS_CHECKBOX | WS_VISIBLE | WS_POPUP, NULL);
    ok(hwnd != 0, "Failed to create button window\n");
    ReleaseCapture();
    SetFocus(hwnd);
    SendMessageA(hwnd, WM_KEYDOWN, VK_SPACE, 0);
    ok(GetCapture() == hwnd, "Should be captured on VK_SPACE WM_KEYDOWN\n");
    SendMessageA(hwnd, WM_KEYUP, VK_SPACE, 0);
    DestroyWindow(hwnd);

    parent = CreateWindowExA(0, "TestParentClass", "Test parent", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
                             100, 100, 200, 200, 0, 0, 0, NULL);
    ok(parent != 0, "Failed to create parent window\n");

    for (i = 0; i < sizeof(button)/sizeof(button[0]); i++)
    {
        MSG msg;
        DWORD style, state;

        trace("%d: button test sequence\n", i);
        hwnd = create_button(button[i].style, parent);

        style = GetWindowLongA(hwnd, GWL_STYLE);
        style &= ~(WS_CHILD | BS_NOTIFY);
        /* XP turns a BS_USERBUTTON into BS_PUSHBUTTON */
        if (button[i].style == BS_USERBUTTON)
            ok(style == BS_PUSHBUTTON, "expected style BS_PUSHBUTTON got %x\n", style);
        else
            ok(style == button[i].style, "expected style %x got %x\n", button[i].style, style);

        dlg_code = SendMessageA(hwnd, WM_GETDLGCODE, 0, 0);
        ok(dlg_code == button[i].dlg_code, "%u: wrong dlg_code %08x\n", i, dlg_code);

        ShowWindow(hwnd, SW_SHOW);
        UpdateWindow(hwnd);
        SetFocus(0);
        flush_events();
        SetFocus(0);
        flush_sequences(sequences, NUM_MSG_SEQUENCES);

        todo = button[i].style != BS_OWNERDRAW;
        ok(GetFocus() == 0, "expected focus 0, got %p\n", GetFocus());
        SetFocus(hwnd);
        SendMessageA(hwnd, WM_APP, 0, 0); /* place a separator mark here */
        while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessageA(&msg);
        ok_sequence(sequences, COMBINED_SEQ_INDEX, button[i].setfocus, "SetFocus(hwnd) on a button", todo);

        todo = button[i].style == BS_OWNERDRAW;
        SetFocus(0);
        SendMessageA(hwnd, WM_APP, 0, 0); /* place a separator mark here */
        while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessageA(&msg);
        ok_sequence(sequences, COMBINED_SEQ_INDEX, button[i].killfocus, "SetFocus(0) on a button", todo);
        ok(GetFocus() == 0, "expected focus 0, got %p\n", GetFocus());

        SendMessageA(hwnd, BM_SETSTYLE, button[i].style | BS_BOTTOM, TRUE);
        SendMessageA(hwnd, WM_APP, 0, 0); /* place a separator mark here */
        while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessageA(&msg);
        ok_sequence(sequences, COMBINED_SEQ_INDEX, button[i].setstyle, "BM_SETSTYLE on a button", TRUE);

        style = GetWindowLongA(hwnd, GWL_STYLE);
        style &= ~(WS_VISIBLE | WS_CHILD | BS_NOTIFY);
        /* XP doesn't turn a BS_USERBUTTON into BS_PUSHBUTTON here! */
        ok(style == button[i].style, "expected style %04x got %04x\n", button[i].style, style);

        state = SendMessageA(hwnd, BM_GETSTATE, 0, 0);
        ok(state == 0, "expected state 0, got %04x\n", state);

        flush_sequences(sequences, NUM_MSG_SEQUENCES);

        SendMessageA(hwnd, BM_SETSTATE, TRUE, 0);
        SendMessageA(hwnd, WM_APP, 0, 0); /* place a separator mark here */
        while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessageA(&msg);
        ok_sequence(sequences, COMBINED_SEQ_INDEX, button[i].setstate, "BM_SETSTATE/TRUE on a button", TRUE);

        state = SendMessageA(hwnd, BM_GETSTATE, 0, 0);
        ok(state == BST_PUSHED, "expected state 0x0004, got %04x\n", state);

        style = GetWindowLongA(hwnd, GWL_STYLE);
        style &= ~(WS_CHILD | BS_NOTIFY | WS_VISIBLE);
        ok(style == button[i].style, "expected style %04x got %04x\n", button[i].style, style);

        flush_sequences(sequences, NUM_MSG_SEQUENCES);

        SendMessageA(hwnd, BM_SETSTATE, FALSE, 0);
        SendMessageA(hwnd, WM_APP, 0, 0); /* place a separator mark here */
        while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessageA(&msg);
        ok_sequence(sequences, COMBINED_SEQ_INDEX, button[i].clearstate, "BM_SETSTATE/FALSE on a button", TRUE);

        state = SendMessageA(hwnd, BM_GETSTATE, 0, 0);
        ok(state == 0, "expected state 0, got %04x\n", state);

        style = GetWindowLongA(hwnd, GWL_STYLE);
        style &= ~(WS_CHILD | BS_NOTIFY | WS_VISIBLE);
        ok(style == button[i].style, "expected style %04x got %04x\n", button[i].style, style);

        state = SendMessageA(hwnd, BM_GETCHECK, 0, 0);
        ok(state == BST_UNCHECKED, "expected BST_UNCHECKED, got %04x\n", state);

        flush_sequences(sequences, NUM_MSG_SEQUENCES);

        if (button[i].style == BS_RADIOBUTTON ||
                button[i].style == BS_AUTORADIOBUTTON)
        {
            seq = setcheck_radio_seq;
            todo = TRUE;
        }
        else
        {
            seq = setcheck_ignored_seq;
            todo = FALSE;
        }
        SendMessageA(hwnd, BM_SETCHECK, BST_UNCHECKED, 0);
        SendMessageA(hwnd, WM_APP, 0, 0); /* place a separator mark here */
        while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessageA(&msg);
        ok_sequence(sequences, COMBINED_SEQ_INDEX, seq, "BM_SETCHECK on a button", todo);

        state = SendMessageA(hwnd, BM_GETCHECK, 0, 0);
        ok(state == BST_UNCHECKED, "expected BST_UNCHECKED, got %04x\n", state);

        style = GetWindowLongA(hwnd, GWL_STYLE);
        style &= ~(WS_CHILD | BS_NOTIFY | WS_VISIBLE);
        ok(style == button[i].style, "expected style %04x got %04x\n", button[i].style, style);

        flush_sequences(sequences, NUM_MSG_SEQUENCES);

        SendMessageA(hwnd, BM_SETCHECK, BST_CHECKED, 0);
        SendMessageA(hwnd, WM_APP, 0, 0); /* place a separator mark here */
        while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessageA(&msg);

        if (button[i].style == BS_PUSHBUTTON ||
                button[i].style == BS_DEFPUSHBUTTON ||
                button[i].style == BS_GROUPBOX ||
                button[i].style == BS_USERBUTTON ||
                button[i].style == BS_OWNERDRAW)
        {
            ok_sequence(sequences, COMBINED_SEQ_INDEX, button[i].setcheck, "BM_SETCHECK on a button", FALSE);
            state = SendMessageA(hwnd, BM_GETCHECK, 0, 0);
            ok(state == BST_UNCHECKED, "expected check BST_UNCHECKED, got %04x\n", state);
        }
        else
        {
            ok_sequence(sequences, COMBINED_SEQ_INDEX, button[i].setcheck, "BM_SETCHECK on a button", TRUE);
            state = SendMessageA(hwnd, BM_GETCHECK, 0, 0);
            ok(state == BST_CHECKED, "expected check BST_CHECKED, got %04x\n", state);
        }

        style = GetWindowLongA(hwnd, GWL_STYLE);
        style &= ~(WS_CHILD | BS_NOTIFY | WS_VISIBLE);
        if (button[i].style == BS_RADIOBUTTON ||
                button[i].style == BS_AUTORADIOBUTTON)
            ok(style == (button[i].style | WS_TABSTOP), "expected style %04x | WS_TABSTOP got %04x\n", button[i].style, style);
        else
            ok(style == button[i].style, "expected style %04x got %04x\n", button[i].style, style);

        DestroyWindow(hwnd);
    }

    DestroyWindow(parent);

    hwnd = create_button(BS_PUSHBUTTON, NULL);

    SetForegroundWindow(hwnd);
    flush_events();

    SetActiveWindow(hwnd);
    SetFocus(0);
    flush_sequences(sequences, NUM_MSG_SEQUENCES);

    SendMessageA(hwnd, WM_LBUTTONDOWN, 0, 0);
    ok_sequence(sequences, COMBINED_SEQ_INDEX, lbuttondown_seq, "WM_LBUTTONDOWN on a button", FALSE);

    SendMessageA(hwnd, WM_LBUTTONUP, 0, 0);
    ok_sequence(sequences, COMBINED_SEQ_INDEX, lbuttonup_seq, "WM_LBUTTONUP on a button", TRUE);

    flush_sequences(sequences, NUM_MSG_SEQUENCES);
    zfont = GetStockObject(SYSTEM_FONT);
    SendMessageA(hwnd, WM_SETFONT, (WPARAM)zfont, TRUE);
    UpdateWindow(hwnd);
    ok_sequence(sequences, COMBINED_SEQ_INDEX, setfont_seq, "WM_SETFONT on a button", FALSE);

    DestroyWindow(hwnd);
}
Пример #23
0
internal void
ProcessPendingMessages()
{
    MSG Message;
    while(PeekMessageA(&Message, 0, 0, 0, PM_REMOVE))
    {
        switch(Message.message)
        {
        case WM_QUIT:
        {
            GlobalRunning = false;
        }
        break;

        case WM_SYSKEYDOWN:
        case WM_SYSKEYUP:
        case WM_KEYDOWN:
        case WM_KEYUP:
        {
            u32 VKCode = (u32)Message.wParam;
            b32 WasDown = (Message.lParam & (1 << 30)) != 0;
            b32 IsDown = (Message.lParam & (1 << 31)) == 0;
            if(WasDown != IsDown)
            {
                if(VKCode == VK_UP)
                {
                }
                else if(VKCode == VK_LEFT)
                {
                }
                else if(VKCode == VK_DOWN)
                {
                }
                else if(VKCode == VK_RIGHT)
                {
                }
                else if(VKCode == VK_ESCAPE)
                {
                }
                else if(VKCode == VK_SPACE)
                {
                }
            }

            if(IsDown)
            {
                b32 AltKeyIsDown = (Message.lParam & (1 << 29));
                if ((VKCode == VK_F4) && AltKeyIsDown)
                {
                    GlobalRunning = false;
                }
            }
        }
        break;
        default:
        {
            TranslateMessage(&Message);
            DispatchMessageA(&Message);
        }
        break;
        };
    }
}
Пример #24
0
/**************************************************************************
 * 				MMSYSTEM_MidiStream_Player	[internal]
 */
static	DWORD	CALLBACK	MMSYSTEM_MidiStream_Player(LPVOID pmt)
{
    WINE_MIDIStream* 	lpMidiStrm = pmt;
    WINE_MIDI*		lpwm;
    MSG			msg;
    DWORD		dwToGo;
    DWORD		dwCurrTC;
    LPMIDIHDR		lpMidiHdr;
    DWORD		dwOffset;

    TRACE("(%p)!\n", lpMidiStrm);

    if (!lpMidiStrm ||
	(lpwm = (LPWINE_MIDI)MMDRV_Get(lpMidiStrm->hDevice, MMDRV_MIDIOUT, FALSE)) == NULL)
	goto the_end;

    /* force thread's queue creation */
    PeekMessageA(&msg, 0, 0, 0, PM_NOREMOVE);

    lpMidiStrm->dwStartTicks = 0;
    lpMidiStrm->dwPulses = 0;

    lpMidiStrm->lpMidiHdr = 0;

    /* midiStreamOpen is waiting for ack */
    SetEvent(lpMidiStrm->hEvent);

start_header:
    lpMidiHdr = lpMidiStrm->lpMidiHdr;
    if (!lpMidiHdr) {
	/* for first message, block until one arrives, then process all that are available */
	GetMessageA(&msg, 0, 0, 0);
	do {
	    if (!MMSYSTEM_MidiStream_MessageHandler(lpMidiStrm, lpwm, &msg))
		goto the_end;
	} while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE));
	goto start_header;
    }

    dwOffset = 0;
    while (dwOffset + offsetof(MIDIEVENT,dwParms) <= lpMidiHdr->dwBytesRecorded) {
	LPMIDIEVENT me = (LPMIDIEVENT)(lpMidiHdr->lpData+dwOffset);

	/* do we have to wait ? */
	if (me->dwDeltaTime) {
	    lpMidiStrm->dwPositionMS += MMSYSTEM_MidiStream_Convert(lpMidiStrm, me->dwDeltaTime);
	    lpMidiStrm->dwPulses += me->dwDeltaTime;

	    dwToGo = lpMidiStrm->dwStartTicks + lpMidiStrm->dwPositionMS;

	    TRACE("%d/%d/%d\n", dwToGo, GetTickCount(), me->dwDeltaTime);
	    while ((dwCurrTC = GetTickCount()) < dwToGo) {
		if (MsgWaitForMultipleObjects(0, NULL, FALSE, dwToGo - dwCurrTC, QS_ALLINPUT) == WAIT_OBJECT_0) {
		    /* got a message, handle it */
		    while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE)) {
			if (!MMSYSTEM_MidiStream_MessageHandler(lpMidiStrm, lpwm, &msg))
			    goto the_end;
			/* is lpMidiHdr still current? */
			if (lpMidiHdr != lpMidiStrm->lpMidiHdr) {
			    goto start_header;
			}
		    }
		} else {
		    /* timeout, so me->dwDeltaTime is elapsed, can break the while loop */
		    break;
		}
	    }
	}
	switch (MEVT_EVENTTYPE(me->dwEvent & ~MEVT_F_CALLBACK)) {
	case MEVT_COMMENT:
	    FIXME("NIY: MEVT_COMMENT\n");
	    /* do nothing, skip bytes */
	    break;
	case MEVT_LONGMSG:
	    midiOutLongMsg(lpMidiStrm->hDevice, lpMidiStrm->lpMidiHdr, MEVT_EVENTPARM(me->dwEvent));
	    break;
	case MEVT_NOP:
	    break;
	case MEVT_SHORTMSG:
	    midiOutShortMsg(lpMidiStrm->hDevice, MEVT_EVENTPARM(me->dwEvent));
	    break;
	case MEVT_TEMPO:
	    lpMidiStrm->dwTempo = MEVT_EVENTPARM(me->dwEvent);
	    break;
	case MEVT_VERSION:
	    break;
	default:
	    FIXME("Unknown MEVT (0x%02x)\n", MEVT_EVENTTYPE(me->dwEvent & ~MEVT_F_CALLBACK));
	    break;
	}
	if (me->dwEvent & MEVT_F_CALLBACK) {
	    /* native fills dwOffset regardless of the cbMidiHdr size argument to midiStreamOut */
	    lpMidiHdr->dwOffset = dwOffset;
	    DriverCallback(lpwm->mod.dwCallback, lpMidiStrm->wFlags,
			   (HDRVR)lpMidiStrm->hDevice, MM_MOM_POSITIONCB,
			   lpwm->mod.dwInstance, (LPARAM)lpMidiHdr, 0L);
	}
	dwOffset += offsetof(MIDIEVENT,dwParms);
	if (me->dwEvent & MEVT_F_LONG)
	    dwOffset += (MEVT_EVENTPARM(me->dwEvent) + 3) & ~3;
    }
    /* done with this header */
    lpMidiStrm->lpMidiHdr = lpMidiHdr->lpNext;
    lpMidiHdr->dwFlags |= MHDR_DONE;
    lpMidiHdr->dwFlags &= ~MHDR_INQUEUE;

    DriverCallback(lpwm->mod.dwCallback, lpMidiStrm->wFlags,
		   (HDRVR)lpMidiStrm->hDevice, MM_MOM_DONE,
		   lpwm->mod.dwInstance, (DWORD_PTR)lpMidiHdr, 0);
    goto start_header;

the_end:
    TRACE("End of thread\n");
    return 0;
}
Пример #25
0
int WinMain(HINSTANCE instance, HINSTANCE previnstance, LPSTR cmdline,
            int cmdshow) {
  win32_gmbdll gmbDLL;
  win32_InitGmbDll(&gmbDLL);
  WNDCLASS tclass = {0};
  tclass.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
  tclass.lpfnWndProc = &gmbWindowProc;
  tclass.hInstance = 0;
  tclass.lpszClassName = "gmb_class_lol";
  tclass.hCursor = LoadCursorA(0, IDC_ARROW);

  ATOM windowClass = RegisterClassA(&tclass);
  if (windowClass == 0) {
    errord((char *)"RegisterClassA");
  }
  HWND window = CreateWindow("gmb_class_lol", "gmb window",
                             WS_OVERLAPPEDWINDOW | WS_VISIBLE, CW_USEDEFAULT,
                             CW_USEDEFAULT, 960, 540, 0, 0, instance, 0);
  if (window == 0) {
    errord((char *)"CreateWindow");
  }
  WIN32WINDOWSIZE size = Win32GetWindowSize(window);
  Win32ResizeWindow(&screenBuffer, size.height, size.width);

// note(caf): use a specific starting address range so we can do some fancy
// stuff in debug mode
#ifdef WIN32_GMB_INTERNAL
  LPVOID StartAddress = (LPVOID)Tibibytes(2);
#else
  LPVOID StartAddress = 0;
#endif
  void *freshmemory = VirtualAlloc(StartAddress, Mibibytes(64),
                                   MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE);
  if (!freshmemory) {
    errord((char *)"VirtualAlloc permanent mem");
  }
  gmbstate state = {0};
  gmbmemory memory = {0};
  state.memory = &memory;
  state.memory->permanent = freshmemory;
  state.memory->permanentBytes = Mibibytes(64);
  state.DEBUGPlatformReadEntireFile = &DEBUGPlatformReadEntireFile;
  state.DEBUGPlatformFreeFile = &DEBUGPlatformFreeFile;
  state.DEBUGPlatformWriteEntireFile = &DEBUGPlatformWriteEntireFile;

  MSG msg;
  HDC hdc = GetDC(window);
  int win32ticks = 0;
  LARGE_INTEGER lastpf;
  LARGE_INTEGER curpf;
  LARGE_INTEGER startFrame;
  QueryPerformanceCounter(&curpf);
  lastpf = curpf;
  startFrame = curpf;
  LARGE_INTEGER freq;
  QueryPerformanceFrequency(&freq);
  uint64 elapsed = curpf.QuadPart - lastpf.QuadPart;
  POINT p;
  real32 ms = 0;
  framebuffer fb = {0};
  inputbuffer ib = {0};
  // note(caf): to watch for live reloading our main dll
  uint64 t = GetTickCount64();
  while (running) {
    if (GetTickCount64() - 1000 > t) {
      t = GetTickCount64();
      DWORD att;
      att = GetFileAttributesA("\\build\\gmb.dll");
      if (att != INVALID_FILE_ATTRIBUTES) {
        HANDLE DllHandle;
        DllHandle = CreateFileA("\\build\\gmb.dll", 0, FILE_SHARE_WRITE, 0,
                                OPEN_EXISTING, 0, 0);
        if (DllHandle == INVALID_HANDLE_VALUE) {
          // TODO(caf): handle errors
        }
        FILETIME DllTime;
        GetFileTime(DllHandle, 0, 0, &DllTime);
        CloseHandle(DllHandle);
        if (DllTime.dwHighDateTime != gmbDLL.lastCreationDate.dwHighDateTime ||
            DllTime.dwLowDateTime != gmbDLL.lastCreationDate.dwLowDateTime) {
          // it existed and was newer, so unload our current copy and load the
          // new one
          win32_UnloadGmbDll(&gmbDLL);
          win32_InitGmbDll(&gmbDLL);
          // TODO(caf): use a lockfile to avoid the race condition of compiler
          // creating file but buffer not flushed when we try to load it
        }
      }
    }
    QueryPerformanceCounter(&startFrame);
    while (PeekMessageA(&msg, window, 0, 0, PM_REMOVE)) {
      if (msg.message == WM_QUIT || msg.message == WM_CLOSE) {
        running = false;
      }
      if (msg.message == WM_KEYDOWN) {
        switch (msg.wParam) {
        case VK_RETURN:
          ib.enter.endedDown = true;
          break;
        case VK_SPACE:
          ib.space.endedDown = true;
          break;
        case VK_DOWN:
          ib.down.endedDown = true;
          break;
        case VK_UP:
          ib.up.endedDown = true;
          break;
        case VK_LEFT:
          ib.left.endedDown = true;
          break;
        case VK_RIGHT:
          ib.right.endedDown = true;
          break;
        default:
          break;
        }
      }
      TranslateMessage(&msg);
      DispatchMessageA(&msg);
    }
    fb.height = screenBuffer.height;
    fb.width = screenBuffer.width;
    fb.stride = 4;
    fb.pixels = screenBuffer.buf;
    GetCursorPos(&p);
    ScreenToClient(window, &p); // takes care of window/cursor offsets
    ib.mousex = p.x;
    ib.mousey = p.y;
    QueryPerformanceCounter(&curpf);
    elapsed = curpf.QuadPart - lastpf.QuadPart;
    lastpf = curpf;
    ms = (real32)((real32)elapsed / (real32)freq.QuadPart) * 1000;
    gmbDLL.gmbMainLoop(&state, &fb, &ib, ms); //(elapsed / freq.QuadPart));
    WIN32WINDOWSIZE size = Win32GetWindowSize(window);
    Win32BlitScreen(hdc, &screenBuffer, size.height, size.width);
    ++win32ticks;
    // QueryPerformanceCounter(&curpf);
    elapsed = curpf.QuadPart - startFrame.QuadPart;
    ms = (real32)((real32)elapsed / (real32)freq.QuadPart) * 1000;
    int msToSleep = int(targetMS) - (int)ms; // intentionally truncating to int
    if (msToSleep > 0) {
      Sleep(msToSleep);
    }
    while (ms < targetMS && ms > 0) {
      QueryPerformanceCounter(&curpf);
      elapsed = curpf.QuadPart - startFrame.QuadPart;
      ms = (real32)((real32)elapsed / (real32)freq.QuadPart) * 1000;
      Sleep(0); // do nothing sleep
    }
    ib = {0};
    // Win32DebugDrawFrameTime(hdc, ms, win32ticks);
  }
  win32_UnloadGmbDll(&gmbDLL);
  return 0;
}
Пример #26
0
internal void
Win32ProcessPendingMessages(game_controller_input* KeyboardController)
{
    MSG Message;

    while(PeekMessageA(&Message, 0, 0, 0, PM_REMOVE))
    {
        switch(Message.message)
        {
            case WM_QUIT:
            {
                GlobalRunning = false;
            }
            break;

            case WM_SYSKEYDOWN:
            case WM_SYSKEYUP:
            case WM_KEYDOWN:
            case WM_KEYUP:
            {
                u32 VKCode = (u32)Message.wParam;

                b32 WasDown = ((Message.lParam & (1 << 30)) != 0);
                b32 IsDown  = ((Message.lParam & (1 << 31)) == 0);

                if(WasDown != IsDown)
                {
                    if(VKCode == 'W')
                    {
                        Win32ProcessKeyboardMessage(&KeyboardController->MoveForward, IsDown);
                    }

                    else if(VKCode == 'A')
                    {
                        Win32ProcessKeyboardMessage(&KeyboardController->MoveLeft, IsDown);
                    }

                    else if(VKCode == 'S')
                    {
                        Win32ProcessKeyboardMessage(&KeyboardController->MoveBackward, IsDown);
                    }

                    else if(VKCode == 'D')
                    {
                        Win32ProcessKeyboardMessage(&KeyboardController->MoveRight, IsDown);
                    }

                    else if(VKCode == VK_UP)
                    {
                        Win32ProcessKeyboardMessage(&KeyboardController->DPadUp, IsDown);
                    }

                    else if(VKCode == VK_LEFT)
                    {
                        Win32ProcessKeyboardMessage(&KeyboardController->DPadLeft, IsDown);
                    }

                    else if(VKCode == VK_DOWN)
                    {
                        Win32ProcessKeyboardMessage(&KeyboardController->DPadDown, IsDown);
                    }

                    else if(VKCode == VK_RIGHT)
                    {
                        Win32ProcessKeyboardMessage(&KeyboardController->DPadRight, IsDown);
                    }

                    else if(VKCode == VK_ESCAPE)
                    {
                        Win32ProcessKeyboardMessage(&KeyboardController->Start, IsDown);
                    }

// NOTE(zak): Bind A, B, X, Y on controller to buttons on keyboard

#if LUDUS_INTERNAL
                    else if(VKCode == 'P')
                    {
                        if(IsDown)
                        {
                            GlobalPause = !GlobalPause;
                        }
                    }
                    else if(VKCode == VK_F1)
                    {
                        if(IsDown)
                        {
                            GlobalDebugMode = !GlobalDebugMode;
                        }
                    }
#endif

                    else if(IsDown)
                    {
                        b32 AltKeyWasDown = (Message.lParam & (1 << 29));
                        if((VKCode == VK_F4) && AltKeyWasDown)
                        {
                            GlobalRunning = false;
                        }

                        if((VKCode == VK_RETURN) && AltKeyWasDown)
                        {
                            Win32ToggleFullscreen(Message.hwnd);
                        }
                    }
                }
            }
            break;

            default:
            {
                TranslateMessage(&Message);
                DispatchMessageA(&Message);
            }
            break;
        }
    }
}
Пример #27
0
static void test_custom_default_button(void)
{
    HWND hdlg, page;
    PROPSHEETPAGEA psp[1];
    PROPSHEETHEADERA psh;
    MSG msg;
    LRESULT result;

    psp[0].dwSize = sizeof (PROPSHEETPAGEA);
    psp[0].dwFlags = PSP_USETITLE;
    psp[0].hInstance = GetModuleHandleA(NULL);
    U(psp[0]).pszTemplate = (LPCSTR)MAKEINTRESOURCE(IDD_PROP_PAGE_WITH_CUSTOM_DEFAULT_BUTTON);
    U2(psp[0]).pszIcon = NULL;
    psp[0].pfnDlgProc = page_with_custom_default_button_dlg_proc;
    psp[0].pszTitle = "Page1";
    psp[0].lParam = 0;

    psh.dwSize = PROPSHEETHEADERA_V1_SIZE;
    psh.dwFlags = PSH_PROPSHEETPAGE | PSH_MODELESS;
    psh.hwndParent = GetDesktopWindow();
    psh.hInstance = GetModuleHandleA(NULL);
    U(psh).pszIcon = NULL;
    psh.pszCaption =  "PropertySheet1";
    psh.nPages = 1;
    U3(psh).ppsp = psp;
    U2(psh).nStartPage = 0;

    /* The goal of the test is to make sure that the Add button is pressed
     * when the ENTER key is pressed and a different control, a combobox,
     * has the keyboard focus. */
    add_button_has_been_pressed = FALSE;

    /* Create the modeless property sheet. */
    hdlg = (HWND)PropertySheetA(&psh);
    ok(hdlg != INVALID_HANDLE_VALUE, "Cannot create the property sheet\n");

    /* Set the Add button as the default button. */
    SendMessageA(hdlg, DM_SETDEFID, (WPARAM)IDC_PS_PUSHBUTTON1, 0);

    /* Make sure the default button is the Add button. */
    result = SendMessageA(hdlg, DM_GETDEFID, 0, 0);
    ok(DC_HASDEFID == HIWORD(result), "The property sheet does not have a default button\n");
    ok(IDC_PS_PUSHBUTTON1 == LOWORD(result), "The default button is not the Add button\n");

    /* At this point, the combobox should have keyboard focus, so we press ENTER.
     * Pull the lever, Kronk! */
    page = (HWND)SendMessageW(hdlg, PSM_GETCURRENTPAGEHWND, 0, 0);
    PostMessageW(GetDlgItem(page, IDC_PS_COMBO1), WM_KEYDOWN, VK_RETURN, 0);

    /* Process all the messages in the queue for this thread. */
    while (PeekMessageA(&msg, NULL, 0, 0, PM_REMOVE))
    {
        /* (!PropSheet_IsDialogMessage(hdlg, &msg)) */
        if (!((BOOL)SendMessageA(hdlg, PSM_ISDIALOGMESSAGE, 0, (LPARAM)&msg)))
        {
            TranslateMessage(&msg);
            DispatchMessageA(&msg);
        }
    }

    ok(add_button_has_been_pressed, "The Add button has not been pressed!\n");

    DestroyWindow(hdlg);
}
Пример #28
0
static inline int run(HINSTANCE hInstance)
{
	const char *windowClassName = "Caveman Class";

	WNDCLASS wc = {};
	wc.style = CS_VREDRAW | CS_HREDRAW | CS_OWNDC;
	wc.lpfnWndProc = windowProc;
	wc.hInstance = hInstance;
	wc.hCursor = LoadCursor(NULL, IDC_ARROW);
	wc.lpszClassName = windowClassName;

	RegisterClassA(&wc);

	HWND window = CreateWindowExA(
		0,
		windowClassName,
		"Caveman",
		WS_MAXIMIZE | WS_OVERLAPPEDWINDOW | WS_VISIBLE,
		CW_USEDEFAULT, CW_USEDEFAULT,
		CW_USEDEFAULT, CW_USEDEFAULT,
		NULL,
		NULL,
		hInstance,
		NULL);
	HDC windowDc = GetDC(window);

	if (window == nullptr)
	{
//TODO consider using GetLastError to produce a more informative error message
		MessageBox(
			NULL,
			"Could not create application window",
			NULL,
			MB_OK | MB_ICONERROR | MB_SETFOREGROUND);
		return 1;
	}

	if (!init(app, FilePath{R"(C:\Windows\Fonts\Arial.ttf)"}))
	{
//TODO show error to user
		return 1;
	}

	for (;;)
	{
		MSG message = {};
		while (PeekMessageA(&message, NULL, 0, 0, PM_REMOVE))
		{
			if (message.message == WM_QUIT)
			{
				goto exit;
			}
			TranslateMessage(&message);
			DispatchMessageA(&message);
		}

		update(app);

		if (app.drawCanvas)
		{
			app.drawCanvas = false;
			if (bitmap.pixels != nullptr)
			{
//TODO investigate if another bitmap blit function is more efficient:
//
//         https://msdn.microsoft.com/en-us/library/windows/desktop/dd183385(v=vs.85).aspx
				StretchDIBits(
					windowDc,
					0, 0, windowSize.width, windowSize.height,
					0, 0, bitmap.width, bitmap.height,
					bitmap.pixels,
					&bitmap.bmi,
					DIB_RGB_COLORS,
					SRCCOPY);
			}
		}
	}

exit:
	return 0;
}
Пример #29
0
static DWORD WINAPI ProcessMsgThread(LPVOID lpParam) {
  IDirectMusicPerformance8Impl* This = lpParam;
  DWORD timeOut = INFINITE;
  MSG msg;
  HRESULT hr;
  REFERENCE_TIME rtCurTime;
  DMUS_PMSGItem* it = NULL;
  DMUS_PMSGItem* cur = NULL;
  DMUS_PMSGItem* it_next = NULL;

  while (TRUE) {
    DWORD dwDec = This->rtLatencyTime + This->dwBumperLength;

    if (timeOut > 0) MsgWaitForMultipleObjects(0, NULL, FALSE, timeOut, QS_POSTMESSAGE|QS_SENDMESSAGE|QS_TIMER);
    timeOut = INFINITE;

    EnterCriticalSection(&This->safe);
    hr = IDirectMusicPerformance8_GetTime((IDirectMusicPerformance8*) This, &rtCurTime, NULL);
    if (FAILED(hr)) {
      goto outrefresh;
    }
    
    for (it = This->imm_head; NULL != it; ) {
      it_next = it->next;
      cur = ProceedMsg(This, it);  
      HeapFree(GetProcessHeap(), 0, cur); 
      it = it_next;
    }

    for (it = This->head; NULL != it && it->rtItemTime < rtCurTime + dwDec; ) {
      it_next = it->next;
      cur = ProceedMsg(This, it);
      HeapFree(GetProcessHeap(), 0, cur);
      it = it_next;
    }
    if (NULL != it) {
      timeOut = ( it->rtItemTime - rtCurTime ) + This->rtLatencyTime;
    }

outrefresh:
    LeaveCriticalSection(&This->safe);
    
    while (PeekMessageA(&msg, NULL, 0, 0, PM_REMOVE)) {
      /** if hwnd we suppose that is a windows event ... */
      if  (NULL != msg.hwnd) {
	TranslateMessage(&msg);
	DispatchMessageA(&msg);
      } else {
	switch (msg.message) {	    
	case WM_QUIT:
	case PROCESSMSG_EXIT:
	  goto outofthread;
	case PROCESSMSG_START:
	  break;
	case PROCESSMSG_ADD:
	  break;
	case PROCESSMSG_REMOVE:
	  break;
	default:
	  ERR("Unhandled message %u. Critical Path\n", msg.message);
	  break;
	}
      }
    }

    /** here we should run a little of current AudioPath */

  }

outofthread:
  TRACE("(%p): Exiting\n", This);
  
  return 0;
}
Пример #30
0
void __fastcall TMainForm::ToolButton6Click(TObject *Sender)
{
	String FileName = "ExpMtr\\mtr.xml";
	TStringList *list = new TStringList;
	TSendThread *Client;
	int mr;
	String err, s;
	char c[512];
	MSG msg;

	if ((err = cVerifData()) != "")	{
		ShowMessage(err);
		return;
	}

	LoginForm->UserEdit->Text = /*"sc910001" + */"sc" + IntToStr(School.SchoolCode);
	LoginForm->PasswordEdit->Text = "jXCHJQQo";

	Client = new TSendThread(true);
	if (LoginForm->ShowModal() != mrOk)
		return;

	Client->User = LoginForm->UserEdit->Text;
	Client->Password = LoginForm->PasswordEdit->Text;
	Client->ms = new TMemoryStream;
	s = "SchoolCode=" + Client->User.SubString(3, 6);
	Client->ms->Write(s.c_str(), 512);
//	Client->ms->Write('\0', 1);
	Client->CommandID = "4";
	Client->srv = GetServerIP();
	Client->FreeOnTerminate = true;

	SendForm->Show();
	SendForm->Memo1->Lines->Append("Соединение с сервером...");

	while (PeekMessage(&msg, this->Handle, WM_USER, THRD_END, PM_REMOVE)); //инициализация и отчистка очереди

	Client->Resume();

	GetMessageA(&msg, 0, THRD_READY, THRD_READY);

	while (!PeekMessageA(&msg, 0, THRD_END, THRD_END, PM_NOREMOVE))	{
		Application->ProcessMessages();
		WaitMessage();
	}

	if (!PostThreadMessageA(Client->ThreadID, MAIN_READY, 0, 0))	{
		Client->Suspend();
		Client->Terminate();
		ShowMessage("Непредвиденная ошибка при попытке отправить сообщение окну.");
    }

	if (msg.wParam)
		ShowMessage("WParam=" + IntToStr(msg.wParam));

	if (msg.lParam) {
		SendForm->Close();
		FillServerMatrixForm(ReceiveStream);
		ServerMatrixForm->Show();
	}
	else	{
        ShowMessage("Ошибка при получении списка матриц.");
    }
}