Currently, I'm developing a GUI editor in C++ using DirectX, and I've created a couple of classes some people may find useful. Soon, I will be releasing the whole project, but at the moment, you may find these objects I've created useful. I'm not going to bother explaining it until I've completed the GUI editor, when I do finish it though, there will be an indepth description of all the methods and how to use the GUIEditer to compile GUIs and how to use the GUIReader library(which I will be creating) that you can use to read and display the GUIs created with the GUIEditor. Please note the below code isn't finished nor cleaned up. There are some parts were I was really lazzy and defined variabled that are constant over and over in the Render methods.
Form.h
[highlight=cpp]#pragma once
#include "stdafx.h"
#include <windows.h>
#include "d3d9.h"
#include "d3dx9.h"
#include "Button.h"
class Form {
private:
LPDIRECT3DSURFACE9 surface;
LPD3DXFONT d3dFont;
char caption[100];
int buttonCount;
bool visible;
D3DCOLOR bgrColor;
D3DCOLOR capColor;
RECT destRect;
RECT capBounds;
public:
Button* childButtons[100]; //You sure as hell shouldn't ever need more then 100 buttons..
Form(LPDIRECT3DDEVICE9 d3dDev, D3DCOLOR srcBgrColor, D3DCOLOR srcCapColor, RECT srcDestRect, char *srcCaption, bool vis);
void AddButton(Button *btn);
bool isVisible();
int Save(char* path);
void Render(LPDIRECT3DDEVICE9 d3dDev, LPDIRECT3DSURFACE9 destSurface);
void SetVisible(bool vis);
};[/highlight]
Form.cpp
[highlight=cpp]
#include "stdafx.h"
#include "Form.h"
Form::Form(LPDIRECT3DDEVICE9 d3dDev, D3DCOLOR srcBgrColor, D3DCOLOR srcCapColor, RECT srcDestRect, char* srcCaption, bool vis)
{
strcpy(caption, srcCaption);
visible = vis;
buttonCount = 0;
destRect = RECT(srcDestRect);
capBounds = RECT(destRect);
capBounds.left = 0;
capBounds.top = 0;
capBounds.bottom = 20;
//REWRITE BELOW METHOD
D3DXCreateFont( d3dDev, 12, 0, FW_BOLD, 0, FALSE, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, DEFAULT_QUALITY,
DEFAULT_PITCH | FF_DONTCARE, TEXT("Arial"), &d3dFont );
d3dDev->CreateOffscreenPlainSurface(srcDestRect.right - srcDestRect.left, srcDestRect.bottom - srcDestRect.top,
D3DFMT_X8R8G8B8, D3DPOOL_DEFAULT, &surface, NULL);
bgrColor = srcBgrColor;
capColor = srcCapColor;
}
void Form::AddButton(Button *btn) {
childButtons[buttonCount] = btn;
buttonCount++;
}
bool Form::isVisible()
{
return visible;
}
int Form::Save(char* path) {
//This is gunna be a hell of a method :X
return 1;
}
void Form::Render(LPDIRECT3DDEVICE9 d3dDev, LPDIRECT3DSURFACE9 d3dSurface) {
if(!visible)
return;
RECT capRendLoc = RECT(capBounds);
capRendLoc.left += destRect.left + 20;
capRendLoc.top += destRect.top + 3;
capRendLoc.right = capRendLoc.left + (10 * strlen(caption));
capRendLoc.bottom = capRendLoc.top + 10;
d3dDev->ColorFill(surface, NULL, bgrColor);
d3dDev->ColorFill(surface, &capBounds, capColor);
for(int i = 0; i < buttonCount; i++)
childButtons[i]->Render(d3dDev, surface, destRect);
d3dDev->StretchRect(surface, NULL, d3dSurface, &destRect, D3DTEXF_NONE);
d3dFont->DrawTextA(NULL, caption, -1, &capRendLoc, 0, D3DCOLOR_XRGB(0,0,0));
}
void Form::SetVisible(bool vis) {
visible = vis;
}
[/highlight]
Button.h
[highlight=cpp]
#pragma once
#include "stdafx.h"
#include "d3d9.h"
#include "d3dx9.h"
#include "windows.h"
class Button {
private:
void (*methodToExecute)();
char caption[100]; //You shouldn't have a captions larger then 100 characters, but if you do

Feel free to change this.
bool visible;
RECT destRect;
LPD3DXFONT d3dFont;
LPDIRECT3DSURFACE9 surface;
public:
Button(LPDIRECT3DDEVICE9 d3dDev, void *srcMethodToExecute, char* caption, int x, int y, bool vis);
void Button::SetCaption(char* srcCaption);
bool isVisible();
void SetVisible(bool vis);
void SetRect(RECT &newRect);
void Render(LPDIRECT3DDEVICE9 d3dDev, LPDIRECT3DSURFACE9 d3dSurface, RECT frmRect);
};
[/highlight]
button.cpp
[highlight=cpp]
#include "stdafx.h"
#include "Button.h"
#include "rectTools.h"
#include <windows.h>
#define _CRT_SECURE_NO_WARNINGS
Button::Button(LPDIRECT3DDEVICE9 d3dDev, void *srcMethodToExecute, char* srcCaption, int x, int y, bool vis) {
strncpy(caption, srcCaption, sizeof(caption));
this->visible = vis;
destRect.top = y;
destRect.left = x;
destRect.right = destRect.left + strlen(caption) * 10;
destRect.bottom = destRect.top + 20;
D3DXCreateFont( d3dDev, 12, 0, FW_BOLD, 0, FALSE, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, DEFAULT_QUALITY,
DEFAULT_PITCH | FF_DONTCARE, TEXT("Arial"), &d3dFont );
HRESULT res = d3dDev->CreateOffscreenPlainSurface(destRect.right, destRect.bottom, D3DFMT_X8R8G8B8,
D3DPOOL_DEFAULT, &surface, NULL);
methodToExecute = (void (__cdecl *)())srcMethodToExecute;
}
void Button::SetRect(RECT &newRect) {
destRect = RECT(newRect);
}
void Button::SetVisible(bool vis) {
visible = vis;
}
void Button::Render(LPDIRECT3DDEVICE9 d3dDev, LPDIRECT3DSURFACE9 d3dSurface, RECT frmRect) {
if(!isVisible())
return;
POINT mPos;
D3DCOLOR btnColor = D3DCOLOR_XRGB(200,200,200);
GetCursorPos(&mPos);
RECT posTestRect(destRect);
posTestRect.left += frmRect.left;
posTestRect.top += frmRect.top;
posTestRect.right += frmRect.left;
posTestRect.bottom += frmRect.top;
if(isInRect(mPos, posTestRect)) {
btnColor = D3DCOLOR_XRGB(100,100,200);
if(GetAsyncKeyState(VK_LBUTTON) & 0x8000)
methodToExecute();
}
RECT btnRect = RECT(destRect);
btnRect.left += 2;
btnRect.right -= 2;
btnRect.top += 2;
btnRect.bottom -= 2;
d3dDev->ColorFill(d3dSurface, &destRect, D3DCOLOR_XRGB(0,0,0));
d3dDev->ColorFill(d3dSurface, &btnRect, btnColor);
}
bool Button::isVisible(){
return visible;
}
void Button::SetCaption(char* srcCaption) {
strncpy(caption, srcCaption, sizeof(caption));
}
[/highlight]