home *** CD-ROM | disk | FTP | other *** search
- // MainFrm.cpp : implementation of the CMainFrame class
- //
-
- #include "stdafx.h"
- #include "MDIDemo.h"
-
- #include "MainFrm.h"
-
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
-
- /////////////////////////////////////////////////////////////////////////////
- // CMainFrame
-
- IMPLEMENT_DYNAMIC(CMainFrame, CMDIFrameWnd)
-
- BEGIN_MESSAGE_MAP(CMainFrame, CMDIFrameWnd)
- //{{AFX_MSG_MAP(CMainFrame)
- ON_WM_CREATE()
- ON_COMMAND(IDR_FILE_OPEN, OnFileOpen)
- ON_COMMAND(ID_TOOLS_REMOVESKIN, OnToolsRemoveskin)
- ON_COMMAND(ID_TOOLS_APPLYSKIN, OnToolsApplyskin)
- ON_COMMAND(ID_SKIN_SETSKINDIR, OnSkinSetskindir)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
-
- static UINT indicators[] =
- {
- ID_SEPARATOR, // status line indicator
- ID_INDICATOR_CAPS,
- ID_INDICATOR_NUM,
- ID_INDICATOR_SCRL,
- };
-
- /////////////////////////////////////////////////////////////////////////////
- // CMainFrame construction/destruction
-
- CMainFrame::CMainFrame()
- {
- // TODO: add member initialization code here
-
- }
-
- CMainFrame::~CMainFrame()
- {
- }
-
- int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
- {
- if (CMDIFrameWnd::OnCreate(lpCreateStruct) == -1)
- return -1;
-
- char str1[256]="";
- GetCurrentDirectory(256,str1);
- theApp.m_ExePath.Format("%s",str1);
-
- if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP
- | CBRS_TOOLTIPS | CBRS_SIZE_FIXED) ||
- !m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
- {
- TRACE0("Failed to create toolbar\n");
- return -1; // fail to create
- }
-
- if (!m_wndStatusBar.Create(this) ||
- !m_wndStatusBar.SetIndicators(indicators,
- sizeof(indicators)/sizeof(UINT)))
- {
- TRACE0("Failed to create status bar\n");
- return -1; // fail to create
- }
-
- // TODO: Delete these three lines if you don't want the toolbar to
- // be dockable
- m_wndToolBar.EnableDocking(CBRS_ALIGN_TOP);
- EnableDocking(CBRS_ALIGN_ANY);
- DockControlBar(&m_wndToolBar);
-
- CString str = theApp.m_ExePath;
-
- HKEY hk;
- DWORD dwData;
-
- /* if (RegCreateKeyEx(HKEY_LOCAL_MACHINE,
- "Software\\SkinCrafter\\SkinCrafter Demo", &hk))
- AfxMessageBox("Error opening reg key");*/
- if(RegOpenKeyEx( HKEY_LOCAL_MACHINE,
- "Software\\SkinCrafter\\SkinCrafter Demo",
- 0, KEY_QUERY_VALUE, &hk) != ERROR_SUCCESS)
- {
- //AfxMessageBox("Error open key");;
- }
-
- char skinPath[_MAX_PATH] = "";
-
- if(RegQueryValueEx(hk,"SkinPath",NULL,NULL,(LPBYTE)skinPath,&dwData) == ERROR_SUCCESS)
- {
- str.Format("%s",skinPath);
- //AfxMessageBox(str+" - from registry");
- }
-
-
- RegCloseKey(hk);
-
- SHFILEINFO shinfo;
- DWORD dw = SHGetFileInfo( str, NULL,
- &shinfo,
- sizeof(shinfo),
- SHGFI_DISPLAYNAME );
- if(dw == 0)
- str = theApp.m_ExePath;
-
- theApp.m_strSkinDir = str;
-
- ((CMainFrame*)AfxGetMainWnd())->FillMenu();
-
- return 0;
- }
-
- BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
- {
- if( !CMDIFrameWnd::PreCreateWindow(cs) )
- return FALSE;
-
- return TRUE;
- }
-
- /////////////////////////////////////////////////////////////////////////////
- // CMainFrame diagnostics
-
- #ifdef _DEBUG
- void CMainFrame::AssertValid() const
- {
- CMDIFrameWnd::AssertValid();
- }
-
- void CMainFrame::Dump(CDumpContext& dc) const
- {
- CMDIFrameWnd::Dump(dc);
- }
-
- #endif //_DEBUG
-
- /////////////////////////////////////////////////////////////////////////////
- // CMainFrame message handlers
-
-
- void CMainFrame::OnFileOpen()
- {
- // TODO: Add your command handler code here
-
- /////////////////////////////////////
-
- CString Filter("SkinCrafter files (*.skf)|*.skf||");
-
- CFileDialog FileDlg(TRUE, "skf", NULL, NULL, Filter);
- FileDlg.m_ofn.lpstrTitle = "Select file";
-
- HKEY hk;
- DWORD dwData;
-
- FileDlg.m_ofn.lpstrInitialDir = theApp.m_strSkinDir;
-
- if(IDOK == FileDlg.DoModal())
- {
- CString SelectedFile = FileDlg.GetPathName();
-
- theApp.m_pSkin.LoadSkinFromFile(SelectedFile);
- theApp.m_pSkin.ApplySkin();
-
- theApp.m_pSkin.UpdateControl(0);
- }
- }
-
- void CMainFrame::OnToolsRemoveskin()
- {
- // TODO: Add your command handler code here
- theApp.m_pSkin.RemoveSkin();
- }
-
- void CMainFrame::OnToolsApplyskin()
- {
- // TODO: Add your command handler code here
- theApp.m_pSkin.ApplySkin();
- }
- static int __stdcall BrowseProc(HWND hWnd, UINT uMsg, LPARAM lParam, LPARAM lpData)
- {
- switch(uMsg)
- {
- case BFFM_INITIALIZED:
- {
- HKEY hk;
- DWORD dwData;
-
- CString str = theApp.m_ExePath;
-
- if(theApp.m_strSkinDir.IsEmpty())
- {
-
-
- if (RegCreateKey(HKEY_LOCAL_MACHINE,
- "Software\\SkinCrafter\\SkinCrafter Demo", &hk))
- int err = 1;
-
- char skinPath[_MAX_PATH] = "";
-
- if(RegQueryValueEx(hk,"SkinPath",NULL,NULL,(LPBYTE)skinPath,&dwData) == ERROR_SUCCESS)
- {
-
- str.Format("%s",skinPath);;
- }
- else
- str = theApp.m_strSkinDir;
-
- RegCloseKey(hk);
-
- SHFILEINFO shinfo;
- DWORD dw = SHGetFileInfo( str, NULL,
- &shinfo,
- sizeof(shinfo),
- SHGFI_DISPLAYNAME );
- if(dw == 0)
- str = theApp.m_ExePath;
- }
- else
- {
- str = theApp.m_strSkinDir;
- }
-
- SendMessage(hWnd,BFFM_SETSELECTION,TRUE,(LPARAM)str.GetBuffer(str.GetLength()));
- str.ReleaseBuffer();
- break;
- }
- default:
- break;
- }
- return 0;
- }
-
-
- void CMainFrame::FillMenu()
- {
- CFileFind findFile;
- CString filemask = theApp.m_strSkinDir+"\\*.skf";
- BOOL bWorking(findFile.FindFile(filemask));
-
- int count = 0;
- m_MenuMap.RemoveAll();
-
- CMenu* pSkinMenu=NULL,*pSkinMenu2=NULL;
-
- if(theApp.m_hMDIMenu)
- {
- for(int i = CMenu::FromHandle(theApp.m_hMDIMenu)->GetMenuItemCount()-1;i>=0;i--)
- {
- CString str;
- CMenu::FromHandle(theApp.m_hMDIMenu)->GetMenuString(i,str,MF_BYPOSITION);
- if(!str.Compare("Skin"))
- {
- pSkinMenu = CMenu::FromHandle(theApp.m_hMDIMenu)->GetSubMenu(i);
- break;
- }
- }
- for(i=pSkinMenu->GetMenuItemCount()-1;i>1;i--)
- {
- pSkinMenu->DeleteMenu(i,MF_BYPOSITION);
- }
- }
-
-
- for(int i = GetMenu()->GetMenuItemCount()-1;i>=0;i--)
- {
- CString str;
- GetMenu()->GetMenuString(i,str,MF_BYPOSITION);
- if(!str.Compare("Skin"))
- {
- pSkinMenu2 = GetMenu()->GetSubMenu(i);
- break;
- }
- }
- //Remove all skin items from previous skin folder if they were
-
- if(pSkinMenu2)
- for(i=pSkinMenu2->GetMenuItemCount()-1;i>1;i--)
- {
- pSkinMenu2->DeleteMenu(i,MF_BYPOSITION);
- }
-
- while (bWorking)
- {
- bWorking = findFile.FindNextFile();
- if (findFile.IsDots() || findFile.IsDirectory())// skip . and .. files; otherwise, we'd recur infinitely!
- continue;
-
- CString filepath= findFile.GetFilePath();
- CString filename = findFile.GetFileName();
- BSTR a, n, e, d;
- theApp.m_pSkin.GetSkinCopyRight(filepath,&n,&a,&d,&e);
-
- CString key;
- key.Format("%d",count+2222);
- m_MenuMap.SetAt(key,filepath);
-
- if(a)
- SysFreeString(a);
- if(d)
- SysFreeString(d);
- if(e)
- SysFreeString(e);
-
- if(n)
- {
- CString name(n);
- SysFreeString(n);
- if(pSkinMenu)
- pSkinMenu->AppendMenu(MF_STRING|MF_ENABLED,count+2222,name);
- if(pSkinMenu!=pSkinMenu2 && pSkinMenu2)
- pSkinMenu2->AppendMenu(MF_STRING|MF_ENABLED,count+2222,name);
- }
- else
- {
- if(pSkinMenu)
- pSkinMenu->AppendMenu(MF_STRING|MF_ENABLED,count+2222,filename);
- if(pSkinMenu!=pSkinMenu2 && pSkinMenu2)
- pSkinMenu2->AppendMenu(MF_STRING|MF_ENABLED,count+2222,filename);
- }
- count++;
-
- }
- findFile.Close();
-
- }
-
- void CMainFrame::OnSkinSetskindir()
- {
- BROWSEINFO bi;
- char foldername[MAX_PATH];
- ZeroMemory(&bi,sizeof(bi));
- bi.pszDisplayName=foldername;
- bi.hwndOwner=m_hWnd;
- bi.lpfn=(BFFCALLBACK)BrowseProc;
-
- CString title("Select Skin Directory");
- bi.lpszTitle=title;
-
- bi.ulFlags=BIF_RETURNFSANCESTORS | BIF_RETURNONLYFSDIRS;
- LPITEMIDLIST lpid= SHBrowseForFolder(&bi);
- if(lpid)
- { IMalloc* pMalloc;
- SHGetPathFromIDList(lpid,foldername);
- SHGetMalloc(&pMalloc);
- pMalloc->Free((void*) lpid);
- pMalloc->Release();
- theApp.m_strSkinDir.Format("%s",foldername);
- }
-
- FillMenu();
- }
-
- LRESULT CMainFrame::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
- {
- switch(message)
- {
- case WM_COMMAND:
- {
- if(HIWORD(wParam)==0)
- {
- WORD a = LOWORD(wParam);
- CString key,path;
- key.Format("%d",a);
- if(m_MenuMap.Lookup(key,path))
- {
- theApp.m_pSkin.LoadSkinFromFile(path);
- theApp.m_pSkin.ApplySkin();
- theApp.m_pSkin.UpdateControl(0);
-
- }
-
- }
- }
- }
- return CMDIFrameWnd::WindowProc(message, wParam, lParam);
- }
-
- BOOL CMainFrame::OnCmdMsg(UINT nID, int nCode, void* pExtra, AFX_CMDHANDLERINFO* pHandlerInfo)
- {
- switch(nCode)
- {
- case CN_UPDATE_COMMAND_UI:
- {
- CCmdUI* pCui = (CCmdUI*)pExtra;
- if(pCui->m_pMenu)
- {
- CMenu* pM = pCui->m_pMenu;
- CMenu* pSkinMenu, *pSkinMenu2;
- for(int i = CMenu::FromHandle(theApp.m_hMDIMenu)->GetMenuItemCount()-1;i>=0;i--)
- {
- CString str;
- CMenu::FromHandle(theApp.m_hMDIMenu)->GetMenuString(i,str,MF_BYPOSITION);
- if(!str.Compare("Skin"))
- {
- pSkinMenu = CMenu::FromHandle(theApp.m_hMDIMenu)->GetSubMenu(i);
- break;
- }
- }
-
- for(i = GetMenu()->GetMenuItemCount()-1;i>=0;i--)
- {
- CString str;
- GetMenu()->GetMenuString(i,str,MF_BYPOSITION);
- if(!str.Compare("Skin"))
- {
- pSkinMenu2 = GetMenu()->GetSubMenu(i);
- break;
- }
- }
-
- if(pM && (pM == pSkinMenu || pM == pSkinMenu2))
- {
- pCui->Enable(TRUE);
- for(int i=pM->GetMenuItemCount()-1;i>1;i--)
- {
- pM->EnableMenuItem(i,TRUE);
- }
- }
-
- return TRUE;
- }
-
- }
- }
-
- return CMDIFrameWnd::OnCmdMsg(nID, nCode, pExtra, pHandlerInfo);
- }
-