tcStatic.cpp 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. // tcStatic.cpp : 定义应用程序的类行为。
  2. //
  3. #include "stdafx.h"
  4. #include "tcStatic.h"
  5. #include "TcStaticDlg.h"
  6. #ifdef _DEBUG
  7. #define new DEBUG_NEW
  8. #endif
  9. // TcStaticApp
  10. BEGIN_MESSAGE_MAP(TcStaticApp, CWinApp)
  11. ON_COMMAND(ID_HELP, &CWinApp::OnHelp)
  12. END_MESSAGE_MAP()
  13. // TcStaticApp 构造
  14. TcStaticApp::TcStaticApp()
  15. {
  16. // TODO: 在此处添加构造代码,
  17. // 将所有重要的初始化放置在 InitInstance 中
  18. }
  19. // 唯一的一个 TcStaticApp 对象
  20. TcStaticApp theApp;
  21. const GUID CDECL BASED_CODE _tlid =
  22. { 0x7728D3E4, 0xA4E8, 0x400B, { 0xA6, 0xA5, 0x62, 0xFB, 0x3B, 0x6E, 0xC, 0xD1 } };
  23. const WORD _wVerMajor = 1;
  24. const WORD _wVerMinor = 0;
  25. // TcStaticApp 初始化
  26. BOOL TcStaticApp::InitInstance()
  27. {
  28. // 如果一个运行在 Windows XP 上的应用程序清单指定要
  29. // 使用 ComCtl32.dll 版本 6 或更高版本来启用可视化方式,
  30. //则需要 InitCommonControlsEx()。否则,将无法创建窗口。
  31. INITCOMMONCONTROLSEX InitCtrls;
  32. InitCtrls.dwSize = sizeof(InitCtrls);
  33. // 将它设置为包括所有要在应用程序中使用的
  34. // 公共控件类。
  35. InitCtrls.dwICC = ICC_WIN95_CLASSES;
  36. InitCommonControlsEx(&InitCtrls);
  37. CWinApp::InitInstance();
  38. if (!AfxSocketInit())
  39. {
  40. AfxMessageBox(IDP_SOCKETS_INIT_FAILED);
  41. return FALSE;
  42. }
  43. // 初始化 OLE 库
  44. if (!AfxOleInit())
  45. {
  46. AfxMessageBox(IDP_OLE_INIT_FAILED);
  47. return FALSE;
  48. }
  49. AfxEnableControlContainer();
  50. // 标准初始化
  51. // 如果未使用这些功能并希望减小
  52. // 最终可执行文件的大小,则应移除下列
  53. // 不需要的特定初始化例程
  54. // 更改用于存储设置的注册表项
  55. // TODO: 应适当修改该字符串,
  56. // 例如修改为公司或组织名
  57. SetRegistryKey(_T("应用程序向导生成的本地应用程序"));
  58. // 分析自动化开关或注册/注销开关的命令行。
  59. CCommandLineInfo cmdInfo;
  60. ParseCommandLine(cmdInfo);
  61. // 应用程序是用 /Embedding 或 /Automation 开关启动的。
  62. //使应用程序作为自动化服务器运行。
  63. if (cmdInfo.m_bRunEmbedded || cmdInfo.m_bRunAutomated)
  64. {
  65. // 通过 CoRegisterClassObject() 注册类工厂。
  66. COleTemplateServer::RegisterAll();
  67. }
  68. // 应用程序是用 /Unregserver 或 /Unregister 开关启动的。移除
  69. // 注册表中的项。
  70. else if (cmdInfo.m_nShellCommand == CCommandLineInfo::AppUnregister)
  71. {
  72. COleObjectFactory::UpdateRegistryAll(FALSE);
  73. AfxOleUnregisterTypeLib(_tlid, _wVerMajor, _wVerMinor);
  74. return FALSE;
  75. }
  76. // 应用程序是以独立方式或用其他开关(如 /Register
  77. // 或 /Regserver)启动的。更新注册表项,包括类型库。
  78. else
  79. {
  80. COleObjectFactory::UpdateRegistryAll();
  81. AfxOleRegisterTypeLib(AfxGetInstanceHandle(), _tlid);
  82. if (cmdInfo.m_nShellCommand == CCommandLineInfo::AppRegister)
  83. return FALSE;
  84. }
  85. TcStaticDlg dlg;
  86. m_pMainWnd = &dlg;
  87. INT_PTR nResponse = dlg.DoModal();
  88. if (nResponse == IDOK)
  89. {
  90. // TODO: 在此放置处理何时用
  91. // “确定”来关闭对话框的代码
  92. }
  93. else if (nResponse == IDCANCEL)
  94. {
  95. // TODO: 在此放置处理何时用
  96. // “取消”来关闭对话框的代码
  97. }
  98. // 由于对话框已关闭,所以将返回 FALSE 以便退出应用程序,
  99. // 而不是启动应用程序的消息泵。
  100. return FALSE;
  101. }