xDialog.cpp
上传用户:louyoung
上传日期:2007-01-02
资源大小:123k
文件大小:3k
源码类别:

ActiveX/DCOM/ATL

开发平台:

Visual C++

  1. // xDialog.cpp : Defines the class behaviors for the application.
  2. //
  3. #include "stdafx.h"
  4. #include "xDialog.h"
  5. #include "xDialogDlg.h"
  6. #ifdef _DEBUG
  7. #define new DEBUG_NEW
  8. #undef THIS_FILE
  9. static char THIS_FILE[] = __FILE__;
  10. #endif
  11. /////////////////////////////////////////////////////////////////////////////
  12. // CXDialogApp
  13. BEGIN_MESSAGE_MAP(CXDialogApp, CWinApp)
  14. //{{AFX_MSG_MAP(CXDialogApp)
  15. // NOTE - the ClassWizard will add and remove mapping macros here.
  16. //    DO NOT EDIT what you see in these blocks of generated code!
  17. //}}AFX_MSG
  18. ON_COMMAND(ID_HELP, CWinApp::OnHelp)
  19. END_MESSAGE_MAP()
  20. /////////////////////////////////////////////////////////////////////////////
  21. // CXDialogApp construction
  22. CXDialogApp::CXDialogApp()
  23. {
  24. // TODO: add construction code here,
  25. // Place all significant initialization in InitInstance
  26. }
  27. /////////////////////////////////////////////////////////////////////////////
  28. // The one and only CXDialogApp object
  29. CXDialogApp theApp;
  30. /////////////////////////////////////////////////////////////////////////////
  31. // CXDialogApp initialization
  32. // Function name : RegisterActiveX
  33. // Description     : Call to register ActiveX control
  34. // Return type : BOOL 
  35. // Argument         : LPCTSTR lpszActiveXFileName
  36. BOOL RegisterActiveX(LPCTSTR lpszActiveXFileName, LPCTSTR lpszFRegister = _T("DllRegisterServer"))
  37. {
  38. static char BASED_CODE szFilter[] = "ActiveX Controls (*.ocx)|*.ocx||";
  39. HINSTANCE hInstance = NULL;
  40. CString sAXFileName(lpszActiveXFileName);
  41. do 
  42. {
  43. if ((hInstance = LoadLibrary(sAXFileName)) == NULL)
  44. {
  45. TRACE(_T("Last error: 0x%08X"), GetLastError());
  46. CString warning;
  47. warning.Format(_T("Load library ""%s"" failed."), sAXFileName);
  48. AfxMessageBox(warning);
  49. CFileDialog fd(TRUE, NULL, sAXFileName, NULL, szFilter , NULL);
  50. if (fd.DoModal() == IDOK)
  51. sAXFileName = fd.GetPathName();
  52. else
  53. break;
  54. }
  55. else
  56. {
  57. FARPROC lpDllEntryPoint = GetProcAddress(hInstance, lpszFRegister);
  58. if (lpDllEntryPoint != NULL)
  59. {
  60. (*lpDllEntryPoint)();
  61. return TRUE;
  62. }
  63. else
  64. {
  65. FreeLibrary(hInstance);
  66. hInstance = NULL;
  67. }
  68. }
  69. } while (hInstance == NULL);
  70. return FALSE;
  71. }
  72. BOOL CXDialogApp::InitInstance()
  73. {
  74. AfxEnableControlContainer();
  75. RegisterActiveX(_T("xFloorWnd.ocx"));
  76. // Standard initialization
  77. // If you are not using these features and wish to reduce the size
  78. //  of your final executable, you should remove from the following
  79. //  the specific initialization routines you do not need.
  80. #ifdef _AFXDLL
  81. Enable3dControls(); // Call this when using MFC in a shared DLL
  82. #else
  83. Enable3dControlsStatic(); // Call this when linking to MFC statically
  84. #endif
  85. CXDialogDlg dlg;
  86. m_pMainWnd = &dlg;
  87. int nResponse = dlg.DoModal();
  88. if (nResponse == IDOK)
  89. {
  90. // TODO: Place code here to handle when the dialog is
  91. //  dismissed with OK
  92. }
  93. else if (nResponse == IDCANCEL)
  94. {
  95. // TODO: Place code here to handle when the dialog is
  96. //  dismissed with Cancel
  97. }
  98. // Since the dialog has been closed, return FALSE so that we exit the
  99. //  application, rather than start the application's message pump.
  100. return FALSE;
  101. }