SocketServer.cpp 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. // SocketServer.cpp : Defines the class behaviors for the application.
  2. //
  3. #include "stdafx.h"
  4. #include "SocketHandle.h"
  5. #include "SocketServer.h"
  6. #include "SocketServerDlg.h"
  7. #include "SocketClientDlg.h"
  8. #ifdef _DEBUG
  9. #define new DEBUG_NEW
  10. #endif
  11. // CSocketServerApp
  12. BEGIN_MESSAGE_MAP(CSocketServerApp, CWinApp)
  13. ON_COMMAND(ID_HELP, &CWinApp::OnHelp)
  14. END_MESSAGE_MAP()
  15. // CSocketServerApp construction
  16. CSocketServerApp::CSocketServerApp()
  17. {
  18. // TODO: add construction code here,
  19. // Place all significant initialization in InitInstance
  20. m_nLinkMode = 0; // server
  21. }
  22. // The one and only CSocketServerApp object
  23. CSocketServerApp theApp;
  24. // CSocketServerApp initialization
  25. BOOL CSocketServerApp::InitInstance()
  26. {
  27. // InitCommonControlsEx() is required on Windows XP if an application
  28. // manifest specifies use of ComCtl32.dll version 6 or later to enable
  29. // visual styles. Otherwise, any window creation will fail.
  30. INITCOMMONCONTROLSEX InitCtrls;
  31. InitCtrls.dwSize = sizeof(InitCtrls);
  32. // Set this to include all the common control classes you want to use
  33. // in your application.
  34. InitCtrls.dwICC = ICC_WIN95_CLASSES;
  35. InitCommonControlsEx(&InitCtrls);
  36. CSocketHandle::InitLibrary( MAKEWORD(2,2) );
  37. CWinApp::InitInstance();
  38. AfxEnableControlContainer();
  39. // Standard initialization
  40. // If you are not using these features and wish to reduce the size
  41. // of your final executable, you should remove from the following
  42. // the specific initialization routines you do not need
  43. // Change the registry key under which our settings are stored
  44. // TODO: You should modify this string to be something appropriate
  45. // such as the name of your company or organization
  46. SetRegistryKey(_T("Local AppWizard-Generated Applications"));
  47. //ParseCommandLineArgs();
  48. CSocketServerDlg dlg1;
  49. CSocketClientDlg dlg2;
  50. switch( m_nLinkMode )
  51. {
  52. case 1:
  53. m_pMainWnd = &dlg2; // Client
  54. break;
  55. case 0:
  56. default:
  57. m_pMainWnd = &dlg1; // Server
  58. break;
  59. }
  60. INT_PTR nResponse = ((CDialog*)m_pMainWnd)->DoModal();
  61. if (nResponse == IDOK)
  62. {
  63. // TODO: Place code here to handle when the dialog is
  64. // dismissed with OK
  65. }
  66. else if (nResponse == IDCANCEL)
  67. {
  68. // TODO: Place code here to handle when the dialog is
  69. // dismissed with Cancel
  70. }
  71. CSocketHandle::ReleaseLibrary();
  72. // Since the dialog has been closed, return FALSE so that we exit the
  73. // application, rather than start the application's message pump.
  74. return FALSE;
  75. }
  76. void CSocketServerApp::ParseCommandLineArgs()
  77. {
  78. CString strCmdLine = m_lpCmdLine;
  79. if (!strCmdLine.IsEmpty())
  80. {
  81. strCmdLine.MakeUpper();
  82. while( !strCmdLine.IsEmpty() )
  83. {
  84. CString strCurrent = strCmdLine;
  85. int nNextPos = strCmdLine.Find(TCHAR(' '));
  86. if (nNextPos > 0)
  87. {
  88. strCurrent = strCmdLine.Left( nNextPos );
  89. strCmdLine.Delete(0, nNextPos+1);
  90. }
  91. else
  92. {
  93. strCurrent = strCmdLine;
  94. strCmdLine = _T("");
  95. }
  96. if (strCurrent == _T("/SERVER") || strCurrent == _T("/S") )
  97. m_nLinkMode = 0;
  98. else if (strCurrent == _T("/CLIENT") || strCurrent == _T("/C") )
  99. m_nLinkMode = 1;
  100. }
  101. }
  102. }