home *** CD-ROM | disk | FTP | other *** search
/ Mastering MFC Development / MMD.ISO / labs / c11 / lab04 / ex01 / gpsnk / gpsnk.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1997-02-20  |  2.3 KB  |  90 lines

  1. // gpsnk.cpp : Defines the class behaviors for the application.
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "gpsnk.h"
  6. #include "gpsnkDlg.h"
  7. #include "GpsSocket.h"
  8.  
  9. #ifdef _DEBUG
  10. #define new DEBUG_NEW
  11. #undef THIS_FILE
  12. static char THIS_FILE[] = __FILE__;
  13. #endif
  14.  
  15. /////////////////////////////////////////////////////////////////////////////
  16. // CGpsnkApp
  17.  
  18. BEGIN_MESSAGE_MAP(CGpsnkApp, CWinApp)
  19.     //{{AFX_MSG_MAP(CGpsnkApp)
  20.         // NOTE - the ClassWizard will add and remove mapping macros here.
  21.         //    DO NOT EDIT what you see in these blocks of generated code!
  22.     //}}AFX_MSG
  23.     ON_COMMAND(ID_HELP, CWinApp::OnHelp)
  24. END_MESSAGE_MAP()
  25.  
  26. /////////////////////////////////////////////////////////////////////////////
  27. // CGpsnkApp construction
  28.  
  29. CGpsnkApp::CGpsnkApp()
  30. {
  31.     // TODO: add construction code here,
  32.     // Place all significant initialization in InitInstance
  33. }
  34.  
  35. /////////////////////////////////////////////////////////////////////////////
  36. // The one and only CGpsnkApp object
  37.  
  38. CGpsnkApp theApp;
  39.  
  40. /////////////////////////////////////////////////////////////////////////////
  41. // CGpsnkApp initialization
  42.  
  43. BOOL CGpsnkApp::InitInstance()
  44. {
  45.     if (!AfxSocketInit())
  46.     {
  47.         AfxMessageBox(IDP_SOCKETS_INIT_FAILED);
  48.         return FALSE;
  49.     }
  50.  
  51.     // Standard initialization
  52.     // If you are not using these features and wish to reduce the size
  53.     //  of your final executable, you should remove from the following
  54.     //  the specific initialization routines you do not need.
  55.  
  56. #ifdef _AFXDLL
  57.     Enable3dControls();            // Call this when using MFC in a shared DLL
  58. #else
  59.     Enable3dControlsStatic();    // Call this when linking to MFC statically
  60. #endif
  61.  
  62.     // Initialize a dialog.
  63.     CGpsnkDlg dlg;
  64.     m_pMainWnd = &dlg;
  65.  
  66.     // Create a listening datagram socket at port 1088.
  67.     CGpsSocket* pSocket= new CGpsSocket(&dlg);
  68.     pSocket->Create(1088, SOCK_DGRAM);
  69.     pSocket->Listen();
  70.  
  71.     int nResponse = dlg.DoModal();
  72.     if (nResponse == IDOK)
  73.     {
  74.         // TODO: Place code here to handle when the dialog is
  75.         //  dismissed with OK
  76.     }
  77.     else if (nResponse == IDCANCEL)
  78.     {
  79.         // TODO: Place code here to handle when the dialog is
  80.         //  dismissed with Cancel
  81.     }
  82.  
  83.     // We're closing down, delete socket.
  84.     delete pSocket;
  85.  
  86.     // Since the dialog has been closed, return FALSE so that we exit the
  87.     //  application, rather than start the application's message pump.
  88.     return FALSE;
  89. }
  90.