Notifications
Clear all

[Closed] SDK ITabbedDialog

Hi, I am looking to getting a Tab control working on a Utility. I have looked at the different samples given within the sdk, but due to both using Render instead of Utility, I cannot getting it to work I believe ITabbedDialog is the way to go, but each time I have tried, it just doesn’t work. Any help would be great

2 Replies

just a slight variation on the blur plugin, if the dialog/rollout is not associated with a parameter map/ param block then it becomes plain ol’ win32 programming…

class TabbedUtilObj : public UtilityObj 
 {
 public:
 
 	HWND			hPanel;			// utility rollout panel
 	IUtil			*iu;
 	Interface		*ip;
 	HWND			floaterHWND;	// our floating window
 	HWND			tabcntrl;		// tab control
 	HWND			tabs[2];		// tab dialogs
 	
 // Constructor/Destructor
 
 	TabbedUtilObj();
 	~TabbedUtilObj() {}
 
 // stuff for the utility panel
 
 	void BeginEditParams(Interface *ip,IUtil *iu);
 	void EndEditParams(Interface *ip,IUtil *iu);
 
 // util panel
 
 	void Init(HWND hWnd)	{}
 	void Destroy(HWND hWnd) {}
 	void DeleteThis()		{}		
 
 // tool window handling routines
 
 	void CreateNewWindow();	
 	void InitWindow();
 	void DestroyWindow();
 	void UpdateUI();
 	INT_PTR NotifyHandler( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
 	void placeChildren();
 };
 
 // our util global static
 
 static TabbedUtilObj tabObj;
 
 //********************************************************************************************
 // the class descriptor
 
 class TabbedUtilObjClassDesc : public ClassDesc2 
 {
 public:
 	int 			IsPublic()					{ return TRUE; }
 	void *			Create(BOOL loading=FALSE)	{ return &tabObj; }
 	const TCHAR *	ClassName()					{ return GetString(IDS_TABBED_CLASS_NAME); }
 	SClass_ID		SuperClassID()				{ return UTILITY_CLASS_ID; }
 	Class_ID		ClassID()					{ return TABBED_UTIL_OBJ_CLASS_ID; }
 	const TCHAR* 	Category()					{ return GetString(IDS_CATEGORY); }
 	const TCHAR*	InternalName()				{ return _T("TabbedUtilObj"); }	
 	HINSTANCE		HInstance()					{ return hInstance; }	// returns owning module handle
 };
 
 static TabbedUtilObjClassDesc TabbedUtilObjDesc;
 ClassDesc2* GetTabbedUtilObjDesc() { return &TabbedUtilObjDesc; }
 
 //*****************************************************************************************
 // function publishing, make some basic functionality available to mxs mostly so we can call our
 // utility from the ui via a macroscript without switching to the utility panel first !
 
 class TabbedUtilObjFnP : public FPStaticInterface 
 {
 public:
 	DECLARE_DESCRIPTOR(TabbedUtilObjFnP);
 
 	enum functionID { kOpenWindow, kCloseWindow, kIsOpen };
 	
 	BEGIN_FUNCTION_MAP			
 		VFN_0(kOpenWindow,  OpenWindow)
 		VFN_0(kCloseWindow, CloseWindow)
 		FN_0(kIsOpen, TYPE_BOOL, IsOpen)
 	END_FUNCTION_MAP
 	
 	void OpenWindow()	{ tabObj.CreateNewWindow(); }
 	void CloseWindow()	{ if(tabObj.floaterHWND)  DestroyWindow(tabObj.floaterHWND); }
 	bool IsOpen()		{ return IsWindowOpen(); }
 
 	static bool IsWindowOpen()			{ return windowOpen; }
 	static void SetWindowOpen(bool val) { windowOpen = val; GetCUIFrameMgr()->SetMacroButtonStates(false); }
 
 private:
 
 	static bool windowOpen;
 };
 
 //**************************************************************************************
 // create the global static instance
 
 static TabbedUtilObjFnP theTabbedUtilObjFnPUtilObjFnP(TABBED_UTIL_OBJ_FP_INTERFACE_ID, _T("Tabbed"), 
 							IDS_TABBED_CLASS_NAME, NULL, FP_CORE,
 							TabbedUtilObjFnP::kOpenWindow, _T("openWindow"), -1, TYPE_VOID, FP_NO_REDRAW, 0,
 							TabbedUtilObjFnP::kCloseWindow, _T("closeWindow"), -1, TYPE_VOID, FP_NO_REDRAW, 0,
 							TabbedUtilObjFnP::kIsOpen, _T("isOpen"), -1, TYPE_BOOL, FP_NO_REDRAW, 0,end);
 
 //**************************************************************************************
 // initialize the showing static
 
 bool TabbedUtilObjFnP::windowOpen = false;
 
 //**************************************************************************************
 
 static INT_PTR CALLBACK TabbedUtilObjPanelProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
 {
 	switch (msg) 
 	{
 		case WM_INITDIALOG:
 
 			tabObj.Init(hWnd); // can we delete these ?
 			break;
 
 		case WM_DESTROY:
 
 			tabObj.Destroy(hWnd); // can we delete these ?
 			break;
 
 		case WM_COMMAND:
 
 			switch (LOWORD(wParam)) 
 			{
 				case IDC_NEW_FLOATER_BTN:
 
 					tabObj.CreateNewWindow();
 					break;
 
 				case IDOK:
 				case IDCANCEL:
 
 					DestroyWindow(hWnd);
 					break;
 			}
 			break;
 
 		case WM_LBUTTONDOWN:
 		case WM_LBUTTONUP:
 		case WM_MOUSEMOVE:
 
 			tabObj.ip->RollupMouseMessage(hWnd,msg,wParam,lParam); 
 			break;
 
 		default:
 			return FALSE;
 	}
 	return TRUE;
 }
 
 //**************************************************************************************
 
 static INT_PTR CALLBACK TabbedSceneTabWindowProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
 {
 	switch (msg) 
 	{
 		case WM_INITDIALOG: 
 		{
 			break;
 		}
 
 		case WM_DESTROY: 
 		{
 			break;
 		}
 	
 		case WM_NOTIFY:
 
 			break;
 
 		case WM_COMMAND:
 
 			switch (LOWORD(wParam)) 
 			{
 				//default:
 				//	return FALSE;
 			}
 			break;
 
 		default:
 			return FALSE;
 	}
 	return TRUE;
 }
 
 //**************************************************************************************
 
 static INT_PTR CALLBACK TabbedNodeTabWindowProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
 {
 	switch (msg) 
 	{
 		case WM_INITDIALOG: 
 		{
 			break;
 		}
 
 		case WM_DESTROY: 
 		{
 			break;
 		}
 
 		case WM_NOTIFY:
 
 			break;
 
 		case WM_COMMAND:
 
 			switch (LOWORD(wParam)) 
 			{
 				//default:
 				//	return FALSE;
 			}
 			break;
 
 		default:
 			return FALSE;
 	}
 	return TRUE;
 }
 
 //**************************************************************************************
 // the main handler callback for our floating tool window
 
 static INT_PTR CALLBACK TabbedUtilObjWindowProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
 {
 	switch (msg) 
 	{
 		case WM_INITDIALOG: 
 		{
 			tabObj.floaterHWND = hWnd;
 			tabObj.InitWindow();
 			tabObj.ip->RegisterDlgWnd(hWnd);
 			tabObj.UpdateUI();
 			TabbedUtilObjFnP::SetWindowOpen(true);
 			break;
 		}
 
 		case WM_DESTROY: 
 		{
 			tabObj.DestroyWindow();
 			tabObj.ip->UnRegisterDlgWnd(hWnd);
 			TabbedUtilObjFnP::SetWindowOpen(false);
 			break;
 		}
 
 		case WM_NOTIFY:
 
 			return tabObj.NotifyHandler(hWnd, msg, wParam, lParam);
 			break;
 
 		case WM_COMMAND:
 
 			switch (LOWORD(wParam)) 
 			{
 // all other win32 dialog handled here		
 
 				case IDOK:
 				case IDCANCEL:
 
 					DestroyWindow(hWnd);
 					break;
 			}
 			break;
 
 		default:
 			return FALSE;
 	}
 	return TRUE;
 }
 
 
 //**************************************************************************************
 // TabbedUtilObj, code for our utility starts here
 
 TabbedUtilObj::TabbedUtilObj()
 {
 	iu = NULL;
 	ip = NULL;	
 	hPanel = NULL;
 	floaterHWND = NULL;
 }
 
 //*****************************************************************************************
 
 void TabbedUtilObj::BeginEditParams(Interface *ip,IUtil *iu) 
 {
 	this->iu = iu;
 	this->ip = ip;
 	hPanel = ip->AddRollupPage(hInstance, MAKEINTRESOURCE(IDD_TABBED_UTIL_PANEL), 
 		TabbedUtilObjPanelProc, GetString(IDS_PARAMS), 0);
 }
 	
 //********************************************************************************************
 
 void TabbedUtilObj::EndEditParams(Interface *ip,IUtil *iu) 
 {
 	this->iu = NULL;
 	ip->DeleteRollupPage(hPanel);
 	hPanel = NULL;
 }
 
 //*****************************************************************************************
 
 void TabbedUtilObj::CreateNewWindow()
 {
 	ip = GetCOREInterface();	// catches any script calls
 	if(floaterHWND == NULL)
 		CreateDialog(hInstance, MAKEINTRESOURCE(IDD_TABBED_WINDOW), ip->GetMAXHWnd(), TabbedUtilObjWindowProc);
 }
 
 //**************************************************************************************
 
 INT_PTR TabbedUtilObj::NotifyHandler(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
 {
 	switch(((LPNMHDR)lParam)->code)
 	{
 		case TCN_SELCHANGING: // message sent because someone changed the tab selection (clicked on another tab)
 		{
 			switch(TabCtrl_GetCurSel(tabcntrl))
 			{
 				case 0:
 					 
 					ShowWindow(tabs[0], SW_HIDE);
 					break;
 				case 1:
 
 					ShowWindow(tabs[1], SW_HIDE);
 					break;
 			}
 			break;
 		}
 		case TCN_SELCHANGE: // message sent because someone changed the tab selection (clicked on another tab)
 		{
 			switch(TabCtrl_GetCurSel(tabcntrl))
 			{
 				case 0:
 					 
 					ShowWindow(tabs[0], SW_SHOW);
 					break;
 				case 1:
 
 					ShowWindow(tabs[1], SW_SHOW);
 					break;
 			}
 			break;
 		}
 	}
 	return TRUE;
 }
 
 void TabbedUtilObj::placeChildren()
 {
 	// compute locations for child dialogs
 	Rect rc;
 	GetWindowRect(floaterHWND, &rc);
 	int originX = rc.left;
 	int originY = rc.top;
 
 	// find display area of tab control
 	GetWindowRect(tabcntrl, &rc);
 	TabCtrl_AdjustRect(tabcntrl, FALSE, &rc);
 
 	// convert to client coordinates
 	rc.left -= originX; rc.right  -= originX;
 	rc.top  -= originY; rc.bottom -= originY;
 
 	// move child dialogs into place
 	MoveWindow(tabs[0], rc.left, rc.top, rc.right-rc.left, rc.bottom-rc.top, FALSE);
 	MoveWindow(tabs[1],  rc.left, rc.top, rc.right-rc.left, rc.bottom-rc.top, FALSE);
 }
 
 //**************************************************************************************
 // Initialize the tool window
 
 void TabbedUtilObj::InitWindow()  
 {
 	tabcntrl = GetDlgItem(floaterHWND, IDC_TAB_CTRL);
 
 	TCITEM ti;
 	ti.mask = TCIF_TEXT; // I'm only having text on the tab
 	ti.pszText = "Scene";
 	TabCtrl_InsertItem(tabcntrl,0,&ti);
 	ti.pszText = "Node";
 	TabCtrl_InsertItem(tabcntrl,1,&ti);
 	TabCtrl_SetCurSel(tabcntrl,0);
 	currentTab = 0;
 
 	tabs[0] = CreateDialog(hInstance,MAKEINTRESOURCE(IDD_TABBED_SCENE_TAB),tabcntrl,TabbedSceneTabWindowProc);
 	tabs[1] = CreateDialog(hInstance,MAKEINTRESOURCE(IDD_TABBED_NODE_TAB),tabcntrl,TabbedNodeTabWindowProc);
 
 	placeChildren();
 
 	switch( TabCtrl_GetCurSel( tabcntrl ) )
 	{
 		case 0:
 			ShowWindow(tabs[1], SW_HIDE);
 			ShowWindow(tabs[0], SW_SHOW);
 			break;
 		case 1:
 			ShowWindow(tabs[0], SW_HIDE);
 			ShowWindow(tabs[1], SW_SHOW);
 			break;
 	}
 }
 
 //**************************************************************************************
 // destroy the tool window
 
 void TabbedUtilObj::DestroyWindow()
 {
 	::DestroyWindow(tabs[0]);
 	::DestroyWindow(tabs[1]);
 	floaterHWND = NULL;
 }
 
 //*****************************************************************************************
 
 void TabbedUtilObj::UpdateUI() {}

Thank you, works like a treat