#include <windows.h>
#include <stdio.h>
#include <iostream>
LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);
char szClassName[ ] = "WindowsApp";
HWND hwnd;
// ########################### NEEDED Global Variable for BTT ############################
typedef struct TNavRes { INT ID; LPTSTR txt; }; // Declare the structure of the result no
TNavRes NavRes; // result of the node
// Declare all
dll functions
typedef bool (*POPENDB)(LPTSTR Filename); // this function open the
DB Connection
typedef int (*PLOADNODES)(int id, int ix); // this function load the NodeList with ParentID number ID
typedef int (*PNNN)(int id); // this function load the NodeList with ParentID number ID
// if id < 0 then load all root nodes from
DB
// if id >= 0 then load all sub nodes from
DB
// result of the function is count of entrys
typedef bool (*PREADNODE)(int Nr, TNavRes* res); // Read the node informations (entry)
// Declare the globale variable of the functions
POPENDB OpenDB;
PLOADNODES LoadNodes;
PREADNODE ReadNode;
PNNN nnn;
// Declare the needed globale variables
HINSTANCE dllhwnd; // This is the
handle for the BTT -
DLL
// ----------------------------------------------------------------------------------------
/* for (i = 0; i < LoadNodes(id, 1); i++){
if (ReadNode(i, &NavRes)){
// LPTSTR buf;
// sprintf(buf, "%i", i);
// writeln(buf);
// Saving now the result in a treeview
// NavRes.ID <= ID of the entry in the
DB (UNIQUE)
// NavRes.txt <= Text of the entry in the
DB for the caption of the node in a treeview
FLoadNodes(NavRes.ID); // open recursive the function if sub notes are available from this node
}
} */
char* itoa(int input){
static char buffer[16];
snprintf(buffer,sizeof(buffer),"%d",input);
return buffer;
}
void FLoadNodes(int id){ // this function load the nodes in recursive methode
int i;
int c;
i = -1;
// nnn(id);
do {
i++;
c = LoadNodes(id, 1);
if (i < c){
if ((bool)ReadNode(i, &NavRes)){
FLoadNodes(NavRes.ID); // open recursive the function if sub notes are available from this node
}
}
c = LoadNodes(id, 1);
} while( (c == 0) || (i >= c) );
}
void FOpenDB(){
char buf[255];
if (dllhwnd != NULL){
OpenDB = (POPENDB) GetProcAddress(dllhwnd, "OpenDB");
LoadNodes = (PLOADNODES) GetProcAddress(dllhwnd, "LoadNodes");
ReadNode = (PREADNODE) GetProcAddress(dllhwnd, "ReadNode");
nnn = (PNNN) GetProcAddress(dllhwnd, "nnn");
if (OpenDB != NULL){
if (OpenDB("C:\\Dokumente und Einstellungen\\Steffen\\Desktop\\BTT.btt") == true){
SetWindowText(hwnd, "Connected");
if (LoadNodes != NULL){
FLoadNodes(-1); // Load now the informations for the treeview starts at root
}
} else {
SetWindowText(hwnd, "not Connected");
}
}
}
}
int
WINAPI WinMain (HINSTANCE hThisInstance,
HINSTANCE hPrevInstance,
LPSTR lpszArgument,
int nFunsterStil)
{
MSG messages;
WNDCLASSEX wincl;
wincl.hInstance = hThisInstance;
wincl.lpszClassName = szClassName;
wincl.lpfnWndProc = WindowProcedure;
wincl.style = CS_DBLCLKS;
wincl.cbSize = sizeof (WNDCLASSEX);
wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
wincl.lpszMenuName = NULL;
wincl.cbClsExtra = 0;
wincl.cbWndExtra = 0;
wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND;
if (!RegisterClassEx (&wincl))
return 0;
hwnd = CreateWindowEx (
0,
szClassName,
"Windows App",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
544,
375,
HWND_DESKTOP,
NULL,
hThisInstance,
NULL
);
ShowWindow (hwnd, nFunsterStil);
dllhwnd = LoadLibrary("E:\\Programmieren\\SitelTools\\BTT\\bttdll\\btt.dll"); // load now the BTT library mapping in the memory
FOpenDB();
while (GetMessage (&messages, NULL, 0, 0))
{
TranslateMessage(&messages);
DispatchMessage(&messages);
}
FreeLibrary(dllhwnd); // give free the BTT library mapping in the memory
return messages.wParam;
}
LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_DESTROY:
PostQuitMessage (0);
break;
default:
return DefWindowProc (hwnd, message, wParam, lParam);
}
return 0;
}