Code:
#include "main.h"
#include <d3d9.h>
#include <d3dx9.h>
#pragma comment(lib,"d3d9.lib")
#pragma comment(lib,"d3dx9.lib")
#include <windows.h>
#pragma once
class m_CItem;
class m_CMenu;
class m_CItem
{
public:
char* itemName;
bool enabled;
private:
};
class ImportFont
{
protected:
LPD3DXFONT m_pFont;
public:
ImportFont::ImportFont(LPDIRECT3DDEVICE9 pDevice,int Size,LPWSTR pFacename)
{
D3DXCreateFontW(pDevice,Size,0,FW_BOLD,1,0,DEFAULT_CHARSET,OUT_DEFAULT_PRECIS,ANTIALIASED_QUALITY,DEFAULT_PITCH|FF_DONTCARE,pFacename,&m_pFont);
}
ImportFont::~ImportFont()
{
if(m_pFont)
{
m_pFont->Release();
m_pFont = NULL;
}
}
VOID ImportFont::LostDevice()
{
if(m_pFont)
m_pFont->OnLostDevice();
}
VOID ImportFont::ResetDevice()
{
if(m_pFont)
m_pFont->OnResetDevice();
}
VOID ImportFont::Draw(INT x,INT y,LPCWSTR pString,D3DCOLOR Color)
{
if(m_pFont)
{
RECT Rect = { x, y, 0, 0 };
m_pFont->DrawTextW(NULL,pString,-1,&Rect,DT_NOCLIP,Color);
}
}
};
class m_CMenu
{
public:
void getInput()
{
if (GetAsyncKeyState(VK_INSERT)&1)
Show = !Show;
if (GetAsyncKeyState(VK_DOWN)&1)
{
if (CurrentChoice < GetArrLength(MenuItems)-1)
CurrentChoice++;
}
if (GetAsyncKeyState(VK_UP)&1)
{
if (CurrentChoice > 0)
CurrentChoice--;
}
if (GetAsyncKeyState(VK_RIGHT)&1)
{
MenuItems[CurrentChoice]->enabled = true;
}
if (GetAsyncKeyState(VK_LEFT)&1)
{
MenuItems[CurrentChoice]->enabled = false;
}
}
~m_CMenu()
{
if (pFont)
{
delete pFont;
pFont = 0;
}
}
m_CMenu(LPDIRECT3DDEVICE9& aDevice, int xx, int yy)
{
height = GetArrLength(MenuItems) * 20 + 10;
width = 100;
pDevice = aDevice;
for (int i = 0; i < GetArrLength(MenuItems); i++)
MenuItems[i] = new m_CItem();
//TODO: add labels here
MenuItems[0]->itemName = "Hello";
MenuItems[1]->itemName = "Hello";
MenuItems[2]->itemName = "Hello";
MenuItems[3]->itemName = "Hello";
MenuItems[4]->itemName = "Hello";
MenuItems[5]->itemName = "Hello";
MenuItems[6]->itemName = "Hello";
MenuItems[7]->itemName = "Hello";
MenuItems[8]->itemName = "Hello";
MenuItems[9]->itemName = "Hello";
//MenuItems[10]->itemName = "Hello";
Show = false;
pFont = new ImportFont(pDevice,14,L"tahoma");
x = xx;
y = yy;
CurrentChoice = 0;
//wchar_t istr[32];
//_itow_s(height, istr, 10);
//MessageBox(0,istr,0,0);
}
int x, y, width, height;
void DrawMenu()
{
if (Show)
{
static D3DRECT rect = {x,y,x+width,y+height};
//pFont->Draw(60,60,L"hello",D3DCOLOR_ARGB(255,255,255,255));
pDevice->Clear(0,&rect,0,D3DCOLOR_ARGB(255,0,0,0),0,0);
pFont->Draw(x+5,y+5,L"Test Hook",D3DCOLOR_ARGB(255,255,255,255));
int location = 20;
for (int i = 0; i < GetArrLength(MenuItems);i++)
{
location += 20;
if (CurrentChoice == i)
{
int len = strlen(MenuItems[i]->itemName)+1;
wchar_t *wText = new wchar_t[len];
memset(wText,0,len);
::MultiByteToWideChar( CP_ACP, NULL,MenuItems[i]->itemName, -1, wText,len );
pFont->Draw(x+5,y+location,wText,D3DCOLOR_ARGB(255,255,255,0));
}
else
{
int len = strlen(MenuItems[i]->itemName)+1;
wchar_t *wText = new wchar_t[len];
memset(wText,0,len);
::MultiByteToWideChar( CP_ACP, NULL,MenuItems[i]->itemName, -1, wText,len );
pFont->Draw(x+5,y+location,wText,D3DCOLOR_ARGB(255,255,255,255));
}
if (MenuItems[i]->enabled)
pFont->Draw(x+width-20,y+location,L"Enabled",D3DCOLOR_ARGB(255,255,255,0));
else
pFont->Draw(x+width-20,y+location,L"Disabled",D3DCOLOR_ARGB(255,255,255,0));
}
}
}
void Set(int Number, char* Name)
{
MenuItems[Number]->itemName = Name;
}
template<typename T, int size>
int GetArrLength(T(&)[size]){return size;}
void Hacks()
{
//todo: add hacks here
}
m_CItem* MenuItems[10];
LPDIRECT3DDEVICE9 pDevice;
ImportFont* pFont;
int CurrentChoice;
bool Show;
};
Yes, It has unneeded functions because i was testing using them. They just make it easier to add things to the menu dynamically.