MobileDlg.cpp 63 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945
  1. // MainDlg.cpp : implementation of the CMobileDlg class
  2. //
  3. /////////////////////////////////////////////////////////////////////////////
  4. #include "stdafx2.h"
  5. #include "resource.h"
  6. #include "MobileDlg.h"
  7. #include <TlHelp32.h>
  8. #define WND_CHILD_HEIGHT 197
  9. #define WND_CHILD_WIDTH 402
  10. #define WND_LARGE_SIZE_X 432
  11. #define WND_LARGE_SIZE_Y 663
  12. #define WND_CHILD_2_HEIGHT 168
  13. #define WND_SMALL_SIZE_X WND_LARGE_SIZE_X
  14. #define WND_SMALL_SIZE_Y (WND_LARGE_SIZE_Y - WND_CHILD_HEIGHT)
  15. #define WND_SMALL_2_SIZE_Y (WND_LARGE_SIZE_Y - WND_CHILD_2_HEIGHT)
  16. #define MOVE_CHILD_CONTROL(nID) \
  17. do{ \
  18. GetDlgItem(nID).GetWindowRect(&rect); \
  19. ScreenToClient(&rect); \
  20. rect.top += nY; \
  21. rect.bottom += nY; \
  22. GetDlgItem(nID).MoveWindow(&rect); \
  23. }while(false)
  24. static UINT statuspanes[] =
  25. {
  26. ID_STATUSBAR_CONSTATUS,
  27. ID_STATUSBAR_MODE,
  28. ID_STATUSBAR_SIGNAL
  29. };
  30. static HANDLE FindProcessByName(const char *pProcessName)
  31. {
  32. PROCESSENTRY32 pe32;
  33. pe32.dwSize = sizeof(pe32);
  34. HANDLE hProcessSnap = ::CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
  35. BOOL bMore = ::Process32First(hProcessSnap, &pe32);
  36. while (bMore)
  37. {
  38. if (_stricmp(pProcessName, pe32.szExeFile) == 0)
  39. {
  40. return OpenProcess(PROCESS_TERMINATE, FALSE, pe32.th32ProcessID);
  41. }
  42. bMore = ::Process32Next(hProcessSnap, &pe32);
  43. }
  44. return NULL;
  45. }
  46. CMobileDlg::CMobileDlg(CMobileDialEntity* pEntity)
  47. : m_pEntity(pEntity), m_bConnected(false),m_nGenType(3),m_nReversedType(3),m_nWhoConnected(0),m_localSIM(TRUE),m_dongleType(0)
  48. //,m_cw1(this, 1), m_cw2(this, 1), m_cw3(this, 1), m_cw4(this, 1), m_cw5(this, 1), m_cw6(this, 1)
  49. {
  50. m_sMBBParam.connectType = 0;
  51. m_sReverseMBBParam.connectType = 0;
  52. }
  53. CMobileDlg::~CMobileDlg() {}
  54. HBRUSH CMobileDlg::OnCtlColorStatic(CDCHandle dc, CStatic wndStatic)
  55. {
  56. if (GetDlgItem(IDC_STATIC_TXT_WARN).m_hWnd == wndStatic.m_hWnd) {
  57. dc.SetTextColor(RGB(255, 0, 0));
  58. dc.SetBkColor(RGB(195, 195, 195));
  59. return (HBRUSH)GetStockObject(LTGRAY_BRUSH);
  60. }
  61. else {
  62. SetMsgHandled(FALSE);
  63. return 0;
  64. }
  65. }
  66. void CMobileDlg::SetDlgSizeToSmall(void)
  67. {
  68. SetWindowPos(NULL, 0, 0, WND_SMALL_SIZE_X, WND_SMALL_SIZE_Y, SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);
  69. ShowProfileCreateCtrl(FALSE);
  70. CloseVirtualKeyboard();
  71. m_btnExpand.SetWindowText("管理配置");
  72. }
  73. void CMobileDlg::SetDlgSizeToLarge(void)
  74. {
  75. SetWindowPos(NULL, 0, 0, WND_LARGE_SIZE_X, WND_LARGE_SIZE_Y, SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);
  76. ShowProfileCreateCtrl(TRUE);
  77. m_btnExpand.SetWindowText("▲");
  78. }
  79. void CMobileDlg::HideRedundance(void)
  80. {
  81. SetWindowPos(NULL, 0, 0, WND_LARGE_SIZE_X, WND_SMALL_2_SIZE_Y, SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);
  82. //////////////////////////////////////////////////////////////////////////
  83. GetDlgItem(IDC_STATIC_CONNECT).ShowWindow(FALSE);
  84. GetDlgItem(IDC_STATIC_TXT_DONGLE).ShowWindow(FALSE);
  85. GetDlgItem(IDC_COMBO_DONGLE).ShowWindow(FALSE);
  86. GetDlgItem(IDC_STATIC_TXT_GTYPE).ShowWindow(FALSE);
  87. GetDlgItem(IDC_COMBO_GTYPE).ShowWindow(FALSE);
  88. GetDlgItem(IDC_BUTTON_CONNECT).ShowWindow(FALSE);
  89. GetDlgItem(IDC_BUTTON_EXPAND).ShowWindow(FALSE);
  90. GetDlgItem(IDC_COMBO_PROFILES).ShowWindow(FALSE);
  91. GetDlgItem(IDC_STATIC_TXT_PROFILE).ShowWindow(FALSE);
  92. GetDlgItem(IDC_STATIC_CARD).ShowWindow(FALSE);
  93. GetDlgItem(IDC_STATIC_TXT_PORT).ShowWindow(FALSE);
  94. GetDlgItem(IDC_STATIC_PORT).ShowWindow(FALSE);
  95. GetDlgItem(IDC_STATIC_TXT_IMEI).ShowWindow(FALSE);
  96. GetDlgItem(IDC_STATIC_IMEI).ShowWindow(FALSE);
  97. GetDlgItem(IDC_STATIC_TXT_MANUFACTURER).ShowWindow(FALSE);
  98. GetDlgItem(IDC_STATIC_MANUFACTURER).ShowWindow(FALSE);
  99. GetDlgItem(IDC_STATIC_TXT_HARDWARE).ShowWindow(FALSE);
  100. GetDlgItem(IDC_STATIC_HARDWARE).ShowWindow(FALSE);
  101. GetDlgItem(IDC_STATIC_TXT_MODEL).ShowWindow(FALSE);
  102. GetDlgItem(IDC_STATIC_MODEL).ShowWindow(FALSE);
  103. GetDlgItem(IDC_STATIC_TXT_DATACLASS).ShowWindow(FALSE);
  104. GetDlgItem(IDC_STATIC_DATACLASS).ShowWindow(FALSE);
  105. GetDlgItem(IDC_STATIC_TXT_FIRMWARE).ShowWindow(FALSE);
  106. GetDlgItem(IDC_STATIC_FIRMWARE).ShowWindow(FALSE);
  107. MoveDlgItems(FALSE);
  108. }
  109. void CMobileDlg::MoveDlgItems(BOOL bShow)
  110. {
  111. RECT rect;
  112. int nY = bShow ? WND_CHILD_HEIGHT : -WND_CHILD_HEIGHT;
  113. #if 1
  114. MOVE_CHILD_CONTROL(IDC_STATIC_CARD);
  115. MOVE_CHILD_CONTROL(IDC_STATIC_TXT_PORT);
  116. MOVE_CHILD_CONTROL(IDC_STATIC_PORT);
  117. MOVE_CHILD_CONTROL(IDC_STATIC_TXT_IMEI);
  118. MOVE_CHILD_CONTROL(IDC_STATIC_IMEI);
  119. MOVE_CHILD_CONTROL(IDC_STATIC_TXT_MANUFACTURER);
  120. MOVE_CHILD_CONTROL(IDC_STATIC_MANUFACTURER);
  121. MOVE_CHILD_CONTROL(IDC_STATIC_TXT_HARDWARE);
  122. MOVE_CHILD_CONTROL(IDC_STATIC_HARDWARE);
  123. MOVE_CHILD_CONTROL(IDC_STATIC_TXT_MODEL);
  124. MOVE_CHILD_CONTROL(IDC_STATIC_MODEL);
  125. MOVE_CHILD_CONTROL(IDC_STATIC_TXT_DATACLASS);
  126. MOVE_CHILD_CONTROL(IDC_STATIC_DATACLASS);
  127. MOVE_CHILD_CONTROL(IDC_STATIC_TXT_FIRMWARE);
  128. MOVE_CHILD_CONTROL(IDC_STATIC_FIRMWARE);
  129. MOVE_CHILD_CONTROL(IDC_STATIC_ADD);
  130. MOVE_CHILD_CONTROL(IDC_BUTTON_QUIT);
  131. MOVE_CHILD_CONTROL(IDC_BUTTON_DEFAULT_CONNECT);
  132. MOVE_CHILD_CONTROL(IDC_STATIC_MBB);
  133. MOVE_CHILD_CONTROL(IDC_CHECK_MNTBYRVC);
  134. MOVE_CHILD_CONTROL(IDC_STATIC_ADVANCED);
  135. MOVE_CHILD_CONTROL(IDC_RADIO_3G);
  136. MOVE_CHILD_CONTROL(IDC_RADIO_4G);
  137. MOVE_CHILD_CONTROL(IDC_RADIO_DEFAULT);
  138. MOVE_CHILD_CONTROL(IDC_RADIO_WEB);
  139. MOVE_CHILD_CONTROL(IDC_RADIO_MBB_WIRE);
  140. MOVE_CHILD_CONTROL(IDC_RADIO_MBB_WLAN);
  141. MOVE_CHILD_CONTROL(IDC_BUTTON_MBB_CONFIG);
  142. MOVE_CHILD_CONTROL(IDC_EDIT_PHONENUM);
  143. MOVE_CHILD_CONTROL(IDC_CHECK_RASIO_PAP);
  144. MOVE_CHILD_CONTROL(IDC_CHECK_RASIO_CHAP);
  145. MOVE_CHILD_CONTROL(IDC_CHECK_RASIO_MSCHAPV2);
  146. #else
  147. if(m_localSIM) {
  148. MOVE_CHILD_CONTROL(IDC_STATIC_CARD);
  149. MOVE_CHILD_CONTROL(IDC_STATIC_TXT_PORT);
  150. MOVE_CHILD_CONTROL(IDC_STATIC_PORT);
  151. MOVE_CHILD_CONTROL(IDC_STATIC_TXT_IMEI);
  152. MOVE_CHILD_CONTROL(IDC_STATIC_IMEI);
  153. MOVE_CHILD_CONTROL(IDC_STATIC_TXT_MANUFACTURER);
  154. MOVE_CHILD_CONTROL(IDC_STATIC_MANUFACTURER);
  155. MOVE_CHILD_CONTROL(IDC_STATIC_TXT_HARDWARE);
  156. MOVE_CHILD_CONTROL(IDC_STATIC_HARDWARE);
  157. MOVE_CHILD_CONTROL(IDC_STATIC_TXT_MODEL);
  158. MOVE_CHILD_CONTROL(IDC_STATIC_MODEL);
  159. MOVE_CHILD_CONTROL(IDC_STATIC_TXT_DATACLASS);
  160. MOVE_CHILD_CONTROL(IDC_STATIC_DATACLASS);
  161. MOVE_CHILD_CONTROL(IDC_STATIC_TXT_FIRMWARE);
  162. MOVE_CHILD_CONTROL(IDC_STATIC_FIRMWARE);
  163. MOVE_CHILD_CONTROL(IDC_STATIC_ADD);
  164. MOVE_CHILD_CONTROL(IDC_BUTTON_QUIT);
  165. MOVE_CHILD_CONTROL(IDC_BUTTON_DEFAULT_CONNECT);
  166. MOVE_CHILD_CONTROL(IDC_STATIC_MBB);
  167. MOVE_CHILD_CONTROL(IDC_CHECK_MNTBYRVC);
  168. MOVE_CHILD_CONTROL(IDC_STATIC_ADVANCED);
  169. MOVE_CHILD_CONTROL(IDC_RADIO_3G);
  170. MOVE_CHILD_CONTROL(IDC_RADIO_4G);
  171. MOVE_CHILD_CONTROL(IDC_RADIO_DEFAULT);
  172. MOVE_CHILD_CONTROL(IDC_EDIT_PHONENUM);
  173. MOVE_CHILD_CONTROL(IDC_CHECK_RASIO_PAP);
  174. MOVE_CHILD_CONTROL(IDC_CHECK_RASIO_CHAP);
  175. MOVE_CHILD_CONTROL(IDC_CHECK_RASIO_MSCHAPV2);
  176. } else {
  177. nY = bShow ? WND_CHILD_2_HEIGHT/2 : -WND_CHILD_2_HEIGHT/2;
  178. MOVE_CHILD_CONTROL(IDC_STATIC_LOGIN);
  179. MOVE_CHILD_CONTROL(IDC_STATIC_TXT_PROFILENAME);
  180. MOVE_CHILD_CONTROL(IDC_EDIT_PROFILE);
  181. MOVE_CHILD_CONTROL(IDC_STATIC_TXT_APN);
  182. MOVE_CHILD_CONTROL(IDC_EDIT_APN);
  183. MOVE_CHILD_CONTROL(IDC_STATIC_TXT_USER);
  184. MOVE_CHILD_CONTROL(IDC_EDIT_USER);
  185. MOVE_CHILD_CONTROL(IDC_STATIC_TXT_PASSWORD);
  186. MOVE_CHILD_CONTROL(IDC_EDIT_PASSWORD);
  187. MOVE_CHILD_CONTROL(IDC_CHECK_VIEW_PASSWORD);
  188. MOVE_CHILD_CONTROL(IDC_STATIC_TXT_MODE);
  189. MOVE_CHILD_CONTROL(IDC_COMBO_CON_MODE);
  190. MOVE_CHILD_CONTROL(IDC_STATIC_TXT_IPTYPE);
  191. MOVE_CHILD_CONTROL(IDC_COMBO_CON_IPTYPE);
  192. MOVE_CHILD_CONTROL(IDC_STATIC_TXT_POINTTYPE);
  193. MOVE_CHILD_CONTROL(IDC_COMBO_PONT_TYPE);
  194. MOVE_CHILD_CONTROL(IDC_CHECK_APN_APPLY);
  195. MOVE_CHILD_CONTROL(IDC_BUTTON_APN_STORE);
  196. //MOVE_CHILD_CONTROL(IDC_BUTTON_DROPUP);
  197. MOVE_CHILD_CONTROL(IDC_BUTTON_CLEAR);
  198. MOVE_CHILD_CONTROL(IDC_BUTTON_DELETE);
  199. MOVE_CHILD_CONTROL(IDC_EDIT_PHONENUM);
  200. MOVE_CHILD_CONTROL(IDC_CHECK_RASIO_PAP);
  201. MOVE_CHILD_CONTROL(IDC_CHECK_RASIO_CHAP);
  202. MOVE_CHILD_CONTROL(IDC_CHECK_RASIO_MSCHAPV2);
  203. nY += (bShow ? WND_CHILD_2_HEIGHT/2 : -WND_CHILD_2_HEIGHT/2);
  204. MOVE_CHILD_CONTROL(IDC_STATIC_ADD);
  205. MOVE_CHILD_CONTROL(IDC_BUTTON_QUIT);
  206. MOVE_CHILD_CONTROL(IDC_BUTTON_DEFAULT_CONNECT);
  207. MOVE_CHILD_CONTROL(IDC_STATIC_MBB);
  208. MOVE_CHILD_CONTROL(IDC_CHECK_MNTBYRVC);
  209. MOVE_CHILD_CONTROL(IDC_STATIC_ADVANCED);
  210. MOVE_CHILD_CONTROL(IDC_RADIO_3G);
  211. MOVE_CHILD_CONTROL(IDC_RADIO_4G);
  212. MOVE_CHILD_CONTROL(IDC_RADIO_DEFAULT);
  213. MOVE_CHILD_CONTROL(IDC_RADIO_WEB);
  214. }
  215. #endif
  216. }
  217. LRESULT CMobileDlg::OnSignalChanged(UINT uMsg, WPARAM wParam, LPARAM lParam)
  218. {
  219. if(m_bConnected) {
  220. CSimpleStringA csStrength("NA");
  221. if(lParam != 0xFFFFFFFF) {
  222. if(m_nWhoConnected == CNT_MBN) {
  223. csStrength = CSimpleStringA::Format("%2.0lf%%", 100.0*(double)lParam/31.0);
  224. } else if(m_nWhoConnected == CNT_MBB) {
  225. csStrength = CSimpleStringA::Format("%2.0lf%%", (double)lParam);
  226. }
  227. }
  228. SetDlgItemTextA(IDC_STATIC_PERCENTAGE, (LPCTSTR)csStrength);
  229. }
  230. return 0;
  231. }
  232. LRESULT CMobileDlg::OnDeviceChanged(UINT uMsg, WPARAM wParam, LPARAM lParam)
  233. {
  234. if(uMsg == WM_DONGLE_CHANGE) {
  235. Dbg("receive WM_DONGLE_CHANGE message");
  236. UpdateDongles();
  237. }
  238. return 0;
  239. }
  240. LRESULT CMobileDlg::OnFatalMsgChanged(UINT uMsg, WPARAM wParam, LPARAM lParam)
  241. {
  242. if(WM_FATALMESSAGE_CHANGE == uMsg) {
  243. if(wParam != 0 && lParam != 0) {
  244. CStatic edit = (CStatic)this->GetDlgItem(IDC_STATIC_TXT_WARN);
  245. CDC cdc(edit.GetDC());
  246. SIZE sz;
  247. if(cdc.GetTextExtent((LPCTSTR)lParam, strlen((LPCTSTR)lParam), &sz)) {
  248. RECT stRect;
  249. edit.GetWindowRect(&stRect);
  250. int post = stRect.left + (stRect.right - stRect.left) / 2;
  251. stRect.left = post - sz.cx / 2;
  252. stRect.right = post + sz.cx / 2;
  253. //stRect.left = stRect.right - sz.cx;
  254. this->ScreenToClient(&stRect);
  255. edit.MoveWindow(&stRect);
  256. edit.GetWindowRect(&stRect);
  257. this->ScreenToClient(&stRect);
  258. this->InvalidateRect(&stRect);
  259. }
  260. SetDlgItemTextA(IDC_STATIC_TXT_WARN, (LPCTSTR)lParam);
  261. GetDlgItem(IDC_STATIC_TXT_WARN).ShowWindow(SW_SHOW);
  262. } else {
  263. SetDlgItemTextA(IDC_STATIC_TXT_WARN, "");
  264. GetDlgItem(IDC_STATIC_TXT_WARN).ShowWindow(SW_HIDE);
  265. }
  266. }
  267. return 0;
  268. }
  269. LRESULT CMobileDlg::OnWlanConnectResult(UINT uMsg, WPARAM wParam, LPARAM lParam)
  270. {
  271. if(WM_CONNECT_WLAN_RESULT == uMsg) {
  272. auto rc = (ErrorCodeEnum)wParam;
  273. LeaveProgressBar();
  274. if (rc != Error_Succeed){
  275. MessageBoxA(CSimpleStringA::Format("连接失败: %s", m_pEntity->GetLastErrMsg()));
  276. } else {
  277. MessageBoxA("连接成功!");
  278. }
  279. }
  280. return 0;
  281. }
  282. LRESULT CMobileDlg::OnProfileResult(UINT uMsg, WPARAM wParam, LPARAM lParam)
  283. {
  284. auto rc = (ErrorCodeEnum)wParam;
  285. LeaveProgressBar();
  286. if (rc != Error_Succeed){
  287. if(lParam == 0) {
  288. MessageBoxA(CSimpleStringA::Format("操作失败: %s", m_pEntity->GetLastErrMsg()));
  289. }
  290. }
  291. else
  292. {
  293. BOOL bApply = m_btnApply.GetCheck();
  294. BOOL bApplyOld = bApply;
  295. if(uMsg == WM_DELETE_PROFILE_RESULT) {
  296. bApply = FALSE;
  297. }
  298. if(m_bConnected) {
  299. if(/*FALSE && */!IsDlgButtonChecked(IDC_CHECK_MNTBYRVC)) {
  300. //停掉连接状态
  301. SendMessageA(WM_COMMAND, MAKEWPARAM(IDC_BUTTON_CONNECT, BN_CLICKED), NULL);
  302. } else if(bApply) {
  303. bApply = FALSE;
  304. Dbg("Because still connected...");
  305. }
  306. }
  307. CSimpleStringA strDongle;
  308. int nIndex = GetInterfaceIdInCombo(strDongle);
  309. if(nIndex >= 0 && strDongle.GetLength() > 0) {
  310. assert(g_DongleInfos.GetCount() > nIndex);
  311. if(m_localSIM) {
  312. //assert((m_bConnected && g_DongleInfos[nIndex].subInfo.mbnCntState == MBN_ACTIVATION_STATE_ACTIVATED )
  313. // || (!m_bConnected && g_DongleInfos[nIndex].subInfo.mbnCntState != MBN_ACTIVATION_STATE_ACTIVATED));
  314. } else {
  315. /*
  316. int nCntType = m_comboCntType.GetCurSel();
  317. for(int i=0; i<g_DongleInfos.GetCount(); ++i) {
  318. if(g_DongleInfos[i].usDeviceType == DEVTYPE_ANDROID_MAIN && nCntType == 3) {
  319. nIndex = i;
  320. break;
  321. } else if(g_DongleInfos[i].usDeviceType == DEVTYPE_ANDROID_VICE && nCntType == 4) {
  322. nIndex = i;
  323. break;
  324. }
  325. }
  326. */
  327. }
  328. if(m_pEntity->UpdateProfileInfo(nIndex)) {
  329. m_comboProfiles.ResetContent();
  330. const MBNProfileList& info = g_DongleInfos[nIndex].profileList;
  331. if(info.GetCount() > 0) {
  332. int aim = 0;
  333. Dbg("connected: %d", m_bConnected ? 1 : 0);
  334. for(int i=0; i<info.GetCount(); ++i) {
  335. m_comboProfiles.AddString(info[i].AccessInfo.strProfileDesc);
  336. Dbg("mProfileDesc:%s vs %s", (LPCTSTR)m_strProfileDesc, (LPCTSTR)info[i].AccessInfo.strProfileDesc);
  337. if(bApply && !info[i].AccessInfo.strProfileDesc.Compare((LPCTSTR)m_strProfileDesc)) {
  338. Dbg("selected: %d", i);
  339. aim = i;
  340. } else if(/*m_bConnected && */g_DongleInfos[nIndex].subInfo.strProfileName.GetLength() > 0) {
  341. Dbg("profileName: %s", (LPCTSTR)g_DongleInfos[nIndex].subInfo.strProfileName);
  342. if(!g_DongleInfos[nIndex].subInfo.strProfileName.Compare(info[i].strProfileName)) {
  343. Dbg("selected2: %d", i);
  344. aim = i;
  345. }
  346. }
  347. }
  348. m_comboProfiles.SetCurSel(aim);
  349. //BOOL bEmpty = TRUE;
  350. //OnCbnSelchangeComboProfiles(NULL, NULL, NULL, bEmpty);
  351. }
  352. } else {
  353. MessageBoxA("更新配置文件列表失败,请重新打开配置窗口!");
  354. EndDialog(-1);
  355. return 0;
  356. }
  357. }
  358. if(uMsg == WM_ADD_PROFILE_RESULT && lParam == 0) {
  359. PostMessage(WM_COMMAND, MAKEWPARAM(IDC_BUTTON_EXPAND, BN_CLICKED), NULL);
  360. MessageBoxA("添加配置成功!");
  361. PostMessage(WM_COMMAND, MAKEWPARAM(IDC_BUTTON_EXPAND, BN_CLICKED), NULL);
  362. } else if(uMsg == WM_DELETE_PROFILE_RESULT && lParam == 0) {
  363. PostMessage(WM_COMMAND, MAKEWPARAM(IDC_BUTTON_EXPAND, BN_CLICKED), NULL);
  364. MessageBoxA("删除配置成功!");
  365. PostMessage(WM_COMMAND, MAKEWPARAM(IDC_BUTTON_EXPAND, BN_CLICKED), NULL);
  366. } else if(uMsg == WM_UPDATE_PROFILE_RESULT && lParam == 0) {
  367. PostMessage(WM_COMMAND, MAKEWPARAM(IDC_BUTTON_EXPAND, BN_CLICKED), NULL);
  368. MessageBoxA("更新配置成功!");
  369. PostMessage(WM_COMMAND, MAKEWPARAM(IDC_BUTTON_EXPAND, BN_CLICKED), NULL);
  370. }
  371. }
  372. return 0;
  373. }
  374. LRESULT CMobileDlg::OnConnectResult(UINT uMsg, WPARAM wParam, LPARAM lParam)
  375. {
  376. Dbg("Receive OnConnectResult msg : %d", lParam);
  377. auto rc = (ErrorCodeEnum)wParam;
  378. if(uMsg != WM_TIMER_SWITCH) {
  379. if(m_bConnected) {
  380. return 0;
  381. }
  382. LeaveProgressBar(WM_TIMER_CONNECT);
  383. }
  384. if(lParam > 0) {
  385. if (rc != Error_Succeed) {
  386. if(uMsg != WM_TIMER_SWITCH) {
  387. MessageBoxA(CSimpleStringA::Format("拨号失败: %s", m_pEntity->GetLastErrMsg()));
  388. } else {
  389. MessageBoxA(CSimpleStringA::Format("切换数据卡失败: %s", m_pEntity->GetLastErrMsg()));
  390. }
  391. } else {//拨号成功或切换数据卡成功
  392. CSimpleStringA strDongle;
  393. int nIndex = GetInterfaceIdInCombo(strDongle);
  394. if(nIndex >= 0) {
  395. ATLASSERT(nIndex >= 0 && strDongle.GetLength() > 0);
  396. if(m_pEntity->UpdateSubInfo(nIndex)) {
  397. Dbg("%d vs %d", nIndex, g_DongleInfos.GetCount());
  398. ATLASSERT(g_DongleInfos.GetCount() > nIndex);
  399. if(uMsg == WM_TIMER_SWITCH) {
  400. if(g_DongleInfos[nIndex].priority > 0) {
  401. m_btnConnect.SetWindowTextA("已应用");
  402. m_btnConnect.EnableWindow(FALSE);
  403. MessageBoxA("切换成功!");
  404. //TODO
  405. if(m_nWhoConnected == CNT_INVALID || !m_bConnected) {
  406. OnFatalMsgChanged(WM_FATALMESSAGE_CHANGE, Error_Succeed, NULL);
  407. }
  408. } else {
  409. m_btnConnect.SetWindowTextA("应用");
  410. m_btnConnect.EnableWindow(TRUE);
  411. MessageBoxA("切换成功,请重新打开窗口!");
  412. EndDialog(-1);
  413. }
  414. } else {//拨号成功
  415. //BOOL fDefault = FALSE;
  416. //OnCbnSelchangeComboDongle(NULL, NULL, NULL, fDefault);
  417. if(g_DongleInfos[nIndex].subInfo.mbnCntState == MBN_ACTIVATION_STATE_ACTIVATED) {
  418. if(g_DongleInfos[nIndex].usDeviceType & DEVTYPE_ANDROID_UKNOWN) {
  419. TriggerConnectState(CNT_ANDROID);
  420. } else if(g_DongleInfos[nIndex].usDeviceType == DEVTYPE_MODEM) {
  421. TriggerConnectState(CNT_RAS);
  422. } else if(g_DongleInfos[nIndex].usDeviceType == DEVTYPE_MBB) {
  423. TriggerConnectState(CNT_MBB);
  424. } else {
  425. TriggerConnectState(CNT_MBN);
  426. }
  427. }
  428. }
  429. SetDlgItemTextA(IDC_STATIC_PORT, ConvertStatusToString(g_DongleInfos[nIndex].state));
  430. OnSignalChanged(uMsg, wParam, g_DongleInfos[nIndex].subInfo.ulSingnal);
  431. } else {
  432. if(uMsg != WM_TIMER_SWITCH) {
  433. MessageBoxA("更新连接状态失败,请重新打开配置窗口!");
  434. } else {
  435. MessageBoxA("更新状态失败,请重新打开配置窗口!");
  436. }
  437. EndDialog(-1);
  438. }
  439. }
  440. }
  441. } else {
  442. if(rc == Error_Succeed) {
  443. UpdateDongles();
  444. }
  445. }
  446. return 0;
  447. }
  448. LRESULT CMobileDlg::OnDisConnectResult(UINT uMsg, WPARAM wParam, LPARAM lParam)
  449. {
  450. Dbg("Receive OnDisConnectResult msg");
  451. auto rc = (ErrorCodeEnum)wParam;
  452. if(m_bConnected == false) {
  453. Dbg("in disconnect receive the disconnect msg");
  454. return 0;
  455. }
  456. LeaveProgressBar(WM_TIMER_DISCONNECT);
  457. if(rc == Error_Succeed) {
  458. CSimpleStringA strDongle;
  459. int nIndex = GetInterfaceIdInCombo(strDongle);
  460. Dbg("%d vs %d", nIndex, g_DongleInfos.GetCount());
  461. ATLASSERT(nIndex >= 0 && strDongle.GetLength() > 0);
  462. ATLASSERT(g_DongleInfos.GetCount() > nIndex);
  463. if(m_pEntity->UpdateSubInfo(nIndex)) {
  464. //BOOL fDefault = FALSE;
  465. //OnCbnSelchangeComboDongle(NULL, NULL, NULL, fDefault);
  466. if(g_DongleInfos[nIndex].subInfo.mbnCntState == MBN_ACTIVATION_STATE_DEACTIVATED) {
  467. TriggerConnectState(CNT_INVALID);
  468. } else {
  469. Dbg("index: %d, cnt state: %d", g_DongleInfos[nIndex].subInfo.mbnCntState);
  470. }
  471. } else {
  472. MessageBoxA("更新连接状态失败,请重新打开配置窗口!");
  473. EndDialog(-1);
  474. }
  475. } else {
  476. MessageBoxA(CSimpleStringA::Format("断连失败: %s", m_pEntity->GetLastErrMsg()));
  477. }
  478. return 0;
  479. }
  480. LRESULT CMobileDlg::OnCustomTimer(UINT uMsg, WPARAM wParam, LPARAM /*lParam*/, BOOL& bHandled)
  481. {
  482. bHandled = FALSE;
  483. if(wParam > WM_TIMER_INVALID && wParam < WM_TIMER_PROCESS_MAX) {
  484. LeaveProgressBar(wParam);
  485. MessageBoxA("等待操作返回超时,为确保信息准确显示,请重新打开对话框!", "消息", MB_OK | MB_ICONWARNING);
  486. EndDialog(wParam);
  487. bHandled = TRUE;
  488. }
  489. return 0;
  490. }
  491. LRESULT CMobileDlg::OnSelAdvancedChange(WORD wNotifyCode, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
  492. {
  493. if(wNotifyCode == BN_CLICKED) {
  494. int store = m_nGenType;
  495. m_nGenType = 3;
  496. if(IsDlgButtonChecked(IDC_RADIO_3G)) {
  497. m_nGenType = 1;
  498. } else if(IsDlgButtonChecked(IDC_RADIO_4G)) {
  499. m_nGenType = 2;
  500. } else if(IsDlgButtonChecked(IDC_RADIO_DEFAULT)) {
  501. m_nGenType = 3;
  502. } else if(IsDlgButtonChecked(IDC_RADIO_WEB)) {
  503. m_nGenType = 4;
  504. }
  505. if(store != m_nGenType) {
  506. m_pEntity->SetAdvancedConfig(m_nGenType);
  507. }
  508. if(m_nReversedType != m_nGenType) {
  509. SetDlgItemTextA(IDC_STATIC_ADVANCED, "终端上网类型-需重启应用:");
  510. } else {
  511. SetDlgItemTextA(IDC_STATIC_ADVANCED, "终端上网类型:");
  512. }
  513. BOOL checked = IsDlgButtonChecked(IDC_RADIO_WEB);
  514. Dbg("IDC_RADIO_WEB checked: %d", checked);
  515. GetDlgItem(IDC_RADIO_MBB_WIRE).EnableWindow(checked);
  516. GetDlgItem(IDC_RADIO_MBB_WLAN).EnableWindow(checked);
  517. if(IsDlgButtonChecked(IDC_RADIO_MBB_WIRE) || IsDlgButtonChecked(IDC_RADIO_MBB_WLAN)) {
  518. GetDlgItem(IDC_BUTTON_MBB_CONFIG).EnableWindow(checked);
  519. } else {
  520. m_pEntity->GetMBBRunConfig(m_sMBBParam, TRUE);
  521. CheckRadioButton(IDC_RADIO_MBB_WIRE, IDC_RADIO_MBB_WLAN,
  522. IDC_RADIO_MBB_WIRE + m_sMBBParam.connectType - 1);
  523. BOOL fDefault = FALSE;
  524. OnSelMBBChange(BN_CLICKED, WM_COMMAND, m_hWnd, fDefault);
  525. }
  526. }
  527. return 0;
  528. }
  529. LRESULT CMobileDlg::OnSelMBBChange(WORD wNotifyCode, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
  530. {
  531. if(wNotifyCode == BN_CLICKED) {
  532. if(IsDlgButtonChecked(IDC_RADIO_MBB_WIRE)) {
  533. m_sMBBParam.connectType = MBB_CONNECT_WIRE;
  534. GetDlgItem(IDC_BUTTON_MBB_CONFIG).EnableWindow(TRUE);
  535. } else if(IsDlgButtonChecked(IDC_RADIO_MBB_WLAN)){
  536. m_sMBBParam.connectType = MBB_CONNECT_WIFI;
  537. GetDlgItem(IDC_BUTTON_MBB_CONFIG).EnableWindow(TRUE);
  538. } else {
  539. ATLASSERT(FALSE);
  540. m_sMBBParam.connectType = MBB_CONNECT_UNKONWN;
  541. GetDlgItem(IDC_BUTTON_MBB_CONFIG).EnableWindow(FALSE);
  542. }
  543. if(HasUpdatedMBBParam()) {
  544. m_pEntity->SEtMBBRunConfig(m_sMBBParam);
  545. m_pEntity->GetMBBRunConfig(m_sReverseMBBParam, FALSE);
  546. ATLASSERT(!this->HasUpdatedMBBParam());
  547. }
  548. }
  549. return 0;
  550. }
  551. LRESULT CMobileDlg::OnWlanConfigOpen(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
  552. {
  553. Dbg("OnWlanConfigOpen happen!");
  554. CWlanConfigDlg dlg(this);
  555. int nRes = dlg.DoModal(m_hWnd);
  556. Dbg("CWlanConfigDlg::DoModal returned: %d, error: %d", nRes, GetLastError());
  557. if(nRes != IDOK_EX) {
  558. return 0;
  559. }
  560. if(dlg.HasUpdated(FALSE) || this->HasUpdatedMBBParam()) {
  561. m_pEntity->SEtMBBRunConfig(m_sMBBParam);
  562. m_pEntity->GetMBBRunConfig(m_sReverseMBBParam, FALSE);
  563. ATLASSERT(!this->HasUpdatedMBBParam());
  564. }
  565. return 0;
  566. }
  567. LRESULT CMobileDlg::OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
  568. {
  569. // set icons
  570. HICON hIcon = AtlLoadIconImage(IDR_MAINFRAME, LR_DEFAULTCOLOR, ::GetSystemMetrics(SM_CXICON), ::GetSystemMetrics(SM_CYICON));
  571. SetIcon(hIcon, TRUE);
  572. HICON hIconSmall = AtlLoadIconImage(IDR_MAINFRAME, LR_DEFAULTCOLOR, ::GetSystemMetrics(SM_CXSMICON), ::GetSystemMetrics(SM_CYSMICON));
  573. SetIcon(hIconSmall, FALSE);
  574. int cx = GetSystemMetrics(SM_CXSCREEN);
  575. RECT rcDlg;
  576. ::GetWindowRect(m_hWnd, &rcDlg);
  577. ::SetWindowPos(m_hWnd, NULL, (cx + rcDlg.left - rcDlg.right)/2, 20, -1, -1, SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
  578. m_pEntity->m_hDialogWnd = m_hWnd;
  579. m_pEntity->m_fsm.SetNotifyWnd(m_hWnd);
  580. SetEvent(m_pEntity->m_hGUIReadyEvent);
  581. m_localSIM = !m_pEntity->IsAndroidControl();
  582. m_ProgressBar.Create(m_hWnd);
  583. //m_strPassword = DEFAULT_PASSWORD_CHECK;
  584. //m_strUserName = "123@szchinacmb.vpdn.gd";
  585. // 完成相关控件的子类化工作
  586. DoDataExchange(FALSE);
  587. InitializeControls();
  588. //GetDlgItem(IDC_RADIO_3G).ShowWindow(FALSE);
  589. //GetDlgItem(IDC_RADIO_4G).ShowWindow(FALSE);
  590. //GetDlgItem(IDC_RADIO_DEFAULT).ShowWindow(FALSE);
  591. //GetDlgItem(IDC_STATIC_ADVANCED).ShowWindow(FALSE);
  592. //SetDlgItemTextA(IDC_RADIO_3G, "卡 1");
  593. //SetDlgItemTextA(IDC_RADIO_4G, "卡 2");
  594. //SetDlgItemTextA(IDC_RADIO_DEFAULT, "自动");
  595. //SetDlgItemTextA(IDC_STATIC_ADVANCED, "双卡管理:");
  596. UpdateDongles();
  597. RECT rect;
  598. GetWindowRect(&rect);
  599. Dbg("%d, %d", rect.right-rect.left, rect.bottom-rect.top);
  600. GetDlgItem(IDC_STATIC_LOGIN).GetWindowRect(&rect);
  601. Dbg("2: %d, %d", rect.right-rect.left, rect.bottom-rect.top);
  602. SetDlgSizeToSmall();
  603. GetWindowRect(&rect);
  604. Dbg("3: %d, %d", rect.right-rect.left, rect.bottom-rect.top);
  605. GetDlgItem(IDC_STATIC_LOGIN).GetWindowRect(&rect);
  606. Dbg("4: %d, %d", rect.right-rect.left, rect.bottom-rect.top);
  607. return TRUE;
  608. }
  609. LRESULT CMobileDlg::OnOK(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
  610. {
  611. CloseVirtualKeyboard();
  612. EndDialog(wID);
  613. return 0;
  614. }
  615. LRESULT CMobileDlg::OnCancel(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
  616. {
  617. CloseVirtualKeyboard();
  618. BOOL fInvalid = FALSE;
  619. if(m_nGenType == 4) {
  620. if(m_sMBBParam.connectType == MBB_CONNECT_UNKONWN) {
  621. fInvalid = TRUE;
  622. } else if(m_sMBBParam.loginParam.strUsername.IsNullOrEmpty()) {
  623. fInvalid = TRUE;
  624. } else if(m_sMBBParam.loginParam.strPassword.IsNullOrEmpty()) {
  625. fInvalid = TRUE;
  626. }else if(m_sMBBParam.connectType == MBB_CONNECT_WIFI) {
  627. if(m_sMBBParam.wlanConnectParam.strUsername.IsNullOrEmpty()) {
  628. fInvalid = TRUE;
  629. } else if(m_sMBBParam.wlanConnectParam.strPassword.IsNullOrEmpty()) {
  630. fInvalid = TRUE;
  631. }
  632. }
  633. }
  634. if(fInvalid) {
  635. MessageBox("请填写华为原装未升驱卡托拨号所需的配置信息!", "提示", MB_OK);
  636. PostMessageA(WM_COMMAND, MAKEWPARAM(IDC_BUTTON_MBB_CONFIG, BN_CLICKED), NULL);
  637. return 0;
  638. }
  639. EndDialog(wID);
  640. return 0;
  641. }
  642. LRESULT CMobileDlg::OnConnect(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
  643. {
  644. int nSel = m_comboDongles.GetCurSel();
  645. int nSel2 = m_comboProfiles.GetCurSel();
  646. int nSel3 = m_comboCntType.GetCurSel();
  647. if(nSel3 == 4 || nSel3 == 3) {//android
  648. m_btnConnect.EnableWindow(FALSE);
  649. int slotID = g_DongleInfos[nSel].usDeviceType - DEVTYPE_ANDROID_UKNOWN;
  650. EnterProgressBar(TIMER_TIMTOUT_MAX, WM_TIMER_SWITCH);
  651. m_btnConnect.SetWindowTextA("切换中\r\n...");
  652. auto rc = m_pEntity->SwitchDefaultSlot(slotID);
  653. LeaveProgressBar(WM_TIMER_SWITCH);
  654. if(rc == Error_Succeed) {
  655. OnConnectResult(WM_TIMER_SWITCH, Error_Succeed, 1);
  656. } else {
  657. MessageBoxA(CSimpleStringA::Format("切换数据卡失败: %s", m_pEntity->GetLastErrMsg()));
  658. m_btnConnect.SetWindowTextA("应用");
  659. m_btnConnect.EnableWindow(TRUE);
  660. }
  661. return 0;
  662. }
  663. if(m_bConnected) {
  664. m_btnConnect.EnableWindow(FALSE);
  665. auto rc = m_pEntity->Disconnect(nSel3, g_DongleInfos[nSel].csInterfaceId);
  666. if(rc == Error_Succeed) {
  667. EnterProgressBar(TIMER_TIMTOUT_MAX, WM_TIMER_DISCONNECT);
  668. m_btnConnect.SetWindowTextA("断开中\r\n...");
  669. } else {
  670. m_btnConnect.EnableWindow(TRUE);
  671. MessageBoxA(CSimpleStringA::Format("断开连接失败: %s", m_pEntity->GetLastErrMsg()));
  672. }
  673. } else {
  674. if(nSel == CB_ERR) {
  675. MessageBoxA("请选择所需连接的网卡!");
  676. return 0;
  677. }
  678. if(nSel2 == CB_ERR) {
  679. MessageBoxA("请选择拨号配置文件 或 新增拨号配置文件!");
  680. return 0;
  681. }
  682. if(nSel3 == CB_ERR || nSel3 == CNT_INVALID) {
  683. MessageBoxA("请选择合适的拨号方式!");
  684. return 0;
  685. }
  686. m_btnConnect.EnableWindow(FALSE);
  687. auto rc = m_pEntity->Connect(nSel3, g_DongleInfos[nSel].csInterfaceId,
  688. g_DongleInfos[nSel].profileList[nSel2].strProfileName);
  689. if(rc == Error_Succeed) {
  690. EnterProgressBar(TIMER_TIMTOUT_MAX, WM_TIMER_CONNECT);
  691. m_btnConnect.SetWindowTextA("连接中\r\n...");
  692. } else {
  693. m_btnConnect.EnableWindow(TRUE);
  694. MessageBoxA(CSimpleStringA::Format("拨号失败: %s", m_pEntity->GetLastErrMsg()));
  695. }
  696. }
  697. return 0;
  698. }
  699. bool CMobileDlg::OpenVirtualKeyboard()
  700. {
  701. HANDLE hKeyboard = FindProcessByName("VirtualKeyboard.exe");
  702. if (hKeyboard == NULL)
  703. {
  704. HINSTANCE hNewExe = ShellExecuteA(NULL, "open", "VirtualKeyboard.exe", NULL, NULL, SW_SHOWNORMAL);
  705. if ((DWORD)hNewExe <= 32)
  706. {
  707. MessageBox("启动触摸键盘失败!", NULL, 0);
  708. return false;
  709. }
  710. }
  711. return true;
  712. }
  713. bool CMobileDlg::CloseVirtualKeyboard()
  714. {
  715. HANDLE hKeyboard = FindProcessByName("VirtualKeyboard.exe");
  716. if (hKeyboard != NULL)
  717. {
  718. TerminateProcess(hKeyboard, 0);
  719. return true;
  720. }
  721. return false;
  722. }
  723. void CMobileDlg::InitializeControls()
  724. {
  725. m_comboDongles = this->GetDlgItem(IDC_COMBO_DONGLE);
  726. //m_comboProfiles = this->GetDlgItem(IDC_COMBO_PROFILES);
  727. m_comboCntType.AddString("Auto");
  728. m_comboCntType.AddString("4G-MBN"); //1
  729. m_comboCntType.AddString("3G-RAS"); //2
  730. m_comboCntType.AddString("主卡"); //3
  731. m_comboCntType.AddString("副卡"); //4
  732. m_comboCntType.AddString("HW-MBB"); //5
  733. m_comboCntType.SetCurSel(CNT_INVALID);
  734. m_comboModeType.AddString("无");
  735. m_comboModeType.AddString("PAP");
  736. m_comboModeType.AddString("CHAP");
  737. m_comboModeType.AddString("MS-CHAP v2");
  738. m_comboModeType.DeleteString(3);
  739. m_comboModeType.AddString("PAP 或 CHAP");
  740. m_comboModeType.SetCurSel(0);
  741. m_comboIPType.AddString("默认");
  742. m_comboIPType.AddString("IPv4");
  743. m_comboIPType.AddString("IPv6");
  744. m_comboIPType.AddString("IPv4v6");
  745. m_comboIPType.AddString("IPv4v6XLAT");
  746. m_comboIPType.SetCurSel(0);
  747. m_comboPointType.AddString("Internet");
  748. //m_comboPointType.AddString("Internet及连接");
  749. //m_comboPointType.AddString("连接");
  750. m_comboPointType.SetCurSel(0);
  751. CheckDlgButton(IDC_CHECK_APN_APPLY, 1);
  752. GetDlgItem(IDC_BUTTON_DROPUP).SetWindowTextA("▲");
  753. GetDlgItem(IDC_BUTTON_DROPUP).ShowWindow(FALSE);
  754. /*
  755. IDC_COMBO_CON_MODE 登录类型选择框 m_comboModeType
  756. IDC_STATIC_TXT_MODE 登录类型
  757. IDC_STATIC_TXT_IPTYPE APN 类型 m_comboIPType
  758. IDC_COMBO_CON_IPTYPE APN 类型选择框
  759. IDC_STATIC_TXT_POINTTYPE 接入点类型 m_comboPointType
  760. IDC_COMBO_PONT_TYPE 接入点类型选择框
  761. */
  762. GetDlgItem(IDC_BUTTON_DEFAULT_CONNECT).ShowWindow(!m_localSIM);
  763. if(!m_localSIM) {
  764. //m_comboPointType.ShowWindow(FALSE);
  765. //SetDlgItemTextA(IDC_STATIC_TXT_PROFILENAME, "配置文件名称:");
  766. //GetDlgItem(IDC_STATIC_TXT_IPTYPE).ShowWindow(FALSE);
  767. //SetDlgItemTextA(IDC_STATIC_TXT_IPTYPE, "APN 类型:");
  768. //GetDlgItem(IDC_COMBO_CON_IPTYPE).ShowWindow(FALSE);
  769. //GetDlgItem(IDC_STATIC_TXT_POINTTYPE).ShowWindow(FALSE);
  770. //GetDlgItem(IDC_COMBO_PONT_TYPE).ShowWindow(FALSE);
  771. //SetDlgItemTextA(IDC_STATIC_TXT_MODE, "身份验证类型:");
  772. //SetDlgItemTextA(IDC_STATIC_LOGIN, "拨号配置(接入点)");
  773. //SetDlgItemTextA(IDC_BUTTON_CONNECT, "应用");
  774. }
  775. CheckDlgButton(IDC_CHECK_MNTBYRVC, m_pEntity->IsManageByUser() ? FALSE : TRUE);
  776. m_nReversedType = m_pEntity->GetCurAdvancedConfig();
  777. m_nGenType = m_pEntity->GetCurAdvancedConfig(true);
  778. Dbg("GenType:%d, ReverseType:%d", m_nGenType, m_nReversedType);
  779. // 默认程序自动管理
  780. GetDlgItem(IDC_CHECK_MNTBYRVC).ShowWindow(FALSE);
  781. if(!m_localSIM) {
  782. GetDlgItem(IDC_RADIO_3G).EnableWindow(FALSE);
  783. GetDlgItem(IDC_RADIO_4G).EnableWindow(FALSE);
  784. GetDlgItem(IDC_RADIO_DEFAULT).EnableWindow(FALSE);
  785. GetDlgItem(IDC_RADIO_WEB).EnableWindow(FALSE);
  786. } else {
  787. CheckRadioButton(IDC_RADIO_3G, IDC_RADIO_WEB, IDC_RADIO_3G + m_nGenType-1);
  788. if(m_nReversedType != m_nGenType) {
  789. SetDlgItemTextA(IDC_STATIC_ADVANCED, "终端上网类型-需重启应用:");
  790. } else {
  791. SetDlgItemTextA(IDC_STATIC_ADVANCED, "终端上网类型:");
  792. }
  793. }
  794. const BOOL checked = IsDlgButtonChecked(IDC_RADIO_WEB);
  795. GetDlgItem(IDC_RADIO_MBB_WIRE).EnableWindow(checked);
  796. GetDlgItem(IDC_RADIO_MBB_WLAN).EnableWindow(checked);
  797. //GetDlgItem(IDC_BUTTON_MBB_CONFIG).EnableWindow(checked);
  798. GetDlgItem(IDC_BUTTON_MBB_CONFIG).ShowWindow(FALSE);
  799. m_pEntity->GetMBBRunConfig(m_sReverseMBBParam, FALSE);
  800. m_pEntity->GetMBBRunConfig(m_sMBBParam, FALSE);
  801. CheckRadioButton(IDC_RADIO_MBB_WIRE, IDC_RADIO_MBB_WLAN,
  802. IDC_RADIO_MBB_WIRE + m_sReverseMBBParam.connectType - 1);
  803. if(m_sReverseMBBParam.connectType != MBB_CONNECT_UNKONWN && checked) {
  804. GetDlgItem(IDC_BUTTON_MBB_CONFIG).EnableWindow(TRUE);
  805. }
  806. }
  807. void CMobileDlg::UpdateDongles()
  808. {
  809. int cnt = m_pEntity->UpdateDongleInfo();
  810. m_comboDongles.ResetContent();
  811. m_comboProfiles.ResetContent();
  812. this->SetWindowTextA((LPCTSTR)CSimpleStringA::Format("APN 拨号配置(%d)", cnt));
  813. if(cnt > 0) {
  814. int cntType = CNT_INVALID;
  815. EnableControls(TRUE);
  816. int aim = 0;
  817. int activeOne = -1;
  818. m_dongleType = 0;
  819. for(int i=0; i<cnt; ++i) {
  820. m_comboDongles.AddString(g_DongleInfos[i].subInfo.strProviderName);
  821. if(g_DongleInfos[i].subInfo.mbnCntState == MBN_ACTIVATION_STATE_ACTIVATED) {
  822. aim = i;
  823. if(g_DongleInfos[aim].usDeviceType & DEVTYPE_ANDROID_UKNOWN) {
  824. cntType = CNT_ANDROID;
  825. } else if(g_DongleInfos[aim].usDeviceType == DEVTYPE_MODEM) {
  826. cntType = CNT_RAS;
  827. } else if(g_DongleInfos[aim].usDeviceType == DEVTYPE_MBB) {
  828. cntType = CNT_MBB;
  829. } else if(g_DongleInfos[aim].usDeviceType == DEVTYPE_INTER){
  830. cntType = CNT_MBN;
  831. }
  832. }
  833. if(g_DongleInfos[i].priority > 0) {
  834. activeOne = i;
  835. }
  836. m_dongleType |= g_DongleInfos[i].usDeviceType;
  837. }
  838. ATLASSERT(aim == 0 || cntType != CNT_INVALID);
  839. m_comboDongles.SetCurSel(aim);
  840. if((m_dongleType & DEVTYPE_ANDROID_UKNOWN) && activeOne == -1) {
  841. SetDlgItemTextA(IDC_STATIC_TXT_WARN, "当前未能识别到默认移动数据应用卡,请进行选择(应用)!");
  842. } else {
  843. GetDlgItem(IDC_STATIC_TXT_WARN).ShowWindow(SW_HIDE);
  844. }
  845. TriggerConnectState(cntType);
  846. if(cntType != CNT_INVALID) {
  847. OnSignalChanged(0, NULL, g_DongleInfos[aim].subInfo.ulSingnal);
  848. }
  849. BOOL bDefault = 0;
  850. OnCbnSelchangeComboDongle(0, 0, NULL, bDefault);
  851. } else {
  852. if(cnt == -2) {
  853. SetDlgItemTextA(IDC_STATIC_TXT_WARN, "当前未连接到多合一,请稍后再试!");
  854. } else if(cnt == -1) {
  855. SetDlgItemTextA(IDC_STATIC_TXT_WARN, "连接多合一管控实体失败!");
  856. } else if(cnt == 0) {
  857. SetDlgItemTextA(IDC_STATIC_TXT_WARN, "未检测到上网卡(或卡槽)相关信息,请检查设备!");
  858. } else if(cnt == -500) {
  859. SetDlgItemTextA(IDC_STATIC_TXT_WARN, m_pEntity->GetLastErrMsg());
  860. }
  861. //将提示栏显示出来
  862. GetDlgItem(IDC_STATIC_TXT_WARN).ShowWindow(SW_SHOW);
  863. TriggerConnectState(CNT_INVALID);
  864. EnableControls(FALSE);
  865. }
  866. }
  867. void CMobileDlg::EnableControls(BOOL bEnable /*= TRUE*/)
  868. {
  869. GetDlgItem(IDC_BUTTON_EXPAND).EnableWindow(bEnable);
  870. GetDlgItem(IDC_BUTTON_APN_STORE).EnableWindow(bEnable);
  871. GetDlgItem(IDC_BUTTON_CONNECT).EnableWindow(bEnable);
  872. GetDlgItem(IDC_COMBO_PROFILES).EnableWindow(bEnable);
  873. GetDlgItem(IDC_COMBO_DONGLE).EnableWindow(bEnable);
  874. GetDlgItem(IDC_COMBO_CON_MODE).EnableWindow(bEnable);
  875. GetDlgItem(IDC_COMBO_CON_IPTYPE).EnableWindow(bEnable);
  876. GetDlgItem(IDC_EDIT_USER).EnableWindow(bEnable);
  877. GetDlgItem(IDC_EDIT_PASSWORD).EnableWindow(bEnable);
  878. GetDlgItem(IDC_CHECK_VIEW_PASSWORD).EnableWindow(bEnable);
  879. GetDlgItem(IDC_EDIT_APN).EnableWindow(bEnable);
  880. GetDlgItem(IDC_CHECK_APN_APPLY).EnableWindow(bEnable);
  881. GetDlgItem(IDC_COMBO_PONT_TYPE).EnableWindow(bEnable);
  882. GetDlgItem(IDC_EDIT_PROFILE).EnableWindow(bEnable);
  883. GetDlgItem(IDC_BUTTON_CLEAR).EnableWindow(bEnable);
  884. GetDlgItem(IDC_BUTTON_DELETE).EnableWindow(bEnable);
  885. GetDlgItem(IDC_CHECK_MNTBYRVC).EnableWindow(bEnable);
  886. //不让用户更改拨号方式
  887. GetDlgItem(IDC_COMBO_GTYPE).EnableWindow(FALSE);
  888. }
  889. void CMobileDlg::EnterProgressBar(DWORD dwTimeout, DWORD nTimerID)
  890. {
  891. EnableWindow(FALSE);
  892. m_ProgressBar.ResetStep();
  893. m_ProgressBar.ShowWindow(SW_SHOW);
  894. m_ProgressBar.CenterWindow();
  895. if(dwTimeout != INFINITE) {
  896. SetTimer(nTimerID, dwTimeout);
  897. }
  898. }
  899. void CMobileDlg::LeaveProgressBar(DWORD nTimerID)
  900. {
  901. if(nTimerID == WM_TIMER_INVALID || KillTimer(nTimerID)) {
  902. m_ProgressBar.ShowWindow(SW_HIDE);
  903. EnableWindow(TRUE);
  904. if(nTimerID == WM_TIMER_CONNECT && !m_btnConnect.IsWindowEnabled()) {
  905. m_btnConnect.EnableWindow(TRUE);
  906. m_btnConnect.SetWindowTextA("连接");
  907. Dbg("set connect btn text");
  908. } else if(nTimerID == WM_TIMER_DISCONNECT && !m_btnConnect.IsWindowEnabled()) {
  909. m_btnConnect.EnableWindow(TRUE);
  910. m_btnConnect.SetWindowTextA("断开连接");
  911. Dbg("set disconnect btn text");
  912. } /*else if(nTimerID == WM_TIMER_SWITCH && !m_btnConnect.IsWindowEnabled()) {
  913. m_btnConnect.EnableWindow(TRUE);
  914. m_btnConnect.SetWindowTextA("应用");
  915. }*/
  916. }
  917. }
  918. void CMobileDlg::TriggerConnectState(int nCntState)
  919. {
  920. Dbg("Enter TriggerConnectState %d", nCntState);
  921. if(nCntState == CNT_MBN || nCntState == CNT_RAS || nCntState == CNT_MBB) {
  922. Dbg("set disconnect text");
  923. m_btnConnect.SetWindowTextA("断开连接");
  924. m_btnConnect.EnableWindow(TRUE);
  925. GetDlgItem(IDC_COMBO_DONGLE).EnableWindow(FALSE); //已连接的情况下,不能选择卡托设备
  926. GetDlgItem(IDC_COMBO_PROFILES).EnableWindow(FALSE); //也不能选择配置文件,所以当前的卡托一定是已连接的
  927. } else if(nCntState == CNT_ANDROID) {
  928. GetDlgItem(IDC_COMBO_DONGLE).EnableWindow(TRUE);
  929. GetDlgItem(IDC_COMBO_PROFILES).EnableWindow(TRUE);
  930. } else if(nCntState == CNT_INVALID) {
  931. Dbg("set connet text");
  932. m_btnConnect.SetWindowTextA("连接");
  933. m_btnConnect.EnableWindow(TRUE);
  934. }
  935. m_bConnected = (nCntState != CNT_INVALID);
  936. m_nWhoConnected = nCntState;
  937. if(m_bConnected) {
  938. SetDlgItemTextA(IDC_STATIC_PERCENTAGE, "0%");
  939. SetDlgItemTextA(IDC_STATIC_SIGNAL, "网络强度:");
  940. SetDlgItemTextA(IDC_STATIC_STATUS, "已连接");
  941. OnFatalMsgChanged(WM_FATALMESSAGE_CHANGE, Error_Succeed, NULL);
  942. } else {
  943. SetDlgItemTextA(IDC_STATIC_PERCENTAGE, "NA");
  944. SetDlgItemTextA(IDC_STATIC_SIGNAL, "");
  945. SetDlgItemTextA(IDC_STATIC_STATUS, "已断开连接");
  946. GetDlgItem(IDC_COMBO_DONGLE).EnableWindow(TRUE);
  947. GetDlgItem(IDC_COMBO_PROFILES).EnableWindow(TRUE);
  948. }
  949. GetDlgItem(IDC_COMBO_GTYPE).EnableWindow(FALSE);
  950. }
  951. void CMobileDlg::ShowProfileCreateCtrl(BOOL bShow /*= TRUE*/)
  952. {
  953. GetDlgItem(IDC_STATIC_LOGIN).ShowWindow(bShow);
  954. GetDlgItem(IDC_STATIC_TXT_PROFILENAME).ShowWindow(bShow);
  955. GetDlgItem(IDC_EDIT_PROFILE).ShowWindow(bShow);
  956. GetDlgItem(IDC_STATIC_TXT_APN).ShowWindow(bShow);
  957. GetDlgItem(IDC_EDIT_APN).ShowWindow(bShow);
  958. GetDlgItem(IDC_STATIC_TXT_USER).ShowWindow(bShow);
  959. GetDlgItem(IDC_EDIT_USER).ShowWindow(bShow);
  960. GetDlgItem(IDC_STATIC_TXT_PASSWORD).ShowWindow(bShow);
  961. GetDlgItem(IDC_EDIT_PASSWORD).ShowWindow(bShow);
  962. GetDlgItem(IDC_CHECK_VIEW_PASSWORD).ShowWindow(bShow);
  963. GetDlgItem(IDC_STATIC_TXT_MODE).ShowWindow(bShow);
  964. GetDlgItem(IDC_COMBO_CON_MODE).ShowWindow(bShow);
  965. const int nSel3 = m_comboCntType.GetCurSel();
  966. if(nSel3 <= CNT_RAS || bShow == FALSE) {
  967. GetDlgItem(IDC_STATIC_TXT_IPTYPE).ShowWindow(bShow);
  968. GetDlgItem(IDC_COMBO_CON_IPTYPE).ShowWindow(bShow);
  969. GetDlgItem(IDC_STATIC_TXT_POINTTYPE).ShowWindow(bShow);
  970. GetDlgItem(IDC_COMBO_PONT_TYPE).ShowWindow(bShow);
  971. }
  972. GetDlgItem(IDC_CHECK_APN_APPLY).ShowWindow(bShow);
  973. GetDlgItem(IDC_BUTTON_APN_STORE).ShowWindow(bShow);
  974. //GetDlgItem(IDC_BUTTON_DROPUP).ShowWindow(bShow);
  975. GetDlgItem(IDC_BUTTON_CLEAR).ShowWindow(bShow);
  976. GetDlgItem(IDC_BUTTON_DELETE).ShowWindow(bShow);
  977. GetDlgItem(IDC_EDIT_PHONENUM).ShowWindow(bShow);
  978. GetDlgItem(IDC_CHECK_RASIO_PAP).ShowWindow(bShow);
  979. GetDlgItem(IDC_CHECK_RASIO_CHAP).ShowWindow(bShow);
  980. GetDlgItem(IDC_CHECK_RASIO_MSCHAPV2).ShowWindow(bShow);
  981. MoveDlgItems(bShow);
  982. }
  983. void CMobileDlg::_ClearProfileTxt()
  984. {
  985. SetDlgItemTextA(IDC_EDIT_PROFILE, "");
  986. SetDlgItemTextA(IDC_EDIT_APN, "");
  987. SetDlgItemTextA(IDC_EDIT_USER, "");
  988. SetDlgItemTextA(IDC_EDIT_PASSWORD, "");
  989. SetDlgItemTextA(IDC_EDIT_PHONENUM, "");
  990. CheckDlgButton(IDC_CHECK_RASIO_PAP, FALSE);
  991. CheckDlgButton(IDC_CHECK_RASIO_CHAP, FALSE);
  992. CheckDlgButton(IDC_CHECK_RASIO_MSCHAPV2, FALSE);
  993. m_strPassword = "";
  994. m_strPhoneNum = "";
  995. m_strUserName = "";
  996. m_comboModeType.SetCurSel(0);
  997. m_comboIPType.SetCurSel(0);
  998. m_comboPointType.SetCurSel(0);
  999. const int nCntType = m_comboCntType.GetCurSel();
  1000. if(nCntType == CNT_MBB) {
  1001. m_comboIPType.SetCurSel(1);
  1002. m_comboIPType.EnableWindow(FALSE);
  1003. m_comboModeType.SetCurSel(1);
  1004. } else {
  1005. m_comboIPType.EnableWindow(TRUE);
  1006. }
  1007. }
  1008. int CMobileDlg::GetInterfaceIdInCombo(CSimpleStringA& strCurDongle, bool bSlient /*= true*/)
  1009. {
  1010. int nSel = 0;
  1011. CString strDongle;
  1012. {
  1013. int selected = m_comboDongles.GetCurSel();
  1014. if(selected < 0) {
  1015. return -1;
  1016. }
  1017. int nLen = m_comboDongles.GetLBTextLen(selected);
  1018. m_comboDongles.GetLBText(selected, strDongle.GetBuffer(nLen));
  1019. strDongle.ReleaseBuffer();
  1020. Dbg("GetInterfaceIdInCombo::selected: %s", (LPCTSTR)strDongle);
  1021. }
  1022. for (int i=0; i<g_DongleInfos.GetCount(); ++i)
  1023. {
  1024. Dbg("GetInterfaceIdInCombo::idx[%d] %s", i, (LPCTSTR)g_DongleInfos[i].subInfo.strProviderName);
  1025. if(!strDongle.Compare((LPCTSTR)g_DongleInfos[i].subInfo.strProviderName)) {
  1026. strCurDongle = g_DongleInfos[i].csInterfaceId;
  1027. nSel = i;
  1028. Dbg("break");
  1029. break;
  1030. }
  1031. }
  1032. return nSel;
  1033. }
  1034. BOOL CMobileDlg::HasUpdatedMBBParam()
  1035. {
  1036. if(m_nGenType != 4) {
  1037. return FALSE;
  1038. }
  1039. if(m_sMBBParam.connectType != m_sReverseMBBParam.connectType) {
  1040. Dbg("@1@");
  1041. return TRUE;
  1042. }
  1043. if(m_sMBBParam.loginParam.strUsername.Compare(
  1044. (LPCTSTR)m_sReverseMBBParam.loginParam.strUsername) != 0) {
  1045. Dbg("@2@");
  1046. return TRUE;
  1047. }
  1048. if(m_sMBBParam.loginParam.strPassword.Compare(
  1049. (LPCTSTR)m_sReverseMBBParam.loginParam.strPassword) != 0) {
  1050. Dbg("@3@");
  1051. return TRUE;
  1052. }
  1053. if(m_sMBBParam.wlanConnectParam.strUsername.Compare(
  1054. (LPCTSTR)m_sReverseMBBParam.wlanConnectParam.strUsername) != 0) {
  1055. Dbg("@4@");
  1056. return TRUE;
  1057. }
  1058. if(m_sMBBParam.wlanConnectParam.strPassword.Compare(
  1059. (LPCTSTR)m_sReverseMBBParam.wlanConnectParam.strPassword) != 0) {
  1060. Dbg("@5@");
  1061. return TRUE;
  1062. }
  1063. if(m_sMBBParam.wlanConnectParam.Flag != m_sReverseMBBParam.wlanConnectParam.Flag) {
  1064. Dbg("@6@");
  1065. return TRUE;
  1066. }
  1067. return FALSE;
  1068. }
  1069. LRESULT CMobileDlg::OnBnClickedButtonApnStore(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
  1070. {
  1071. CloseVirtualKeyboard();
  1072. DoDataExchange(TRUE);
  1073. const int nCntType = m_comboCntType.GetCurSel();
  1074. int nSel = m_comboProfiles.GetCurSel();
  1075. CSimpleStringA strCurDongle;
  1076. int nIndex = GetInterfaceIdInCombo(strCurDongle);
  1077. Dbg("nIndex : %d vs nSel: %d", nIndex, nSel);
  1078. if(nCntType <= 0) {
  1079. //TODO:在之前应该设为该选择框不可用
  1080. MessageBoxA("意料之外的拨号类型!");
  1081. return 0;
  1082. }
  1083. BOOL bAndroid = (nCntType == 4 || nCntType == 3) ? TRUE : FALSE;
  1084. if(nIndex < 0) {
  1085. MessageBoxA(bAndroid ? "请选择要为其添加配置的卡槽!" : "请选择要为其添加配置的网卡!");
  1086. return 0;
  1087. } else if(strCurDongle.GetLength() <= 0) {
  1088. MessageBoxA(bAndroid ? "数据卡不存在,请关闭后重新打开当前配置窗口!" : "无线网卡不存在,请关闭后重新打开当前配置窗口!");
  1089. return 0;
  1090. }
  1091. BOOL bUpdate = FALSE;
  1092. if(GetDlgItem(IDC_BUTTON_DELETE).IsWindowEnabled()) {
  1093. bUpdate = TRUE;
  1094. if(bAndroid || nCntType == CNT_MBB) {
  1095. //let it empty.
  1096. } else if(g_DongleInfos[nIndex].subInfo.mbnCntState == MBN_ACTIVATION_STATE_ACTIVATED) {
  1097. MessageBox("请先断开连接再进行更新保存!", "提示", MB_OK);
  1098. return 0;
  1099. }
  1100. }
  1101. //Profile description.
  1102. CEdit edit = GetDlgItem(IDC_EDIT_PROFILE);
  1103. int nLen = edit.GetWindowTextLength();
  1104. if(nLen <= 0) {
  1105. MessageBoxA("请输入配置文件名称!");
  1106. return 0;
  1107. }
  1108. edit.GetWindowText(m_strProfileDesc.GetBuffer(nLen), nLen + 1);
  1109. m_strProfileDesc.ReleaseBuffer();
  1110. CString strApn;
  1111. nLen = m_edtAPN.GetWindowTextLength();
  1112. if((nCntType == CNT_MBN || nCntType == CNT_MBB) && nLen <= 0) {
  1113. MessageBoxA("请输入接入点(APN)名称!");
  1114. return 0;
  1115. }
  1116. m_edtAPN.GetWindowText(strApn.GetBuffer(nLen + 1), nLen + 1);
  1117. strApn.ReleaseBuffer(nLen);
  1118. strApn.TrimLeft();
  1119. strApn.TrimRight();
  1120. m_strUserName.TrimLeft();
  1121. m_strUserName.TrimRight();
  1122. if(m_strUserName.GetLength() <= 0) {
  1123. MessageBoxA("请输入用户名!");
  1124. return 0;
  1125. }
  1126. m_strPassword.TrimLeft();
  1127. m_strPassword.TrimRight();
  1128. if(m_strPassword.GetLength() <= 0) {
  1129. MessageBoxA("请输入密码!");
  1130. return 0;
  1131. } else if(nCntType == CNT_MBB) {
  1132. std::string password((LPCTSTR)m_strPassword);
  1133. if(std::string::npos != password.find_first_of(",\":;\\&%+'<>?")) {
  1134. MessageBoxA("密码中不能包含(,\":;\\&%+'<>?)等字符!");
  1135. return 0;
  1136. }
  1137. }
  1138. /*
  1139. if(m_strPassword.GetLength() <= 0) {
  1140. MessageBoxA("请输入密码!");
  1141. return 0;
  1142. } else if(!m_strPassword.Compare(DEFAULT_PASSWORD_CHECK)) {
  1143. //在修改的情况下表示没有修改密码,//在新建的情况下需要提示为无效密码
  1144. m_strPassword = "";
  1145. if(bUpdate) {
  1146. m_strPassword = "";
  1147. } else {
  1148. MessageBoxA("该密码无效,请进行修改!");
  1149. return 0;
  1150. }
  1151. }
  1152. */
  1153. if(nCntType == CNT_RAS && m_strPhoneNum.GetLength() <= 0) {
  1154. MessageBoxA(("请输入电话号码!"));
  1155. return 0;
  1156. }
  1157. //是否立即应用
  1158. CButton btnCheck = GetDlgItem(IDC_CHECK_APN_APPLY);
  1159. bool bApplyNow = (btnCheck.GetCheck() != 0);
  1160. if(bAndroid) {
  1161. strCurDongle = nCntType == 3 ? "MAIN" : "VICE";
  1162. /*
  1163. for(int i=0; i<g_DongleInfos.GetCount(); ++i) {
  1164. if(g_DongleInfos[i].usDeviceType == DEVTYPE_ANDROID_MAIN && nCntType == 3) {
  1165. nIndex = i;
  1166. break;
  1167. } else if(g_DongleInfos[i].usDeviceType == DEVTYPE_ANDROID_VICE && nCntType == 4) {
  1168. nIndex = i;
  1169. break;
  1170. }
  1171. }
  1172. */
  1173. }
  1174. int aim = -1;
  1175. for(int i=0; i<g_DongleInfos[nIndex].profileList.GetCount(); ++i) {
  1176. if(!g_DongleInfos[nIndex].profileList[i].AccessInfo.strProfileDesc.Compare((LPCTSTR)m_strProfileDesc)) {
  1177. if(!bUpdate) {
  1178. MessageBoxA("该配置文件名称已存在,请尝试更换名称!");
  1179. return 0;
  1180. } else {
  1181. aim = i;
  1182. break;
  1183. }
  1184. }
  1185. }
  1186. if(bUpdate && aim == -1) {
  1187. assert(FALSE);
  1188. }
  1189. AccessKeyInfo newInfo;
  1190. memset(&newInfo, 0, sizeof(newInfo));
  1191. newInfo.strProfileDesc = (LPCTSTR)m_strProfileDesc;
  1192. newInfo.strAccessString = (LPCTSTR)strApn;
  1193. newInfo.strUserName = (LPCTSTR)m_strUserName;
  1194. newInfo.strPassword = (LPCTSTR)m_strPassword;
  1195. if(bAndroid) {
  1196. newInfo.usCntType = CNT_ANDROID;
  1197. } else {
  1198. newInfo.usCntType = nCntType;
  1199. }
  1200. newInfo.usAPType = 0;
  1201. if(nCntType == CNT_MBN || bAndroid || nCntType == CNT_MBB) {
  1202. {
  1203. int selected = m_comboModeType.GetCurSel();
  1204. if(selected < 0) {
  1205. MessageBoxA(bAndroid ? "请选择合适的身份验证类型!" : "请选择合适的登录类型!");
  1206. return 0;
  1207. }
  1208. nLen = m_comboModeType.GetLBTextLen(selected);
  1209. if(nCntType == CNT_MBN) {
  1210. CString strTemp;
  1211. m_comboModeType.GetLBText(selected, strTemp.GetBuffer(nLen));
  1212. strTemp.ReleaseBuffer();
  1213. if(!strTemp.Compare("无")) {
  1214. strTemp = "NONE";
  1215. } else if(!strTemp.Compare("MS-CHAP v2")) {
  1216. strTemp = "MsCHAPv2";
  1217. }
  1218. newInfo.strAuthProtocol = strTemp;
  1219. } else {//CNT_MBB
  1220. if(selected == 1) {
  1221. newInfo.usAPType = AUPR_PAP;
  1222. } else if(selected == 2) {
  1223. newInfo.usAPType = AUPR_CHAP;
  1224. } else if(selected == 3) {
  1225. newInfo.usAPType = AUPR_PAPORCHAP;
  1226. }
  1227. }
  1228. }
  1229. if(nCntType == CNT_MBN || nCntType == CNT_MBB)
  1230. {
  1231. const int selected = m_comboIPType.GetCurSel();
  1232. if(selected < 0) {
  1233. MessageBoxA("请选择合适的IP类型!");
  1234. return 0;
  1235. } else if((nCntType == CNT_MBB && (selected < 0 || selected > 3))) {
  1236. MessageBoxA("不支持的IP类型!");
  1237. return 0;
  1238. }
  1239. nLen = m_comboIPType.GetLBTextLen(selected);
  1240. CString strTemp;
  1241. m_comboIPType.GetLBText(selected, strTemp.GetBuffer(nLen));
  1242. strTemp.ReleaseBuffer();
  1243. if(nCntType == CNT_MBN) {
  1244. if(!strTemp.Compare("默认")) {
  1245. strTemp = "Default";
  1246. } else if(!strTemp.Compare("IPv4v6XLAT")) {
  1247. strTemp = "XLAT";
  1248. }
  1249. }
  1250. newInfo.strIPType = (LPCTSTR)strTemp;
  1251. }
  1252. if(nCntType == CNT_MBN)
  1253. {
  1254. int selected = m_comboPointType.GetCurSel();
  1255. if(selected < 0) {
  1256. MessageBoxA("请选择合适的接入点类型!");
  1257. return 0;
  1258. }
  1259. nLen = m_comboPointType.GetLBTextLen(selected);
  1260. CString strTemp;
  1261. m_comboPointType.GetLBText(selected, strTemp.GetBuffer(nLen));
  1262. strTemp.ReleaseBuffer();
  1263. }
  1264. } else {
  1265. {
  1266. bool fChooseLeastOne = false;
  1267. if(IsDlgButtonChecked(IDC_CHECK_RASIO_PAP)) {
  1268. newInfo.usAPType |= AUPR_PAP;
  1269. fChooseLeastOne = true;
  1270. }
  1271. if(IsDlgButtonChecked(IDC_CHECK_RASIO_CHAP)) {
  1272. newInfo.usAPType |= AUPR_CHAP;
  1273. fChooseLeastOne = true;
  1274. }
  1275. if(IsDlgButtonChecked(IDC_CHECK_RASIO_MSCHAPV2)) {
  1276. newInfo.usAPType |= AUPR_MSV2;
  1277. fChooseLeastOne = true;
  1278. }
  1279. if(!fChooseLeastOne) {
  1280. MessageBoxA("请至少选择一个登录类型(密码身份验证协议)!");
  1281. return 0;
  1282. }
  1283. }
  1284. newInfo.strPhoneNum = (LPCTSTR)m_strPhoneNum;
  1285. }
  1286. EnterProgressBar(TIMER_TIMTOUT_MAX);
  1287. if(!bUpdate) {
  1288. auto rc = m_pEntity->AddNewProfile(strCurDongle, newInfo, bApplyNow);
  1289. if(rc == Error_Pending) {
  1290. } else {
  1291. if(rc != Error_Succeed) {
  1292. LeaveProgressBar(WM_TIMER_PROCESS);
  1293. MessageBoxA(CSimpleStringA::Format("添加拨号配置失败: %s", m_pEntity->GetLastErrMsg()));
  1294. } else {
  1295. Dbg("PostMessage WM_ADD_PROFILE_RESULT");
  1296. PostMessage(WM_ADD_PROFILE_RESULT, Error_Succeed, 0);
  1297. }
  1298. }
  1299. } else {
  1300. auto rc = m_pEntity->UpdateProfile(strCurDongle,
  1301. g_DongleInfos[nIndex].profileList[aim].strProfileName, newInfo, bApplyNow);
  1302. if(rc == Error_Pending) {
  1303. } else {
  1304. LeaveProgressBar(WM_TIMER_PROCESS);
  1305. if(rc != Error_Succeed) {
  1306. MessageBoxA(CSimpleStringA::Format("更新拨号配置失败: %s", m_pEntity->GetLastErrMsg()));
  1307. } else {
  1308. Dbg("PostMessage WM_UPDATE_PROFILE_RESULT");
  1309. PostMessage(WM_UPDATE_PROFILE_RESULT, Error_Succeed, 0);
  1310. }
  1311. }
  1312. }
  1313. return 0;
  1314. }
  1315. LRESULT CMobileDlg::OnCbnSelchangeComboDongle(
  1316. WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
  1317. {
  1318. CSimpleStringA strCurDongle;
  1319. int nIndex = GetInterfaceIdInCombo(strCurDongle);
  1320. if(nIndex < 0) {
  1321. Dbg("GetInterfaceIdInCombo failed: %d", nIndex);
  1322. return 0;
  1323. } else if(strCurDongle.GetLength() <= 0) {
  1324. Dbg("GetInterfaceIdInCombo failed2: %d", nIndex);
  1325. return 0;
  1326. }
  1327. if(g_DongleInfos[nIndex].usDeviceType == DEVTYPE_INTER) {
  1328. m_comboCntType.SetCurSel(CNT_MBN);
  1329. } else if(g_DongleInfos[nIndex].usDeviceType == DEVTYPE_MODEM) {
  1330. m_comboCntType.SetCurSel(CNT_RAS);
  1331. } else if(g_DongleInfos[nIndex].usDeviceType == DEVTYPE_ANDROID_MAIN) {
  1332. m_comboCntType.SetCurSel(3);
  1333. } else if(g_DongleInfos[nIndex].usDeviceType == DEVTYPE_ANDROID_VICE) {
  1334. m_comboCntType.SetCurSel(4);
  1335. } else if(g_DongleInfos[nIndex].usDeviceType == DEVTYPE_MBB) {
  1336. m_comboCntType.SetCurSel(CNT_MBB);
  1337. } else {
  1338. m_comboCntType.SetCurSel(0);
  1339. }
  1340. if(g_DongleInfos[nIndex].usDeviceType & DEVTYPE_ANDROID_UKNOWN) {
  1341. if(g_DongleInfos[nIndex].priority > 0) {
  1342. m_btnConnect.SetWindowTextA("已应用");
  1343. m_btnConnect.EnableWindow(FALSE);
  1344. } else {
  1345. m_btnConnect.SetWindowTextA("应用");
  1346. m_btnConnect.EnableWindow(TRUE);
  1347. }
  1348. m_comboPointType.ShowWindow(FALSE);
  1349. } else {
  1350. if(g_DongleInfos[nIndex].subInfo.mbnCntState == MBN_ACTIVATION_STATE_ACTIVATED) {
  1351. m_btnConnect.SetWindowTextA("断开连接");
  1352. m_btnConnect.EnableWindow(TRUE);
  1353. } else {
  1354. m_btnConnect.SetWindowTextA("连接");
  1355. m_btnConnect.EnableWindow(TRUE);
  1356. }
  1357. m_comboPointType.ShowWindow(TRUE);
  1358. }
  1359. m_comboProfiles.ResetContent();
  1360. const MBNProfileList& info = g_DongleInfos[nIndex].profileList;
  1361. Dbg("CbnSelchangeComboDongle: %s", g_DongleInfos[nIndex].subInfo.strProfileName);
  1362. Dbg("[%d] profile count: %d", nIndex, info.GetCount());
  1363. int aim = -1;
  1364. if(info.GetCount() > 0) {
  1365. for(int i=0; i<info.GetCount(); ++i) {
  1366. m_comboProfiles.AddString(info[i].AccessInfo.strProfileDesc);
  1367. Dbg("%s - %s", (LPCTSTR)info[i].strProfileName, (LPCTSTR)info[i].AccessInfo.strProfileDesc);
  1368. // m_bConnected && ?? [12/4/2019 19:18 @Gifur]
  1369. if(aim == -1 &&/*m_bConnected && */g_DongleInfos[nIndex].subInfo.strProfileName.GetLength() > 0) {
  1370. if(!g_DongleInfos[nIndex].subInfo.strProfileName.Compare(info[i].strProfileName)) {
  1371. Dbg("Here: %d", i);
  1372. aim = i;
  1373. }
  1374. }
  1375. }
  1376. if(aim == -1) {
  1377. aim = 0;
  1378. }
  1379. m_comboProfiles.SetCurSel(aim);
  1380. }
  1381. BOOL bEmpty = TRUE;
  1382. OnCbnSelchangeComboProfiles(NULL, NULL, NULL, bEmpty);
  1383. //第三层固定信息
  1384. //制造商
  1385. SetDlgItemTextA(IDC_STATIC_MANUFACTURER, g_DongleInfos[nIndex].subInfo.strManufacturer);
  1386. //型号
  1387. SetDlgItemTextA(IDC_STATIC_MODEL, g_DongleInfos[nIndex].subInfo.strMode);
  1388. //固件
  1389. SetDlgItemTextA(IDC_STATIC_FIRMWARE, g_DongleInfos[nIndex].subInfo.strFirmware);
  1390. //网络类型
  1391. SetDlgItemTextA(IDC_STATIC_HARDWARE, g_DongleInfos[nIndex].subInfo.strCellularClass);
  1392. //IMEI
  1393. SetDlgItemTextA(IDC_STATIC_IMEI, g_DongleInfos[nIndex].subInfo.strDeviceID);
  1394. //状态
  1395. SetDlgItemTextA(IDC_STATIC_PORT, ConvertStatusToString(g_DongleInfos[nIndex].state));
  1396. //数据类
  1397. SetDlgItemTextA(IDC_STATIC_DATACLASS, g_DongleInfos[nIndex].subInfo.strDataClass);
  1398. return 0;
  1399. }
  1400. LRESULT CMobileDlg::OnBnClickedButtonExpand(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& bHandled)
  1401. {
  1402. char szBtnTxt[128] = {0};
  1403. m_btnExpand.GetWindowTextA(szBtnTxt, 128);
  1404. if(!strcmp(szBtnTxt, "管理配置")) {
  1405. SetDlgSizeToLarge();
  1406. OnCbnSelchangeComboProfiles(NULL, NULL, NULL, bHandled);
  1407. } else {
  1408. SetDlgSizeToSmall();
  1409. }
  1410. return 0;
  1411. }
  1412. LRESULT CMobileDlg::OnBnClickedCheckMntbyrvc(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
  1413. {
  1414. m_pEntity->RequireManageByUser(!IsDlgButtonChecked(IDC_CHECK_MNTBYRVC));
  1415. return 0;
  1416. }
  1417. LRESULT CMobileDlg::OnBnClickedButtonDropup(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
  1418. {
  1419. SetDlgSizeToSmall();
  1420. return 0;
  1421. }
  1422. LRESULT CMobileDlg::OnBnClickedButtonClear(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
  1423. {
  1424. char szBtnTxt[128] = {0};
  1425. BOOL bClear = FALSE;
  1426. m_btnClear.GetWindowTextA(szBtnTxt, 128);
  1427. if(!strcmp(szBtnTxt, "新建")) {//点击了新建
  1428. CloseVirtualKeyboard();
  1429. GetDlgItem(IDC_BUTTON_DELETE).EnableWindow(FALSE);
  1430. GetDlgItem(IDC_EDIT_PROFILE).EnableWindow(TRUE);
  1431. m_btnClear.SetWindowTextA("清除");
  1432. bClear = TRUE;
  1433. CheckDlgButton(IDC_CHECK_APN_APPLY, TRUE);
  1434. } else if(!strcmp(szBtnTxt, "清除")) {
  1435. bClear = TRUE;
  1436. }
  1437. if(bClear) {
  1438. _ClearProfileTxt();
  1439. }
  1440. return 0;
  1441. }
  1442. LRESULT CMobileDlg::OnBnClickedButtonDefaultConnect(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
  1443. {
  1444. UINT_PTR uRes = MessageBoxA("该操作不可撤销!确定要恢复默认密码进行连接?", "确认", MB_OKCANCEL | MB_ICONQUESTION);
  1445. if(uRes == IDOK) {
  1446. EnterProgressBar(65 * 1000);
  1447. auto rc = m_pEntity->ConnectWIFIWithDefault();
  1448. if(rc == Error_Succeed) {
  1449. //MessageBoxA("尝试使用默认密码连接成功!");
  1450. } else {
  1451. LeaveProgressBar(WM_TIMER_PROCESS);
  1452. MessageBoxA(CSimpleStringA::Format("尝试使用默认密码连接失败: %s", m_pEntity->GetLastErrMsg()));
  1453. }
  1454. }
  1455. return 0;
  1456. }
  1457. LRESULT CMobileDlg::OnCbnSelchangeComboProfiles(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
  1458. {
  1459. char szBtnTxt[128] = {0};
  1460. m_btnExpand.GetWindowTextA(szBtnTxt, 128);
  1461. if(!!strcmp(szBtnTxt, "管理配置")) { //扩展
  1462. GetDlgItem(IDC_EDIT_PROFILE).EnableWindow(FALSE);
  1463. m_btnClear.SetWindowTextA("新建");
  1464. OnCbnSelchangeComboGtype(wNotifyCode, wID, hWndCtl, bHandled);
  1465. do
  1466. {
  1467. const int nSel = m_comboProfiles.GetCurSel();
  1468. CSimpleStringA strDongle;
  1469. const int nIndex = GetInterfaceIdInCombo(strDongle);
  1470. if(nIndex < 0 || nSel < 0 || strDongle.GetLength() <= 0) {
  1471. Dbg("nIndex : %d, nSel : %d", nIndex, nSel);
  1472. GetDlgItem(IDC_BUTTON_DELETE).EnableWindow(FALSE);
  1473. break;
  1474. }
  1475. _ClearProfileTxt();
  1476. {
  1477. const MBNProfileList& info = g_DongleInfos[nIndex].profileList;
  1478. m_strPassword = (LPCTSTR)info[nSel].AccessInfo.strPassword;
  1479. if(info[nSel].AccessInfo.strPassword == DEFAULT_PASSWORD_CHECK) {
  1480. m_strPassword = "";
  1481. }
  1482. m_strUserName = (LPCTSTR)info[nSel].AccessInfo.strUserName;
  1483. m_edtAPN.SetWindowTextA((LPCTSTR)info[nSel].AccessInfo.strAccessString);
  1484. GetDlgItem(IDC_EDIT_PROFILE).SetWindowTextA((LPCTSTR)info[nSel].AccessInfo.strProfileDesc);
  1485. if(info[nSel].AccessInfo.usCntType == CNT_RAS) {
  1486. assert(m_comboCntType.GetCurSel() == CNT_RAS);
  1487. Dbg("RAS for %s", (LPCTSTR)info[nSel].AccessInfo.strProfileDesc);
  1488. //GetDlgItem(IDC_EDIT_PHONENUM).SetWindowTextA((LPCTSTR)info[nSel].AccessInfo.strPhoneNum);
  1489. m_strPhoneNum = (LPCTSTR)info[nSel].AccessInfo.strPhoneNum;
  1490. Dbg("Set phone num: %s", (LPCTSTR)info[nSel].AccessInfo.strPhoneNum);
  1491. Dbg("usAPType: 0x%X", info[nSel].AccessInfo.usAPType);
  1492. if((info[nSel].AccessInfo.usAPType & AUPR_PAP) == AUPR_PAP) {
  1493. CheckDlgButton(IDC_CHECK_RASIO_PAP, TRUE);
  1494. } else {
  1495. CheckDlgButton(IDC_CHECK_RASIO_PAP, FALSE);
  1496. }
  1497. if((info[nSel].AccessInfo.usAPType & AUPR_CHAP) == AUPR_CHAP) {
  1498. CheckDlgButton(IDC_CHECK_RASIO_CHAP, TRUE);
  1499. } else {
  1500. CheckDlgButton(IDC_CHECK_RASIO_CHAP, FALSE);
  1501. }
  1502. if((info[nSel].AccessInfo.usAPType & AUPR_MSV2) == AUPR_MSV2) {
  1503. CheckDlgButton(IDC_CHECK_RASIO_MSCHAPV2, TRUE);
  1504. } else {
  1505. CheckDlgButton(IDC_CHECK_RASIO_MSCHAPV2, FALSE);
  1506. }
  1507. m_strPhoneNum = (LPCTSTR)info[nSel].AccessInfo.strPhoneNum;
  1508. }
  1509. else if(info[nSel].AccessInfo.usCntType == CNT_MBN) {
  1510. //change test
  1511. Dbg("@3");
  1512. if(m_comboModeType.SelectString(-1, info[nSel].AccessInfo.strAuthProtocol) == CB_ERR) {
  1513. Dbg("Enter: %s", (LPCTSTR)info[nSel].AccessInfo.strAuthProtocol);
  1514. if(!strncmp(info[nSel].AccessInfo.strAuthProtocol, "NONE", strlen("NONE"))) {
  1515. m_comboModeType.SetCurSel(0);
  1516. Dbg("mode type: set 0");
  1517. } else if(!strncmp(info[nSel].AccessInfo.strAuthProtocol, "MsCHAPv2", strlen("MsCHAPv2"))) {
  1518. m_comboModeType.SetCurSel(3);
  1519. Dbg("mode type: set 3");
  1520. } else {
  1521. m_comboModeType.SetCurSel(0);
  1522. Dbg("mode type: set 0");
  1523. }
  1524. }
  1525. Dbg("@4");
  1526. CheckDlgButton(IDC_CHECK_APN_APPLY, info[nSel].AccessInfo.IsDefault);
  1527. } else if(info[nSel].AccessInfo.usCntType == CNT_ANDROID
  1528. || info[nSel].AccessInfo.usCntType == CNT_MBB) {
  1529. //change test
  1530. Dbg("usAPType: 0x%X", info[nSel].AccessInfo.usAPType);
  1531. if(info[nSel].AccessInfo.usAPType == AUPR_PAP) {
  1532. m_comboModeType.SetCurSel(1);
  1533. } else if(info[nSel].AccessInfo.usAPType == AUPR_CHAP) {
  1534. m_comboModeType.SetCurSel(2);
  1535. } else if(info[nSel].AccessInfo.usAPType == AUPR_PAPORCHAP) {
  1536. m_comboModeType.SetCurSel(3);
  1537. } else {
  1538. m_comboModeType.SetCurSel(0);
  1539. }
  1540. Dbg("@1");
  1541. CheckDlgButton(IDC_CHECK_APN_APPLY, info[nSel].AccessInfo.IsDefault);
  1542. }
  1543. else {
  1544. Dbg("Cannot recognize connect type 0x%X", info[nSel].AccessInfo.usCntType);
  1545. }
  1546. if(info[nSel].AccessInfo.usCntType == CNT_MBN || info[nSel].AccessInfo.usCntType == CNT_MBB) {
  1547. Dbg("@2: %s", (LPCTSTR)info[nSel].AccessInfo.strIPType);
  1548. if(m_comboIPType.SelectString(-1, info[nSel].AccessInfo.strIPType) == CB_ERR) {
  1549. Dbg("Enter: %s", (LPCTSTR)info[nSel].AccessInfo.strIPType);
  1550. if(!strncmp(info[nSel].AccessInfo.strIPType, "Default", strlen("Default"))) {
  1551. m_comboIPType.SetCurSel(0);
  1552. Dbg("iptype: set 0");
  1553. } else if(!strncmp(info[nSel].AccessInfo.strIPType, "XLAT", strlen("XLAT"))) {
  1554. m_comboIPType.SetCurSel(4);
  1555. Dbg("iptype: set 4");
  1556. } else {
  1557. m_comboIPType.SetCurSel(0);
  1558. Dbg("iptype: set 0");
  1559. }
  1560. }
  1561. //cannot set ip type to MBB [12/5/2019 14:36 @Gifur]
  1562. if(info[nSel].AccessInfo.usCntType == CNT_MBB) {
  1563. m_comboIPType.EnableWindow(FALSE);
  1564. }
  1565. }
  1566. DoDataExchange(FALSE);
  1567. GetDlgItem(IDC_BUTTON_DELETE).EnableWindow(TRUE);
  1568. }
  1569. }while(false);
  1570. }
  1571. return 0;
  1572. }
  1573. LRESULT CMobileDlg::OnBnClickedButtonDelete(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
  1574. {
  1575. const int nSel3 = m_comboCntType.GetCurSel();
  1576. int nSel = m_comboProfiles.GetCurSel();
  1577. CSimpleStringA strDongle;
  1578. int nIndex = GetInterfaceIdInCombo(strDongle);
  1579. Dbg("interface index : %d vs profile sel: %d", nIndex, nSel);
  1580. if(nIndex >= 0 && strDongle.GetLength() > 0 && nSel >= 0) {
  1581. if(g_DongleInfos[nIndex].subInfo.mbnCntState == MBN_ACTIVATION_STATE_ACTIVATED && nSel3 <= CNT_RAS) {
  1582. MessageBox("请先断开连接再执行删除操作!", "提示", MB_OK);
  1583. return 0;
  1584. }
  1585. CloseVirtualKeyboard();
  1586. UINT_PTR uRes = MessageBox(CSimpleStringA::Format("确定要删除配置文件 %s ?",
  1587. (LPCTSTR)g_DongleInfos[nIndex].profileList[nSel].AccessInfo.strProfileDesc), "确认", MB_OKCANCEL | MB_ICONQUESTION);
  1588. if(uRes == IDOK) {
  1589. EnterProgressBar(TIMER_TIMTOUT_MAX);
  1590. auto rc = m_pEntity->DeleteProfile(nIndex, nSel);
  1591. if(rc == Error_Succeed) {
  1592. const USHORT cntType = g_DongleInfos[nIndex].profileList[nSel].AccessInfo.usCntType;
  1593. if(cntType == CNT_RAS || cntType == CNT_ANDROID || cntType == CNT_MBB) {
  1594. PostMessage(WM_DELETE_PROFILE_RESULT, Error_Succeed);
  1595. }
  1596. } else {
  1597. LeaveProgressBar(WM_TIMER_PROCESS);
  1598. MessageBoxA(CSimpleStringA::Format("删除失败: %s", m_pEntity->GetLastErrMsg()));
  1599. }
  1600. }
  1601. }
  1602. return 0;
  1603. }
  1604. LRESULT CMobileDlg::OnCbnSelchangeComboGtype(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
  1605. {
  1606. char szBtnTxt[128] = {0};
  1607. m_btnExpand.GetWindowTextA(szBtnTxt, 128);
  1608. if(!strcmp(szBtnTxt, "管理配置")) {
  1609. return 0;
  1610. }
  1611. const int nSel = m_comboCntType.GetCurSel();
  1612. BOOL bMBNShow = FALSE;
  1613. if(nSel <= CNT_MBN || nSel == CNT_MBB) {//MBN or MBB
  1614. bMBNShow = TRUE;
  1615. SetDlgItemTextA(IDC_STATIC_TXT_MODE, "登录类型:");
  1616. SetDlgItemTextA(IDC_STATIC_LOGIN, "拨号配置(接入点)");
  1617. SetDlgItemTextA(IDC_STATIC_TXT_IPTYPE, "IP类型:");
  1618. SetDlgItemTextA(IDC_STATIC_TXT_PROFILENAME, "配置文件名称:");
  1619. } else if(nSel == CNT_RAS) {//RAS
  1620. bMBNShow = FALSE;
  1621. SetDlgItemTextA(IDC_STATIC_TXT_MODE, "电话号码:");
  1622. SetDlgItemTextA(IDC_STATIC_LOGIN, "拨号配置(电话簿)");
  1623. SetDlgItemTextA(IDC_STATIC_TXT_IPTYPE, "登录类型:");
  1624. SetDlgItemTextA(IDC_STATIC_TXT_PROFILENAME, "拨号配置名称:");
  1625. } else if(nSel == 3 || nSel == 4) {//Android
  1626. SetDlgItemTextA(IDC_STATIC_TXT_MODE, "身份验证:");
  1627. SetDlgItemTextA(IDC_STATIC_LOGIN, "拨号配置(接入点)");
  1628. SetDlgItemTextA(IDC_STATIC_TXT_IPTYPE, "APN 类型:");
  1629. SetDlgItemTextA(IDC_STATIC_TXT_PROFILENAME, "配置文件名称:");
  1630. GetDlgItem(IDC_STATIC_TXT_IPTYPE).ShowWindow(FALSE);
  1631. GetDlgItem(IDC_COMBO_CON_IPTYPE).ShowWindow(FALSE);
  1632. GetDlgItem(IDC_STATIC_TXT_POINTTYPE).ShowWindow(FALSE);
  1633. GetDlgItem(IDC_COMBO_PONT_TYPE).ShowWindow(FALSE);
  1634. bMBNShow = TRUE;
  1635. }
  1636. else {
  1637. return 0;
  1638. }
  1639. GetDlgItem(IDC_COMBO_CON_MODE).ShowWindow(bMBNShow);
  1640. GetDlgItem(IDC_EDIT_PHONENUM).ShowWindow(!bMBNShow);
  1641. GetDlgItem(IDC_CHECK_RASIO_PAP).ShowWindow(!bMBNShow);
  1642. GetDlgItem(IDC_CHECK_RASIO_CHAP).ShowWindow(!bMBNShow);
  1643. GetDlgItem(IDC_CHECK_RASIO_MSCHAPV2).ShowWindow(!bMBNShow);
  1644. if(nSel <= CNT_RAS) {
  1645. GetDlgItem(IDC_STATIC_TXT_POINTTYPE).ShowWindow(bMBNShow);
  1646. GetDlgItem(IDC_COMBO_PONT_TYPE).ShowWindow(bMBNShow);
  1647. GetDlgItem(IDC_COMBO_CON_IPTYPE).ShowWindow(bMBNShow);
  1648. }
  1649. if(bMBNShow) {
  1650. if(nSel <= CNT_MBN || nSel == CNT_MBB) {
  1651. if(wv == 8 && nSel != CNT_MBB) {
  1652. GetDlgItem(IDC_COMBO_PONT_TYPE).ShowWindow(FALSE);
  1653. GetDlgItem(IDC_COMBO_CON_IPTYPE).ShowWindow(FALSE);
  1654. GetDlgItem(IDC_STATIC_TXT_IPTYPE).ShowWindow(FALSE);
  1655. GetDlgItem(IDC_STATIC_TXT_POINTTYPE).ShowWindow(FALSE);
  1656. GetDlgItem(IDC_CHECK_APN_APPLY).ShowWindow(FALSE);
  1657. } else {
  1658. GetDlgItem(IDC_COMBO_CON_IPTYPE).ShowWindow(TRUE);
  1659. GetDlgItem(IDC_STATIC_TXT_IPTYPE).ShowWindow(TRUE);
  1660. if(nSel == CNT_MBB) {
  1661. GetDlgItem(IDC_COMBO_PONT_TYPE).ShowWindow(FALSE);
  1662. GetDlgItem(IDC_STATIC_TXT_POINTTYPE).ShowWindow(FALSE);
  1663. GetDlgItem(IDC_STATIC_TXT_IPTYPE).EnableWindow(FALSE);
  1664. } else {
  1665. GetDlgItem(IDC_COMBO_PONT_TYPE).ShowWindow(TRUE);
  1666. GetDlgItem(IDC_STATIC_TXT_POINTTYPE).ShowWindow(TRUE);
  1667. GetDlgItem(IDC_STATIC_TXT_IPTYPE).EnableWindow(TRUE);
  1668. }
  1669. GetDlgItem(IDC_CHECK_APN_APPLY).ShowWindow(TRUE);
  1670. }
  1671. } else {
  1672. GetDlgItem(IDC_CHECK_APN_APPLY).ShowWindow(TRUE);
  1673. }
  1674. } else {
  1675. GetDlgItem(IDC_CHECK_APN_APPLY).ShowWindow(FALSE);
  1676. if(wv == 8) {
  1677. GetDlgItem(IDC_STATIC_TXT_IPTYPE).ShowWindow(TRUE);
  1678. }
  1679. }
  1680. if(nSel == CNT_MBB) {
  1681. m_comboModeType.ResetContent();
  1682. m_comboModeType.AddString("自动");
  1683. m_comboModeType.AddString("PAP");
  1684. m_comboModeType.AddString("CHAP");
  1685. m_comboModeType.AddString("无");
  1686. } else if(nSel == CNT_MBN) {
  1687. m_comboModeType.ResetContent();
  1688. m_comboModeType.AddString("无");
  1689. m_comboModeType.AddString("PAP");
  1690. m_comboModeType.AddString("CHAP");
  1691. m_comboModeType.AddString("MS-CHAP v2");
  1692. m_comboModeType.SetCurSel(0);
  1693. } else if(nSel == 3 || nSel == 4) {//Android
  1694. m_comboModeType.ResetContent();
  1695. m_comboModeType.AddString("无");
  1696. m_comboModeType.AddString("PAP");
  1697. m_comboModeType.AddString("CHAP");
  1698. m_comboModeType.AddString("PAP 或 CHAP");
  1699. m_comboModeType.SetCurSel(0);
  1700. }
  1701. return 0;
  1702. }
  1703. LRESULT CMobileDlg::OnBnClickedCheckViewPassword(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
  1704. {
  1705. CEdit edit = (CEdit)this->GetDlgItem(IDC_EDIT_PASSWORD);
  1706. if(IsDlgButtonChecked(IDC_CHECK_VIEW_PASSWORD)) {
  1707. edit.SetPasswordChar(0);
  1708. } else {
  1709. edit.SetPasswordChar('*');
  1710. }
  1711. edit.RedrawWindow();
  1712. return 0;
  1713. }
  1714. void CMobileDlg::OnSetFocus(HWND hWnd)
  1715. {
  1716. OpenVirtualKeyboard();
  1717. SetMsgHandled(FALSE);
  1718. }
  1719. void CMobileDlg::OnKillFocus(HWND hWnd)
  1720. {
  1721. SetMsgHandled(FALSE);
  1722. }
  1723. LRESULT CMobileDlg::OnEnSetfocusEdit(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& bHandled)
  1724. {
  1725. OpenVirtualKeyboard();
  1726. return 0;
  1727. }
  1728. LRESULT CMobileDlg::OnEnKillfocusEdit(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& bHandled)
  1729. {
  1730. return 0;
  1731. }
  1732. LRESULT CWlanConfigDlg::OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
  1733. {
  1734. int cx = GetSystemMetrics(SM_CXSCREEN);
  1735. RECT rcDlg;
  1736. ::GetWindowRect(m_hWnd, &rcDlg);
  1737. ::SetWindowPos(m_hWnd, NULL, (cx + rcDlg.left - rcDlg.right)/2, 40, -1, -1, SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
  1738. const MBBParams* originalParam = &m_pDlg->m_sMBBParam;
  1739. GetDlgItem(IDC_EDIT_MBB_LOGIN_USERNAME).SetWindowTextA(originalParam->loginParam.strUsername);
  1740. GetDlgItem(IDC_EDIT_MBB_LOGIN_PSW).SetWindowTextA(originalParam->loginParam.strPassword);
  1741. GetDlgItem(IDC_EDIT_MBB_WLAN_SSID).SetWindowTextA(originalParam->wlanConnectParam.strUsername);
  1742. GetDlgItem(IDC_EDIT_MBB_WLAN_PSW).SetWindowTextA(originalParam->wlanConnectParam.strPassword);
  1743. CheckDlgButton(IDC_CHECK_WLAN_HIDDEN, originalParam->wlanConnectParam.Flag);
  1744. if(originalParam->connectType == 1) {
  1745. GetDlgItem(IDC_EDIT_MBB_WLAN_SSID).EnableWindow(FALSE);
  1746. GetDlgItem(IDC_EDIT_MBB_WLAN_PSW).EnableWindow(FALSE);
  1747. GetDlgItem(IDC_CHECK_WLAN_HIDDEN).EnableWindow(FALSE);
  1748. }
  1749. //CheckDlgButton(IDC_CHECK_WLAN_HIDDEN, FALSE);
  1750. //GetDlgItem(IDC_CHECK_WLAN_HIDDEN).EnableWindow(FALSE);
  1751. return TRUE;
  1752. }
  1753. BOOL CWlanConfigDlg::HasUpdated(BOOL refresh /*= TRUE*/)
  1754. {
  1755. if(refresh) {
  1756. UpdateValue();
  1757. }
  1758. BOOL changed = FALSE;
  1759. MBBParams* originalParam = &m_pDlg->m_sMBBParam;
  1760. if(originalParam->loginParam.strUsername.Compare((LPCTSTR)m_strLoginUsername) != 0) {
  1761. originalParam->loginParam.strUsername = (LPCTSTR)m_strLoginUsername;
  1762. changed = TRUE;
  1763. }
  1764. if(originalParam->loginParam.strPassword.Compare((LPCTSTR)m_strLoginPassword) != 0) {
  1765. originalParam->loginParam.strPassword = (LPCTSTR)m_strLoginPassword;
  1766. changed = TRUE;
  1767. }
  1768. if(originalParam->wlanConnectParam.strUsername.Compare((LPCTSTR)m_strWlanSSID) != 0) {
  1769. originalParam->wlanConnectParam.strUsername = (LPCTSTR)m_strWlanSSID;
  1770. changed = TRUE;
  1771. }
  1772. if(originalParam->wlanConnectParam.strPassword.Compare((LPCTSTR)m_strWlanPassword) != 0) {
  1773. originalParam->wlanConnectParam.strPassword = (LPCTSTR)m_strWlanPassword;
  1774. changed = TRUE;
  1775. }
  1776. if(originalParam->wlanConnectParam.Flag != m_fHidden) {
  1777. originalParam->wlanConnectParam.Flag = m_fHidden;
  1778. changed = TRUE;
  1779. }
  1780. return changed;
  1781. }