void Test_GetKeyState() { HWND hwnd; MSG msg; hwnd = CreateTestWindow(); hKbdHook = SetWindowsHookEx(WH_KEYBOARD, KeyboardProc, GetModuleHandleA( NULL ), 0); hKbdLLHook = SetWindowsHookEx(WH_KEYBOARD_LL, LowLevelKeyboardProc, GetModuleHandleA( NULL ), 0); ok(hKbdHook!=NULL," \n"); ok(hKbdLLHook!=NULL," \n"); keybd_event(VK_LMENU, 0, 0,0); while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessageA( &msg ); keybd_event(VK_LMENU, 0, KEYEVENTF_KEYUP,0); //fixme this hangs the test //while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE|PM_NOYIELD )) DispatchMessageA( &msg ); DestroyWindow(hwnd); while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessageA( &msg ); UnhookWindowsHookEx (hKbdHook); UnhookWindowsHookEx (hKbdLLHook); }
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; }
unsigned WINAPI CreateWndThreadA( LPVOID pThreadParam) { HWND hWnd = CreateWindowA( "Azureus Window Hook", NULL, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInstance, NULL); if( hWnd == NULL){ printf( "Failed to create window\n" ); return( 0 ); }else{ MSG Msg; while(GetMessageA(&Msg, hWnd, 0, 0)) { TranslateMessage(&Msg); DispatchMessageA(&Msg); } return Msg.wParam; } }
static HWND CreateTestWindow() { MSG msg; WNDCLASSA wclass; HANDLE hInstance = GetModuleHandleA( NULL ); HWND hWndTest; wclass.lpszClassName = "MouseInputTestClass"; wclass.style = CS_HREDRAW | CS_VREDRAW; wclass.lpfnWndProc = WndProc; wclass.hInstance = hInstance; wclass.hIcon = LoadIconA( 0, IDI_APPLICATION ); wclass.hCursor = LoadCursorA( NULL, IDC_ARROW ); wclass.hbrBackground = (HBRUSH)( COLOR_WINDOW + 1 ); wclass.lpszMenuName = 0; wclass.cbClsExtra = 0; wclass.cbWndExtra = 0; RegisterClassA( &wclass ); /* create the test window that will receive the keystrokes */ hWndTest = CreateWindowA( wclass.lpszClassName, "MouseInputTestTest", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, 0, 100, 100, NULL, NULL, hInstance, NULL); assert( hWndTest ); ShowWindow( hWndTest, SW_SHOWMAXIMIZED); SetWindowPos( hWndTest, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE ); SetForegroundWindow( hWndTest ); UpdateWindow( hWndTest); SetFocus(hWndTest); /* flush pending messages */ while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessageA( &msg ); return hWndTest; }
static void test_messages(void) { WNDCLASSA cls; HWND win; MSG msg; HANDLE thread; DWORD tid; InitializeCriticalSection(&clipboard_cs); memset(&cls, 0, sizeof(cls)); cls.lpfnWndProc = clipboard_wnd_proc; cls.hInstance = GetModuleHandleA(NULL); cls.lpszClassName = "clipboard_test"; RegisterClassA(&cls); win = CreateWindowA("clipboard_test", NULL, 0, 0, 0, 0, 0, NULL, 0, NULL, 0); ok(win != NULL, "CreateWindow failed: %d\n", GetLastError()); thread = CreateThread(NULL, 0, clipboard_thread, (void*)win, 0, &tid); ok(thread != NULL, "CreateThread failed: %d\n", GetLastError()); while(GetMessageA(&msg, NULL, 0, 0)) { TranslateMessage(&msg); DispatchMessageA(&msg); } ok(WaitForSingleObject(thread, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n"); CloseHandle(thread); UnregisterClassA("clipboard_test", GetModuleHandleA(NULL)); DeleteCriticalSection(&clipboard_cs); }
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; }
void message_loop() { MSG msg; while (GetMessage(&msg, 0, 0, 0)) { DispatchMessageA(&msg); TranslateMessage(&msg); } }
/****************************************************************** * mmTaskBlock (WINMM.@) */ VOID WINAPI mmTaskBlock(DWORD tid) { MSG msg; do { GetMessageA(&msg, 0, 0, 0); if (msg.hwnd) DispatchMessageA(&msg); } while (msg.message != WM_USER); }
/* process any pending messages */ static void do_events(void) { MSG msg; while (PeekMessageA(&msg, NULL, 0, 0, PM_REMOVE)) { TranslateMessage(&msg); DispatchMessageA(&msg); } }
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; }
static DWORD WINAPI Thread2( _Inout_opt_ PVOID Parameter) { MSG msg; LRESULT ret; WPARAM wParam; hWndThread2 = CreateWindowExW(0, L"SendTest", NULL, 0, 10, 10, 20, 20, NULL, NULL, 0, NULL); ok(hWndThread2 != NULL, "CreateWindow failed\n"); while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) { if (!(msg.message > WM_USER || IsDWmMsg(msg.message) || IseKeyMsg(msg.message))) RECORD_MESSAGE(2, msg.message, POST, 0, 0); DispatchMessageA(&msg); } wParam = (WPARAM)Parameter; ret = SendMessage(hWndThread1, WM_SENDTOOTHERTHREAD, wParam, dwThread2); ok(ret == 0, "ret = %lu\n", ret); while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) { if (!(msg.message > WM_USER || IsDWmMsg(msg.message) || IseKeyMsg(msg.message))) RECORD_MESSAGE(2, msg.message, POST, 0, 0); DispatchMessageA(&msg); } DestroyWindow(hWndThread2); while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) { if (!(msg.message > WM_USER || IsDWmMsg(msg.message) || IseKeyMsg(msg.message))) RECORD_MESSAGE(2, msg.message, POST, 0, 0); DispatchMessageA(&msg); } return 7; }
static void cleanup(void) { MSG msg; PostMessageA(hProgressParentWnd, WM_CLOSE, 0, 0); while (GetMessageA(&msg,0,0,0)) { TranslateMessage(&msg); DispatchMessageA(&msg); } UnregisterClassA(progressTestClass, GetModuleHandleA(NULL)); }
static void FlushMessages() { MSG msg; while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) { int iwnd = get_iwnd(msg.hwnd); if(!(msg.message > WM_USER || !iwnd || IsDWmMsg(msg.message) || IseKeyMsg(msg.message))) RECOND_MESSAGE(iwnd, msg.message, POST,0,0); DispatchMessageA( &msg ); } }
static DWORD WINAPI Thread1( _Inout_opt_ PVOID Parameter) { MSG msg; hWndThread1 = CreateWindowExW(0, L"SendTest", NULL, 0, 10, 10, 20, 20, NULL, NULL, 0, NULL); ok(hWndThread1 != NULL, "CreateWindow failed\n"); while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) { if (!(msg.message > WM_USER || IsDWmMsg(msg.message) || IseKeyMsg(msg.message))) RECORD_MESSAGE(1, msg.message, POST, 0, 0); DispatchMessageA(&msg); } ResumeThread(hThread2); while (MsgWaitForMultipleObjectsEx(1, &hThread2, FALSE, QS_ALLEVENTS, MWMO_ALERTABLE) != WAIT_OBJECT_0) { while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) { if (!(msg.message > WM_USER || IsDWmMsg(msg.message) || IseKeyMsg(msg.message))) RECORD_MESSAGE(1, msg.message, POST, 0, 0); DispatchMessageA(&msg); } } DestroyWindow(hWndThread1); while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) { if (!(msg.message > WM_USER || IsDWmMsg(msg.message) || IseKeyMsg(msg.message))) RECORD_MESSAGE(1, msg.message, POST, 0, 0); DispatchMessageA(&msg); } return 6; }
/* 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(); } }
static void cleanup(void) { MSG msg; PostMessageA(hComboExParentWnd, WM_CLOSE, 0, 0); while (GetMessageA(&msg,0,0,0)) { TranslateMessage(&msg); DispatchMessageA(&msg); } DestroyWindow(hComboExParentWnd); UnregisterClassA(ComboExTestClass, GetModuleHandleA(NULL)); }
/* 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(); } }
//-------------------------------------------------------------------------------------- // This function is used only briefly in CHT IME handling, // so accelerator isn't processed. DXUTAPI void CDXUTIMEEditBox::PumpMessage() { MSG msg; while (PeekMessageW(&msg, nullptr, 0, 0, PM_NOREMOVE)) { if (!GetMessageW(&msg, nullptr, 0, 0)) { PostQuitMessage((int)msg.wParam); return; } TranslateMessage(&msg); DispatchMessageA(&msg); } }
static DWORD WINAPI drop_window_therad(void *arg) { struct DragParam *param = arg; WNDCLASSA cls; WINDOWINFO info; BOOL r; MSG msg; memset(&cls, 0, sizeof(cls)); cls.lpfnWndProc = drop_window_proc; cls.hInstance = GetModuleHandleA(NULL); cls.lpszClassName = "drop test"; RegisterClassA(&cls); param->hwnd = CreateWindowA("drop test", NULL, 0, 0, 0, 0, 0, NULL, 0, NULL, 0); ok(param->hwnd != NULL, "CreateWindow failed: %d\n", GetLastError()); memset(&info, 0, sizeof(info)); info.cbSize = sizeof(info); r = GetWindowInfo(param->hwnd, &info); ok(r, "got %d\n", r); ok(!(info.dwExStyle & WS_EX_ACCEPTFILES), "got %08x\n", info.dwExStyle); DragAcceptFiles(param->hwnd, TRUE); memset(&info, 0, sizeof(info)); info.cbSize = sizeof(info); r = GetWindowInfo(param->hwnd, &info); ok(r, "got %d\n", r); ok((info.dwExStyle & WS_EX_ACCEPTFILES), "got %08x\n", info.dwExStyle); SetEvent(param->ready); while ((r = GetMessageA(&msg, NULL, 0, 0)) != 0) { if (r == (BOOL)-1) { ok(0, "unexpected return value, got %d\n", r); break; } DispatchMessageA(&msg); } DestroyWindow(param->hwnd); UnregisterClassA("drop test", GetModuleHandleA(NULL)); return 0; }
void CShortcut::SendEventBackToControl() { #ifndef KEYHOOK_EXPORTS CWinThread* pThread=GetTrayIconWnd()->GetLocateDlgThread(); if (pThread!=NULL) { const MSG* pMsg=pThread->GetCurrentMessage(); ASSERT(pMsg!=NULL); TranslateMessage(pMsg); if (IsUnicodeSystem()) DispatchMessageW(pMsg); else DispatchMessageA(pMsg); } #endif }
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(); } } }
static DWORD WINAPI create_window(LPVOID param) { wnd_param *param1 = param; DWORD ret; MSG msg; ret = SetThreadDesktop(param1->hdesk); ok(ret, "SetThreadDesktop failed!\n"); param1->hwnd = CreateWindowA("test_class", param1->wnd_name, WS_POPUP, 0, 0, 100, 100, NULL, NULL, NULL, NULL); ok(param1->hwnd != 0, "CreateWindowA failed!\n"); ret = SetEvent(param1->hevent); ok(ret, "SetEvent failed!\n"); while (GetMessageA(&msg, 0, 0, 0)) { TranslateMessage(&msg); DispatchMessageA(&msg); } return 0; }
static void FlushMessages() { MSG msg; while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) { int iwnd = get_iwnd(msg.hwnd); if(iwnd) { if(msg.message == WM_SYSTIMER) { RECOND_MESSAGE(iwnd, msg.message, POST,msg.wParam,0); if(ignore_timer) continue; } else if(!(msg.message > WM_USER || !iwnd || IsDWmMsg(msg.message) || IseKeyMsg(msg.message))) RECOND_MESSAGE(iwnd, msg.message, POST,0,0); } DispatchMessageA( &msg ); } }
static void FlushMessages() { MSG msg; LRESULT res; while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) { int iwnd = get_iwnd(msg.hwnd); if( iwnd >= 0 && msg.message > 0 && msg.message < WM_APP && msg.message != WM_TIMER) record_message(&data[0].cache, iwnd, msg.message, POST, msg.wParam,0); DispatchMessageA( &msg ); } /* Use SendMessage to sync with the other queues */ res = SendMessageTimeout(data[1].hWnd, WM_APP, 0,0, SMTO_NORMAL, 1000, NULL); ok (res != ERROR_TIMEOUT, "SendMessageTimeout timed out\n"); res = SendMessageTimeout(data[2].hWnd, WM_APP, 0,0, SMTO_NORMAL, 1000, NULL); ok (res != ERROR_TIMEOUT, "SendMessageTimeout timed out\n"); res = SendMessageTimeout(data[3].hWnd, WM_APP, 0,0, SMTO_NORMAL, 1000, NULL); ok (res != ERROR_TIMEOUT, "SendMessageTimeout timed out\n"); res = SendMessageTimeout(data[4].hWnd, WM_APP, 0,0, SMTO_NORMAL, 1000, NULL); ok (res != ERROR_TIMEOUT, "SendMessageTimeout timed out\n"); }
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; }
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); } } } }
/* 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); }
int CALLBACK WinMain(HINSTANCE Instance, HINSTANCE PrevInstance, LPSTR CommandLine, int ShowCode) { Win32LoadXInput(); WNDCLASSA WindowClass = {}; Win32ResizeDIBSection(&GlobalBackbuffer, 1280, 720); WindowClass.style = CS_HREDRAW|CS_VREDRAW|CS_OWNDC; WindowClass.lpfnWndProc = Win32MainWindowCallback; WindowClass.hInstance = Instance; // WindowClass.hIcon = ; WindowClass.lpszClassName = "HandmadeHeroWindowClass"; if (RegisterClassA(&WindowClass)) { HWND Window = CreateWindowExA(0, WindowClass.lpszClassName, "Handmade Hero", WS_OVERLAPPEDWINDOW|WS_VISIBLE, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, 0, 0, Instance, 0); if (Window) { // NOTE: Since we specified CS_OWNDC, we can just // get one device context and use it forever because we // are not sharing it with anyone. HDC DeviceContext = GetDC(Window); // NOTE: Graphics test int XOffset = 0; int YOffset = 0; win32_sound_output SoundOutput = {}; // TODO: Make this like sixty seconds? SoundOutput.SamplesPerSecond = 48000; SoundOutput.ToneHz = 256; SoundOutput.ToneVolume = 3000; SoundOutput.WavePeriod = SoundOutput.SamplesPerSecond / SoundOutput.ToneHz; SoundOutput.BytesPerSample = sizeof(int16) * 2; SoundOutput.SecondaryBufferSize = SoundOutput.SamplesPerSecond * SoundOutput.BytesPerSample; SoundOutput.LatencySampleCount = SoundOutput.SamplesPerSecond / 15; Win32InitDSound(Window, SoundOutput.SamplesPerSecond, SoundOutput.SecondaryBufferSize); Win32FillSoundBuffer(&SoundOutput, 0, SoundOutput.LatencySampleCount * SoundOutput.BytesPerSample); GlobalSecondaryBuffer->Play(0, 0, DSBPLAY_LOOPING); GlobalRunning = true; while(GlobalRunning) { MSG Message; while(PeekMessage(&Message, 0, 0, 0, PM_REMOVE)) { if (Message.message == WM_QUIT) { GlobalRunning = false; } TranslateMessage(&Message); DispatchMessageA(&Message); } // TODO: Should we poll this more frequently for (DWORD ControllerIndex = 0; ControllerIndex < XUSER_MAX_COUNT; ++ControllerIndex) { XINPUT_STATE ControllerState; if (XInputGetState(ControllerIndex, &ControllerState) == ERROR_SUCCESS) { // NOTE: This controller is plugged in // TODO: See if ControllerState.dwPacketNumber increments too rapidly XINPUT_GAMEPAD *Pad = &ControllerState.Gamepad; bool32 Up = (Pad->wButtons & XINPUT_GAMEPAD_DPAD_UP); bool32 Down = (Pad->wButtons & XINPUT_GAMEPAD_DPAD_DOWN); bool32 Left = (Pad->wButtons & XINPUT_GAMEPAD_DPAD_LEFT); bool32 Right = (Pad->wButtons & XINPUT_GAMEPAD_DPAD_RIGHT); bool32 Start = (Pad->wButtons & XINPUT_GAMEPAD_START); bool32 Back = (Pad->wButtons & XINPUT_GAMEPAD_BACK); bool32 LeftShoulder = (Pad->wButtons & XINPUT_GAMEPAD_LEFT_SHOULDER); bool32 RightShoulder = (Pad->wButtons & XINPUT_GAMEPAD_RIGHT_SHOULDER); bool32 AButton = (Pad->wButtons & XINPUT_GAMEPAD_A); bool32 BButton = (Pad->wButtons & XINPUT_GAMEPAD_B); bool32 XButton = (Pad->wButtons & XINPUT_GAMEPAD_X); bool32 YButton = (Pad->wButtons & XINPUT_GAMEPAD_Y); int16 StickX = Pad->sThumbLX; int16 StickY = Pad->sThumbLY; // TODO: We will do deadzone handling later using // XINPUT_GAMEPAD_LEFT_THUMB_DEADZONE // XINPUT_GAMEPAD_RIGHT_THUMB_DEADZONE XOffset += StickX / 4096; YOffset += StickY / 4096; SoundOutput.ToneHz = 512 + (int)(256.0f * ((real32)StickY / 30000.0f)); SoundOutput.WavePeriod = SoundOutput.SamplesPerSecond / SoundOutput.ToneHz; } else { // NOTE: The controller is not available } } RenderWeirdGradient(&GlobalBackbuffer, XOffset, YOffset); // NOTE: DirectSound output test DWORD PlayCursor; DWORD WriteCursor; if (SUCCEEDED(GlobalSecondaryBuffer->GetCurrentPosition(&PlayCursor, &WriteCursor))) { DWORD ByteToLock = (SoundOutput.RunningSampleIndex * SoundOutput.BytesPerSample) % SoundOutput.SecondaryBufferSize; DWORD TargetCursor = (PlayCursor + (SoundOutput.LatencySampleCount * SoundOutput.BytesPerSample)) % SoundOutput.SecondaryBufferSize; DWORD BytesToWrite; // TODO: Change this to using a lower latency offset from the playcursor // when we actually start having sound effects. if (ByteToLock > TargetCursor) { BytesToWrite = SoundOutput.SecondaryBufferSize - ByteToLock; BytesToWrite += TargetCursor; } else { BytesToWrite = TargetCursor - ByteToLock; } Win32FillSoundBuffer(&SoundOutput, ByteToLock, BytesToWrite); } win32_window_dimension Dimension = Win32GetWindowDimension(Window); Win32DisplayBufferInWindow(&GlobalBackbuffer, DeviceContext, Dimension.Width, Dimension.Height); } } else { // TODO: Logging } } else { // TODO: Logging } return 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; }
int CALLBACK WinMain(_In_ HINSTANCE _HInstance, _In_ HINSTANCE _HPrevInstance, _In_ LPSTR _LpCmdLine, _In_ int _NCmdShow) { LARGE_INTEGER perfCountFrequencyResult; QueryPerformanceFrequency(&perfCountFrequencyResult); int64 perfCountFrequency = perfCountFrequencyResult.QuadPart; Win32LoadXInput(); WNDCLASS windowClass = {}; Win32ResizeDIBSection(&GlobalBackbuffer, 1280, 720); windowClass.style = CS_OWNDC|CS_HREDRAW|CS_VREDRAW; windowClass.lpfnWndProc = MainWindowCallback; windowClass.hInstance = _HInstance; //WindowClass.hIcon; //WindowClass.lpszMenuName; windowClass.lpszClassName = "HandmadeHeroWindowClass"; if (!RegisterClass(&windowClass)) { // TODO(jungyoun.la): Logging return 0; } HWND windowHandle = CreateWindowExA( 0, windowClass.lpszClassName, "Handmade Hero", WS_OVERLAPPEDWINDOW | WS_VISIBLE, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, 0, 0, _HInstance, 0); if (!windowHandle) { // TODO(jungyoun.la): Logging return 0; } HDC deviceContext = GetDC(windowHandle); int32 blueOffset = 0; int32 greenOffset = 0; win32_sound_output soundOutput = {}; soundOutput.SamplesPerSecond = 48000; soundOutput.ToneHz = 256; soundOutput.ToneVolume = 3000; soundOutput.WavePeriod = soundOutput.SamplesPerSecond / soundOutput.ToneHz; soundOutput.BytesPerSample = sizeof(int16) * 2; soundOutput.SecondaryBufferSize = soundOutput.SamplesPerSecond * soundOutput.BytesPerSample; soundOutput.LatencySampleCount = soundOutput.SamplesPerSecond / 15; Win32InitDSound(windowHandle, soundOutput.SamplesPerSecond, soundOutput.SecondaryBufferSize); Win32FillSoundBuffer(&soundOutput, 0, soundOutput.LatencySampleCount * soundOutput.BytesPerSample); GlobalSecondaryBuffer->Play(0, 0, DSBPLAY_LOOPING); GlobalRunning = true; // @See(jungyoun.la): https://msdn.microsoft.com/en-us/library/windows/desktop/dn553408(v=vs.85).aspx LARGE_INTEGER lastCounter; QueryPerformanceCounter(&lastCounter); uint64 lastCycleCount = __rdtsc(); while (GlobalRunning) { MSG message; while (PeekMessage(&message, 0, 0, 0, PM_REMOVE)) { if (message.message == WM_QUIT) { GlobalRunning = false; } TranslateMessage(&message); DispatchMessageA(&message); } // TODO(jungyoun.la): Should we poll this more frequently. for (DWORD controllerIndex = 0; controllerIndex < XUSER_MAX_COUNT; controllerIndex++) { XINPUT_STATE controllerState; ZeroMemory(&controllerState, sizeof(XINPUT_STATE)); if (XInputGetState(controllerIndex, &controllerState) == ERROR_SUCCESS) { // Controller is connected XINPUT_GAMEPAD* pad = &controllerState.Gamepad; bool up = (pad->wButtons & XINPUT_GAMEPAD_DPAD_UP); bool down = (pad->wButtons & XINPUT_GAMEPAD_DPAD_DOWN); bool left = (pad->wButtons & XINPUT_GAMEPAD_DPAD_LEFT); bool right = (pad->wButtons & XINPUT_GAMEPAD_DPAD_RIGHT); bool start = (pad->wButtons & XINPUT_GAMEPAD_START); bool back = (pad->wButtons & XINPUT_GAMEPAD_BACK); bool leftShoulder = (pad->wButtons & XINPUT_GAMEPAD_LEFT_SHOULDER); bool rightShoulder = (pad->wButtons & XINPUT_GAMEPAD_RIGHT_SHOULDER); bool aButton = (pad->wButtons & XINPUT_GAMEPAD_A); bool bButton = (pad->wButtons & XINPUT_GAMEPAD_B); bool xButton = (pad->wButtons & XINPUT_GAMEPAD_X); bool yButton = (pad->wButtons & XINPUT_GAMEPAD_Y); int16 stickX = pad->sThumbLX; int16 stickY = pad->sThumbLY; blueOffset += stickX >> 12; greenOffset -= stickY >> 12; } else { // Controller is not connected } }