MainDlg.cpp 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774
  1. // MainDlg.cpp : implementation of the CMainDlg class
  2. //
  3. /////////////////////////////////////////////////////////////////////////////
  4. #include "stdafx.h"
  5. #include "MainDlg.h"
  6. #include "StabtypeControl.h"
  7. #include "CLashConfig.h"
  8. #include "SysProxy.h"
  9. CMainDlg::CMainDlg() : SHostWnd(_T("LAYOUT:XML_MAINWND")), m_base_clash(nullptr), pNodeAdapter(nullptr)
  10. {
  11. m_bLayoutInited = FALSE;
  12. m_refresh = false;
  13. m_connect_mage = nullptr;
  14. }
  15. CMainDlg::~CMainDlg()
  16. {
  17. if (m_base_clash)
  18. {
  19. delete m_base_clash;
  20. m_base_clash = nullptr;
  21. }
  22. if (m_connect_mage)
  23. {
  24. delete m_connect_mage;
  25. m_connect_mage = nullptr;
  26. }
  27. }
  28. int CMainDlg::OnCreate(LPCREATESTRUCT lpCreateStruct)
  29. {
  30. SetMsgHandled(FALSE);
  31. return 0;
  32. }
  33. BOOL CMainDlg::OnInitDialog(HWND hWnd, LPARAM lParam)
  34. {
  35. m_bLayoutInited = TRUE;
  36. Init();
  37. OnConnecting_UdateUi(false, CONNECT_NODE_MSG,L"");
  38. /*CManageNetWork m_manageNetwork;
  39. m_manageNetwork.GetNodeList();*/
  40. CManageNetWork::getSingletonPtr()->GetNodeList();
  41. return 0;
  42. }
  43. void CMainDlg::Init()
  44. {
  45. CApp::getSingletonPtr()->SetupDataDirectory();
  46. //FindChildByName2<STabCtrl>(L"tabmain");
  47. if (!m_base_clash)
  48. {
  49. m_base_clash = new CLashConfig();
  50. m_base_clash->InitClash();
  51. m_base_clash->StartClash();
  52. }
  53. if (!m_connect_mage)
  54. {
  55. m_connect_mage = new CConnectMage();
  56. m_connect_mage->SetClashConfig((CLashConfig*)m_base_clash);
  57. m_connect_mage->Init();
  58. }
  59. SysMode list;
  60. list.id = 0;
  61. list.name = L"系统代理";
  62. list.proxy_mode = PROXY_MODE::sys_mode;
  63. SysMode list1;
  64. list1.id = 1;
  65. list1.name = L"网卡代理";
  66. list1.proxy_mode = PROXY_MODE::tun_mode;
  67. m_sysmode_vctor.push_back(list);
  68. m_sysmode_vctor.push_back(list1);
  69. RouteMode route;
  70. route.id = 0;
  71. route.name = L"智能";
  72. route.route_mode = ROUT_MODE::cn_mode;
  73. RouteMode route2;
  74. route2.id = 1;
  75. route2.name = L"全局";
  76. route2.route_mode = ROUT_MODE::qg_mode;
  77. m_route_vctor.push_back(route);
  78. m_route_vctor.push_back(route2);
  79. StabtypeControl* tabtype = FindChildByName2<StabtypeControl>(L"sysmode");
  80. if (tabtype)
  81. {
  82. for (auto i = 0; i < m_sysmode_vctor.size(); i++)
  83. {
  84. tabtype->ItemCreateChildren(m_sysmode_vctor[i].id, m_sysmode_vctor[i].name,i == 0 ? true : false );
  85. }
  86. if (m_sysmode_vctor.size() > 0)
  87. {
  88. CApp::getSingletonPtr()->SetSysMode(PROXY_MODE::sys_mode);
  89. }
  90. tabtype->GetEventSet()->subscribeEvent(EVT_TABTYPE_CONTROL,
  91. Subscriber(&CMainDlg::OnSysModeType, this));
  92. }
  93. StabtypeControl* routetype = FindChildByName2<StabtypeControl>(L"routemode");
  94. if (routetype)
  95. {
  96. for (auto i = 0; i < m_route_vctor.size(); i++)
  97. {
  98. routetype->ItemCreateChildren(m_route_vctor[i].id, m_route_vctor[i].name, i == 0 ? true : false);
  99. }
  100. if (m_route_vctor.size() > 0)
  101. {
  102. CApp::getSingletonPtr()->SetRouteMode(ROUT_MODE::cn_mode);
  103. }
  104. routetype->GetEventSet()->subscribeEvent(EVT_TABTYPE_CONTROL,
  105. Subscriber(&CMainDlg::OnRouteModeType, this));
  106. }
  107. auto funRecent2 = std::bind(&CMainDlg::ShowView, this, std::placeholders::_1, std::placeholders::_2);
  108. auto funRecent3 = std::bind(&CMainDlg::ItemRClick, this, std::placeholders::_1);
  109. STileView* pTileView = FindChildByName2<STileView>("nodeList");
  110. if (pTileView)
  111. {
  112. pTileView->SetFocus();
  113. /*std::vector<SStringT> vctInfo{ L"Test1",L"Fun1", L"Ming", L"Get" };*/
  114. pNodeAdapter = new CNodeAdapter(pTileView);
  115. pTileView->SetAdapter(pNodeAdapter);
  116. pNodeAdapter->SetShowView(funRecent2);
  117. pNodeAdapter->SetItemClickCallBack(funRecent3);
  118. //pNodeAdapter->Release();
  119. }
  120. UpDateUserInfo();
  121. }
  122. void CMainDlg::OnNode()
  123. {
  124. STabCtrl* m_tab_main = FindChildByName2<STabCtrl>(L"tabmain");
  125. if (m_tab_main)
  126. {
  127. m_tab_main->SetCurSel(1);
  128. m_tab_main->Invalidate();
  129. }
  130. STileView* pTileView = FindChildByName2<STileView>("nodeList");
  131. if (pTileView)
  132. {
  133. pTileView->SetFocus();
  134. }
  135. }
  136. void CMainDlg::OnBackNode()
  137. {
  138. STabCtrl* m_tab_main = FindChildByName2<STabCtrl>(L"tabmain");
  139. if (m_tab_main)
  140. {
  141. m_tab_main->SetCurSel(0);
  142. m_tab_main->Invalidate();
  143. }
  144. }
  145. bool CMainDlg::OnSysModeType(SOUI::EventArgs* pEvt)
  146. {
  147. SOUI::EventTabtypeControl* pTestControlEvent =
  148. SOUI::sobj_cast<SOUI::EventTabtypeControl>(pEvt);
  149. if (!pTestControlEvent)
  150. {
  151. return false;
  152. }
  153. CApp::getSingletonPtr()->SetSysMode(m_sysmode_vctor[pTestControlEvent->nIndex].proxy_mode);
  154. return true;
  155. }
  156. bool CMainDlg::OnRouteModeType(SOUI::EventArgs* pEvt)
  157. {
  158. SOUI::EventTabtypeControl* pTestControlEvent =
  159. SOUI::sobj_cast<SOUI::EventTabtypeControl>(pEvt);
  160. if (!pTestControlEvent)
  161. {
  162. return false;
  163. }
  164. CApp::getSingletonPtr()->SetRouteMode(m_route_vctor[pTestControlEvent->nIndex].route_mode);
  165. return true;
  166. }
  167. void CMainDlg::OnAuthFinish(SOUI::EventArgs* pEvt)
  168. {
  169. EventAUTH* e2 = sobj_cast<EventAUTH>(pEvt);
  170. if (!e2)
  171. {
  172. return;
  173. }
  174. if (e2->status != 200)
  175. {
  176. OnConnecting_UdateUi(TRUE, L"未连接");
  177. SMessageBox(m_hWnd, e2->msg, L"提醒", 0);
  178. }
  179. else
  180. {
  181. OnConnect();
  182. }
  183. }
  184. void CMainDlg::OnServerListFinish(SOUI::EventArgs* pEvt)
  185. {
  186. EventNodeList* e2 = sobj_cast<EventNodeList>(pEvt);
  187. if (!e2)
  188. {
  189. return;
  190. }
  191. if (e2->status != 200 )
  192. {
  193. if (m_refresh)
  194. {
  195. SStatic* refresh_status = FindChildByName2<SStatic>(L"refresh_status");
  196. if (refresh_status)
  197. {
  198. refresh_status->SetWindowTextW(e2->msg);
  199. refresh_status->Invalidate();
  200. }
  201. SStatic* text_touch = FindChildByName2<SStatic>(L"text_touch");
  202. if (text_touch)
  203. {
  204. text_touch->SetWindowTextW(e2->msg);
  205. text_touch->Invalidate();
  206. }
  207. OnConnecting_UdateUi(TRUE, e2->msg);
  208. m_refresh = false;
  209. }
  210. else {
  211. UPdateMsgStatus(e2->msg);
  212. OnConnecting_UdateUi(TRUE, e2->msg);
  213. }
  214. }
  215. else if (e2->status == 200)
  216. {
  217. if (m_refresh)
  218. {
  219. SStatic* refresh_status = FindChildByName2<SStatic>(L"refresh_status");
  220. if (refresh_status)
  221. {
  222. refresh_status->SetWindowTextW(L"更新完成..");
  223. refresh_status->Invalidate();
  224. }
  225. SStatic* text_touch = FindChildByName2<SStatic>(L"text_touch");
  226. if (text_touch)
  227. {
  228. text_touch->SetWindowTextW(L"更新完成...");
  229. text_touch->Invalidate();
  230. }
  231. m_refresh = false;
  232. }
  233. else {
  234. OnConnecting_UdateUi(TRUE, SUEECS_NODE_MSG);
  235. CManageNetWork::getSingletonPtr()->GetVersion();
  236. }
  237. //更新 节点数据
  238. if (pNodeAdapter)
  239. {
  240. pNodeAdapter->SetCount(CApp::getSingletonPtr()->GetServerList()->vectlistmode.size());
  241. }
  242. }
  243. }
  244. void CMainDlg::OnVersionFinish(SOUI::EventArgs* pEvt)
  245. {
  246. EventVerions* e2 = sobj_cast<EventVerions>(pEvt);
  247. if (!e2)
  248. {
  249. return;
  250. }
  251. if (e2->status == 200)
  252. {
  253. UPdateVersionMsgStatus(e2->msg, S_CA2W(CApp::getSingletonPtr()->GetVerinfo()->appdownload.c_str()),e2->versionupdate);
  254. }
  255. else {
  256. UPdateVersionMsgStatus(e2->msg);
  257. }
  258. }
  259. void CMainDlg::OnConnectFinish(SOUI::EventArgs* pEvt)
  260. {
  261. EventConnect* e2 = sobj_cast<EventConnect>(pEvt);
  262. if (!e2)
  263. {
  264. return;
  265. }
  266. if (e2->status == ConnectState::Stop)
  267. {
  268. OnConnecting_UdateUi(true, e2->msg, L"", false);
  269. OnUpdataNodeName();
  270. } else if (e2->status == ConnectState::SwitchConfigSuccEss)
  271. {
  272. OnConnecting_UdateUi(true, e2->msg, L"", true);
  273. OnUpdataNodeName();
  274. } else if (e2->status == ConnectState::SwitchNodeSuccEss)
  275. {
  276. OnConnecting_UdateUi(true, e2->msg, L"", true);
  277. OnUpdataNodeName();
  278. }
  279. }
  280. void CMainDlg::OnClashPreoceeQutFinish(SOUI::EventArgs* pEvt)
  281. {
  282. if (m_base_clash)
  283. {
  284. m_base_clash->StartClash();
  285. }
  286. if (m_connect_mage)
  287. {
  288. m_connect_mage->ReqConfig();
  289. }
  290. }
  291. void CMainDlg::UPdateMsgStatus(SStringW msg)
  292. {
  293. //text_touch
  294. SStatic* text_touch = FindChildByName2<SStatic>(L"text_touch");
  295. if (text_touch)
  296. {
  297. text_touch->SetWindowTextW(msg);
  298. text_touch->EnableWindow(FALSE);
  299. text_touch->Invalidate();
  300. }
  301. }
  302. void CMainDlg::UPdateVersionMsgStatus(SStringW msg, SStringW url,int appversionupdate)
  303. {
  304. SLink* app_version = FindChildByName2<SLink>(L"app_version");
  305. if (app_version)
  306. {
  307. if (!url.IsEmpty())
  308. {
  309. app_version->SetAttribute(L"href", url);
  310. }
  311. app_version->SetWindowTextW(msg);
  312. app_version->EnableWindow(true);
  313. app_version->Invalidate();
  314. }
  315. if (appversionupdate == 1)
  316. {
  317. SMessageBox(m_hWnd, msg, L"更新提示", 0);
  318. ::ShellExecute(NULL, _T("open"), url, NULL, NULL, SW_SHOWNORMAL);
  319. }
  320. }
  321. void CMainDlg::UpDateUserInfo()
  322. {
  323. CUserInfo* userinfo = CApp::getSingletonPtr()->GetUserinfo();
  324. if (!userinfo)
  325. {
  326. return;
  327. }
  328. SStatic* username = FindChildByName2<SStatic>(L"username");
  329. if (username)
  330. {
  331. SStringW enable = L"禁用";
  332. if (CApp::getSingletonPtr()->GetUserinfo()->enable == true)
  333. {
  334. enable = L"启用" ;
  335. }
  336. else {
  337. enable = L"禁用";
  338. }
  339. username->SetWindowTextW(SStringW().Format(L"用户名:%s 代理状态:%s", S_CA2W(userinfo->username.c_str()), enable));
  340. username->EnableWindow(FALSE);
  341. username->Invalidate();
  342. }
  343. SStatic* username_time = FindChildByName2<SStatic>(L"username_time");
  344. if (username_time)
  345. {
  346. username_time->SetWindowTextW(SStringW().Format(L"到期时间:%s", S_CA2W(userinfo->expiretime.c_str())));
  347. username_time->EnableWindow(FALSE);
  348. username_time->Invalidate();
  349. }
  350. SStatic* username_liulaing = FindChildByName2<SStatic>(L"username_liulaing");
  351. if (username_liulaing)
  352. {
  353. username_liulaing->SetWindowTextW(SStringW().Format(L"用户流量:%s", S_CA2W(userinfo->unusedTraffic.c_str())));
  354. username_liulaing->EnableWindow(FALSE);
  355. username_liulaing->Invalidate();
  356. }
  357. SLink* username_jiaocheng = FindChildByName2<SLink>(L"username_jiaocheng");
  358. if (username_jiaocheng)
  359. {
  360. username_jiaocheng->SetAttribute(L"href", CApp::getSingletonPtr()->GetSysconfig()->GetTutorialLink());
  361. username_jiaocheng->EnableWindow(true);
  362. username_jiaocheng->Invalidate();
  363. }
  364. SLink* username_chongzhi = FindChildByName2<SLink>(L"username_chongzhi");
  365. if (username_chongzhi)
  366. {
  367. username_chongzhi->SetAttribute(L"href", CApp::getSingletonPtr()->GetSysconfig()->GetBuyLink());
  368. username_chongzhi->EnableWindow(true);
  369. username_chongzhi->Invalidate();
  370. }
  371. SLink* username_tuiguang = FindChildByName2<SLink>(L"username_tuiguang");
  372. if (username_tuiguang)
  373. {
  374. username_tuiguang->SetAttribute(L"href", CApp::getSingletonPtr()->GetSysconfig()->GetAffLink());
  375. username_tuiguang->EnableWindow(true);
  376. username_tuiguang->Invalidate();
  377. }
  378. SLink* username_online_kf = FindChildByName2<SLink>(L"username_online_kf");
  379. if (username_online_kf)
  380. {
  381. username_online_kf->SetAttribute(L"href", CApp::getSingletonPtr()->GetSysconfig()->GetOnlineLink());
  382. username_online_kf->EnableWindow(true);
  383. username_online_kf->Invalidate();
  384. }
  385. if (m_base_clash)
  386. {
  387. auto http_prot = m_base_clash->GetHttpPort();
  388. auto sock_prot = m_base_clash->GetSocketPort();
  389. SStatic* httpproxy = FindChildByName2<SStatic>(L"httpproxy");
  390. if (httpproxy)
  391. {
  392. httpproxy->SetWindowTextW(SStringW().Format(L"http proxy 127.0.0.1:%d", http_prot));
  393. httpproxy->EnableWindow(FALSE);
  394. httpproxy->Invalidate();
  395. }
  396. SStatic* socksproxy = FindChildByName2<SStatic>(L"socksproxy");
  397. if (socksproxy)
  398. {
  399. socksproxy->SetWindowTextW(SStringW().Format(L"socks proxy 127.0.0.1:%d", sock_prot));
  400. socksproxy->EnableWindow(FALSE);
  401. socksproxy->Invalidate();
  402. }
  403. }
  404. }
  405. void CMainDlg::ShowView(int nItem, SWindow* pItem)
  406. {
  407. if (!pNodeAdapter)
  408. {
  409. return;
  410. }
  411. CServerList* p = CApp::getSingletonPtr()->GetServerList();
  412. if (!p)
  413. {
  414. return;
  415. }
  416. auto vectorserverlist = p->vectlistmode;
  417. SStatic* servername = pItem->FindChildByName2<SStatic>(L"servername");
  418. if (servername)
  419. {
  420. servername->SetWindowTextW(S_CA2W(vectorserverlist[nItem].name.c_str(),CP_UTF8));
  421. }
  422. SStatic* serverms = pItem->FindChildByName2<SStatic>(L"serverms");
  423. if (serverms)
  424. {
  425. SStringW msg = L"";
  426. SStringW color = L"";
  427. //SLOG_DEBUG(vectorserverlist[nItem].online_users);
  428. if(vectorserverlist[nItem].online_users < 29) { //空闲
  429. msg = L"空闲";
  430. color = L"#6aa84f";
  431. }
  432. else if (vectorserverlist[nItem].online_users > 30 && vectorserverlist[nItem].online_users < 150) {
  433. msg = L"正常";
  434. color = L"#6aa84f";
  435. }
  436. else if (vectorserverlist[nItem].online_users > 151 && vectorserverlist[nItem].online_users < 200) {
  437. msg = L"繁忙";
  438. color = L"#7c7c7c";
  439. }
  440. else if (vectorserverlist[nItem].online_users > 201 && vectorserverlist[nItem].online_users < 500){
  441. msg = L"拥挤";
  442. color = L"#696969";
  443. }
  444. else {
  445. msg = L"维护";
  446. color = L"#696969";
  447. }
  448. serverms->SetWindowTextW(msg);
  449. serverms->SetAttribute(L"colorText", color);
  450. }
  451. }
  452. void CMainDlg::ItemRClick(int nItem)
  453. {
  454. CServerList* p = CApp::getSingletonPtr()->GetServerList();
  455. if (!p)
  456. {
  457. return;
  458. }
  459. auto vectorserverlist = p->vectlistmode;
  460. auto name = vectorserverlist[nItem].name;
  461. OnBackNode();
  462. SLOG_DEBUG(name.c_str());
  463. //切换CLash api
  464. if (m_connect_mage)
  465. {
  466. m_connect_mage->SetNodeName(name);
  467. m_connect_mage->ReqConfig();
  468. }
  469. CApp::getSingletonPtr()->SetSelect_node(name);
  470. OnUpdataNodeName();
  471. }
  472. void CMainDlg::OnRefresh()
  473. {
  474. if (m_refresh)
  475. {
  476. return;
  477. }
  478. //更新 节点数据
  479. if (pNodeAdapter)
  480. {
  481. pNodeAdapter->SetCount(0);
  482. }
  483. CManageNetWork::getSingletonPtr()->GetNodeList();
  484. m_refresh = true;
  485. //refresh_status
  486. SStatic* refresh_status = FindChildByName2<SStatic>(L"refresh_status");
  487. if (refresh_status)
  488. {
  489. refresh_status->SetWindowTextW(L"正在刷新节点...");
  490. refresh_status->Invalidate();
  491. }
  492. SStatic* text_touch = FindChildByName2<SStatic>(L"text_touch");
  493. if (text_touch)
  494. {
  495. text_touch->SetWindowTextW(L"正在刷新节点...");
  496. text_touch->Invalidate();
  497. }
  498. }
  499. void CMainDlg::OnConnect()
  500. {
  501. if (!m_connect_mage)
  502. {
  503. return;
  504. }
  505. if (m_connect_mage->GetConnectStatus() == ConnectState::Stop)
  506. {
  507. m_connect_mage->ReqConfig();
  508. OnConnecting_UdateUi(false, L"正在启动中..", L"", false);
  509. }
  510. else {
  511. m_connect_mage->Stop();
  512. DisableSystemProxy();
  513. OnConnecting_UdateUi(true, L"停止成功", L"", false);
  514. }
  515. }
  516. void CMainDlg::OnAuth()
  517. {
  518. if (m_connect_mage->GetConnectStatus() == ConnectState::Stop) {
  519. OnConnecting_UdateUi(false, L"正在验证中..", L"", false);
  520. CManageNetWork::getSingletonPtr()->Auth();
  521. }
  522. else {
  523. OnConnect();
  524. }
  525. }
  526. void CMainDlg::OnUpdataNodeName(SStringW nodename)
  527. {
  528. SStatic* node_name = FindChildByName2<SStatic>(L"node_name");
  529. if (node_name)
  530. {
  531. if (nodename.IsEmpty())
  532. {
  533. if (!CApp::getSingletonPtr()->GetSelect_node().empty())
  534. {
  535. node_name->SetWindowTextW(S_CA2W(CApp::getSingletonPtr()->GetSelect_node().c_str(), CP_UTF8));
  536. }
  537. else {
  538. if (!CApp::getSingletonPtr()->GetServerList()->node_name.empty());
  539. {
  540. node_name->SetWindowTextW(S_CA2W(CApp::getSingletonPtr()->GetServerList()->node_name.c_str(), CP_UTF8));
  541. }
  542. }
  543. }
  544. else {
  545. //node_name->SetWindowTextW(nodename);
  546. }
  547. node_name->Invalidate();
  548. }
  549. }
  550. void CMainDlg::OnRefreshUser()
  551. {
  552. SStatic* username_time = FindChildByName2<SStatic>(L"username_time");
  553. if (username_time)
  554. {
  555. username_time->SetWindowTextW(L"正在刷新");
  556. username_time->EnableWindow(FALSE);
  557. username_time->Invalidate();
  558. }
  559. CManageNetWork::getSingletonPtr()->Login(CManageNetWork::getSingletonPtr()->GetUsername().GetBuffer(0), CManageNetWork::getSingletonPtr()->GetPassWord().GetBuffer(0));
  560. }
  561. void CMainDlg::OnLoginFinish(EventArgs* e)
  562. {
  563. EventLogin* e2 = sobj_cast<EventLogin>(e);
  564. if (!e2)
  565. {
  566. return;
  567. }
  568. if (e2->status == 200)
  569. {
  570. UpDateUserInfo();
  571. }
  572. }
  573. //连接状态 更新UI
  574. void CMainDlg::OnConnecting_UdateUi(bool b,SStringW msg,SStringW acc_msg,bool connect)
  575. {
  576. SWindow* selectnode = FindChildByName2<SWindow>(L"selectnode");
  577. if (selectnode)
  578. {
  579. selectnode->EnableWindow(b);
  580. selectnode->Invalidate();
  581. }
  582. SImageButton* Refresh = FindChildByName2<SImageButton>(L"OnRefresh");
  583. if (Refresh)
  584. {
  585. Refresh->EnableWindow(b);
  586. Refresh->Invalidate();
  587. }
  588. SStatic* text_touch = FindChildByName2<SStatic>(L"text_touch");
  589. if (text_touch)
  590. {
  591. text_touch->SetWindowTextW(msg);
  592. text_touch->EnableWindow(b);
  593. text_touch->Invalidate();
  594. }
  595. SImageButton* connect_touch = FindChildByName2<SImageButton>(L"connect_touch");
  596. if (connect_touch)
  597. {
  598. if (connect)
  599. {
  600. connect_touch->SetAttribute(L"skin", L"skin_btnswitchon");
  601. }
  602. else {
  603. connect_touch->SetAttribute(L"skin", L"skin_btnswitchoff");
  604. }
  605. connect_touch->EnableWindow(b);
  606. connect_touch->Invalidate();
  607. }
  608. }
  609. //TODO:消息映射
  610. void CMainDlg::OnClose()
  611. {
  612. ShowWindow(SW_HIDE);
  613. }
  614. void CMainDlg::OnMaximize()
  615. {
  616. SendMessage(WM_SYSCOMMAND, SC_MAXIMIZE);
  617. }
  618. void CMainDlg::OnRestore()
  619. {
  620. SendMessage(WM_SYSCOMMAND, SC_RESTORE);
  621. }
  622. void CMainDlg::OnMinimize()
  623. {
  624. SendMessage(WM_SYSCOMMAND, SC_MINIMIZE);
  625. }
  626. void ShowConsoleWindow(bool show) {
  627. const HWND hWnd = CProcessManager::getSingletonPtr()->GetConsoleWindow();
  628. if (hWnd)
  629. {
  630. ShowWindow(hWnd, show ? SW_SHOW : SW_HIDE);
  631. if (show)
  632. SetForegroundWindow(hWnd);
  633. }
  634. }
  635. void CMainDlg::OnCommand(UINT uNotifyCode, int nID, HWND wndCtl) {
  636. if (uNotifyCode == 0)
  637. {
  638. if (nID == 2)
  639. {
  640. const HWND hWndConsole = CProcessManager::getSingletonPtr()->GetConsoleWindow();
  641. if (hWndConsole)
  642. {
  643. ShowConsoleWindow(!::IsWindowVisible(hWndConsole));
  644. }
  645. else
  646. ShowConsoleWindow(false);
  647. }
  648. else if (nID == 6) {
  649. if (m_refresh)
  650. {
  651. SMessageBox(m_hWnd, L"正在刷新,无法退出", L"提示", 0);
  652. }
  653. else {
  654. if (m_base_clash)
  655. {
  656. DisableSystemProxy();
  657. CProcessManager::getSingletonPtr()->SendStopSignal();
  658. WaitForSingleObject(CProcessManager::getSingletonPtr()->GetClashProcessInfo().hProcess, 3000);
  659. CProcessManager::getSingletonPtr()->Stop();
  660. m_base_clash->StopClash();
  661. delete m_base_clash;
  662. m_base_clash = nullptr;
  663. }
  664. CSimpleWnd::DestroyWindow();
  665. }
  666. }
  667. }
  668. }