#pragma once #include //#include "KUIUtil.h" class KUIWnd; class KUIFactory { public: typedef KUIWnd* (*WndCreateFn)(); static KUIFactory* GetInstance() { static KUIFactory obj; return &obj; } bool RegisterCreator(WndCreateFn fn, LPCSTR lpszClassName) { WndCreateFn find; if( true == m_hashCreateTable.lookup(lpszClassName,find) ) { assert(false && "Register Same Class Name Error"); return false; } m_hashCreateTable.add(lpszClassName, fn); return true; } bool UnRegisterCreatetor(LPCSTR lpszClassName) { return m_hashCreateTable.erase(lpszClassName); } bool IsRegister(LPCSTR lpszName) { WndCreateFn find; return m_hashCreateTable.lookup(lpszName,find); } KUIWnd* CreateObject(LPCSTR lpszClassName) { WndCreateFn find; if( false == m_hashCreateTable.lookup( lpszClassName,find) ) { #ifndef NDEBUG #ifndef _RELEASE char buff[128]; sprintf(buff, "Create Wnd invalid class name ( %s )", lpszClassName); MessageBox( NULL, buff, "Error", MB_OK); #endif #endif return NULL; } return find(); } protected: KHash m_hashCreateTable; };