SHARE
TWEET

Overlay

a guest Oct 10th, 2017 111 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #define _CRT_SECURE_NO_WARNINGS
  2.  
  3. #include <Windows.h>
  4. #include <iostream>
  5. #include <d3dx9.h>
  6. #include <d3d9.h>
  7.  
  8. #pragma comment(lib, "d3dx9")
  9. #pragma comment(lib, "d3d9")
  10.  
  11. #include <dwmapi.h>
  12. #pragma comment(lib, "dwmapi.lib")
  13.  
  14. LPDIRECT3DDEVICE9 pDevice;
  15. LPD3DXFONT pFont;
  16.  
  17. LPD3DXSPRITE pSprite;
  18. LPD3DXLINE line;
  19.  
  20. int ScreenW = 0, ScreenH = 0;
  21. MARGINS margin = { 0, 0, ScreenW, ScreenH };
  22.  
  23. LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
  24.  
  25. void Render()
  26. {
  27.     pDevice->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_ARGB(0, 0, 0, 0), 1.0f, 0);
  28.     pDevice->BeginScene();
  29.  
  30.     int x = ScreenW / 2, y = ScreenH / 2;
  31.     RECT FontRect = { x, y, x + 500, y + 50 };
  32.     pFont->DrawTextA(NULL, "TEST", -1, &FontRect, DT_LEFT | DT_WORDBREAK, D3DCOLOR_ARGB(255, 255, 255, 255));
  33.  
  34.     pDevice->EndScene();
  35.     pDevice->Present(NULL, NULL, NULL, NULL);
  36. }
  37.  
  38. LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
  39. {
  40.     switch (message)
  41.     {
  42.     case WM_PAINT:
  43.         Render();
  44.         break;
  45.     case WM_CREATE:
  46.         DwmExtendFrameIntoClientArea(hWnd, &margin);
  47.         break;
  48.  
  49.     case WM_DESTROY:
  50.         PostQuitMessage(0);
  51.         return 0;
  52.  
  53.     default:
  54.         return DefWindowProc(hWnd, message, wParam, lParam);
  55.     }
  56.  
  57.     return DefWindowProc(hWnd, message, wParam, lParam);
  58. }
  59.  
  60. HWND twnd = 0;
  61.  
  62. int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE prevInstance, LPSTR lpCmdLine, int nShowCmd)
  63. {
  64.     //AllocConsole();
  65.     //freopen("CONIN$", "r", stdin);
  66.     //freopen("CONOUT$", "w", stdout);
  67.     //freopen("CONOUT$", "w", stderr);
  68.  
  69.     RECT rc;
  70.  
  71.     while (!twnd)
  72.         twnd = FindWindow(L"UnrealWindow", 0);
  73.  
  74.     if (twnd != NULL)
  75.     {
  76.         GetWindowRect(twnd, &rc);
  77.         ScreenW = rc.right - rc.left;
  78.         ScreenH = rc.bottom - rc.top;
  79.     } else {
  80.         MessageBoxA(NULL, "Not running", NULL, NULL);
  81.     }
  82.  
  83.     WNDCLASSEX wc;
  84.  
  85.     ZeroMemory(&wc, sizeof(WNDCLASSEX));
  86.  
  87.     wc.cbSize = sizeof(WNDCLASSEX);
  88.     wc.style = CS_HREDRAW | CS_VREDRAW;
  89.     wc.lpfnWndProc = WindowProc;
  90.     wc.hInstance = hInstance;
  91.     wc.hCursor = LoadCursor(NULL, IDC_ARROW);
  92.     wc.hbrBackground = (HBRUSH)RGB(0, 0, 0);
  93.     wc.lpszClassName = L"TEST";
  94.  
  95.     //Extras
  96.     //wc.cbClsExtra = NULL;
  97.     //wc.cbWndExtra = NULL;
  98.  
  99.     if (!RegisterClassEx(&wc)) printf("Failed to Register class");
  100.  
  101.     HWND hWnd = CreateWindowEx(WS_EX_LAYERED | WS_EX_TRANSPARENT,
  102.         L"TEST",
  103.         L"TEST",
  104.         WS_POPUP,
  105.         0, 0,
  106.         ScreenW, ScreenH,
  107.         NULL,
  108.         NULL,
  109.         hInstance,
  110.         NULL);
  111.  
  112.     if (!hWnd) printf("Failed to create window");
  113.  
  114.     SetLayeredWindowAttributes(hWnd, RGB(0, 0, 0), 0, ULW_COLORKEY);
  115.     SetLayeredWindowAttributes(hWnd, 0, 255, LWA_ALPHA);
  116.  
  117.     ShowWindow(hWnd, nShowCmd);
  118.  
  119.     LPDIRECT3D9 d3d = Direct3DCreate9(D3D_SDK_VERSION);
  120.  
  121.     if (d3d == nullptr)
  122.         exit(1);
  123.  
  124.     D3DPRESENT_PARAMETERS d3dpp;
  125.  
  126.     ZeroMemory(&d3dpp, sizeof(d3dpp));
  127.     d3dpp.Windowed = TRUE;
  128.     d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
  129.     d3dpp.hDeviceWindow = hWnd;    // set the window to be used by Direct3D
  130.     d3dpp.BackBufferFormat = D3DFMT_A8R8G8B8; //D3DFMT_X8R8G8B8; // set the back buffer format to 32-bit
  131.     d3dpp.BackBufferWidth = ScreenW;    // set the width of the buffer
  132.     d3dpp.BackBufferHeight = ScreenH;    // set the height of the buffer
  133.  
  134.     d3dpp.EnableAutoDepthStencil = TRUE;
  135.     d3dpp.AutoDepthStencilFormat = D3DFMT_D16;
  136.  
  137.     //D3DPRESENT_INTERVAL_ONE With VSync
  138. //  d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE;
  139.  
  140.     //New
  141.     //d3dpp.MultiSampleQuality = D3DMULTISAMPLE_NONE;
  142.  
  143.     d3d->CreateDevice(D3DADAPTER_DEFAULT,
  144.         D3DDEVTYPE_HAL,
  145.         hWnd,
  146.         D3DCREATE_SOFTWARE_VERTEXPROCESSING,
  147.         &d3dpp,
  148.         &pDevice);
  149.  
  150.     if (pDevice == nullptr)
  151.         exit(1);
  152.  
  153.  
  154.     D3DXCreateFont(pDevice, 20, 0, FW_NORMAL, 0, FALSE, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_SWISS, L"Tahoma", &pFont);
  155.  
  156.     D3DXCreateSprite(pDevice, &pSprite);
  157.     D3DXCreateLine(pDevice, &line);
  158.  
  159.     //CreateThread(0, 0, (LPTHREAD_START_ROUTINE)RenderAndUpdateThread, 0, 0, 0);
  160.  
  161.     MSG msg;
  162.     ZeroMemory(&msg, sizeof(msg));
  163.     while (msg.message != WM_QUIT)
  164.     {
  165.         if (PeekMessage(&msg, NULL, 0U, 0U, PM_REMOVE))
  166.         {
  167.             TranslateMessage(&msg);
  168.             DispatchMessage(&msg);
  169.         }
  170.  
  171.         /*HWND hwnd2 = GetForegroundWindow();
  172.         HWND hwnd3 = GetWindow(hwnd2, GW_HWNDPREV);
  173.         SetWindowPos(hWnd, hwnd3, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
  174.         */
  175.  
  176.         HWND hwnd2 = GetForegroundWindow();
  177.         HWND hwnd3 = GetWindow(hwnd2, GW_HWNDPREV);
  178.         SetWindowPos(hWnd, hwnd3, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
  179.  
  180.         Render();
  181.  
  182.         Sleep(5); // optimization
  183.     }
  184. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top