home *** CD-ROM | disk | FTP | other *** search
/ PC World 2003 June / PCWorld_2003-06_cd.bin / KOMUNIK / MIRRORIT / SRC / MIRRORIT.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1999-02-10  |  8.1 KB  |  344 lines

  1. // MirrorIt.cpp : Defines the class behaviors for the application.
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "MirrorIt.h"
  6.  
  7. #include "MainFrm.h"
  8. #include "MirrorItDoc.h"
  9. #include "MirrorItView.h"
  10. #include <stdio.h>
  11.  
  12. #ifdef _DEBUG
  13. #define new DEBUG_NEW
  14. #undef THIS_FILE
  15. static char THIS_FILE[] = __FILE__;
  16. #endif
  17.  
  18. /////////////////////////////////////////////////////////////////////////////
  19. // CMirrorItApp
  20.  
  21. BEGIN_MESSAGE_MAP(CMirrorItApp, CWinApp)
  22.     //{{AFX_MSG_MAP(CMirrorItApp)
  23.     ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
  24.     //}}AFX_MSG_MAP
  25.     // Standard file based document commands
  26.     ON_COMMAND(ID_FILE_NEW, CWinApp::OnFileNew)
  27.     ON_COMMAND(ID_FILE_OPEN, CWinApp::OnFileOpen)
  28. END_MESSAGE_MAP()
  29.  
  30. /////////////////////////////////////////////////////////////////////////////
  31. // CMirrorItApp construction
  32.  
  33. CMirrorItApp::CMirrorItApp()
  34. {
  35.     // TODO: add construction code here,
  36.     // Place all significant initialization in InitInstance
  37. //    theDumpFile.Open("C:\\1.txt", CFile::modeCreate | CFile::modeWrite);
  38. }
  39.  
  40. /////////////////////////////////////////////////////////////////////////////
  41. // The one and only CMirrorItApp object
  42.  
  43. CMirrorItApp theApp;
  44.  
  45. /////////////////////////////////////////////////////////////////////////////
  46. // CMirrorItApp initialization
  47.  
  48. BOOL CMirrorItApp::InitInstance()
  49. {
  50.     if (!AfxSocketInit())
  51.     {
  52.         AfxMessageBox(IDP_SOCKETS_INIT_FAILED);
  53.         return FALSE;
  54.     }
  55.  
  56.     AfxEnableControlContainer();
  57.  
  58.     // Standard initialization
  59.     // If you are not using these features and wish to reduce the size
  60.     //  of your final executable, you should remove from the following
  61.     //  the specific initialization routines you do not need.
  62.  
  63. #ifdef _AFXDLL
  64.     Enable3dControls();            // Call this when using MFC in a shared DLL
  65. #else
  66.     Enable3dControlsStatic();    // Call this when linking to MFC statically
  67. #endif
  68.  
  69.     // Change the registry key under which our settings are stored.
  70.     // You should modify this string to be something appropriate
  71.     // such as the name of your company or organization.
  72.     SetRegistryKey(_T("CoDe"));
  73.  
  74.     LoadStdProfileSettings();  // Load standard INI file options (including MRU)
  75.     LoadMimeTypes();
  76.  
  77.     // Register the application's document templates.  Document templates
  78.     //  serve as the connection between documents, frame windows and views.
  79.  
  80.     CSingleDocTemplate* pDocTemplate;
  81.     pDocTemplate = new CSingleDocTemplate(
  82.         IDR_MAINFRAME,
  83.         RUNTIME_CLASS(CMirrorItDoc),
  84.         RUNTIME_CLASS(CMainFrame),       // main SDI frame window
  85.         RUNTIME_CLASS(CMirrorItView));
  86.     AddDocTemplate(pDocTemplate);
  87.  
  88.     // Enable DDE Execute open
  89.     EnableShellOpen();
  90.     RegisterShellFileTypes(TRUE);
  91.  
  92.     // Parse command line for standard shell commands, DDE, file open
  93.     CCommandLineInfo cmdInfo;
  94.     ParseCommandLine(cmdInfo);
  95.  
  96.     // Dispatch commands specified on the command line
  97.     if (!ProcessShellCommand(cmdInfo))
  98.         return FALSE;
  99.  
  100.     // The one and only window has been initialized, so show and update it.
  101.     m_pMainWnd->ShowWindow(SW_SHOW);
  102.     m_pMainWnd->UpdateWindow();
  103.  
  104.     // Enable drag/drop open
  105.     m_pMainWnd->DragAcceptFiles();
  106.  
  107.     return TRUE;
  108. }
  109.  
  110. /////////////////////////////////////////////////////////////////////////////
  111. // CAboutDlg dialog used for App About
  112.  
  113. class CAboutDlg : public CDialog
  114. {
  115. public:
  116.     CAboutDlg();
  117.  
  118. // Dialog Data
  119.     //{{AFX_DATA(CAboutDlg)
  120.     enum { IDD = IDD_ABOUTBOX };
  121.     //}}AFX_DATA
  122.  
  123.     // ClassWizard generated virtual function overrides
  124.     //{{AFX_VIRTUAL(CAboutDlg)
  125.     protected:
  126.     virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
  127.     //}}AFX_VIRTUAL
  128.  
  129. // Implementation
  130. protected:
  131.     //{{AFX_MSG(CAboutDlg)
  132.         // No message handlers
  133.     //}}AFX_MSG
  134.     DECLARE_MESSAGE_MAP()
  135. };
  136.  
  137. CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
  138. {
  139.     //{{AFX_DATA_INIT(CAboutDlg)
  140.     //}}AFX_DATA_INIT
  141. }
  142.  
  143. void CAboutDlg::DoDataExchange(CDataExchange* pDX)
  144. {
  145.     CDialog::DoDataExchange(pDX);
  146.     //{{AFX_DATA_MAP(CAboutDlg)
  147.     //}}AFX_DATA_MAP
  148. }
  149.  
  150. BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
  151.     //{{AFX_MSG_MAP(CAboutDlg)
  152.         // No message handlers
  153.     //}}AFX_MSG_MAP
  154. END_MESSAGE_MAP()
  155.  
  156. // App command to run the dialog
  157. void CMirrorItApp::OnAppAbout()
  158. {
  159.     CAboutDlg aboutDlg;
  160.     aboutDlg.DoModal();
  161. }
  162.  
  163. /////////////////////////////////////////////////////////////////////////////
  164. // CMirrorItApp commands
  165.  
  166. void CMirrorItApp::LoadMimeTypes()
  167. {
  168.     int i = GetProfileInt("MimeTypes", "count", -1);
  169.     if (i == -1)
  170.     {
  171.         HANDLE resloc, res;
  172.  
  173.         resloc = FindResource(AfxGetInstanceHandle(), MAKEINTRESOURCE(IDR_MIMETYPES), "MIMETYPES");
  174.         if ((res = LoadResource(AfxGetInstanceHandle(), (HRSRC) resloc)) == 0) return;
  175.         LPSTR str = (LPTSTR) LockResource(res);
  176.         LPSTR strend = str + SizeofResource(AfxGetInstanceHandle(), (HRSRC) resloc);
  177.  
  178.         CString temp;
  179.  
  180.         i = 0;
  181.         while (str < strend)
  182.         {
  183.             if (*str == '\n')
  184.             {
  185.                 AddMimeType(temp, i);
  186.             }
  187.             else
  188.             if (*str != '\r')
  189.             {
  190.                 temp += *str;
  191.             }
  192.             str++;
  193.         }
  194.  
  195.         AddMimeType(temp, i);
  196.  
  197.         WriteProfileInt("MimeTypes", "count", i);
  198.  
  199.         UnlockResource(res);
  200.         FreeResource(res);
  201.     }
  202.     else
  203.     {
  204.         for (int j = 0; j < i; j++)
  205.         {
  206.             CString temp;
  207.             char buf[10];
  208.  
  209.             sprintf(buf, "%ld", j);
  210.             temp = GetProfileString("MimeTypes", buf);
  211.             if (!temp.IsEmpty())
  212.                 m_MimeTypes.AddTail(temp);
  213.         }
  214.     }
  215.  
  216. }
  217.  
  218. void CMirrorItApp::AddMimeType(CString & temp, int & i)
  219. {
  220.     if (!temp.IsEmpty())
  221.     {
  222.         char buf[10];
  223.         sprintf(buf, "%ld", i);
  224.         WriteProfileString("MimeTypes", buf, (LPCSTR) temp);
  225.         i++;
  226.         m_MimeTypes.AddTail(temp);
  227.     }
  228.     temp.Empty();
  229. }
  230.  
  231. int CMirrorItApp::ExitInstance() 
  232. {
  233. //    theDumpFile.Close();
  234.     
  235.     return CWinApp::ExitInstance();
  236. }
  237.  
  238.  
  239. void CMirrorItApp::WinHelp(DWORD dwData, UINT nCmd) 
  240. {
  241. #if 0
  242.     CString dir, help = m_pszHelpFilePath;
  243.  
  244.     dir = help = help.Left(help.ReverseFind('\\'));
  245.     help +=  "\\html\\";
  246. //    AfxMessageBox(help);
  247.     if (nCmd == HELP_CONTEXT)
  248.     {
  249.         switch(dwData)
  250.         {
  251.         case 0x10000 + ID_FILE_NEW:
  252.         case 0x10000 + ID_FILE_OPEN:
  253.         case 0x10000 + ID_FILE_SAVE:
  254.         case 0x10000 + ID_FILE_SAVE_AS:
  255.         case 0x10000 + ID_APP_EXIT:
  256.         case 0x20000 + AFX_IDD_FILEOPEN:
  257.         case 0x20000 + AFX_IDD_FILESAVE:
  258.             help += "filemenu.html";
  259.             break;
  260.  
  261.         case 0x10000 + ID_EDIT_CLEAR:
  262.         case 0x10000 + ID_EDIT_COPY:
  263.         case 0x10000 + ID_EDIT_CUT:
  264.         case 0x10000 + ID_EDIT_PASTE:
  265.             help += "editmenu.html";
  266.             break;
  267.  
  268.         case 0x10000 + IDM_VIEW_LARGEICONS:
  269.         case 0x10000 + IDM_VIEW_SMALLICONS:
  270.         case 0x10000 + IDM_VIEW_LIST:
  271.         case 0x10000 + IDM_VIEW_DETAILS: 
  272.         case 0x10000 + ID_VIEW_TOOLBAR: 
  273.         case 0x10000 + ID_VIEW_STATUS_BAR: 
  274.             help += "viewmenu.html";
  275.             break;
  276.  
  277.         case 0x10000 + ID_SESSION_ADD:
  278.         case 0x10000 + ID_SESSION_REMOVE:
  279.         case 0x10000 + ID_SESSION_PROPERTIES:
  280.         case 0x10000 + ID_SESSION_MOVEUP:
  281.         case 0x10000 + ID_SESSION_MOVEDOWN:
  282.         case 0x10000 + ID_SESSION_START: 
  283.             help += "sessionmenu.html";
  284.             break;
  285.             
  286.         case 0x20000 + IDD_ABOUTBOX:
  287.         case 0x10000 + ID_APP_ABOUT:
  288.             help += "copyright.html";
  289.             break;
  290.  
  291.         case 0x20000 + IDD_DOWNLOAD:
  292.             help += "sessionmenustartdownloading.html";
  293.             break;
  294.             
  295.         case 0x20000 + IDD_SESSIONPROPERTIESMAIN:
  296.             help += "editmenupropertiesgeneral.html";
  297.             break;
  298.             
  299.         case 0x20000 + IDD_SESSIONPROPERTIESMIRROR:
  300.             help += "editmenupropertiesmirror.html";
  301.             break;
  302.             
  303.         case 0x20000 + IDD_SESSIONPROPERTIESFILENAMES:
  304.             help += "editmenupropertiesfilenames.html";
  305.             break;
  306.             
  307.         case 0x20000 + IDD_SESSIONPROPERTIESFILETYPES:
  308.             help += "editmenupropertiesmimetypes.html";
  309.             break;
  310.             
  311.         case 0x20000 + IDD_SESSIONPROPERTIESLIMITS:
  312.             help += "editmenupropertieslimits.html";
  313.             break;
  314.             
  315.         case 0x20000 + IDD_SESSIONPROPERTIESADVANCED:
  316.             help += "editmenupropertiesadvanced.html";
  317.             break;
  318.             
  319.         case 0x20000 + IDD_SESSIONPROPERTIESPROXY:
  320.             help += "editmenupropertiesproxy.html";
  321.             break;
  322.             
  323.         case 0x20000 + IDD_SESSIONPROPERTIESPASSWORD:
  324.             help += "editmenupropertiesauthentication.html";
  325.             break;
  326.             
  327.         default:
  328.             help += "index.html";
  329.         }
  330.     }
  331.     else
  332.     {
  333.         help += "index.html";
  334.     }
  335.     
  336.     int i = (int)::ShellExecute(0, NULL, (LPCSTR)help, NULL, (LPCSTR)dir, SW_SHOWNORMAL);
  337.     if (i < 32)
  338.     {
  339.         AfxMessageBox(IDS_HELPERROR, MB_OK | MB_ICONEXCLAMATION);
  340.     }
  341. #endif    
  342. //    CWinApp::WinHelp(dwData, nCmd);
  343. }
  344.