Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define WINVER 0x0501
- #define _WIN32_WINNT 0x0501
- #include <windows.h>
- #include <d3d9.h>
- //#include <stdio.h>
- #define WIDTH 640
- #define HEIGHT 480
- int flash = 0;
- int stop = 0;
- LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
- {
- switch(message) {
- case WM_CLOSE:
- DestroyWindow(hWnd);
- stop = 1;
- break;
- case WM_DESTROY:
- PostQuitMessage(0);
- stop = 1;
- break;
- case WM_INPUT: {
- UINT dwSize;
- GetRawInputData((HRAWINPUT)lParam, RID_INPUT, NULL, &dwSize, sizeof(RAWINPUTHEADER));
- LPBYTE lpb = new BYTE[dwSize];
- if (lpb == NULL) return 0;
- GetRawInputData((HRAWINPUT)lParam, RID_INPUT, lpb, &dwSize, sizeof(RAWINPUTHEADER));
- RAWINPUT* raw = (RAWINPUT*)lpb;
- if (raw->header.dwType == RIM_TYPEMOUSE) {
- LONG x = raw->data.mouse.lLastX;
- LONG y = raw->data.mouse.lLastY;
- #define THRESH (2)
- if (y < -THRESH)
- flash = 1;
- else if (y > THRESH)
- flash = 0;
- }
- delete[] lpb;
- }
- //fall through
- default:
- return DefWindowProc(hWnd, message, wParam, lParam);
- }
- return 0;
- }
- int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
- {
- HWND hWnd;
- WNDCLASSEX wc;
- MSG msg;
- ZeroMemory(&wc, sizeof(WNDCLASSEX));
- wc.cbSize = sizeof(WNDCLASSEX);
- wc.style = CS_HREDRAW | CS_VREDRAW;
- wc.lpfnWndProc = WindowProc;
- wc.hInstance = hInstance;
- wc.hCursor = LoadCursor(NULL, IDC_ARROW);
- wc.lpszClassName = "somewindowclass";
- RegisterClassEx(&wc);
- hWnd = CreateWindowEx(0, "somewindowclass", "test",
- WS_EX_TOPMOST | WS_POPUP,
- 0, 0, WIDTH, HEIGHT,
- NULL, NULL, hInstance, NULL);
- ShowWindow(hWnd, nCmdShow);
- LPDIRECT3D9 d3d;
- LPDIRECT3DDEVICE9 d3ddev;
- d3d = Direct3DCreate9(D3D_SDK_VERSION);
- D3DPRESENT_PARAMETERS d3dpp;
- ZeroMemory(&d3dpp, sizeof(d3dpp));
- d3dpp.Windowed = FALSE;
- d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
- d3dpp.hDeviceWindow = hWnd;
- d3dpp.BackBufferFormat = D3DFMT_X8R8G8B8;
- d3dpp.BackBufferWidth = WIDTH;
- d3dpp.BackBufferHeight = HEIGHT;
- d3d->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd,
- D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &d3ddev);
- RAWINPUTDEVICE Rid[1];
- Rid[0].usUsagePage = 0x01;
- Rid[0].usUsage = 0x02;
- Rid[0].dwFlags = RIDEV_NOLEGACY;
- Rid[0].hwndTarget = 0;
- RegisterRawInputDevices(Rid, 1, sizeof(Rid[0]));
- while(!stop) {
- while(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) {
- TranslateMessage(&msg);
- DispatchMessage(&msg);
- }
- if(msg.message == WM_QUIT)
- stop = 1;
- d3ddev->Clear(0, NULL, D3DCLEAR_TARGET, flash ? D3DCOLOR_XRGB(255,255,255) : D3DCOLOR_XRGB(0, 0, 0), 1.0f, 0);
- //flash = 0;
- d3ddev->Present(NULL, NULL, NULL, NULL);
- }
- d3ddev->Release();
- d3d->Release();
- return msg.wParam;
- }
Advertisement
Add Comment
Please, Sign In to add comment