Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

218 lines
6.0 KiB

  1. // KeyRing.cpp : Defines the class behaviors for the application.
  2. //
  3. #include "stdafx.h"
  4. #include <afxdisp.h> // MFC OLE automation classes
  5. #include "KeyRing.h"
  6. #include "MainFrm.h"
  7. #include "KeyObjs.h"
  8. #include "KRDoc.h"
  9. #include "KRView.h"
  10. #ifdef _DEBUG
  11. #define new DEBUG_NEW
  12. #undef THIS_FILE
  13. static char THIS_FILE[] = __FILE__;
  14. #endif
  15. extern CKeyRingDoc* g_pDocument;
  16. // remote machine specified in the command line
  17. CString g_szRemoteCommand;
  18. #define CMD_SEPS _T("/ ")
  19. #define CMD_REMOTE _T("remote:")
  20. /////////////////////////////////////////////////////////////////////////////
  21. // CKeyRingApp
  22. BEGIN_MESSAGE_MAP(CKeyRingApp, CWinApp)
  23. //{{AFX_MSG_MAP(CKeyRingApp)
  24. ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
  25. // NOTE - the ClassWizard will add and remove mapping macros here.
  26. // DO NOT EDIT what you see in these blocks of generated code!
  27. //}}AFX_MSG_MAP
  28. // Standard file based document commands
  29. ON_COMMAND(ID_FILE_NEW, CWinApp::OnFileNew)
  30. ON_COMMAND(ID_FILE_OPEN, CWinApp::OnFileOpen)
  31. // Standard print setup command
  32. ON_COMMAND(ID_FILE_PRINT_SETUP, CWinApp::OnFilePrintSetup)
  33. END_MESSAGE_MAP()
  34. /////////////////////////////////////////////////////////////////////////////
  35. // CKeyRingApp construction
  36. CKeyRingApp::CKeyRingApp():
  37. m_fInitialized( FALSE )
  38. {
  39. }
  40. /////////////////////////////////////////////////////////////////////////////
  41. // The one and only CKeyRingApp object
  42. CKeyRingApp theApp;
  43. int CKeyRingApp::ExitInstance()
  44. {
  45. CoUninitialize();
  46. return CWinApp::ExitInstance();
  47. }
  48. /////////////////////////////////////////////////////////////////////////////
  49. // CKeyRingApp initialization
  50. //----------------------------------------------------------------------
  51. BOOL CKeyRingApp::DealWithParameters()
  52. {
  53. BOOL fAnswer = FALSE;
  54. CString sz = m_lpCmdLine;
  55. sz.TrimRight();
  56. // the first one is easy. If there is no command line, invoke the UI and leave
  57. if ( sz.IsEmpty() )
  58. return FALSE;
  59. // copy the command line into a buffer
  60. TCHAR buff[MAX_PATH];
  61. strcpy( buff, sz );
  62. // just so we don't do it in the loop, initialize the open: string
  63. // length variable
  64. WORD cchConnect = strlen( CMD_REMOTE );
  65. // parse out the arguments
  66. PCHAR pTok;
  67. pTok = strtok( buff, CMD_SEPS );
  68. while ( pTok )
  69. {
  70. // look for the connect: command
  71. if ( _strnicmp(pTok, CMD_REMOTE, cchConnect) == 0 )
  72. {
  73. // just put the command parameter in a string
  74. g_szRemoteCommand = pTok;
  75. g_szRemoteCommand = g_szRemoteCommand.Right(
  76. g_szRemoteCommand.GetLength() - cchConnect );
  77. }
  78. // Get next token
  79. pTok = strtok( NULL, CMD_SEPS );
  80. }
  81. return fAnswer;
  82. }
  83. //----------------------------------------------------------------------
  84. BOOL CKeyRingApp::InitInstance()
  85. {
  86. BOOL f;
  87. HRESULT hRes = CoInitialize(NULL);
  88. AfxEnableControlContainer();
  89. if ( hRes == S_OK )
  90. f = TRUE;
  91. // check for remote specifications on the command line
  92. DealWithParameters();
  93. // Standard initialization
  94. // If you are not using these features and wish to reduce the size
  95. // of your final executable, you should remove from the following
  96. // the specific initialization routines you do not need.
  97. #ifdef _AFXDLL
  98. Enable3dControls(); // Call this when using MFC in a shared DLL
  99. #else
  100. Enable3dControlsStatic(); // Call this when linking to MFC statically
  101. #endif
  102. // Register the application's document templates. Document templates
  103. // serve as the connection between documents, frame windows and views.
  104. CSingleDocTemplate* pDocTemplate;
  105. pDocTemplate = new CSingleDocTemplate(
  106. IDR_MAINFRAME,
  107. RUNTIME_CLASS(CKeyRingDoc),
  108. RUNTIME_CLASS(CMainFrame), // main SDI frame window
  109. RUNTIME_CLASS(CKeyRingView));
  110. AddDocTemplate(pDocTemplate);
  111. // save the command line for later use
  112. CString szCmdLine = m_lpCmdLine;
  113. /*
  114. // kill the command line now that we have caputured it. If we don't do this
  115. // then MFC takes a stab at "opening" the file that is named. Duh. We aren't
  116. // trying to open a file. We want to connect to that machine.
  117. m_lpCmdLine[0] = 0;
  118. */
  119. // Parse command line for standard shell commands, DDE, file open
  120. CCommandLineInfo cmdInfo;
  121. ParseCommandLine(cmdInfo);
  122. // Dispatch commands specified on the command line
  123. if (!ProcessShellCommand(cmdInfo))
  124. return FALSE;
  125. // finally, we need to redirect the winhelp file location to something more desirable
  126. CString sz;
  127. CString szHelpPath;
  128. sz.LoadString( IDS_HELPLOC_KEYRINGHELP );
  129. // expand the path
  130. ExpandEnvironmentStrings(
  131. sz, // pointer to string with environment variables
  132. szHelpPath.GetBuffer(MAX_PATH + 1), // pointer to string with expanded environment variables
  133. MAX_PATH // maximum characters in expanded string
  134. );
  135. szHelpPath.ReleaseBuffer();
  136. // free the existing path, and copy in the new one
  137. free((void*)m_pszHelpFilePath);
  138. m_pszHelpFilePath = _tcsdup(szHelpPath);
  139. return TRUE;
  140. }
  141. //----------------------------------------------------------------------
  142. // App command to run the dialog
  143. void CKeyRingApp::OnAppAbout()
  144. {
  145. // load the about strings
  146. CString szAbout1;
  147. CString szAbout2;
  148. szAbout1.LoadString(IDS_ABOUT_MAIN);
  149. szAbout2.LoadString(IDS_ABOUT_SECONDARY);
  150. // run the shell about dialog
  151. ShellAbout( AfxGetMainWnd()->GetSafeHwnd(), szAbout1,szAbout2, LoadIcon(IDR_MAINFRAME) );
  152. }
  153. /////////////////////////////////////////////////////////////////////////////
  154. // CKeyRingApp commands
  155. BOOL CKeyRingApp::OnIdle(LONG lCount)
  156. {
  157. Sleep(1000);
  158. // the first time we get here, initialize the remote machines
  159. if ( !m_fInitialized )
  160. {
  161. // we are initializing here because it can take some time
  162. // and we want the main window to be showing
  163. ASSERT( g_pDocument );
  164. g_pDocument->Initialize();
  165. // set the flag so we don't do this again
  166. m_fInitialized = TRUE;
  167. }
  168. return CWinApp::OnIdle(lCount);
  169. }