// Main program file generated by Zinc Designer.

#include "p_image.inc"
#include "image.hpp"

int ZafApplication::Main(void)
{
	// Ensure main() is linked properly.
	LinkMain();

	// Establish access to external objects and data.
	ZafStorage *storage = new ZafStorage(ZAF_ITEXT("p_image.znc"), ZAF_FILE_READ);
	if (storage->Error())
	{
		zafErrorSystem->ReportError(ZAF_NULLP(ZafWindowObject),
			ZAF_ITEXT("Error"), ZAF_DIALOG_OK,
			ZAF_ITEXT("P_image.znc could not be found."));
		delete storage;
		return (-1);
	}

	zafObjectPersistence = new UserPersist(storage);

	// Load the main window from the data (.znc) file.
	ZafWindow *window = new ImageControlWin(ZAF_ITEXT("MainWindow"));

	// Attach the main window to the window manager, or in other words,
	// make it appear on the screen.
	zafWindowManager->Add(window);

	// Close all windows if the main window is closed.
	zafWindowManager->screenID = window->screenID;

	// Process events.
	// (This functions passes events from the event manager to the
	// window manager until an S_EXIT is received or until there on no
	// more windows attached to the window manager.)
	Control();

	delete zafObjectPersistence;
	zafObjectPersistence = ZAF_NULLP(ZafObjectPersistence);
	delete storage;

	// Return success.
	return (0);
}
