#include "dialog.h"

std::map <int, rDialog*> DialogIDs;

LRESULT CALLBACK DlgProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	int id = GetDlgCtrlID(hWnd);
	switch(message)
    {
		case WM_INITDIALOG:
			DialogIDs[id] = (rDialog*)lParam;
			DialogIDs[id] -> hWND = hWnd;
			DialogIDs[id] -> rInitProc(hWnd);
			return true;

		case WM_COMMAND:
			DialogIDs[id] -> rCommandProc(hWnd, wParam);
			return true;
	}
	return false;
}

void rDialog::Create(int Resourse)
{
	Create(NULL, Resourse);
}

void rDialog::Create(HINSTANCE hInstance, int Resourse)
{
	DialogBoxParam(hInstance, MAKEINTRESOURCE(Resourse), NULL, (DLGPROC)DlgProc, (LPARAM)this);
}

void rDialog::OpenFileNameDialog(char* filename, char* filter)
{
	OPENFILENAME o;
	memset(&o, 0, sizeof(o));
	o.lStructSize = sizeof(o);
	o.hInstance = 0;
	o.lpstrFilter = filter;
	o.lpstrFile = (LPSTR)filename;
	o.nMaxFile = 256;
	o.Flags = OFN_EXPLORER;
	GetOpenFileName(&o);
}