Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _CRT_SECURE_NO_WARNINGS
- #include <Windows.h>
- #include <iostream>
- #include <d3dx9.h>
- #include <d3d9.h>
- #pragma comment(lib, "d3dx9")
- #pragma comment(lib, "d3d9")
- #include <dwmapi.h>
- #pragma comment(lib, "dwmapi.lib")
- LPDIRECT3DDEVICE9 pDevice;
- LPD3DXFONT pFont;
- LPD3DXSPRITE pSprite;
- LPD3DXLINE line;
- int ScreenW = 0, ScreenH = 0;
- MARGINS margin = { 0, 0, ScreenW, ScreenH };
- LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
- void Render()
- {
- pDevice->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_ARGB(0, 0, 0, 0), 1.0f, 0);
- pDevice->BeginScene();
- int x = ScreenW / 2, y = ScreenH / 2;
- RECT FontRect = { x, y, x + 500, y + 50 };
- pFont->DrawTextA(NULL, "TEST", -1, &FontRect, DT_LEFT | DT_WORDBREAK, D3DCOLOR_ARGB(255, 255, 255, 255));
- pDevice->EndScene();
- pDevice->Present(NULL, NULL, NULL, NULL);
- }
- LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
- {
- switch (message)
- {
- case WM_PAINT:
- Render();
- break;
- case WM_CREATE:
- DwmExtendFrameIntoClientArea(hWnd, &margin);
- break;
- case WM_DESTROY:
- PostQuitMessage(0);
- return 0;
- default:
- return DefWindowProc(hWnd, message, wParam, lParam);
- }
- return DefWindowProc(hWnd, message, wParam, lParam);
- }
- HWND twnd = 0;
- int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE prevInstance, LPSTR lpCmdLine, int nShowCmd)
- {
- //AllocConsole();
- //freopen("CONIN$", "r", stdin);
- //freopen("CONOUT$", "w", stdout);
- //freopen("CONOUT$", "w", stderr);
- RECT rc;
- while (!twnd)
- twnd = FindWindow(L"UnrealWindow", 0);
- if (twnd != NULL)
- {
- GetWindowRect(twnd, &rc);
- ScreenW = rc.right - rc.left;
- ScreenH = rc.bottom - rc.top;
- } else {
- MessageBoxA(NULL, "Not running", NULL, NULL);
- }
- WNDCLASSEX wc;
- 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.hbrBackground = (HBRUSH)RGB(0, 0, 0);
- wc.lpszClassName = L"TEST";
- //Extras
- //wc.cbClsExtra = NULL;
- //wc.cbWndExtra = NULL;
- if (!RegisterClassEx(&wc)) printf("Failed to Register class");
- HWND hWnd = CreateWindowEx(WS_EX_LAYERED | WS_EX_TRANSPARENT,
- L"TEST",
- L"TEST",
- WS_POPUP,
- 0, 0,
- ScreenW, ScreenH,
- NULL,
- NULL,
- hInstance,
- NULL);
- if (!hWnd) printf("Failed to create window");
- SetLayeredWindowAttributes(hWnd, RGB(0, 0, 0), 0, ULW_COLORKEY);
- SetLayeredWindowAttributes(hWnd, 0, 255, LWA_ALPHA);
- ShowWindow(hWnd, nShowCmd);
- LPDIRECT3D9 d3d = Direct3DCreate9(D3D_SDK_VERSION);
- if (d3d == nullptr)
- exit(1);
- D3DPRESENT_PARAMETERS d3dpp;
- ZeroMemory(&d3dpp, sizeof(d3dpp));
- d3dpp.Windowed = TRUE;
- d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
- d3dpp.hDeviceWindow = hWnd; // set the window to be used by Direct3D
- d3dpp.BackBufferFormat = D3DFMT_A8R8G8B8; //D3DFMT_X8R8G8B8; // set the back buffer format to 32-bit
- d3dpp.BackBufferWidth = ScreenW; // set the width of the buffer
- d3dpp.BackBufferHeight = ScreenH; // set the height of the buffer
- d3dpp.EnableAutoDepthStencil = TRUE;
- d3dpp.AutoDepthStencilFormat = D3DFMT_D16;
- //D3DPRESENT_INTERVAL_ONE With VSync
- // d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE;
- //New
- //d3dpp.MultiSampleQuality = D3DMULTISAMPLE_NONE;
- d3d->CreateDevice(D3DADAPTER_DEFAULT,
- D3DDEVTYPE_HAL,
- hWnd,
- D3DCREATE_SOFTWARE_VERTEXPROCESSING,
- &d3dpp,
- &pDevice);
- if (pDevice == nullptr)
- exit(1);
- D3DXCreateFont(pDevice, 20, 0, FW_NORMAL, 0, FALSE, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_SWISS, L"Tahoma", &pFont);
- D3DXCreateSprite(pDevice, &pSprite);
- D3DXCreateLine(pDevice, &line);
- //CreateThread(0, 0, (LPTHREAD_START_ROUTINE)RenderAndUpdateThread, 0, 0, 0);
- MSG msg;
- ZeroMemory(&msg, sizeof(msg));
- while (msg.message != WM_QUIT)
- {
- if (PeekMessage(&msg, NULL, 0U, 0U, PM_REMOVE))
- {
- TranslateMessage(&msg);
- DispatchMessage(&msg);
- }
- /*HWND hwnd2 = GetForegroundWindow();
- HWND hwnd3 = GetWindow(hwnd2, GW_HWNDPREV);
- SetWindowPos(hWnd, hwnd3, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
- */
- HWND hwnd2 = GetForegroundWindow();
- HWND hwnd3 = GetWindow(hwnd2, GW_HWNDPREV);
- SetWindowPos(hWnd, hwnd3, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
- Render();
- Sleep(5); // optimization
- }
- }
Add Comment
Please, Sign In to add comment