OldSchoolHack GUI
Direct3D9 Beispielprojekt
#define WIN32_LEAN_AND_MEAN
#define NOMINMAX
#include <windows.h>
#include <Shellapi.h>
#include <d3dx9.h>
#undef MessageBox
#include <iostream>
#include <sstream>
#include <memory>
#pragma comment(lib, "d3d9.lib")
#pragma comment(lib, "d3dx9.lib")
//---------------------------------------------------------------------------
#include "OSHGui.hpp"
#include "Drawing\Direct3D9\RendererDX9.hpp"
#include "Input\Windows.hpp"
//---------------------------------------------------------------------------
using namespace OSHGui;
//---------------------------------------------------------------------------
LPDIRECT3D9 pD3D = nullptr;
LPDIRECT3DDEVICE9 pDevice = nullptr;
D3DPRESENT_PARAMETERS pp;
Input::Windows input;
class MainForm : public Form
{
private:
LinkLabel *linkLabel;
void InitializeComponent()
{
this->SetText("OldSchoolHack GUI by KN4CK3R");
this->SetSize(Drawing::Size(218, 289));
linkLabel = new LinkLabel();
linkLabel->SetName("linkLabel");
linkLabel->SetLocation(Drawing::Point(3, 9));
linkLabel->SetText("visit www.oldschoolhack.de");
linkLabel->GetClickEvent() += ClickEventHandler(std::bind(&MainForm::linkLabel_Click, this, std::placeholders::_1));
this->AddControl(linkLabel);
}
public:
MainForm() : Form()
{
InitializeComponent();
}
void linkLabel_Click(Control *control)
{
ShellExecute(0, "open", "www.oldschoolhack.de", NULL, NULL, SW_SHOWNORMAL);
}
};
//---------------------------------------------------------------------------
HRESULT D3DInit(HWND hwnd)
{
srand(GetTickCount());
if (!(pD3D = Direct3DCreate9(D3D_SDK_VERSION)))
{
return E_FAIL;
}
RECT ClientRect;
GetClientRect(hwnd, &ClientRect);
ZeroMemory(&pp, sizeof(pp));
pp.SwapEffect = D3DSWAPEFFECT_DISCARD;
pp.BackBufferFormat = D3DFMT_X8R8G8B8;
pp.FullScreen_RefreshRateInHz = D3DPRESENT_RATE_DEFAULT;
pp.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE;
pp.Windowed = TRUE;
pp.BackBufferWidth = ClientRect.right;
pp.BackBufferHeight = ClientRect.bottom;
if (FAILED(pD3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hwnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &pp, &pDevice)))
{
return E_FAIL;
}
::ShowCursor(false);
D3DXMATRIX Projection;
D3DXMatrixPerspectiveFovLH(&Projection, D3DXToRadian(45.0f), 584.0f / 562.0f, 1.0f, 100.0f);
pDevice->SetTransform(D3DTS_PROJECTION, &Projection);
Application::Instance()->Create(new Drawing::RendererDX9(pDevice)); //create Application
Application::Instance()->Run(std::shared_ptr<Form>(new MainForm())); //set our mainform
Application::Instance()->Enable(); //enable GUI
return S_OK;
}
//---------------------------------------------------------------------------
void D3DRender()
{
if(!pDevice)
{
return;
}
pDevice->Clear(0, 0, D3DCLEAR_TARGET, 0xFF123456, 1.0f, 0);
pDevice->BeginScene();
Application::Instance()->GetRenderer()->Begin(); //begin rendering
Application::Instance()->GetRenderer()->SetRenderRectangle(Drawing::Rectangle(0, 0, 700, 400)); //set the rendering size
//render stuff
Application::Instance()->Render(); //render gui
Application::Instance()->GetRenderer()->End(); //end rendering
pDevice->EndScene();
pDevice->Present(0,0,0,0);
}
//---------------------------------------------------------------------------
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
WNDCLASS wc;
ZeroMemory(&wc, sizeof(wc));
wc.style = CS_CLASSDC;
wc.lpfnWndProc = DefWindowProc;
wc.hInstance = GetModuleHandle(0);
wc.lpszClassName = "OSHGui";
wc.hCursor = LoadCursor(0, IDC_ARROW);
RegisterClass(&wc);
HWND hwnd = CreateWindowA("OSHGui", "OSHGui", WS_OVERLAPPEDWINDOW, 100, 100, 700, 400, GetDesktopWindow(), 0, wc.hInstance, 0);
if (SUCCEEDED(D3DInit(hwnd)))
{
ShowWindow(hwnd, SW_SHOWDEFAULT );
UpdateWindow(hwnd);
MSG msg;
ZeroMemory(&msg, sizeof(msg));
while (true)
{
if (!IsWindowVisible(hwnd))
break;
if (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
{
input.ProcessMessage(&msg);
if (msg.message == WM_QUIT)
break;
TranslateMessage(&msg);
DispatchMessage(&msg);
}
else
{
D3DRender();
}
}
}
if(pDevice)
{
pDevice->Release();
}
if(pD3D)
{
pD3D->Release();
}
UnregisterClass("OSHGui", wc.hInstance);
return 0;
}