C++ DirectX, What am i doing wrong
Code:
#include <Windows.h>
#include <d3dx9.h>
#include <d3d9.h>
#include <dwmapi.h>
#include <TlHelp32.h>
#include <DXGI.h>
#include <D3DCommon.h>
#include <DWrite.h>
#include <stdio.h>
#define CALLBACK __stdcall
#define WINAPI __stdcall
#define WINAPIV __cdecl
#define APIENTRY WINAPI
#define APIPRIVATE __stdcall
#define PASCAL __stdcall
#pragma comment(lib, "d3dx9.lib")
#pragma comment(lib, "d3d9.lib")
#pragma comment(lib, "dwmapi.lib")
void RenderIt(){
}
int Width = 800;
int Height = 600;
HWND hWnd;
MSG Message;
HWND TargetWnd;
RECT TargetRect;
RECT CheckWnd;
void DrawLine(LPDIRECT3DDEVICE9 Device_Interface,int bx,int by,int bw,D3DCOLOR COLOR)
{
D3DRECT rec;
rec.x1 = bx-bw;//makes line longer/shorter going lef
rec.y1 = by;//base y
rec.x2 = bx+bw;//makes line longer/shorter going right
rec.y2 = by+1;//makes line one pixel tall
Device_Interface->Clear(1,&rec,D3DCLEAR_TARGET,COLOR,0,0);
}
const MARGINS Margin =
{
0,
0,
Width,
Height
};
LRESULT CALLBACK Proc(HWND hWndx, UINT Message, WPARAM wParam, LPARAM lParam)
{
switch(Message)
{
case WM_PAINT:
DwmExtendFrameIntoClientArea(hWndx, &Margin);
case WM_DESTROY:
PostQuitMessage(0);
return 0;
default:
return DefWindowProc( hWndx, Message, wParam, lParam);
}
return 0;
}
const wchar_t *GetWC(const char *c)
{
const size_t cSize = strlen(c)+1;
wchar_t* wc = new wchar_t[cSize];
mbstowcs (wc, c, cSize);
return wc;
}
DWORD GetModuleBaseAddress(char* DLLName, DWORD iProcId)
{
HANDLE hSnap;
MODULEENTRY32 xModule;
hSnap = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, iProcId);
xModule.dwSize = sizeof(MODULEENTRY32);
if (Module32First(hSnap, &xModule))
{
while (Module32Next(hSnap, &xModule))
{
if (wcscmp(xModule.szModule, GetWC(DLLName)) == 0)
{
CloseHandle(hSnap);
return (DWORD)xModule.modBaseAddr;
}
}
}
CloseHandle(hSnap);
return 0;
}
void DrawString(int x, int y, D3DCOLOR color, LPD3DXFONT g_pFont, const char *fmt) //function to draw text won't go in detail in this tutorial
{
RECT FontPos = { x, y, x + 120, y + 16 };
char buf[1024] = {'\0'};
va_list va_alist;
va_start(va_alist, fmt);
vsprintf_s(buf, fmt, va_alist);
va_end(va_alist);
g_pFont->DrawTextA(NULL, buf, -1, &FontPos, DT_NOCLIP, color);
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hInstancePrev, LPSTR CmdLine, int CmdShow)
{
LPWSTR ptr = (L"Overlay");
WNDCLASSEX OverlayWnd;
OverlayWnd.cbClsExtra = 0;
OverlayWnd.cbSize = sizeof(WNDCLASSEX);
OverlayWnd.cbWndExtra = 0;
OverlayWnd.hbrBackground = (HBRUSH)CreateSolidBrush(RGB(0,0,0));
OverlayWnd.hCursor = LoadCursor(0, IDC_ARROW);
OverlayWnd.hIcon = LoadIcon(0, IDI_APPLICATION);
OverlayWnd.hIconSm = LoadIcon(0, IDI_APPLICATION);
OverlayWnd.hInstance = hInstance;
OverlayWnd.lpfnWndProc = Proc;
OverlayWnd.lpszClassName = ptr;
OverlayWnd.lpszMenuName = ptr;
OverlayWnd.style = CS_HREDRAW | CS_VREDRAW;
if(!RegisterClassEx(&OverlayWnd))
exit(1);
HWND hwidd = hWnd;
IDirect3D9* g_pD3D = Direct3DCreate9(D3D_SDK_VERSION);
LPDIRECT3DDEVICE9 pDevice = NULL;
D3DPRESENT_PARAMETERS d3dpp;
ZeroMemory(&d3dpp,sizeof(d3dpp));
d3dpp.Windowed = true; //use our global windowed variable to tell if the program is windowed or not
d3dpp.hDeviceWindow = hwidd; //give the window handle of the window we created above
d3dpp.BackBufferCount = 1; //set it to only use 1 backbuffer
d3dpp.BackBufferWidth = Width; //set the buffer to our window width
d3dpp.BackBufferHeight = Height; //set the buffer to out window height
d3dpp.BackBufferFormat = D3DFMT_X8R8G8B8; //the backbuffer format
d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD; //SwapEffect
d3dpp.Windowed = TRUE;
d3dpp.SwapEffect = D3DSWAPEFFECT_COPY;
g_pD3D->CreateDevice(D3DADAPTER_DEFAULT,D3DDEVTYPE_HAL,hwidd,D3DCREATE_SOFTWARE_VERTEXPROCESSING,&d3dpp,&pDevice);
for(;;)
{
if(PeekMessage(&Message, hWnd, 0, 0, PM_REMOVE))
{
TranslateMessage(&Message);
DispatchMessage(&Message);
}
TargetWnd = FindWindow(0, L"Counter-Strike Source");
GetWindowRect( TargetWnd, &TargetRect);
MoveWindow( hWnd, TargetRect.left, TargetRect.top, TargetRect.right - TargetRect.left, TargetRect.bottom - TargetRect.top, true);
if(!TargetWnd)
{
exit(0);
}
else{
DWORD pid;
GetWindowThreadProcessId(TargetWnd, &pid);
DWORD EngineModule, ClientModule;
EngineModule = GetModuleBaseAddress("engine.dll", pid);
ClientModule = GetModuleBaseAddress("client.dll", pid);
pDevice->BeginScene();
LPD3DXFONT font;
D3DXCreateFont( pDevice, 30, 0, FW_NORMAL, 0, FALSE, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, ANTIALIASED_QUALITY, DEFAULT_PITCH | FF_DONTCARE, TEXT("Arial"), &font );
DrawString(100, 100,D3DCOLOR_ARGB(100, 100, 100, 100),font,"ANAAAA");
pDevice->EndScene();
}
}
return 0;
}
Nothing happens

