MainFrm.cpp 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509
  1. // MainFrm.cpp : implementation of the CMainFrame class
  2. //
  3. #include "stdafx.h"
  4. #include "LYFZSendMsg.h"
  5. #include "resource.h"
  6. #include "MainFrm.h"
  7. #include "TakeFrom.h"
  8. #include "DesignFrom.h"
  9. #include "ChoosePhotoSkin.h"
  10. #include "SqlDlg.h"
  11. #include "MyAccount.h"
  12. #include "LogForm.h"
  13. #include <Mmsystem.h>
  14. #ifdef _DEBUG
  15. #define new DEBUG_NEW
  16. #undef THIS_FILE
  17. static char THIS_FILE[] = __FILE__;
  18. #endif
  19. //extern CMainCtrl g_tMainCtrl;
  20. extern int g_bDebug;
  21. #define IPC_CUSTOM_MSG2 _T("{a4Fa76E2-w78F-2aD5-q98A-Y0B0D078u2}")
  22. UINT g_wmClose = RegisterWindowMessage(IPC_CUSTOM_MSG2);
  23. #define WM_ICON_NOTIFY WM_USER+12
  24. extern HWND g_hConnectWnd;
  25. CRect g_rc;
  26. CMainFrame *g_pMainWnd=NULL;
  27. HWND g_hSendWnd=NULL;
  28. extern CString newGUID();
  29. BOOL g_bNeedCoon=1;
  30. BOOL g_bAutoRun=0;
  31. /////////////////////////////////////////////////////////////////////////////
  32. // CMainFrame
  33. /////////////////////////////////////////////////////////////////////////////
  34. float m_WidthScale;
  35. float m_HeightScale;
  36. BOOL CALLBACK EnumChildProc(HWND hwnd,LPARAM lParam)
  37. {
  38. CRect rtCtrl,rtWnd;
  39. if(hwnd)
  40. {
  41. ::GetWindowRect(hwnd,&rtCtrl);
  42. ::GetWindowRect(GetParent(hwnd),&rtWnd);
  43. rtCtrl.OffsetRect(-rtWnd.left,-rtWnd.top);
  44. float temp;
  45. temp= (float)rtCtrl.left*m_WidthScale;
  46. rtCtrl.left = (int)temp;
  47. temp= (float)rtCtrl.top*m_HeightScale;
  48. rtCtrl.top = (int)temp;
  49. temp = (float)rtCtrl.right*m_WidthScale;
  50. rtCtrl.right = (int)temp;
  51. temp =(float)rtCtrl.bottom*m_HeightScale;
  52. rtCtrl.bottom =(int)temp;
  53. ::MoveWindow(hwnd,rtCtrl.left,rtCtrl.top,rtCtrl.Width(),rtCtrl.Height(),TRUE);
  54. return TRUE;
  55. }
  56. else
  57. {
  58. return FALSE;
  59. }
  60. }
  61. IMPLEMENT_DYNCREATE(CMainFrame, CMDIFrameWnd)
  62. BEGIN_MESSAGE_MAP(CMainFrame, CMDIFrameWnd)
  63. //{{AFX_MSG_MAP(CMainFrame)
  64. ON_WM_CREATE()
  65. ON_WM_DESTROY()
  66. ON_WM_CLOSE()
  67. ON_WM_TIMER()
  68. ON_COMMAND(IDM_TODAY, OnToday)
  69. ON_COMMAND(IDM_DINDAN, OnDindan)
  70. ON_COMMAND(IDM_MSGREG, OnMsgreg)
  71. ON_COMMAND(IDM_EXIT, OnExit)
  72. ON_COMMAND(IDM_OPEN, OnOpen)
  73. ON_COMMAND(IDM_AUTORUN, OnAutorun)
  74. ON_COMMAND(IDM_CLIENTIP, OnClientip)
  75. ON_WM_NCLBUTTONDBLCLK()
  76. ON_WM_NCHITTEST()
  77. ON_COMMAND(IDM_LOG, OnLog)
  78. //}}AFX_MSG_MAP
  79. ON_MESSAGE(WM_ICON_NOTIFY, OnTrayNotification)
  80. ON_REGISTERED_MESSAGE(g_wmClose, OnAbortClose)
  81. END_MESSAGE_MAP()
  82. static UINT indicators[] =
  83. {
  84. ID_SEPARATOR, // status line indicator
  85. ID_INDICATOR_CAPS,
  86. ID_INDICATOR_NUM,
  87. ID_INDICATOR_SCRL,
  88. };
  89. LRESULT CMainFrame::OnAbortClose(WPARAM wParam, LPARAM lParam)
  90. {
  91. return 1;
  92. }
  93. /////////////////////////////////////////////////////////////////////////////
  94. // CMainFrame construction/destruction
  95. #if defined(VC70) || defined(VC60)
  96. UINT CMainFrame::OnNcHitTest(CPoint point)
  97. {
  98. if (CWnd::OnNcHitTest(point) == HTRIGHT || CWnd::OnNcHitTest(point) == HTLEFT || CWnd::OnNcHitTest(point) == HTTOP || CWnd::OnNcHitTest(point) == HTBOTTOM)
  99. return HTCLIENT;
  100. return CWnd::OnNcHitTest(point);
  101. }
  102. #else
  103. LRESULT CMainFrame::OnNcHitTest(CPoint point)
  104. {
  105. if (CWnd::OnNcHitTest(point) == HTRIGHT || CWnd::OnNcHitTest(point) == HTLEFT || CWnd::OnNcHitTest(point) == HTTOP || CWnd::OnNcHitTest(point) == HTBOTTOM)
  106. return HTCLIENT;
  107. return CWnd::OnNcHitTest(point);
  108. }
  109. #endif
  110. void CMainFrame::OnNcLButtonDblClk(UINT nFlags, CPoint point)
  111. {
  112. if(nFlags != HTCAPTION)
  113. CMDIFrameWnd::OnNcLButtonDblClk(nFlags, point);
  114. }
  115. CMainFrame::CMainFrame()
  116. {
  117. // TODO: add member initialization code here
  118. m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
  119. CString version = _T ("Version 1.0");
  120. g_bAutoRun=AfxGetApp()->GetProfileInt (version, "brun", 0);
  121. }
  122. CMainFrame::~CMainFrame()
  123. {
  124. }
  125. void LoadImageFromFile(Bitmap **img, CString path)
  126. {
  127. try
  128. {
  129. if(!::PathFileExists (path))return;
  130. if(*img)delete *img;
  131. *img=NULL;
  132. BSTR bstr= path.AllocSysString();
  133. *img= Bitmap::FromFile(bstr);
  134. SysFreeString(bstr);
  135. }
  136. catch(...)
  137. {
  138. }
  139. }
  140. int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
  141. {
  142. if (CMDIFrameWnd::OnCreate(lpCreateStruct) == -1)
  143. return -1;
  144. if(!m_wndClient.SubclassWindow (m_hWndMDIClient))
  145. {
  146. return -1;
  147. }
  148. if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP
  149. | CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
  150. !m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
  151. {
  152. TRACE0("Failed to create toolbar\n");
  153. return -1; // fail to create
  154. }
  155. m_wndToolBar.LoadTrueColorToolBar(90, IDB_NORMAL, 0, IDB_DISABLE);
  156. // second toolbar must have different ID
  157. // TODO: Delete these three lines if you don't want the toolbar to
  158. // be dockable
  159. ::GetWindowRect (this->m_hWndMDIClient, g_rc);
  160. g_pMainWnd=this;
  161. m_WidthScale = (float)g_rc.Width ()/722;
  162. m_HeightScale = (float)g_rc.Height ()/533;
  163. WriteLogin("启动成功");
  164. m_TrayIcon.Create(this,WM_ICON_NOTIFY,"信息服务器" ,m_hIcon,IDR_MENUtray); //构造
  165. OnClose(); // 隐藏窗口;
  166. // 运行线程,处理短信发送;
  167. ((CLYFZSendMsgApp*)AfxGetApp())->RunThread();
  168. SetTimer (1, 10*60*1000, NULL); // OnTimer 打开其他程序;
  169. return 0;
  170. }
  171. BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
  172. {
  173. if( !CMDIFrameWnd::PreCreateWindow(cs) )
  174. return FALSE;
  175. // TODO: Modify the Window class or styles here by modifying
  176. // the CREATESTRUCT cs
  177. cs.style&=~WS_MAXIMIZEBOX;
  178. cs.style&=~WS_THICKFRAME;
  179. RECT rect;
  180. HWND hWnd = ::FindWindow("Shell_TrayWnd", 0);
  181. ::GetWindowRect(hWnd,&rect);
  182. cs.x=0;
  183. cs.y=0;
  184. cs.cx=GetSystemMetrics(SM_CXSCREEN);
  185. cs.cy=GetSystemMetrics(SM_CYSCREEN)-(rect.bottom -rect.top)+3;
  186. return TRUE;
  187. }
  188. /////////////////////////////////////////////////////////////////////////////
  189. // CMainFrame diagnostics
  190. #ifdef _DEBUG
  191. void CMainFrame::AssertValid() const
  192. {
  193. CMDIFrameWnd::AssertValid();
  194. }
  195. void CMainFrame::Dump(CDumpContext& dc) const
  196. {
  197. CMDIFrameWnd::Dump(dc);
  198. }
  199. #endif //_DEBUG
  200. /////////////////////////////////////////////////////////////////////////////
  201. // CMainFrame message handlers
  202. void CMainFrame::OnDestroy()
  203. {
  204. m_Mdi.DeleteAll();
  205. CMDIFrameWnd::OnDestroy();
  206. }
  207. void CMainFrame::OnClose()
  208. {
  209. // TODO: Add your message handler code here and/or call default
  210. ShowWindow(SW_HIDE); //隐藏窗口
  211. }
  212. LRESULT CMainFrame::OnTrayNotification(WPARAM wParam,LPARAM lParam)
  213. {
  214. return m_TrayIcon.OnTrayNotification(wParam,lParam);
  215. }
  216. ///////////////////////////////////////////////////////
  217. //减少代码
  218. #define OPEN_MENU(x) m_Mdi.Append(pName, RUNTIME_CLASS(x), IDR_MAINFRAME, this, nID)
  219. //减少代码
  220. ///////////////////////////////////////////////////////////////////////////////
  221. DWORD CMainFrame::GetConnectionID()
  222. {
  223. return m_dwConnectionID;
  224. }
  225. void CMainFrame::SetConnectionID(DWORD dwConnection)
  226. {
  227. m_dwConnectionID = dwConnection;
  228. }
  229. void CMainFrame::ProcessChatMessageRequest2(BYTE code)
  230. {
  231. }
  232. void CMainFrame::ProcessChatMessageRequest2(CString sql)
  233. {
  234. }
  235. void CMainFrame::ProcessChatMessageRequest2(BYTE *pData, int length)
  236. {
  237. }
  238. BOOL CMainFrame::ProcessChatMessageRequest(void *szDataBuf, int nDataLen)
  239. {
  240. return 1;
  241. }
  242. //ACEESS+TCPIP实现网络版
  243. BOOL CMainFrame::OnConnect()
  244. {
  245. return 1;
  246. }
  247. void CMainFrame::ProcessNetEvent(int nEventType, void *pRecvMsg, DWORD dwDataLen)
  248. {
  249. ///////
  250. }
  251. void CMainFrame::OnTimer(UINT nIDEvent)
  252. {
  253. // TODO: Add your message handler code here and/or call default
  254. if(nIDEvent==1 && g_bDebug==0)
  255. {
  256. ShellExecute(NULL, _T("open"), g_mainpath+"\\AutoRun2.exe", NULL, NULL, SW_SHOWNORMAL);
  257. ShellExecute(NULL, _T("open"), g_mainpath+"\\AutoRun3.exe", NULL, NULL, SW_SHOWNORMAL);
  258. ShellExecute(NULL, _T("open"), g_mainpath+"\\LYFZReceiveMsg.exe", "0", NULL, SW_SHOWNORMAL);
  259. ShellExecute(NULL, _T("open"), g_mainpath+"\\LYFZReceiveMsg.exe", "1", NULL, SW_SHOWNORMAL);
  260. ShellExecute(NULL, _T("open"), g_mainpath+"\\LYFZReceiveMsg.exe", "2", NULL, SW_SHOWNORMAL);
  261. ShellExecute(NULL, _T("open"), g_mainpath+"\\LYFZReceiveMsg.exe", "3", NULL, SW_SHOWNORMAL);
  262. ShellExecute(NULL, _T("open"), g_mainpath+"\\LYFZReceiveMsg.exe", "4", NULL, SW_SHOWNORMAL);
  263. ShellExecute(NULL, _T("open"), g_mainpath+"\\LYFZReceiveMsg.exe", "5", NULL, SW_SHOWNORMAL);
  264. ShellExecute(NULL, _T("open"), g_mainpath+"\\LYFZReceiveMsg.exe", "6", NULL, SW_SHOWNORMAL);
  265. ShellExecute(NULL, _T("open"), g_mainpath+"\\LYFZIPReceive.exe", "0", NULL, SW_SHOWNORMAL);
  266. ShellExecute(NULL, _T("open"), g_mainpath+"\\LYFZIPReceive.exe", "1", NULL, SW_SHOWNORMAL);
  267. ShellExecute(NULL, _T("open"), g_mainpath+"\\LYFZIPReceive.exe", "2", NULL, SW_SHOWNORMAL);
  268. ShellExecute(NULL, _T("open"), g_mainpath+"\\LYFZIPReceive.exe", "3", NULL, SW_SHOWNORMAL);
  269. ShellExecute(NULL, _T("open"), g_mainpath+"\\LYFZIPReceive.exe", "4", NULL, SW_SHOWNORMAL);
  270. ShellExecute(NULL, _T("open"), g_mainpath+"\\LYFZIPReceive.exe", "5", NULL, SW_SHOWNORMAL);
  271. ShellExecute(NULL, _T("open"), g_mainpath+"\\LYFZIPReceive.exe", "6", NULL, SW_SHOWNORMAL);
  272. }
  273. }
  274. void CMainFrame::ProcessLoginResponse(void *pLoginResult)
  275. {
  276. }
  277. BOOL CMainFrame::ProcessLoginRequest()
  278. {
  279. return 1;
  280. }
  281. void CMainFrame::OnOutbarNotify(CString strMsg)
  282. {
  283. }
  284. void CMainFrame::AutoUpdate()
  285. {
  286. }
  287. BOOL g_bInSkin=0;
  288. BOOL CMainFrame::PreTranslateMessage(MSG* pMsg)
  289. {
  290. // TODO: Add your specialized code here and/or call the base class
  291. if(pMsg->message==WM_KEYDOWN)
  292. {
  293. switch (pMsg->wParam)
  294. {
  295. case VK_F3:
  296. ChangePsw();
  297. break;
  298. }
  299. }
  300. return CMDIFrameWnd::PreTranslateMessage(pMsg);
  301. }
  302. void CMainFrame::GetSkin()
  303. {
  304. }
  305. void CMainFrame::PrintDinDan(CString m_id)
  306. {
  307. }
  308. void CMainFrame::SetSelFolder(int pos)
  309. {
  310. }
  311. void CMainFrame::ToPhotoPrint()
  312. {
  313. }
  314. void CMainFrame::GetOcx()
  315. {
  316. }
  317. CArray<CStringArray, CStringArray>g_List1array;
  318. DWORD g_nLeng=0;
  319. BYTE *g_pData=NULL;
  320. void CMainFrame::ProcessChatMessageResponse(void *pResponse)
  321. {
  322. }
  323. void CMainFrame::AddHistoryMenu(CArray<CStringArray, CStringArray>*hisyeararray)
  324. {
  325. }
  326. void CMainFrame::OnHistory(UINT nID)
  327. {
  328. }
  329. void CMainFrame::PrintDinDan2(CString m_id)
  330. {
  331. }
  332. void CMainFrame::OnToday()
  333. {
  334. // TODO: Add your command handler code here
  335. // TODO: Add your command handler code here
  336. UINT nID=1;
  337. LPSTR pName ;
  338. pName = (LPSTR)(LPCSTR)"客户资料";
  339. OPEN_MENU(TakeFrom);
  340. }
  341. void CMainFrame::OnDindan()
  342. {
  343. UINT nID=1;
  344. LPSTR pName ;
  345. pName = (LPSTR)(LPCSTR)"我的账户";
  346. OPEN_MENU(MyAccount);
  347. }
  348. void CMainFrame::ChangePsw()
  349. {
  350. }
  351. void CMainFrame::OnMsgreg()
  352. {
  353. // TODO: Add your command handler code here
  354. UINT nID=1;
  355. LPSTR pName ;
  356. pName = (LPSTR)(LPCSTR)"发送记录";
  357. OPEN_MENU(DesignFrom);
  358. }
  359. extern DWORD FindAppProcessID(CString path);
  360. void CMainFrame::OnExit()
  361. {
  362. // TODO: Add your command handler code here
  363. ((CLYFZSendMsgApp*)AfxGetApp())->TerminateThread();
  364. m_TrayIcon.RemoveIcon();
  365. if(m_Mdi.MainClose())
  366. CMDIFrameWnd::OnClose();
  367. // exit(-1);
  368. }
  369. void CMainFrame::OnOpen()
  370. {
  371. // TODO: Add your command handler code here
  372. ShowWindow(SW_SHOW);
  373. }
  374. void CMainFrame::OnAutorun()
  375. {
  376. // TODO: Add your command handler code here
  377. g_bAutoRun=!g_bAutoRun;
  378. CString version = _T ("Version 1.0");
  379. AfxGetApp()->WriteProfileInt (version, "brun", g_bAutoRun);
  380. TCHAR szKey[MAX_PATH];
  381. HKEY hKey=0;
  382. DWORD disp=0;
  383. lstrcpy(szKey,"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run");
  384. if(g_bAutoRun)
  385. {
  386. int lResult=RegCreateKeyEx(HKEY_LOCAL_MACHINE,szKey,0,NULL,REG_OPTION_VOLATILE, KEY_ALL_ACCESS,NULL,&hKey,&disp);
  387. if(lResult==ERROR_SUCCESS)
  388. {
  389. TCHAR szDir[MAX_PATH];
  390. ::GetModuleFileName (NULL, szDir, MAX_PATH);
  391. lResult=RegSetValueEx(hKey,"YLGLMSGMANAGE",0,REG_SZ,(const unsigned char*)szDir,lstrlen(szDir));
  392. RegCloseKey(hKey);
  393. }
  394. }
  395. else
  396. {
  397. int lResult=RegCreateKeyEx(HKEY_LOCAL_MACHINE,szKey,0,NULL,REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS,NULL,&hKey,&disp);
  398. if(lResult==ERROR_SUCCESS)
  399. {
  400. RegDeleteValue(hKey,"YLGLMSGMANAGE");
  401. RegDeleteKey (hKey,"YLGLMSGMANAGE");
  402. RegCloseKey(hKey);
  403. }
  404. }
  405. }
  406. void CMainFrame::OnExit2()
  407. {
  408. }
  409. void CMainFrame::OnClientip()
  410. {
  411. // TODO: Add your command handler code here
  412. UINT nID=1;
  413. LPSTR pName ;
  414. pName = (LPSTR)(LPCSTR)"域名管理";
  415. }
  416. void CMainFrame::OnLog()
  417. {
  418. // TODO: Add your command handler code here
  419. UINT nID=1;
  420. LPSTR pName ;
  421. pName = (LPSTR)(LPCSTR)"系统日志";
  422. OPEN_MENU(LogFrom);
  423. }