IDE.cpp 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356
  1. // IDE.cpp : 定义应用程序的类行为。
  2. //
  3. #include "stdafx.h"
  4. #include "IDE.h"
  5. #include "MainFrm.h"
  6. #include "ChildFrm.h"
  7. #include "IDEDoc.h"
  8. #include "IDEView.h"
  9. #include "SysLib.h"
  10. #include ".\ide.h"
  11. #include "StartupDlg.h"
  12. #include "Login.h"
  13. #include "gooddc.h"
  14. #include "public.h"
  15. #include "md5class.h"
  16. //#include "conv.h"
  17. #ifdef _DEBUG
  18. #define new DEBUG_NEW
  19. #endif
  20. extern CRITICAL_SECTION g_CSLimit;
  21. // CIDEApp
  22. BEGIN_MESSAGE_MAP(CIDEApp, CWinApp)
  23. ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
  24. // 基于文件的标准文档命令
  25. ON_COMMAND(ID_FILE_NEW, CWinApp::OnFileNew)
  26. ON_COMMAND(ID_FILE_OPEN, CWinApp::OnFileOpen)
  27. // 标准打印设置命令
  28. ON_COMMAND(ID_FILE_PRINT_SETUP, CWinApp::OnFilePrintSetup)
  29. ON_COMMAND(ID_APP_EXIT, OnAppExit)
  30. END_MESSAGE_MAP()
  31. // CIDEApp 构造
  32. CIDEApp::CIDEApp()
  33. {
  34. // TODO: 在此处添加构造代码,
  35. // 将所有重要的初始化放置在 InitInstance 中
  36. }
  37. // 唯一的一个 CIDEApp 对象
  38. CIDEApp theApp;
  39. CMainFrame *g_pMainFrm = NULL;
  40. // CIDEApp 初始化
  41. HANDLE hMutex;
  42. BOOL CIDEApp::InitInstance()
  43. {
  44. // 如果一个运行在 Windows XP 上的应用程序清单指定要
  45. // 使用 ComCtl32.dll 版本 6 或更高版本来启用可视化方式,
  46. //则需要 InitCommonControls()。否则,将无法创建窗口。
  47. CString StrName="Runner Monitor";
  48. hMutex=OpenMutex(MUTEX_ALL_ACCESS,FALSE,StrName);
  49. if(hMutex==NULL)
  50. {
  51. hMutex=::CreateMutex(NULL,NULL,StrName);
  52. }
  53. else
  54. {
  55. MessageBox(NULL,"运行器已经打开!","温馨提示",MB_ICONINFORMATION);
  56. return FALSE;
  57. }
  58. InitializeCriticalSection(&g_CSLimit);
  59. InitCommonControls();
  60. CoInitialize( NULL );
  61. CWinApp::InitInstance();
  62. //// 初始化 OLE 库
  63. if (!AfxOleInit())
  64. {
  65. AfxMessageBox(IDP_OLE_INIT_FAILED);
  66. return FALSE;
  67. }
  68. AfxEnableControlContainer();
  69. // 标准初始化
  70. // 如果未使用这些功能并希望减小
  71. // 最终可执行文件的大小,则应移除下列
  72. // 不需要的特定初始化例程
  73. // 更改用于存储设置的注册表项
  74. // TODO: 应适当修改该字符串,
  75. // 例如修改为公司或组织名
  76. SetRegistryKey(g_strAppwizardCreateApp);
  77. LoadStdProfileSettings(4); // 加载标准 INI 文件选项(包括 MRU)
  78. // START GDI+ SUB SYSTEM
  79. GdiplusStartup(&m_gdiplusToken, &m_gdiplusStartupInput, NULL);
  80. MTVERIFY( g_hRunObject = ::CreateEvent(
  81. NULL, /* Security */
  82. TRUE, /* Manual event */
  83. 0, /* Clear on creation */
  84. 0 ));//"IDE::g_hRunObject") );
  85. //InitPrintQueue();
  86. GetSysData();
  87. g_Login();
  88. GetResourceString();
  89. CStartupDlg dlg;
  90. dlg.Create(IDD_STARTUP);
  91. char* lpBmpFile = "Bitmap\\home.bmp";
  92. BITMAPFILEHEADER bf;
  93. BITMAPINFOHEADER bi;
  94. FILE* fp = fopen(lpBmpFile,"rb");
  95. if (fp)
  96. {
  97. fread(&bf,sizeof(bf),1,fp);
  98. fread(&bi,sizeof(bi),1,fp);
  99. fclose(fp);
  100. int nCX = GetSystemMetrics(SM_CXSCREEN);
  101. int nCY = GetSystemMetrics(SM_CYSCREEN);
  102. int nW = bi.biWidth;
  103. int nH = bi.biHeight;
  104. dlg.MoveWindow((nCX-nW)/2,(nCY-nH)/2,nW,nH);
  105. }
  106. dlg.ShowWindow(TRUE);
  107. CDC* pDC = dlg.GetDC();
  108. CRect rect;
  109. dlg.GetClientRect(rect);
  110. int screenx=GetSystemMetrics(SM_CXSCREEN);
  111. int screeny=GetSystemMetrics(SM_CYSCREEN);
  112. DisplayBMP(pDC, 0, 0, rect.Width(), rect.Height(), lpBmpFile, FALSE);
  113. dlg.ReleaseDC(pDC);
  114. Sleep(3000);
  115. dlg.ShowWindow(FALSE);
  116. // 注册应用程序的文档模板。文档模板
  117. // 将用作文档、框架窗口和视图之间的连接
  118. CMultiDocTemplate* pDocTemplate;
  119. pDocTemplate = new CMultiDocTemplate(IDR_MAINFRAME,
  120. RUNTIME_CLASS(CIDEDoc),
  121. RUNTIME_CLASS(CChildFrame), // 自定义 MDI 子框架
  122. RUNTIME_CLASS(CIDEView));
  123. AddDocTemplate(pDocTemplate);
  124. // 创建主 MDI 框架窗口
  125. CMainFrame* pMainFrame = new CMainFrame;
  126. pMainFrame->m_pDoc = (CIDEDoc *)pDocTemplate->CreateNewDocument();
  127. if ( !pMainFrame )
  128. {
  129. MessageBox(NULL,"pMainFrame == NULL", g_strTip, MB_ICONWARNING);
  130. return FALSE;
  131. }
  132. if ( !pMainFrame->LoadFrame(IDR_MAINFRAME) )
  133. {
  134. MessageBox(NULL,"资源文件不对1", g_strTip, MB_ICONWARNING);
  135. return FALSE;
  136. }
  137. m_pMainWnd = pMainFrame;
  138. // 仅当具有后缀时才调用 DragAcceptFiles
  139. // 在 MDI 应用程序中,这应在设置 m_pMainWnd 之后立即发生
  140. // 分析标准外壳命令、DDE、打开文件操作的命令行
  141. CCommandLineInfo cmdInfo;
  142. ParseCommandLine(cmdInfo);
  143. // 调度在命令行中指定的命令。如果
  144. // 用 /RegServer、/Register、/Unregserver 或 /Unregister 启动应用程序,则返回 FALSE。
  145. cmdInfo.m_nShellCommand = CCommandLineInfo::FileNothing;
  146. if (!ProcessShellCommand(cmdInfo))
  147. {
  148. MessageBox(NULL,"资源文件不对2", g_strTip, MB_ICONWARNING);
  149. return FALSE;
  150. }
  151. // 主窗口已初始化,因此显示它并对其进行更新
  152. m_pMainWnd->SetWindowText(g_strStoneuIspcms);
  153. pMainFrame->ShowWindow(m_nCmdShow);
  154. //if( g_bFullScreen )
  155. //{
  156. // m_pMainWnd->ShowWindow(SW_SHOWMAXIMIZED);//窗口最大化 关于全屏
  157. //}
  158. pMainFrame->UpdateWindow();
  159. g_pMainFrm = pMainFrame;
  160. return TRUE;
  161. }
  162. int CIDEApp::ExitInstance()
  163. {
  164. // TODO: 在此添加专用代码和/或调用基类
  165. GdiplusShutdown( m_gdiplusToken );
  166. if( g_hRunObject )
  167. MTVERIFY( SetEvent( g_hRunObject ) );
  168. if(g_hLangDLL)
  169. {
  170. AfxFreeLibrary(g_hLangDLL);
  171. }
  172. // Shutdown GDI+ subystem
  173. GdiplusShutdown(m_gdiplusToken);
  174. //释放权限所占的内存
  175. ::CloseHandle( hMutex );
  176. hMutex = NULL;
  177. DeleteCriticalSection( &g_CSLimit );
  178. CoUninitialize();
  179. return CWinApp::ExitInstance();
  180. }
  181. void CIDEApp::OnAppExit()
  182. {
  183. // TODO: 在此添加命令处理程序代码
  184. CMainFrame *pMainFrm=(CMainFrame*)m_pMainWnd;
  185. pMainFrm->m_nViewCount = 0;
  186. pMainFrm->OnSuperEnd();
  187. }
  188. // 用于应用程序“关于”菜单项的 CAboutDlg 对话框
  189. class CAboutDlg : public CDialog
  190. {
  191. public:
  192. CAboutDlg();
  193. // 对话框数据
  194. enum { IDD = IDD_ABOUTBOX };
  195. protected:
  196. virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV 支持
  197. // 实现
  198. protected:
  199. DECLARE_MESSAGE_MAP()
  200. public:
  201. virtual BOOL OnInitDialog();
  202. };
  203. CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
  204. {
  205. }
  206. void CAboutDlg::DoDataExchange(CDataExchange* pDX)
  207. {
  208. CDialog::DoDataExchange(pDX);
  209. }
  210. BOOL CAboutDlg::OnInitDialog()
  211. {
  212. CDialog::OnInitDialog();
  213. // TODO: 在此添加额外的初始化
  214. CString str;
  215. str.Format("【ver:%s】",g_strVersion );
  216. GetDlgItem(IDC_STA_VERSION)->SetWindowText(str);
  217. return TRUE; // return TRUE unless you set the focus to a control
  218. // 异常: OCX 属性页应返回 FALSE
  219. }
  220. BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
  221. END_MESSAGE_MAP()
  222. // 用于运行对话框的应用程序命令
  223. void CIDEApp::OnAppAbout()
  224. {
  225. CAboutDlg aboutDlg;
  226. aboutDlg.DoModal();
  227. }
  228. // CIDEApp 消息处理程序
  229. int CIDEApp::IsNoDlgLogin()//自动登录 -1:不是 0:失败 1:成功
  230. {
  231. int nRet = -1;
  232. CHAR strFile[MAX_FILE_LENGTH + 1] = "";
  233. wsprintf(strFile, "%s\\set.ini", g_strDirectory);
  234. char RUN[MAX_PATH] = {0};
  235. memset(RUN, 0, sizeof(RUN));
  236. ////是否是没对话框登录
  237. //if ( GetPrivateProfileString("User", "NoDlgLogin","",RUN, 10, strFile) != 0)
  238. //{
  239. // if( RUN[0] == '0' )
  240. // return nRet;
  241. //}
  242. //WritePrivateProfileString("User", "NoDlgLogin", "0", strFile);
  243. if( g_iAutoRunSystem==0 )
  244. return nRet;
  245. GetPrivateProfileString("User", "UserID","", g_strLoginUserID,sizeof(g_strLoginUserID), strFile );
  246. memset(g_strDefaultUserID, 0, sizeof(g_strDefaultUserID) );
  247. strcpy(g_strDefaultUserID, g_strLoginUserID);
  248. GetPrivateProfileString("User", "UserPwd","", g_strLoginPwd,sizeof(g_strLoginPwd), strFile );
  249. memset(g_strDefaultUserPwd, 0, sizeof(g_strDefaultUserPwd) );
  250. strcpy(g_strDefaultUserPwd, g_strLoginPwd);
  251. CString sUserID,sUserPwd;
  252. sUserID = g_strLoginUserID;
  253. sUserPwd = g_strLoginPwd;
  254. if( sUserID=="" || sUserPwd=="" )
  255. return nRet;
  256. ///////////////////////////////////////////////////////////////////////////////
  257. char Path[_MAX_PATH] = {0};
  258. strcat(Path, g_strDirectory);
  259. strcat(Path,"\\");
  260. strcat(Path, _PROJECTDIR);
  261. strcat(Path,"\\");
  262. strcat(Path, "runpara.ini");
  263. //CString str;
  264. if ( GetPrivateProfileString("RUNPARA", "STARTRUN","",RUN, 10, Path) != 0)
  265. {
  266. g_bStartRun = (RUN[0] == '1' ? true:false);
  267. }
  268. if ( GetPrivateProfileString("RUNPARA", "FULLSCREEN","",RUN, 10, Path) != 0)
  269. {
  270. g_bFullScreen = RUN[0] == '1' ? true:false;
  271. }
  272. CMD5 md5;
  273. md5.setPlainText( (char *)(LPCTSTR)sUserPwd );
  274. if( ( ( strcmp(g_strDefaultUserPwd, "") != 0 ) && (strcmp(g_strLoginUserID, (char*)(LPCTSTR)sUserID) != 0 ) ) ||
  275. ( strcmp(g_strDefaultUserPwd, "") == 0 ) ||
  276. (strcmp(g_strLoginUserID, (char*)(LPCTSTR)sUserID) != 0 ) ||
  277. ( strcmp(g_strDefaultUserPwd, sUserPwd) != 0 ) ||
  278. (strcmp(g_strLoginUserID, "") == 0) )
  279. {
  280. sUserPwd = CString(md5.getMD5Digest());
  281. }
  282. return 1;
  283. }