Well, here's my first DarkGDK app. With a small (incomplete) GUI library.
#include <DarkGDK.h>
#include <globstruct.h>
// Window processing procedure
LRESULT CALLBACK WndProcGUI(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
// Pre-Setup
int i = 0;
// Messages
switch(msg)
{
// Window has been closed?
case WM_CLOSE:
DestroyWindow(hWnd);
return 0;
}
// Process the default window procecedure
return DefWindowProc(hWnd,msg,wParam,lParam);
}
HWND g_hWindows[0xffff];
void ConstructorWindows(void)
{
for(int i = 0; i < 0xffff; i++)
{
g_hWindows[i] = NULL;
}
}
// Make an extra window
void dbMakeWindow(int id, int width=500, int height=400, char* title="", int parent=0)
{
if (id > 0)
{
id--;
if (g_hWindows[id] == NULL)
{
// Register the window class
WNDCLASSEX wc;
wc.cbSize = sizeof(WNDCLASSEX);
wc.style = 0;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.lpfnWndProc = WndProcGUI;
wc.hInstance = GetModuleHandle(NULL);
wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = NULL; //(HBRUSH)COLOR_WINDOW;
wc.lpszMenuName = NULL;
wc.lpszClassName = "WndProcGUI";
RegisterClassEx(&wc);
// Create the window
HWND hWnd = NULL;
HWND hParent = NULL;
if (parent == 0) hParent = g_pGlob->hWnd; else hParent = g_hWindows[parent];
hWnd = CreateWindow("WndProcGUI",title,WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,CW_USEDEFAULT,width,height,hParent,0,GetModuleHandle(0),0);
if (!hWnd)
{
MessageBoxA(g_pGlob->hWnd, "Runtime Error G1001! Unable to create window!", "Error", MB_ICONERROR | MB_OK);
g_iDarkGameSDKQuit = 1;
}
else
{
ShowWindow(hWnd,SW_SHOW);
UpdateWindow(hWnd);
SetFocus(hWnd);
g_hWindows[id] = hWnd;
}
}
else
{
MessageBoxA(g_pGlob->hWnd, "Runtime Error G1002! Window already exists!", "Error", MB_ICONERROR | MB_OK);
g_iDarkGameSDKQuit = 1;
}
}
else
{
MessageBoxA(g_pGlob->hWnd, "Runtime Error G1000! Invalid window ID!", "Error", MB_ICONERROR | MB_OK);
g_iDarkGameSDKQuit = 1;
}
}
// Delete a window
void dbDeleteWindow(int id)
{
if (id > 0)
{
id--;
DestroyWindow(g_hWindows[id]);
g_hWindows[id] = NULL;
}
else if (id == 0)
{
DestroyWindow(g_pGlob->hWnd);
}
else
{
MessageBoxA(g_pGlob->hWnd, "Runtime Error G1000! Invalid window ID!", "Error", MB_ICONERROR | MB_OK);
g_iDarkGameSDKQuit = 1;
}
}
// Check if a window exists
int dbWindowExist(int id)
{
if (id > 0)
{
id--;
if (g_hWindows[id] != NULL)
{
return 1;
}
}
return 0;
}
// Render to a window
void dbRenderToWindow(int index)
{
if (dbWindowExist(index))
{
IDirect3DDevice9* pDevice;
pDevice = dbGetDirect3DDevice();
pDevice->BeginScene();
pDevice->EndScene();
pDevice->Present(NULL, NULL, g_hWindows[index-1], NULL);
}
}
// Set the title of a window
void dbSetWindowTitle(int index, char* text)
{
if (dbWindowExist(index))
{
SetWindowTextA(g_hWindows[index-1], text);
}
}
// Main function for DGDK (I think)
void DarkGDK(void)
{
// Required
ConstructorWindows();
// Syncing
dbSyncOn();
dbMakeObjectCube(1, 100.0f);
dbMakeWindow(1);
dbMakeWindow(2, 320, 240, "Window", 0);
dbSetWindowTitle(1, "My Window!");
// Other code here
while(LoopGDK())
{
dbTurnObjectLeft(1, 0.3f);
dbSync();
dbRenderToWindow(1);
dbRenderToWindow(2);
}
dbDeleteWindow(1);
}
I wanted to keep it as much DGDK styled as possible (Meaning no OOP). Code taken from WinGUI's old version and reused in slightly different way. I made this because someone asked me if it was possible to render to multiple windows, so here's the code.
Screenshot uploaded.
Cheers,
-naota
"I choose to believe, what I was programmed to believe!"
Aex.Uni forums