//////////////////////////////////////////////////// //Classe per la configurazione dei menu utente //in base alle informazioni indicate // //Realizzato da Francesco Germinara (c) 2004 //Copyright SofTech di Francesco Germinara (c) 2004 // //Date: 11/02/2004 //////////////////////////////////////////////////// /* Legal notice This class can be used freely for any use. Any comment or implemntations of this class are welcome. CFgMenuCfg is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. CFgMenuCfg is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. Thanks, Francesco Germinara www.germinara.it francesco@germinara.it Max Menu Level = 3 Max Toolbar = 6 */ /* Examples IN CTestmnuApp.h #include"CFgMenuCfg.h" ///////////////////////////////////////////////////////////////////////////// // CTestmnuApp: // See testmnu.cpp for the implementation of this class // class CTestmnuApp : public CWinApp { public: CTestmnuApp(); CFgMenuCfg myCFgMenuCfg; ... ... }; IN MainFrm.cpp int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct) { ... ... //Before return ... //From File ... theApp.myCFgMenuCfg.InitCfgMenu("FG","C:\\",GetMenu(),&m_wndToolBar); theApp.myCFgMenuCfg.LoadFromUserProfile(); theApp.myCFgMenuCfg.RebuildMenu(); //Manually theApp.myCFgMenuCfg.SetUserId("FG","C:\\"); theApp.myCFgMenuCfg.Attach(GetMenu(),&m_wndToolBar); theApp.myCFgMenuCfg.SetMenuItem("Barra di st&ato"); //No button associated theApp.myCFgMenuCfg.SetMenuItem("&Incolla\tCtrl+V",6); theApp.myCFgMenuCfg.SetMenuItem("provare",11); theApp.myCFgMenuCfg.SaveToFile(); //Memorizza info ... theApp.myCFgMenuCfg.RebuildMenu(); return 0; } */ /* Notice: The class can use a text file for make dinamically modification to menu items and button toolbar based on the usercode that login on the applications. // FG_CFGMENU.MNU -> userid+_CFGMENU.MNU // // contents... // // index menuitemname id id pospos op op // mnubtnmnubtnmnubtn // // where // // index = index array element // // id mnu = ID resource of the menu (actually not used) // id btn = ID resource of the button on the ToolBar (actually not used) // pos mnu= Position (0-based) of the menu item // pos btn= Position (0-based) of the menu item // op mnu = Operation on menu item: 0=Delete 1=Retain // op btn = Operation on button item of toolbar: 0=Delete 1=Retain // // The simplest way to creare this file is from CFgMenuCfg itself with // the use of .SaveToFile() or .SaveToFile(CString filename) methods. // // // {000}{Barra di st&ato}{0}{0}{0}{-1}{0}{0} // {001}{&Incolla Ctrl+V}{0}{0}{0}{6}{0}{0} // {002}{provare}{0}{0}{0}{11}{0}{0} // // */ #if !defined(_CFG_MENU_CFG_INCLUDED_) #define _CFG_MENU_CFG_INCLUDED_ #define _MNU_DELETE 0 #define _MNU_RETAIN 1 #if _MSC_VER > 1000 #pragma once #endif // _MSC_VER > 1000 #include "TreeCtrlEx.h" class CfgMenuItemClass{ CString m_strName; int m_nIdMenu; int m_nIdButton; int m_nPosMenu; int m_nPosButton; int m_nStyleMenu; int m_nStyleButton; CString m_strIdMnuName; CString m_strIdToolBarName; public: CMenu *pMenu; CMenu *pSubMenu; CMenu *pSubSubMenu; CToolBar *pToolBar1; CToolBar *pToolBar2; CToolBar *pToolBar3; CToolBar *pToolBar4; CToolBar *pToolBar5; CToolBar *pToolBar6; HTREEITEM m_nItem; //in the tree control void SetHitemButton(HTREEITEM nItem){ m_nItem=nItem; } HTREEITEM GetHitemButton(){ return m_nItem; } void Clear(){ m_strName=""; m_nIdMenu=0; m_nIdButton=0; m_nPosMenu=0; m_nPosButton=-1; m_nStyleMenu=0; m_nStyleButton=0; pMenu=NULL; pSubMenu=NULL; pSubSubMenu=NULL; pToolBar1=NULL; pToolBar2=NULL; pToolBar3=NULL; pToolBar4=NULL; pToolBar5=NULL; pToolBar6=NULL; m_nItem=NULL; m_strIdMnuName=""; m_strIdToolBarName=""; }; void SetValue(CString strName,int nIdMenu,int nIdButton,int nPosMenu,int nPosButton,int nStyleMenu,int nStyleButton,CMenu *pWndMenu,CMenu *pWndSubMenu,CToolBar* pWndMenuToolBar1,CString strIdMnuName="",CMenu *pWndSubSubMenu=NULL,CToolBar* pWndMenuToolBar2=NULL,CToolBar* pWndMenuToolBar3=NULL,CToolBar* pWndMenuToolBar4=NULL,CToolBar* pWndMenuToolBar5=NULL,CToolBar* pWndMenuToolBar6=NULL,CString strIdToolBar=""){ m_strName=strName; m_nIdMenu=nIdMenu; m_nIdButton=nIdButton; m_nPosMenu=nPosMenu; m_nPosButton=nPosButton; m_nStyleMenu=nStyleMenu; m_nStyleButton=nStyleButton; pMenu=pWndMenu; pSubMenu=pWndSubMenu; pSubSubMenu=pWndSubSubMenu; pToolBar1=pWndMenuToolBar1; pToolBar2=pWndMenuToolBar2; pToolBar3=pWndMenuToolBar3; pToolBar4=pWndMenuToolBar4; pToolBar5=pWndMenuToolBar5; pToolBar6=pWndMenuToolBar6 ; m_strIdMnuName=strIdMnuName; m_strIdToolBarName=strIdToolBar; } CString GetName(){ CString strName; strName=m_strName; strName.TrimRight(); return strName; } CString GetIdStrMenu(){ return m_strIdMnuName; } CString GetIdStrToolBar(){ return m_strIdToolBarName; } int GetIdMenu(){ return m_nIdMenu;}; int GetIdButton(){ return m_nIdButton;}; int GetPosMenu(){ return m_nPosMenu;}; int GetPosButton(){ return m_nPosButton;}; void SetPosButton(int newPosButton,CString strIdToolBarName){ m_nPosButton=newPosButton; m_strIdToolBarName=strIdToolBarName; }; int GetStyleMenu(){ return m_nStyleMenu;}; int GetStyleButton(){ return m_nStyleButton;}; void ShiftLeftPosButton(){ m_nPosButton--; } }; #define CFGMENUMAXITEM 300 class CFgMenuCfg { private: CfgMenuItemClass m_cfgMenuItems[CFGMENUMAXITEM]; int m_nItems; CString m_strUserCode; CString m_strPathPgm; int nPosSub; BOOL ParseRow(int& nIndex,CString& strName,int& nIdMenu,int& nIdButton,int& nPosMenu,int& nPosButton,int& nStyleMenu,int& nStyleButton,CString row,CString& strIdMenu,CString& strIdToolBar); //Parse a Row Data File public: CFgMenuCfg(); ~CFgMenuCfg(); CString OnSaveMenu(); //interlal use void OnLoadResource();//interlal use enum eToken{eMENU=0,ePOPUP,eMENUITEM,eBEGIN,eEND,eTOOLBAR,eBUTTON,eSEPARATOR,eSPACE,eCOMMA,eVIRGOLETTE,eNEWLINE,eCOMMENT,eINCLUDE,eSTRINGA,eNONE}; int ParseRow(CString strRow,int &nPos); //internal use only by ParserResource() CString GetToken(CString strRow,eToken eTk,int &nPos); //internal use only by ParserResource() CString m_strFileRC; //Resource File Name to analyze CString m_strFileMNU; //Destination MNU file. CMenu *pMenu; CMenu *pSubMenu; CMenu *pSubSubMenu; CToolBar *pToolBar; CToolBar *pToolBar2; CToolBar *pToolBar3; CToolBar *pToolBar4; CToolBar *pToolBar5; CToolBar *pToolBar6; CString m_strIDToolBar1; CString m_strIDToolBar2; CString m_strIDToolBar3; CString m_strIDToolBar4; CString m_strIDToolBar5; CString m_strIDToolBar6; int Count(){return m_nItems;}; CfgMenuItemClass* GetByIndex(int nIndex); //Restituisce l'elemento trovato //EASY USE void InitCfgMenu(CString usrID,CString strPathUserProfile,CMenu *mainMnu,CToolBar *pToolBar,CString strIDToolBar1="",CToolBar *pToolBar2=NULL,CString strIDToolBar2="",CToolBar *pToolBar3=NULL,CString strIDToolBar3="",CToolBar *pToolBar4=NULL,CString strIDToolBar4="",CToolBar *pToolBar5=NULL,CString strIDToolBar5="",CToolBar *pToolBar6=NULL,CString strIDToolBar6=""); //Init Data in MainFrameWnd void SetMenuItem(CString strName,int nPosButton=-1,int nStyleMenu=_MNU_DELETE,int nStyleButton=_MNU_DELETE); //Imposta voce di menu void RebuildMenu(); //Internal USE void Attach(CMenu *pWndMenu,CToolBar* pWndToolBar,CToolBar* pWndToolBar2=NULL,CToolBar* pWndToolBar3=NULL,CToolBar* pWndToolBar4=NULL,CToolBar* pWndToolBar5=NULL,CToolBar* pWndToolBar6=NULL,CString strIDToolBar1="",CString strIDToolBar2="",CString strIDToolBar3="",CString strIDToolBar4="",CString strIDToolBar5="",CString strIDToolBar6=""); // Attach default Item Menu void SetUserId(CString usrCode,CString strPathPgm); //Imposta il codice utente o niente void SetMenuItem(CString strName,int nIdMenu,int nIdButton,int nPosMenu,int nPosButton,int nStyleMenu,int nStyleButton,CString strIdMenu="",CString strIdToolBar=""); //Imposta voce di menu int FindByName(CString strName); //Cerco l'indice di un menu CfgMenuItemClass* GetByName(CString strName); //Restituisce l'elemento trovato o NULL se non è stato trovato void ResetContents(); //Reset Class Contents int FindMenuItem(CMenu* Menu, LPCTSTR MenuString); //Cerca un menu per nome e restituisce la posizione int FindSubSubMenuItem(CMenu* Menu, LPCTSTR MenuString);//Cerca submenu un menu per nome e restituisce la posizione int FindSubMenuItemByPos(CMenu* Menu,int mnuPos, LPCTSTR MenuString); //Cerca la posizione di un sottomenu int FindMenuItemAll(CMenu* Menu, LPCTSTR MenuString,int& nPosMainMenu);//Cerca nei menu e in tutti i sotto menu void DeleteMenu(CString strName); //Delete a single menu void DeleteButton(CfgMenuItemClass* pTmpItem,CToolBar *pTmpToolBar,CString strIdToolBar);//Delete a single button on a specified toolbar void RemoveAllSeparator(); //Remove all Separator from menu and from toolbar void RemoveAllSeparatorFromSubMenu(CMenu *pMenu,int posMenu); //Remove all Separator from submenu void RemoveAllSeparatorFromButton(CToolBar *pToolBar);//Remove separator from toolbar int SearchStrIDMnu(CString strIdMenu);//Search Index for a menu by strIdMenu bool SetButtonPos(int posButton,CString strIdMenu,CString strIdToolBar);//Set Button Position by strIdMenu void SetHitem(CString strIdMenu,HTREEITEM nItem); //Set HTREEITEM //Advanced USE BOOL LoadFromUserProfile(); //Imposta informazioni del menu in base all'utente Return TRUE=OK BOOL SaveToFile(CString filename); //Save informations contents to ASCII FILE Return TRUE=OK BOOL SaveToFile(CString strNameFile,CTreeCtrlEx *pTree); BOOL SaveToFile(); //Save to User profile file //PARSE RESOURCE FILE AND GENERATE MNU FILE void ParserResource(); }; #endif //_CFG_MENU_CFG_INCLUDED_