I thought I should post it here, you may find it useful.

Header
[php]
#pragma once
#include "d3d9.h"
#include "d3dx9.h"
#include "stringTools.h"
#include "rectTools.h"
#include "GameEngineSettings.h"
#include <iostream>
#include <fstream>

struct Tile {
char sourceLoc[300];
char caption[100];
int flags;
};


class CTileManager {
unsigned int TilesLoaded;
LPDIRECT3DTEXTURE9 texture;
LPD3DXSPRITE hSpriteHandler;
LPD3DXFONT d3dFont;
public:
int numberOfTiles;
int tileWidth, tileHeight;
char sourceSpdf[300];
D3DXIMAGE_INFO textureInfo;
Tile* tiles;
CTileManager();
int LoadTiles(LPD3DXSPRITE hSpriteHandler, char* spdfFilePath);
bool Render(int tile, int x, int y, bool selectableObject, bool centerTopLeft, bool fullScreen = false, int opacity = -1.0f);
};
[/php]

Source
[php]/*
* PUT DOCK HERE
*
*
*
*/
#include "stdafx.h"
#include "CTileManager.h"
#define _CRT_SECURE_NO_WARNINGS

CTileManager::CTileManager() {
}

int CTileManager::LoadTiles(LPD3DXSPRITE pSprite, char* spdfFilePath) {
using namespace std;
char buffer[300];
strcpy(sourceSpdf, spdfFilePath);
GAME_ROOTDIR(buffer, 300);
strcat(buffer, sourceSpdf);


//int vTileNum, hTileNum; //currently Unused
LPDIRECT3DDEVICE9 d3dDev;
hSpriteHandler = pSprite;
hSpriteHandler->GetDevice(&d3dDev);
D3DXCreateFontA(d3dDev, 13, 0, FW_THIN, 1, false, DEFAULT_CHARSET,
OUT_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PALETTE|FF_SCRIPT, "", &d3dFont);

char* textureFilePath = NULL;
tiles = NULL;
std::ifstream* fileIn = new ifstream(buffer);
if(!fileIn->is_open())
return -4; //-4 == unable to open spdfFile.

bool spdf_end = false;
char* charsInRow = new char[100];
while(!fileIn->eof() && !spdf_end) {
fileIn->getline(charsInRow, 100);
if(strcmp(charsInRow,"") == 0)
continue;
else if(startsWith("//",charsInRow))
continue;
else if(startsWith("TPATH",charsInRow)){
textureFilePath = extractString(charsInRow, ':');
char* buffer = new char[300];
memset(buffer, 0, 300);

GAME_ROOTDIR(buffer,300);
strcat(buffer, "//");
strcat(buffer, textureFilePath);
D3DXGetImageInfoFromFileA(buffer, &textureInfo);

if(D3DXCreateTextureFromFileA(d3dDev, buffer, &texture) != D3D_OK)
return -3; // -3 == unable to locate specified path

} else if(startsWith("TN", charsInRow)) {
numberOfTiles = extractInt(charsInRow, ':');
tiles = new Tile[numberOfTiles];
} else if(startsWith("EH", charsInRow)) {
tileHeight = extractInt(charsInRow, ':');
} else if(startsWith("EW", charsInRow)) {
tileWidth = extractInt(charsInRow, ':');
} else if(startsWith("SEGNAME:", charsInRow)) {
for(int i = 0;!fileIn->eof() && !spdf_end && i < numberOfTiles; i++) {
if(textureFilePath == NULL || tiles == NULL)
return -6; //-6 == TextureFilePathUndefined

memset(charsInRow, 0, 100);
fileIn->getline(charsInRow, 100);
if(strcmp(charsInRow, "") == 0)
continue;

if(startsWith("SPDF_END", charsInRow)) {
spdf_end = true;
break;
}
char* buffer;
char buffer2[100];
memset(buffer2, 0, sizeof(buffer2));
buffer = splitString(buffer2, charsInRow, ':');
memset(&tiles[i], 0, sizeof(Tile));
strncpy(tiles[i].caption, buffer2, sizeof(tiles[i].caption));
//strncpy(tiles[i].sourceLoc, textureFilePath, sizeof(tiles[i].sourceLoc));
tiles[i].flags = extractInt(charsInRow, NULL);
}
}
}
return 1;
}

bool CTileManager::Render(int tile, int x, int y, bool selectableObject, bool centerTopLeft, bool fullScreen, int opacity) {
bool clicked = false;
D3DXVECTOR3 pos;
D3DXVECTOR3 vCenter;
RECT srcRect;
RECT fontDest;
RECT bounds;
D3DCOLOR captionColor = D3DCOLOR_ARGB(200, 255,255,255);
D3DCOLOR imageColor = D3DCOLOR_ARGB(200, 100, 100, 120);


if(!fullScreen) {
srcRect.left = tile * tileWidth;
srcRect.right = srcRect.left + tileWidth;
srcRect.top = 0;
srcRect.bottom = tileHeight;
} else {
srcRect.left = 0;
srcRect.right = textureInfo.Width;
srcRect.top = 0;
srcRect.bottom = textureInfo.Height;
}

pos.x = x; pos.y = y;
pos.z = 0;

bounds = RECT(srcRect);
bounds.top +=y;
bounds.bottom +=y;
bounds.left = x;
bounds.right = bounds.left + tileWidth;



if(mouseIsIn(bounds)) {
captionColor = D3DCOLOR_ARGB(255,255,255,0);
imageColor = D3DCOLOR_XRGB(255,255,255);
if(GetAsyncKeyState(VK_LBUTTON)&0x8000)
clicked = true;
}
vCenter.z = 0;
if(!centerTopLeft) {
vCenter.x = (srcRect.right - srcRect.left) / 2;
vCenter.y = (srcRect.bottom - srcRect.top) / 2;
}else
vCenter.x = vCenter.y = 0;

fontDest.top = pos.y + (tileHeight / 2);
fontDest.bottom = fontDest.top + tileHeight;
fontDest.left = pos.x + tileWidth + 10;
fontDest.right = fontDest.left + tileWidth + 5;


if(selectableObject) {
hSpriteHandler->Draw(texture, &srcRect, &vCenter, &pos, imageColor);
d3dFont->DrawTextA(hSpriteHandler, tiles[tile].caption, -1, &fontDest, DT_CENTER, captionColor);
}
//D3DXVECTOR3
/* if(width > 0)
xw = width;
if(height > 0)
yh = height;*/
if(opacity > 0)
hSpriteHandler->Draw(texture, &srcRect, &vCenter, &pos, D3DCOLOR_ARGB(opacity,255,255,255));
else
hSpriteHandler->Draw(texture, &srcRect, &vCenter, &pos, D3DCOLOR_XRGB(255,255,255));

return clicked;
}[/php]