MobileDlg.cpp 66 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999
  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. m_wlanClickedTimes = 0;
  608. return TRUE;
  609. }
  610. LRESULT CMobileDlg::OnOK(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
  611. {
  612. CloseVirtualKeyboard();
  613. EndDialog(wID);
  614. return 0;
  615. }
  616. LRESULT CMobileDlg::OnCancel(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
  617. {
  618. CloseVirtualKeyboard();
  619. BOOL fInvalid = FALSE;
  620. if(m_nGenType == 4) {
  621. if(m_sMBBParam.connectType == MBB_CONNECT_UNKONWN) {
  622. fInvalid = TRUE;
  623. } else if(m_sMBBParam.loginParam.strUsername.IsNullOrEmpty()) {
  624. fInvalid = TRUE;
  625. } else if(m_sMBBParam.loginParam.strPassword.IsNullOrEmpty()) {
  626. fInvalid = TRUE;
  627. }else if(m_sMBBParam.connectType == MBB_CONNECT_WIFI) {
  628. if(m_sMBBParam.wlanConnectParam.strUsername.IsNullOrEmpty()) {
  629. fInvalid = TRUE;
  630. } else if(m_sMBBParam.wlanConnectParam.strPassword.IsNullOrEmpty()) {
  631. fInvalid = TRUE;
  632. }
  633. }
  634. }
  635. if(fInvalid) {
  636. MessageBox("请填写华为原装未升驱卡托拨号所需的配置信息!", "提示", MB_OK);
  637. PostMessageA(WM_COMMAND, MAKEWPARAM(IDC_BUTTON_MBB_CONFIG, BN_CLICKED), NULL);
  638. return 0;
  639. }
  640. EndDialog(wID);
  641. return 0;
  642. }
  643. LRESULT CMobileDlg::OnConnect(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
  644. {
  645. int nSel = m_comboDongles.GetCurSel();
  646. int nSel2 = m_comboProfiles.GetCurSel();
  647. int nSel3 = m_comboCntType.GetCurSel();
  648. if(nSel3 == 4 || nSel3 == 3) {//android
  649. m_btnConnect.EnableWindow(FALSE);
  650. int slotID = g_DongleInfos[nSel].usDeviceType - DEVTYPE_ANDROID_UKNOWN;
  651. EnterProgressBar(TIMER_TIMTOUT_MAX, WM_TIMER_SWITCH);
  652. m_btnConnect.SetWindowTextA("切换中\r\n...");
  653. auto rc = m_pEntity->SwitchDefaultSlot(slotID);
  654. LeaveProgressBar(WM_TIMER_SWITCH);
  655. if(rc == Error_Succeed) {
  656. OnConnectResult(WM_TIMER_SWITCH, Error_Succeed, 1);
  657. } else {
  658. MessageBoxA(CSimpleStringA::Format("切换数据卡失败: %s", m_pEntity->GetLastErrMsg()));
  659. m_btnConnect.SetWindowTextA("应用");
  660. m_btnConnect.EnableWindow(TRUE);
  661. }
  662. return 0;
  663. }
  664. if(m_bConnected) {
  665. m_btnConnect.EnableWindow(FALSE);
  666. auto rc = m_pEntity->Disconnect(nSel3, g_DongleInfos[nSel].csInterfaceId);
  667. if(rc == Error_Succeed) {
  668. EnterProgressBar(TIMER_TIMTOUT_MAX, WM_TIMER_DISCONNECT);
  669. m_btnConnect.SetWindowTextA("断开中\r\n...");
  670. } else {
  671. m_btnConnect.EnableWindow(TRUE);
  672. MessageBoxA(CSimpleStringA::Format("断开连接失败: %s", m_pEntity->GetLastErrMsg()));
  673. }
  674. } else {
  675. if(nSel == CB_ERR) {
  676. MessageBoxA("请选择所需连接的网卡!");
  677. return 0;
  678. }
  679. if(nSel2 == CB_ERR) {
  680. MessageBoxA("请选择拨号配置文件 或 新增拨号配置文件!");
  681. return 0;
  682. }
  683. if(nSel3 == CB_ERR || nSel3 == CNT_INVALID) {
  684. MessageBoxA("请选择合适的拨号方式!");
  685. return 0;
  686. }
  687. m_btnConnect.EnableWindow(FALSE);
  688. auto rc = m_pEntity->Connect(nSel3, g_DongleInfos[nSel].csInterfaceId,
  689. g_DongleInfos[nSel].profileList[nSel2].strProfileName);
  690. if(rc == Error_Succeed) {
  691. EnterProgressBar(TIMER_TIMTOUT_MAX, WM_TIMER_CONNECT);
  692. m_btnConnect.SetWindowTextA("连接中\r\n...");
  693. } else {
  694. m_btnConnect.EnableWindow(TRUE);
  695. MessageBoxA(CSimpleStringA::Format("拨号失败: %s", m_pEntity->GetLastErrMsg()));
  696. }
  697. }
  698. return 0;
  699. }
  700. bool CMobileDlg::OpenVirtualKeyboard()
  701. {
  702. HANDLE hKeyboard = FindProcessByName("VirtualKeyboard.exe");
  703. if (hKeyboard == NULL)
  704. {
  705. HINSTANCE hNewExe = ShellExecuteA(NULL, "open", "VirtualKeyboard.exe", NULL, NULL, SW_SHOWNORMAL);
  706. if ((DWORD)hNewExe <= 32)
  707. {
  708. //MessageBoxA(NULL, "启动触摸键盘失败!", NULL, 0);
  709. return false;
  710. }
  711. }
  712. return true;
  713. }
  714. bool CMobileDlg::CloseVirtualKeyboard()
  715. {
  716. HANDLE hKeyboard = FindProcessByName("VirtualKeyboard.exe");
  717. if (hKeyboard != NULL)
  718. {
  719. TerminateProcess(hKeyboard, 0);
  720. return true;
  721. }
  722. return false;
  723. }
  724. void CMobileDlg::InitializeControls()
  725. {
  726. m_comboDongles = this->GetDlgItem(IDC_COMBO_DONGLE);
  727. //m_comboProfiles = this->GetDlgItem(IDC_COMBO_PROFILES);
  728. m_comboCntType.AddString("Auto");
  729. m_comboCntType.AddString("4G-MBN"); //1
  730. m_comboCntType.AddString("3G-RAS"); //2
  731. m_comboCntType.AddString("主卡"); //3
  732. m_comboCntType.AddString("副卡"); //4
  733. m_comboCntType.AddString("HW-MBB"); //5
  734. m_comboCntType.SetCurSel(CNT_INVALID);
  735. m_comboModeType.AddString("无");
  736. m_comboModeType.AddString("PAP");
  737. m_comboModeType.AddString("CHAP");
  738. m_comboModeType.AddString("MS-CHAP v2");
  739. m_comboModeType.DeleteString(3);
  740. m_comboModeType.AddString("PAP 或 CHAP");
  741. m_comboModeType.SetCurSel(0);
  742. m_comboIPType.AddString("默认");
  743. m_comboIPType.AddString("IPv4");
  744. m_comboIPType.AddString("IPv6");
  745. m_comboIPType.AddString("IPv4v6");
  746. m_comboIPType.AddString("IPv4v6XLAT");
  747. m_comboIPType.SetCurSel(0);
  748. m_comboPointType.AddString("Internet");
  749. //m_comboPointType.AddString("Internet及连接");
  750. //m_comboPointType.AddString("连接");
  751. m_comboPointType.SetCurSel(0);
  752. CheckDlgButton(IDC_CHECK_APN_APPLY, 1);
  753. GetDlgItem(IDC_BUTTON_DROPUP).SetWindowTextA("▲");
  754. GetDlgItem(IDC_BUTTON_DROPUP).ShowWindow(FALSE);
  755. /*
  756. IDC_COMBO_CON_MODE 登录类型选择框 m_comboModeType
  757. IDC_STATIC_TXT_MODE 登录类型
  758. IDC_STATIC_TXT_IPTYPE APN 类型 m_comboIPType
  759. IDC_COMBO_CON_IPTYPE APN 类型选择框
  760. IDC_STATIC_TXT_POINTTYPE 接入点类型 m_comboPointType
  761. IDC_COMBO_PONT_TYPE 接入点类型选择框
  762. */
  763. GetDlgItem(IDC_BUTTON_DEFAULT_CONNECT).ShowWindow(!m_localSIM);
  764. if(!m_localSIM) {
  765. //m_comboPointType.ShowWindow(FALSE);
  766. //SetDlgItemTextA(IDC_STATIC_TXT_PROFILENAME, "配置文件名称:");
  767. //GetDlgItem(IDC_STATIC_TXT_IPTYPE).ShowWindow(FALSE);
  768. //SetDlgItemTextA(IDC_STATIC_TXT_IPTYPE, "APN 类型:");
  769. //GetDlgItem(IDC_COMBO_CON_IPTYPE).ShowWindow(FALSE);
  770. //GetDlgItem(IDC_STATIC_TXT_POINTTYPE).ShowWindow(FALSE);
  771. //GetDlgItem(IDC_COMBO_PONT_TYPE).ShowWindow(FALSE);
  772. //SetDlgItemTextA(IDC_STATIC_TXT_MODE, "身份验证类型:");
  773. //SetDlgItemTextA(IDC_STATIC_LOGIN, "拨号配置(接入点)");
  774. //SetDlgItemTextA(IDC_BUTTON_CONNECT, "应用");
  775. }
  776. CheckDlgButton(IDC_CHECK_MNTBYRVC, m_pEntity->IsManageByUser() ? FALSE : TRUE);
  777. m_nReversedType = m_pEntity->GetCurAdvancedConfig();
  778. m_nGenType = m_pEntity->GetCurAdvancedConfig(true);
  779. Dbg("GenType:%d, ReverseType:%d", m_nGenType, m_nReversedType);
  780. // 默认程序自动管理
  781. GetDlgItem(IDC_CHECK_MNTBYRVC).ShowWindow(FALSE);
  782. if(!m_localSIM) {
  783. GetDlgItem(IDC_RADIO_3G).EnableWindow(FALSE);
  784. GetDlgItem(IDC_RADIO_4G).EnableWindow(FALSE);
  785. GetDlgItem(IDC_RADIO_DEFAULT).EnableWindow(FALSE);
  786. GetDlgItem(IDC_RADIO_WEB).EnableWindow(FALSE);
  787. } else {
  788. CheckRadioButton(IDC_RADIO_3G, IDC_RADIO_WEB, IDC_RADIO_3G + m_nGenType-1);
  789. if(m_nReversedType != m_nGenType) {
  790. SetDlgItemTextA(IDC_STATIC_ADVANCED, "终端上网类型-需重启应用:");
  791. } else {
  792. SetDlgItemTextA(IDC_STATIC_ADVANCED, "终端上网类型:");
  793. }
  794. }
  795. const BOOL checked = IsDlgButtonChecked(IDC_RADIO_WEB);
  796. GetDlgItem(IDC_RADIO_MBB_WIRE).EnableWindow(checked);
  797. GetDlgItem(IDC_RADIO_MBB_WLAN).EnableWindow(checked);
  798. // 恢复手工配置MIFI登录参数和WIFI连接配置 [6/16/2020 11:23 @Gifur]
  799. //GetDlgItem(IDC_BUTTON_MBB_CONFIG).EnableWindow(checked);
  800. GetDlgItem(IDC_BUTTON_MBB_CONFIG).ShowWindow(FALSE);
  801. m_pEntity->GetMBBRunConfig(m_sReverseMBBParam, FALSE);
  802. m_pEntity->GetMBBRunConfig(m_sMBBParam, FALSE);
  803. CheckRadioButton(IDC_RADIO_MBB_WIRE, IDC_RADIO_MBB_WLAN,
  804. IDC_RADIO_MBB_WIRE + m_sReverseMBBParam.connectType - 1);
  805. if(m_sReverseMBBParam.connectType != MBB_CONNECT_UNKONWN && checked) {
  806. GetDlgItem(IDC_BUTTON_MBB_CONFIG).EnableWindow(TRUE);
  807. }
  808. }
  809. void CMobileDlg::UpdateDongles()
  810. {
  811. int cnt = m_pEntity->UpdateDongleInfo();
  812. m_comboDongles.ResetContent();
  813. m_comboProfiles.ResetContent();
  814. this->SetWindowTextA((LPCTSTR)CSimpleStringA::Format("APN 拨号配置(%d) -v%s", cnt, MOD_VERSION));
  815. if(cnt > 0) {
  816. int cntType = CNT_INVALID;
  817. EnableControls(TRUE);
  818. int aim = 0;
  819. int activeOne = -1;
  820. m_dongleType = 0;
  821. for(int i=0; i<cnt; ++i) {
  822. m_comboDongles.AddString(g_DongleInfos[i].subInfo.strProviderName);
  823. if(g_DongleInfos[i].subInfo.mbnCntState == MBN_ACTIVATION_STATE_ACTIVATED) {
  824. aim = i;
  825. if(g_DongleInfos[aim].usDeviceType & DEVTYPE_ANDROID_UKNOWN) {
  826. cntType = CNT_ANDROID;
  827. } else if(g_DongleInfos[aim].usDeviceType == DEVTYPE_MODEM) {
  828. cntType = CNT_RAS;
  829. } else if(g_DongleInfos[aim].usDeviceType == DEVTYPE_MBB) {
  830. cntType = CNT_MBB;
  831. } else if(g_DongleInfos[aim].usDeviceType == DEVTYPE_INTER){
  832. cntType = CNT_MBN;
  833. }
  834. }
  835. if(g_DongleInfos[i].priority > 0) {
  836. activeOne = i;
  837. }
  838. m_dongleType |= g_DongleInfos[i].usDeviceType;
  839. }
  840. ATLASSERT(aim == 0 || cntType != CNT_INVALID);
  841. m_comboDongles.SetCurSel(aim);
  842. if((m_dongleType & DEVTYPE_ANDROID_UKNOWN) && activeOne == -1) {
  843. SetDlgItemTextA(IDC_STATIC_TXT_WARN, "当前未能识别到默认移动数据应用卡,请进行选择(应用)!");
  844. } else {
  845. GetDlgItem(IDC_STATIC_TXT_WARN).ShowWindow(SW_HIDE);
  846. }
  847. TriggerConnectState(cntType);
  848. if(cntType != CNT_INVALID) {
  849. OnSignalChanged(0, NULL, g_DongleInfos[aim].subInfo.ulSingnal);
  850. }
  851. BOOL bDefault = 0;
  852. OnCbnSelchangeComboDongle(0, 0, NULL, bDefault);
  853. } else {
  854. if(cnt == -2) {
  855. SetDlgItemTextA(IDC_STATIC_TXT_WARN, "当前未连接到多合一,请稍后再试!");
  856. } else if(cnt == -1) {
  857. SetDlgItemTextA(IDC_STATIC_TXT_WARN, "连接多合一管控实体失败!");
  858. } else if(cnt == 0) {
  859. SetDlgItemTextA(IDC_STATIC_TXT_WARN, "未检测到上网卡(或卡槽)相关信息,请检查设备!");
  860. } else if(cnt == -500) {
  861. SetDlgItemTextA(IDC_STATIC_TXT_WARN, m_pEntity->GetLastErrMsg());
  862. }
  863. //将提示栏显示出来
  864. GetDlgItem(IDC_STATIC_TXT_WARN).ShowWindow(SW_SHOW);
  865. TriggerConnectState(CNT_INVALID);
  866. EnableControls(FALSE);
  867. }
  868. }
  869. void CMobileDlg::EnableControls(BOOL bEnable /*= TRUE*/)
  870. {
  871. GetDlgItem(IDC_BUTTON_EXPAND).EnableWindow(bEnable);
  872. GetDlgItem(IDC_BUTTON_APN_STORE).EnableWindow(bEnable);
  873. GetDlgItem(IDC_BUTTON_CONNECT).EnableWindow(bEnable);
  874. GetDlgItem(IDC_COMBO_PROFILES).EnableWindow(bEnable);
  875. GetDlgItem(IDC_COMBO_DONGLE).EnableWindow(bEnable);
  876. GetDlgItem(IDC_COMBO_CON_MODE).EnableWindow(bEnable);
  877. GetDlgItem(IDC_COMBO_CON_IPTYPE).EnableWindow(bEnable);
  878. GetDlgItem(IDC_EDIT_USER).EnableWindow(bEnable);
  879. GetDlgItem(IDC_EDIT_PASSWORD).EnableWindow(bEnable);
  880. GetDlgItem(IDC_CHECK_VIEW_PASSWORD).EnableWindow(bEnable);
  881. GetDlgItem(IDC_EDIT_APN).EnableWindow(bEnable);
  882. GetDlgItem(IDC_CHECK_APN_APPLY).EnableWindow(bEnable);
  883. GetDlgItem(IDC_COMBO_PONT_TYPE).EnableWindow(bEnable);
  884. GetDlgItem(IDC_EDIT_PROFILE).EnableWindow(bEnable);
  885. GetDlgItem(IDC_BUTTON_CLEAR).EnableWindow(bEnable);
  886. GetDlgItem(IDC_BUTTON_DELETE).EnableWindow(bEnable);
  887. GetDlgItem(IDC_CHECK_MNTBYRVC).EnableWindow(bEnable);
  888. //不让用户更改拨号方式
  889. GetDlgItem(IDC_COMBO_GTYPE).EnableWindow(FALSE);
  890. }
  891. void CMobileDlg::EnterProgressBar(DWORD dwTimeout, DWORD nTimerID)
  892. {
  893. EnableWindow(FALSE);
  894. m_ProgressBar.ResetStep();
  895. m_ProgressBar.ShowWindow(SW_SHOW);
  896. m_ProgressBar.CenterWindow();
  897. if(dwTimeout != INFINITE) {
  898. SetTimer(nTimerID, dwTimeout);
  899. }
  900. }
  901. void CMobileDlg::LeaveProgressBar(DWORD nTimerID)
  902. {
  903. if(nTimerID == WM_TIMER_INVALID || KillTimer(nTimerID)) {
  904. m_ProgressBar.ShowWindow(SW_HIDE);
  905. EnableWindow(TRUE);
  906. if(nTimerID == WM_TIMER_CONNECT && !m_btnConnect.IsWindowEnabled()) {
  907. m_btnConnect.EnableWindow(TRUE);
  908. m_btnConnect.SetWindowTextA("连接");
  909. Dbg("set connect btn text");
  910. } else if(nTimerID == WM_TIMER_DISCONNECT && !m_btnConnect.IsWindowEnabled()) {
  911. m_btnConnect.EnableWindow(TRUE);
  912. m_btnConnect.SetWindowTextA("断开连接");
  913. Dbg("set disconnect btn text");
  914. } /*else if(nTimerID == WM_TIMER_SWITCH && !m_btnConnect.IsWindowEnabled()) {
  915. m_btnConnect.EnableWindow(TRUE);
  916. m_btnConnect.SetWindowTextA("应用");
  917. }*/
  918. }
  919. }
  920. void CMobileDlg::TriggerConnectState(int nCntState)
  921. {
  922. Dbg("Enter TriggerConnectState %d", nCntState);
  923. if(nCntState == CNT_MBN || nCntState == CNT_RAS || nCntState == CNT_MBB) {
  924. Dbg("set disconnect text");
  925. m_btnConnect.SetWindowTextA("断开连接");
  926. m_btnConnect.EnableWindow(TRUE);
  927. GetDlgItem(IDC_COMBO_DONGLE).EnableWindow(FALSE); //已连接的情况下,不能选择卡托设备
  928. GetDlgItem(IDC_COMBO_PROFILES).EnableWindow(FALSE); //也不能选择配置文件,所以当前的卡托一定是已连接的
  929. } else if(nCntState == CNT_ANDROID) {
  930. GetDlgItem(IDC_COMBO_DONGLE).EnableWindow(TRUE);
  931. GetDlgItem(IDC_COMBO_PROFILES).EnableWindow(TRUE);
  932. } else if(nCntState == CNT_INVALID) {
  933. Dbg("set connet text");
  934. m_btnConnect.SetWindowTextA("连接");
  935. m_btnConnect.EnableWindow(TRUE);
  936. }
  937. m_bConnected = (nCntState != CNT_INVALID);
  938. m_nWhoConnected = nCntState;
  939. if(m_bConnected) {
  940. SetDlgItemTextA(IDC_STATIC_PERCENTAGE, "0%");
  941. SetDlgItemTextA(IDC_STATIC_SIGNAL, "网络强度:");
  942. SetDlgItemTextA(IDC_STATIC_STATUS, "已连接");
  943. OnFatalMsgChanged(WM_FATALMESSAGE_CHANGE, Error_Succeed, NULL);
  944. } else {
  945. SetDlgItemTextA(IDC_STATIC_PERCENTAGE, "NA");
  946. SetDlgItemTextA(IDC_STATIC_SIGNAL, "");
  947. SetDlgItemTextA(IDC_STATIC_STATUS, "已断开连接");
  948. GetDlgItem(IDC_COMBO_DONGLE).EnableWindow(TRUE);
  949. GetDlgItem(IDC_COMBO_PROFILES).EnableWindow(TRUE);
  950. }
  951. GetDlgItem(IDC_COMBO_GTYPE).EnableWindow(FALSE);
  952. }
  953. void CMobileDlg::ShowProfileCreateCtrl(BOOL bShow /*= TRUE*/)
  954. {
  955. GetDlgItem(IDC_STATIC_LOGIN).ShowWindow(bShow);
  956. GetDlgItem(IDC_STATIC_TXT_PROFILENAME).ShowWindow(bShow);
  957. GetDlgItem(IDC_EDIT_PROFILE).ShowWindow(bShow);
  958. GetDlgItem(IDC_STATIC_TXT_APN).ShowWindow(bShow);
  959. GetDlgItem(IDC_EDIT_APN).ShowWindow(bShow);
  960. GetDlgItem(IDC_STATIC_TXT_USER).ShowWindow(bShow);
  961. GetDlgItem(IDC_EDIT_USER).ShowWindow(bShow);
  962. GetDlgItem(IDC_STATIC_TXT_PASSWORD).ShowWindow(bShow);
  963. GetDlgItem(IDC_EDIT_PASSWORD).ShowWindow(bShow);
  964. GetDlgItem(IDC_CHECK_VIEW_PASSWORD).ShowWindow(bShow);
  965. GetDlgItem(IDC_STATIC_TXT_MODE).ShowWindow(bShow);
  966. GetDlgItem(IDC_COMBO_CON_MODE).ShowWindow(bShow);
  967. const int nSel3 = m_comboCntType.GetCurSel();
  968. if(nSel3 <= CNT_RAS || bShow == FALSE) {
  969. GetDlgItem(IDC_STATIC_TXT_IPTYPE).ShowWindow(bShow);
  970. GetDlgItem(IDC_COMBO_CON_IPTYPE).ShowWindow(bShow);
  971. GetDlgItem(IDC_STATIC_TXT_POINTTYPE).ShowWindow(bShow);
  972. GetDlgItem(IDC_COMBO_PONT_TYPE).ShowWindow(bShow);
  973. }
  974. GetDlgItem(IDC_CHECK_APN_APPLY).ShowWindow(bShow);
  975. GetDlgItem(IDC_BUTTON_APN_STORE).ShowWindow(bShow);
  976. //GetDlgItem(IDC_BUTTON_DROPUP).ShowWindow(bShow);
  977. GetDlgItem(IDC_BUTTON_CLEAR).ShowWindow(bShow);
  978. GetDlgItem(IDC_BUTTON_DELETE).ShowWindow(bShow);
  979. GetDlgItem(IDC_EDIT_PHONENUM).ShowWindow(bShow);
  980. GetDlgItem(IDC_CHECK_RASIO_PAP).ShowWindow(bShow);
  981. GetDlgItem(IDC_CHECK_RASIO_CHAP).ShowWindow(bShow);
  982. GetDlgItem(IDC_CHECK_RASIO_MSCHAPV2).ShowWindow(bShow);
  983. MoveDlgItems(bShow);
  984. }
  985. void CMobileDlg::_ClearProfileTxt()
  986. {
  987. SetDlgItemTextA(IDC_EDIT_PROFILE, "");
  988. SetDlgItemTextA(IDC_EDIT_APN, "");
  989. SetDlgItemTextA(IDC_EDIT_USER, "");
  990. SetDlgItemTextA(IDC_EDIT_PASSWORD, "");
  991. SetDlgItemTextA(IDC_EDIT_PHONENUM, "");
  992. CheckDlgButton(IDC_CHECK_RASIO_PAP, FALSE);
  993. CheckDlgButton(IDC_CHECK_RASIO_CHAP, FALSE);
  994. CheckDlgButton(IDC_CHECK_RASIO_MSCHAPV2, FALSE);
  995. m_strPassword = "";
  996. m_strPhoneNum = "";
  997. m_strUserName = "";
  998. m_comboModeType.SetCurSel(0);
  999. m_comboIPType.SetCurSel(0);
  1000. m_comboPointType.SetCurSel(0);
  1001. const int nCntType = m_comboCntType.GetCurSel();
  1002. if(nCntType == CNT_MBB) {
  1003. m_comboIPType.SetCurSel(1);
  1004. m_comboIPType.EnableWindow(FALSE);
  1005. m_comboModeType.SetCurSel(1);
  1006. } else {
  1007. m_comboIPType.EnableWindow(TRUE);
  1008. }
  1009. }
  1010. int CMobileDlg::GetInterfaceIdInCombo(CSimpleStringA& strCurDongle, bool bSlient /*= true*/)
  1011. {
  1012. int nSel = 0;
  1013. CString strDongle;
  1014. {
  1015. int selected = m_comboDongles.GetCurSel();
  1016. if(selected < 0) {
  1017. return -1;
  1018. }
  1019. int nLen = m_comboDongles.GetLBTextLen(selected);
  1020. m_comboDongles.GetLBText(selected, strDongle.GetBuffer(nLen));
  1021. strDongle.ReleaseBuffer();
  1022. Dbg("GetInterfaceIdInCombo::selected: %s", (LPCTSTR)strDongle);
  1023. }
  1024. for (int i=0; i<g_DongleInfos.GetCount(); ++i)
  1025. {
  1026. Dbg("GetInterfaceIdInCombo::idx[%d] %s", i, (LPCTSTR)g_DongleInfos[i].subInfo.strProviderName);
  1027. if(!strDongle.Compare((LPCTSTR)g_DongleInfos[i].subInfo.strProviderName)) {
  1028. strCurDongle = g_DongleInfos[i].csInterfaceId;
  1029. nSel = i;
  1030. Dbg("break");
  1031. break;
  1032. }
  1033. }
  1034. return nSel;
  1035. }
  1036. BOOL CMobileDlg::HasUpdatedMBBParam()
  1037. {
  1038. if(m_nGenType != 4) {
  1039. return FALSE;
  1040. }
  1041. if(m_sMBBParam.connectType != m_sReverseMBBParam.connectType) {
  1042. Dbg("@1@");
  1043. return TRUE;
  1044. }
  1045. if(m_sMBBParam.loginParam.strUsername.Compare(
  1046. (LPCTSTR)m_sReverseMBBParam.loginParam.strUsername) != 0) {
  1047. Dbg("@2@");
  1048. return TRUE;
  1049. }
  1050. if(m_sMBBParam.loginParam.strPassword.Compare(
  1051. (LPCTSTR)m_sReverseMBBParam.loginParam.strPassword) != 0) {
  1052. Dbg("@3@");
  1053. return TRUE;
  1054. }
  1055. if(m_sMBBParam.wlanConnectParam.strUsername.Compare(
  1056. (LPCTSTR)m_sReverseMBBParam.wlanConnectParam.strUsername) != 0) {
  1057. Dbg("@4@");
  1058. return TRUE;
  1059. }
  1060. if(m_sMBBParam.wlanConnectParam.strPassword.Compare(
  1061. (LPCTSTR)m_sReverseMBBParam.wlanConnectParam.strPassword) != 0) {
  1062. Dbg("@5@");
  1063. return TRUE;
  1064. }
  1065. if(m_sMBBParam.wlanConnectParam.Flag != m_sReverseMBBParam.wlanConnectParam.Flag) {
  1066. Dbg("@6@");
  1067. return TRUE;
  1068. }
  1069. return FALSE;
  1070. }
  1071. LRESULT CMobileDlg::OnBnClickedButtonApnStore(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
  1072. {
  1073. CloseVirtualKeyboard();
  1074. DoDataExchange(TRUE);
  1075. const int nCntType = m_comboCntType.GetCurSel();
  1076. int nSel = m_comboProfiles.GetCurSel();
  1077. CSimpleStringA strCurDongle;
  1078. int nIndex = GetInterfaceIdInCombo(strCurDongle);
  1079. Dbg("nIndex : %d vs nSel: %d", nIndex, nSel);
  1080. if(nCntType <= 0) {
  1081. //TODO:在之前应该设为该选择框不可用
  1082. MessageBoxA("意料之外的拨号类型!");
  1083. return 0;
  1084. }
  1085. BOOL bAndroid = (nCntType == 4 || nCntType == 3) ? TRUE : FALSE;
  1086. if(nIndex < 0) {
  1087. MessageBoxA(bAndroid ? "请选择要为其添加配置的卡槽!" : "请选择要为其添加配置的网卡!");
  1088. return 0;
  1089. } else if(strCurDongle.GetLength() <= 0) {
  1090. MessageBoxA(bAndroid ? "数据卡不存在,请关闭后重新打开当前配置窗口!" : "无线网卡不存在,请关闭后重新打开当前配置窗口!");
  1091. return 0;
  1092. }
  1093. BOOL bUpdate = FALSE;
  1094. if(GetDlgItem(IDC_BUTTON_DELETE).IsWindowEnabled()) {
  1095. bUpdate = TRUE;
  1096. if(bAndroid || nCntType == CNT_MBB) {
  1097. //let it empty.
  1098. } else if(g_DongleInfos[nIndex].subInfo.mbnCntState == MBN_ACTIVATION_STATE_ACTIVATED) {
  1099. MessageBox("请先断开连接再进行更新保存!", "提示", MB_OK);
  1100. return 0;
  1101. }
  1102. }
  1103. //Profile description.
  1104. CEdit edit = GetDlgItem(IDC_EDIT_PROFILE);
  1105. int nLen = edit.GetWindowTextLength();
  1106. if(nLen <= 0) {
  1107. MessageBoxA("请输入配置文件名称!");
  1108. return 0;
  1109. }
  1110. edit.GetWindowText(m_strProfileDesc.GetBuffer(nLen), nLen + 1);
  1111. m_strProfileDesc.ReleaseBuffer();
  1112. CString strApn;
  1113. nLen = m_edtAPN.GetWindowTextLength();
  1114. if((nCntType == CNT_MBN || nCntType == CNT_MBB) && nLen <= 0) {
  1115. MessageBoxA("请输入接入点(APN)名称!");
  1116. return 0;
  1117. }
  1118. m_edtAPN.GetWindowText(strApn.GetBuffer(nLen + 1), nLen + 1);
  1119. strApn.ReleaseBuffer(nLen);
  1120. strApn.TrimLeft();
  1121. strApn.TrimRight();
  1122. m_strUserName.TrimLeft();
  1123. m_strUserName.TrimRight();
  1124. if(m_strUserName.GetLength() <= 0) {
  1125. MessageBoxA("请输入用户名!");
  1126. return 0;
  1127. }
  1128. m_strPassword.TrimLeft();
  1129. m_strPassword.TrimRight();
  1130. if(m_strPassword.GetLength() <= 0) {
  1131. MessageBoxA("请输入密码!");
  1132. return 0;
  1133. } else if(nCntType == CNT_MBB) {
  1134. std::string password((LPCTSTR)m_strPassword);
  1135. if(std::string::npos != password.find_first_of(",\":;\\&%+'<>?")) {
  1136. MessageBoxA("密码中不能包含(,\":;\\&%+'<>?)等字符!");
  1137. return 0;
  1138. }
  1139. }
  1140. /*
  1141. if(m_strPassword.GetLength() <= 0) {
  1142. MessageBoxA("请输入密码!");
  1143. return 0;
  1144. } else if(!m_strPassword.Compare(DEFAULT_PASSWORD_CHECK)) {
  1145. //在修改的情况下表示没有修改密码,//在新建的情况下需要提示为无效密码
  1146. m_strPassword = "";
  1147. if(bUpdate) {
  1148. m_strPassword = "";
  1149. } else {
  1150. MessageBoxA("该密码无效,请进行修改!");
  1151. return 0;
  1152. }
  1153. }
  1154. */
  1155. if(nCntType == CNT_RAS && m_strPhoneNum.GetLength() <= 0) {
  1156. MessageBoxA(("请输入电话号码!"));
  1157. return 0;
  1158. }
  1159. //是否立即应用
  1160. CButton btnCheck = GetDlgItem(IDC_CHECK_APN_APPLY);
  1161. bool bApplyNow = (btnCheck.GetCheck() != 0);
  1162. if(bAndroid) {
  1163. strCurDongle = nCntType == 3 ? "MAIN" : "VICE";
  1164. /*
  1165. for(int i=0; i<g_DongleInfos.GetCount(); ++i) {
  1166. if(g_DongleInfos[i].usDeviceType == DEVTYPE_ANDROID_MAIN && nCntType == 3) {
  1167. nIndex = i;
  1168. break;
  1169. } else if(g_DongleInfos[i].usDeviceType == DEVTYPE_ANDROID_VICE && nCntType == 4) {
  1170. nIndex = i;
  1171. break;
  1172. }
  1173. }
  1174. */
  1175. }
  1176. int aim = -1;
  1177. for(int i=0; i<g_DongleInfos[nIndex].profileList.GetCount(); ++i) {
  1178. if(!g_DongleInfos[nIndex].profileList[i].AccessInfo.strProfileDesc.Compare((LPCTSTR)m_strProfileDesc)) {
  1179. if(!bUpdate) {
  1180. MessageBoxA("该配置文件名称已存在,请尝试更换名称!");
  1181. return 0;
  1182. } else {
  1183. aim = i;
  1184. break;
  1185. }
  1186. }
  1187. }
  1188. if(bUpdate && aim == -1) {
  1189. assert(FALSE);
  1190. }
  1191. AccessKeyInfo newInfo;
  1192. memset(&newInfo, 0, sizeof(newInfo));
  1193. newInfo.strProfileDesc = (LPCTSTR)m_strProfileDesc;
  1194. newInfo.strAccessString = (LPCTSTR)strApn;
  1195. newInfo.strUserName = (LPCTSTR)m_strUserName;
  1196. newInfo.strPassword = (LPCTSTR)m_strPassword;
  1197. if(bAndroid) {
  1198. newInfo.usCntType = CNT_ANDROID;
  1199. } else {
  1200. newInfo.usCntType = nCntType;
  1201. }
  1202. newInfo.usAPType = 0;
  1203. if(nCntType == CNT_MBN || bAndroid || nCntType == CNT_MBB) {
  1204. {
  1205. int selected = m_comboModeType.GetCurSel();
  1206. if(selected < 0) {
  1207. MessageBoxA(bAndroid ? "请选择合适的身份验证类型!" : "请选择合适的登录类型!");
  1208. return 0;
  1209. }
  1210. nLen = m_comboModeType.GetLBTextLen(selected);
  1211. if(nCntType == CNT_MBN) {
  1212. CString strTemp;
  1213. m_comboModeType.GetLBText(selected, strTemp.GetBuffer(nLen));
  1214. strTemp.ReleaseBuffer();
  1215. if(!strTemp.Compare("无")) {
  1216. strTemp = "NONE";
  1217. } else if(!strTemp.Compare("MS-CHAP v2")) {
  1218. strTemp = "MsCHAPv2";
  1219. }
  1220. newInfo.strAuthProtocol = strTemp;
  1221. } else {//CNT_MBB
  1222. if(selected == 1) {
  1223. newInfo.usAPType = AUPR_PAP;
  1224. } else if(selected == 2) {
  1225. newInfo.usAPType = AUPR_CHAP;
  1226. } else if(selected == 3) {
  1227. newInfo.usAPType = AUPR_PAPORCHAP;
  1228. }
  1229. }
  1230. }
  1231. if(nCntType == CNT_MBN || nCntType == CNT_MBB)
  1232. {
  1233. const int selected = m_comboIPType.GetCurSel();
  1234. if(selected < 0) {
  1235. MessageBoxA("请选择合适的IP类型!");
  1236. return 0;
  1237. } else if((nCntType == CNT_MBB && (selected < 0 || selected > 3))) {
  1238. MessageBoxA("不支持的IP类型!");
  1239. return 0;
  1240. }
  1241. nLen = m_comboIPType.GetLBTextLen(selected);
  1242. CString strTemp;
  1243. m_comboIPType.GetLBText(selected, strTemp.GetBuffer(nLen));
  1244. strTemp.ReleaseBuffer();
  1245. if(nCntType == CNT_MBN) {
  1246. if(!strTemp.Compare("默认")) {
  1247. strTemp = "Default";
  1248. } else if(!strTemp.Compare("IPv4v6XLAT")) {
  1249. strTemp = "XLAT";
  1250. }
  1251. }
  1252. newInfo.strIPType = (LPCTSTR)strTemp;
  1253. }
  1254. if(nCntType == CNT_MBN)
  1255. {
  1256. int selected = m_comboPointType.GetCurSel();
  1257. if(selected < 0) {
  1258. MessageBoxA("请选择合适的接入点类型!");
  1259. return 0;
  1260. }
  1261. nLen = m_comboPointType.GetLBTextLen(selected);
  1262. CString strTemp;
  1263. m_comboPointType.GetLBText(selected, strTemp.GetBuffer(nLen));
  1264. strTemp.ReleaseBuffer();
  1265. }
  1266. } else {
  1267. {
  1268. bool fChooseLeastOne = false;
  1269. if(IsDlgButtonChecked(IDC_CHECK_RASIO_PAP)) {
  1270. newInfo.usAPType |= AUPR_PAP;
  1271. fChooseLeastOne = true;
  1272. }
  1273. if(IsDlgButtonChecked(IDC_CHECK_RASIO_CHAP)) {
  1274. newInfo.usAPType |= AUPR_CHAP;
  1275. fChooseLeastOne = true;
  1276. }
  1277. if(IsDlgButtonChecked(IDC_CHECK_RASIO_MSCHAPV2)) {
  1278. newInfo.usAPType |= AUPR_MSV2;
  1279. fChooseLeastOne = true;
  1280. }
  1281. if(!fChooseLeastOne) {
  1282. MessageBoxA("请至少选择一个登录类型(密码身份验证协议)!");
  1283. return 0;
  1284. }
  1285. }
  1286. newInfo.strPhoneNum = (LPCTSTR)m_strPhoneNum;
  1287. }
  1288. EnterProgressBar(TIMER_TIMTOUT_MAX);
  1289. if(!bUpdate) {
  1290. auto rc = m_pEntity->AddNewProfile(strCurDongle, newInfo, bApplyNow);
  1291. if(rc == Error_Pending) {
  1292. } else {
  1293. if(rc != Error_Succeed) {
  1294. LeaveProgressBar(WM_TIMER_PROCESS);
  1295. MessageBoxA(CSimpleStringA::Format("添加拨号配置失败: %s", m_pEntity->GetLastErrMsg()));
  1296. } else {
  1297. Dbg("PostMessage WM_ADD_PROFILE_RESULT");
  1298. PostMessage(WM_ADD_PROFILE_RESULT, Error_Succeed, 0);
  1299. }
  1300. }
  1301. } else {
  1302. auto rc = m_pEntity->UpdateProfile(strCurDongle,
  1303. g_DongleInfos[nIndex].profileList[aim].strProfileName, newInfo, bApplyNow);
  1304. if(rc == Error_Pending) {
  1305. } else {
  1306. LeaveProgressBar(WM_TIMER_PROCESS);
  1307. if(rc != Error_Succeed) {
  1308. MessageBoxA(CSimpleStringA::Format("更新拨号配置失败: %s", m_pEntity->GetLastErrMsg()));
  1309. } else {
  1310. Dbg("PostMessage WM_UPDATE_PROFILE_RESULT");
  1311. PostMessage(WM_UPDATE_PROFILE_RESULT, Error_Succeed, 0);
  1312. }
  1313. }
  1314. }
  1315. return 0;
  1316. }
  1317. LRESULT CMobileDlg::OnCbnSelchangeComboDongle(
  1318. WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
  1319. {
  1320. CSimpleStringA strCurDongle;
  1321. int nIndex = GetInterfaceIdInCombo(strCurDongle);
  1322. if(nIndex < 0) {
  1323. Dbg("GetInterfaceIdInCombo failed: %d", nIndex);
  1324. return 0;
  1325. } else if(strCurDongle.GetLength() <= 0) {
  1326. Dbg("GetInterfaceIdInCombo failed2: %d", nIndex);
  1327. return 0;
  1328. }
  1329. if(g_DongleInfos[nIndex].usDeviceType == DEVTYPE_INTER) {
  1330. m_comboCntType.SetCurSel(CNT_MBN);
  1331. } else if(g_DongleInfos[nIndex].usDeviceType == DEVTYPE_MODEM) {
  1332. m_comboCntType.SetCurSel(CNT_RAS);
  1333. } else if(g_DongleInfos[nIndex].usDeviceType == DEVTYPE_ANDROID_MAIN) {
  1334. m_comboCntType.SetCurSel(3);
  1335. } else if(g_DongleInfos[nIndex].usDeviceType == DEVTYPE_ANDROID_VICE) {
  1336. m_comboCntType.SetCurSel(4);
  1337. } else if(g_DongleInfos[nIndex].usDeviceType == DEVTYPE_MBB) {
  1338. m_comboCntType.SetCurSel(CNT_MBB);
  1339. } else {
  1340. m_comboCntType.SetCurSel(0);
  1341. }
  1342. if(g_DongleInfos[nIndex].usDeviceType & DEVTYPE_ANDROID_UKNOWN) {
  1343. if(g_DongleInfos[nIndex].priority > 0) {
  1344. m_btnConnect.SetWindowTextA("已应用");
  1345. m_btnConnect.EnableWindow(FALSE);
  1346. } else {
  1347. m_btnConnect.SetWindowTextA("应用");
  1348. m_btnConnect.EnableWindow(TRUE);
  1349. }
  1350. m_comboPointType.ShowWindow(FALSE);
  1351. } else {
  1352. if(g_DongleInfos[nIndex].subInfo.mbnCntState == MBN_ACTIVATION_STATE_ACTIVATED) {
  1353. m_btnConnect.SetWindowTextA("断开连接");
  1354. m_btnConnect.EnableWindow(TRUE);
  1355. } else {
  1356. m_btnConnect.SetWindowTextA("连接");
  1357. m_btnConnect.EnableWindow(TRUE);
  1358. }
  1359. // 在简洁版本中,该字段会出来 [5/12/2020 12:10 @Gifur]
  1360. {
  1361. char szBtnTxt[128] = {0};
  1362. m_btnExpand.GetWindowTextA(szBtnTxt, 128);
  1363. if(!!strcmp(szBtnTxt, "管理配置")) {
  1364. m_comboPointType.ShowWindow(TRUE);
  1365. }
  1366. }
  1367. }
  1368. m_comboProfiles.ResetContent();
  1369. const MBNProfileList& info = g_DongleInfos[nIndex].profileList;
  1370. Dbg("CbnSelchangeComboDongle: %s", g_DongleInfos[nIndex].subInfo.strProfileName);
  1371. Dbg("[%d] profile count: %d", nIndex, info.GetCount());
  1372. int aim = -1;
  1373. if(info.GetCount() > 0) {
  1374. for(int i=0; i<info.GetCount(); ++i) {
  1375. m_comboProfiles.AddString(info[i].AccessInfo.strProfileDesc);
  1376. Dbg("%s - %s", (LPCTSTR)info[i].strProfileName, (LPCTSTR)info[i].AccessInfo.strProfileDesc);
  1377. // m_bConnected && ?? [12/4/2019 19:18 @Gifur]
  1378. if(aim == -1 &&/*m_bConnected && */g_DongleInfos[nIndex].subInfo.strProfileName.GetLength() > 0) {
  1379. if(!g_DongleInfos[nIndex].subInfo.strProfileName.Compare(info[i].strProfileName)) {
  1380. Dbg("Here: %d", i);
  1381. aim = i;
  1382. }
  1383. }
  1384. }
  1385. if(aim == -1) {
  1386. aim = 0;
  1387. }
  1388. m_comboProfiles.SetCurSel(aim);
  1389. }
  1390. BOOL bEmpty = TRUE;
  1391. OnCbnSelchangeComboProfiles(NULL, NULL, NULL, bEmpty);
  1392. //第三层固定信息
  1393. //制造商
  1394. SetDlgItemTextA(IDC_STATIC_MANUFACTURER, g_DongleInfos[nIndex].subInfo.strManufacturer);
  1395. //型号
  1396. SetDlgItemTextA(IDC_STATIC_MODEL, g_DongleInfos[nIndex].subInfo.strMode);
  1397. //固件
  1398. SetDlgItemTextA(IDC_STATIC_FIRMWARE, g_DongleInfos[nIndex].subInfo.strFirmware);
  1399. //网络类型
  1400. SetDlgItemTextA(IDC_STATIC_HARDWARE, g_DongleInfos[nIndex].subInfo.strCellularClass);
  1401. //IMEI
  1402. SetDlgItemTextA(IDC_STATIC_IMEI, g_DongleInfos[nIndex].subInfo.strDeviceID);
  1403. //状态
  1404. SetDlgItemTextA(IDC_STATIC_PORT, ConvertStatusToString(g_DongleInfos[nIndex].state));
  1405. //数据类
  1406. SetDlgItemTextA(IDC_STATIC_DATACLASS, g_DongleInfos[nIndex].subInfo.strDataClass);
  1407. return 0;
  1408. }
  1409. LRESULT CMobileDlg::OnBnClickedButtonExpand(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& bHandled)
  1410. {
  1411. char szBtnTxt[128] = {0};
  1412. m_btnExpand.GetWindowTextA(szBtnTxt, 128);
  1413. if(!strcmp(szBtnTxt, "管理配置")) {
  1414. SetDlgSizeToLarge();
  1415. OnCbnSelchangeComboProfiles(NULL, NULL, NULL, bHandled);
  1416. } else {
  1417. SetDlgSizeToSmall();
  1418. }
  1419. return 0;
  1420. }
  1421. LRESULT CMobileDlg::OnBnClickedCheckMntbyrvc(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
  1422. {
  1423. m_pEntity->RequireManageByUser(!IsDlgButtonChecked(IDC_CHECK_MNTBYRVC));
  1424. return 0;
  1425. }
  1426. LRESULT CMobileDlg::OnBnClickedButtonDropup(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
  1427. {
  1428. SetDlgSizeToSmall();
  1429. return 0;
  1430. }
  1431. LRESULT CMobileDlg::OnBnClickedButtonClear(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
  1432. {
  1433. char szBtnTxt[128] = {0};
  1434. BOOL bClear = FALSE;
  1435. m_btnClear.GetWindowTextA(szBtnTxt, 128);
  1436. if(!strcmp(szBtnTxt, "新建")) {//点击了新建
  1437. CloseVirtualKeyboard();
  1438. GetDlgItem(IDC_BUTTON_DELETE).EnableWindow(FALSE);
  1439. GetDlgItem(IDC_EDIT_PROFILE).EnableWindow(TRUE);
  1440. m_btnClear.SetWindowTextA("清除");
  1441. bClear = TRUE;
  1442. CheckDlgButton(IDC_CHECK_APN_APPLY, TRUE);
  1443. } else if(!strcmp(szBtnTxt, "清除")) {
  1444. bClear = TRUE;
  1445. }
  1446. if(bClear) {
  1447. _ClearProfileTxt();
  1448. }
  1449. return 0;
  1450. }
  1451. LRESULT CMobileDlg::OnBnClickedButtonDefaultConnect(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
  1452. {
  1453. UINT_PTR uRes = MessageBoxA("该操作不可撤销!确定要恢复默认密码进行连接?", "确认", MB_OKCANCEL | MB_ICONQUESTION);
  1454. if(uRes == IDOK) {
  1455. EnterProgressBar(65 * 1000);
  1456. auto rc = m_pEntity->ConnectWIFIWithDefault();
  1457. if(rc == Error_Succeed) {
  1458. //MessageBoxA("尝试使用默认密码连接成功!");
  1459. } else {
  1460. LeaveProgressBar(WM_TIMER_PROCESS);
  1461. MessageBoxA(CSimpleStringA::Format("尝试使用默认密码连接失败: %s", m_pEntity->GetLastErrMsg()));
  1462. }
  1463. }
  1464. return 0;
  1465. }
  1466. LRESULT CMobileDlg::OnCbnSelchangeComboProfiles(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
  1467. {
  1468. char szBtnTxt[128] = {0};
  1469. m_btnExpand.GetWindowTextA(szBtnTxt, 128);
  1470. if(!!strcmp(szBtnTxt, "管理配置")) { //扩展
  1471. GetDlgItem(IDC_EDIT_PROFILE).EnableWindow(FALSE);
  1472. m_btnClear.SetWindowTextA("新建");
  1473. OnCbnSelchangeComboGtype(wNotifyCode, wID, hWndCtl, bHandled);
  1474. do
  1475. {
  1476. const int nSel = m_comboProfiles.GetCurSel();
  1477. CSimpleStringA strDongle;
  1478. const int nIndex = GetInterfaceIdInCombo(strDongle);
  1479. if(nIndex < 0 || nSel < 0 || strDongle.GetLength() <= 0) {
  1480. Dbg("nIndex : %d, nSel : %d", nIndex, nSel);
  1481. GetDlgItem(IDC_BUTTON_DELETE).EnableWindow(FALSE);
  1482. break;
  1483. }
  1484. _ClearProfileTxt();
  1485. {
  1486. const MBNProfileList& info = g_DongleInfos[nIndex].profileList;
  1487. m_strPassword = (LPCTSTR)info[nSel].AccessInfo.strPassword;
  1488. if(info[nSel].AccessInfo.strPassword == DEFAULT_PASSWORD_CHECK) {
  1489. m_strPassword = "";
  1490. }
  1491. m_strUserName = (LPCTSTR)info[nSel].AccessInfo.strUserName;
  1492. m_edtAPN.SetWindowTextA((LPCTSTR)info[nSel].AccessInfo.strAccessString);
  1493. GetDlgItem(IDC_EDIT_PROFILE).SetWindowTextA((LPCTSTR)info[nSel].AccessInfo.strProfileDesc);
  1494. if(info[nSel].AccessInfo.usCntType == CNT_RAS) {
  1495. assert(m_comboCntType.GetCurSel() == CNT_RAS);
  1496. Dbg("RAS for %s", (LPCTSTR)info[nSel].AccessInfo.strProfileDesc);
  1497. //GetDlgItem(IDC_EDIT_PHONENUM).SetWindowTextA((LPCTSTR)info[nSel].AccessInfo.strPhoneNum);
  1498. m_strPhoneNum = (LPCTSTR)info[nSel].AccessInfo.strPhoneNum;
  1499. Dbg("Set phone num: %s", (LPCTSTR)info[nSel].AccessInfo.strPhoneNum);
  1500. Dbg("usAPType: 0x%X", info[nSel].AccessInfo.usAPType);
  1501. if((info[nSel].AccessInfo.usAPType & AUPR_PAP) == AUPR_PAP) {
  1502. CheckDlgButton(IDC_CHECK_RASIO_PAP, TRUE);
  1503. } else {
  1504. CheckDlgButton(IDC_CHECK_RASIO_PAP, FALSE);
  1505. }
  1506. if((info[nSel].AccessInfo.usAPType & AUPR_CHAP) == AUPR_CHAP) {
  1507. CheckDlgButton(IDC_CHECK_RASIO_CHAP, TRUE);
  1508. } else {
  1509. CheckDlgButton(IDC_CHECK_RASIO_CHAP, FALSE);
  1510. }
  1511. if((info[nSel].AccessInfo.usAPType & AUPR_MSV2) == AUPR_MSV2) {
  1512. CheckDlgButton(IDC_CHECK_RASIO_MSCHAPV2, TRUE);
  1513. } else {
  1514. CheckDlgButton(IDC_CHECK_RASIO_MSCHAPV2, FALSE);
  1515. }
  1516. m_strPhoneNum = (LPCTSTR)info[nSel].AccessInfo.strPhoneNum;
  1517. }
  1518. else if(info[nSel].AccessInfo.usCntType == CNT_MBN) {
  1519. //change test
  1520. Dbg("@3");
  1521. if(m_comboModeType.SelectString(-1, info[nSel].AccessInfo.strAuthProtocol) == CB_ERR) {
  1522. Dbg("Enter: %s", (LPCTSTR)info[nSel].AccessInfo.strAuthProtocol);
  1523. if(!strncmp(info[nSel].AccessInfo.strAuthProtocol, "NONE", strlen("NONE"))) {
  1524. m_comboModeType.SetCurSel(0);
  1525. Dbg("mode type: set 0");
  1526. } else if(!strncmp(info[nSel].AccessInfo.strAuthProtocol, "MsCHAPv2", strlen("MsCHAPv2"))) {
  1527. m_comboModeType.SetCurSel(3);
  1528. Dbg("mode type: set 3");
  1529. } else {
  1530. m_comboModeType.SetCurSel(0);
  1531. Dbg("mode type: set 0");
  1532. }
  1533. }
  1534. Dbg("@4");
  1535. CheckDlgButton(IDC_CHECK_APN_APPLY, info[nSel].AccessInfo.IsDefault);
  1536. } else if(info[nSel].AccessInfo.usCntType == CNT_ANDROID
  1537. || info[nSel].AccessInfo.usCntType == CNT_MBB) {
  1538. //change test
  1539. Dbg("usAPType: 0x%X", info[nSel].AccessInfo.usAPType);
  1540. if(info[nSel].AccessInfo.usAPType == AUPR_PAP) {
  1541. m_comboModeType.SetCurSel(1);
  1542. } else if(info[nSel].AccessInfo.usAPType == AUPR_CHAP) {
  1543. m_comboModeType.SetCurSel(2);
  1544. } else if(info[nSel].AccessInfo.usAPType == AUPR_PAPORCHAP) {
  1545. m_comboModeType.SetCurSel(3);
  1546. } else {
  1547. m_comboModeType.SetCurSel(0);
  1548. }
  1549. Dbg("@1");
  1550. CheckDlgButton(IDC_CHECK_APN_APPLY, info[nSel].AccessInfo.IsDefault);
  1551. }
  1552. else {
  1553. Dbg("Cannot recognize connect type 0x%X", info[nSel].AccessInfo.usCntType);
  1554. }
  1555. if(info[nSel].AccessInfo.usCntType == CNT_MBN || info[nSel].AccessInfo.usCntType == CNT_MBB) {
  1556. Dbg("@2: %s", (LPCTSTR)info[nSel].AccessInfo.strIPType);
  1557. if(m_comboIPType.SelectString(-1, info[nSel].AccessInfo.strIPType) == CB_ERR) {
  1558. Dbg("Enter: %s", (LPCTSTR)info[nSel].AccessInfo.strIPType);
  1559. if(!strncmp(info[nSel].AccessInfo.strIPType, "Default", strlen("Default"))) {
  1560. m_comboIPType.SetCurSel(0);
  1561. Dbg("iptype: set 0");
  1562. } else if(!strncmp(info[nSel].AccessInfo.strIPType, "XLAT", strlen("XLAT"))) {
  1563. m_comboIPType.SetCurSel(4);
  1564. Dbg("iptype: set 4");
  1565. } else {
  1566. m_comboIPType.SetCurSel(0);
  1567. Dbg("iptype: set 0");
  1568. }
  1569. }
  1570. //cannot set ip type to MBB [12/5/2019 14:36 @Gifur]
  1571. if(info[nSel].AccessInfo.usCntType == CNT_MBB) {
  1572. m_comboIPType.EnableWindow(FALSE);
  1573. }
  1574. }
  1575. DoDataExchange(FALSE);
  1576. GetDlgItem(IDC_BUTTON_DELETE).EnableWindow(TRUE);
  1577. }
  1578. }while(false);
  1579. }
  1580. return 0;
  1581. }
  1582. LRESULT CMobileDlg::OnBnClickedButtonDelete(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
  1583. {
  1584. const int nSel3 = m_comboCntType.GetCurSel();
  1585. int nSel = m_comboProfiles.GetCurSel();
  1586. CSimpleStringA strDongle;
  1587. int nIndex = GetInterfaceIdInCombo(strDongle);
  1588. Dbg("interface index : %d vs profile sel: %d", nIndex, nSel);
  1589. if(nIndex >= 0 && strDongle.GetLength() > 0 && nSel >= 0) {
  1590. if(g_DongleInfos[nIndex].subInfo.mbnCntState == MBN_ACTIVATION_STATE_ACTIVATED && nSel3 <= CNT_RAS) {
  1591. MessageBox("请先断开连接再执行删除操作!", "提示", MB_OK);
  1592. return 0;
  1593. }
  1594. CloseVirtualKeyboard();
  1595. UINT_PTR uRes = MessageBox(CSimpleStringA::Format("确定要删除配置文件 %s ?",
  1596. (LPCTSTR)g_DongleInfos[nIndex].profileList[nSel].AccessInfo.strProfileDesc), "确认", MB_OKCANCEL | MB_ICONQUESTION);
  1597. if(uRes == IDOK) {
  1598. EnterProgressBar(TIMER_TIMTOUT_MAX);
  1599. auto rc = m_pEntity->DeleteProfile(nIndex, nSel);
  1600. if(rc == Error_Succeed) {
  1601. const USHORT cntType = g_DongleInfos[nIndex].profileList[nSel].AccessInfo.usCntType;
  1602. if(cntType == CNT_RAS || cntType == CNT_ANDROID || cntType == CNT_MBB) {
  1603. PostMessage(WM_DELETE_PROFILE_RESULT, Error_Succeed);
  1604. }
  1605. } else {
  1606. LeaveProgressBar(WM_TIMER_PROCESS);
  1607. MessageBoxA(CSimpleStringA::Format("删除失败: %s", m_pEntity->GetLastErrMsg()));
  1608. }
  1609. }
  1610. }
  1611. return 0;
  1612. }
  1613. LRESULT CMobileDlg::OnCbnSelchangeComboGtype(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
  1614. {
  1615. char szBtnTxt[128] = {0};
  1616. m_btnExpand.GetWindowTextA(szBtnTxt, 128);
  1617. if(!strcmp(szBtnTxt, "管理配置")) {
  1618. return 0;
  1619. }
  1620. const int nSel = m_comboCntType.GetCurSel();
  1621. BOOL bMBNShow = FALSE;
  1622. if(nSel <= CNT_MBN || nSel == CNT_MBB) {//MBN or MBB
  1623. bMBNShow = TRUE;
  1624. SetDlgItemTextA(IDC_STATIC_TXT_MODE, "登录类型:");
  1625. SetDlgItemTextA(IDC_STATIC_LOGIN, "拨号配置(接入点)");
  1626. SetDlgItemTextA(IDC_STATIC_TXT_IPTYPE, "IP类型:");
  1627. SetDlgItemTextA(IDC_STATIC_TXT_PROFILENAME, "配置文件名称:");
  1628. } else if(nSel == CNT_RAS) {//RAS
  1629. bMBNShow = FALSE;
  1630. SetDlgItemTextA(IDC_STATIC_TXT_MODE, "电话号码:");
  1631. SetDlgItemTextA(IDC_STATIC_LOGIN, "拨号配置(电话簿)");
  1632. SetDlgItemTextA(IDC_STATIC_TXT_IPTYPE, "登录类型:");
  1633. SetDlgItemTextA(IDC_STATIC_TXT_PROFILENAME, "拨号配置名称:");
  1634. } else if(nSel == 3 || nSel == 4) {//Android
  1635. SetDlgItemTextA(IDC_STATIC_TXT_MODE, "身份验证:");
  1636. SetDlgItemTextA(IDC_STATIC_LOGIN, "拨号配置(接入点)");
  1637. SetDlgItemTextA(IDC_STATIC_TXT_IPTYPE, "APN 类型:");
  1638. SetDlgItemTextA(IDC_STATIC_TXT_PROFILENAME, "配置文件名称:");
  1639. GetDlgItem(IDC_STATIC_TXT_IPTYPE).ShowWindow(FALSE);
  1640. GetDlgItem(IDC_COMBO_CON_IPTYPE).ShowWindow(FALSE);
  1641. GetDlgItem(IDC_STATIC_TXT_POINTTYPE).ShowWindow(FALSE);
  1642. GetDlgItem(IDC_COMBO_PONT_TYPE).ShowWindow(FALSE);
  1643. bMBNShow = TRUE;
  1644. }
  1645. else {
  1646. return 0;
  1647. }
  1648. GetDlgItem(IDC_COMBO_CON_MODE).ShowWindow(bMBNShow);
  1649. GetDlgItem(IDC_EDIT_PHONENUM).ShowWindow(!bMBNShow);
  1650. GetDlgItem(IDC_CHECK_RASIO_PAP).ShowWindow(!bMBNShow);
  1651. GetDlgItem(IDC_CHECK_RASIO_CHAP).ShowWindow(!bMBNShow);
  1652. GetDlgItem(IDC_CHECK_RASIO_MSCHAPV2).ShowWindow(!bMBNShow);
  1653. if(nSel <= CNT_RAS) {
  1654. GetDlgItem(IDC_STATIC_TXT_POINTTYPE).ShowWindow(bMBNShow);
  1655. GetDlgItem(IDC_COMBO_PONT_TYPE).ShowWindow(bMBNShow);
  1656. GetDlgItem(IDC_COMBO_CON_IPTYPE).ShowWindow(bMBNShow);
  1657. }
  1658. if(bMBNShow) {
  1659. if(nSel <= CNT_MBN || nSel == CNT_MBB) {
  1660. if(wv == 8 && nSel != CNT_MBB) {
  1661. GetDlgItem(IDC_COMBO_PONT_TYPE).ShowWindow(FALSE);
  1662. GetDlgItem(IDC_COMBO_CON_IPTYPE).ShowWindow(FALSE);
  1663. GetDlgItem(IDC_STATIC_TXT_IPTYPE).ShowWindow(FALSE);
  1664. GetDlgItem(IDC_STATIC_TXT_POINTTYPE).ShowWindow(FALSE);
  1665. GetDlgItem(IDC_CHECK_APN_APPLY).ShowWindow(FALSE);
  1666. } else {
  1667. GetDlgItem(IDC_COMBO_CON_IPTYPE).ShowWindow(TRUE);
  1668. GetDlgItem(IDC_STATIC_TXT_IPTYPE).ShowWindow(TRUE);
  1669. if(nSel == CNT_MBB) {
  1670. GetDlgItem(IDC_COMBO_PONT_TYPE).ShowWindow(FALSE);
  1671. GetDlgItem(IDC_STATIC_TXT_POINTTYPE).ShowWindow(FALSE);
  1672. GetDlgItem(IDC_STATIC_TXT_IPTYPE).EnableWindow(FALSE);
  1673. } else {
  1674. GetDlgItem(IDC_COMBO_PONT_TYPE).ShowWindow(TRUE);
  1675. GetDlgItem(IDC_STATIC_TXT_POINTTYPE).ShowWindow(TRUE);
  1676. GetDlgItem(IDC_STATIC_TXT_IPTYPE).EnableWindow(TRUE);
  1677. }
  1678. GetDlgItem(IDC_CHECK_APN_APPLY).ShowWindow(TRUE);
  1679. }
  1680. } else {
  1681. GetDlgItem(IDC_CHECK_APN_APPLY).ShowWindow(TRUE);
  1682. }
  1683. } else {
  1684. GetDlgItem(IDC_CHECK_APN_APPLY).ShowWindow(FALSE);
  1685. if(wv == 8) {
  1686. GetDlgItem(IDC_STATIC_TXT_IPTYPE).ShowWindow(TRUE);
  1687. }
  1688. }
  1689. if(nSel == CNT_MBB) {
  1690. m_comboModeType.ResetContent();
  1691. m_comboModeType.AddString("自动");
  1692. m_comboModeType.AddString("PAP");
  1693. m_comboModeType.AddString("CHAP");
  1694. m_comboModeType.AddString("无");
  1695. } else if(nSel == CNT_MBN) {
  1696. m_comboModeType.ResetContent();
  1697. m_comboModeType.AddString("无");
  1698. m_comboModeType.AddString("PAP");
  1699. m_comboModeType.AddString("CHAP");
  1700. m_comboModeType.AddString("MS-CHAP v2");
  1701. m_comboModeType.SetCurSel(0);
  1702. } else if(nSel == 3 || nSel == 4) {//Android
  1703. m_comboModeType.ResetContent();
  1704. m_comboModeType.AddString("无");
  1705. m_comboModeType.AddString("PAP");
  1706. m_comboModeType.AddString("CHAP");
  1707. m_comboModeType.AddString("PAP 或 CHAP");
  1708. m_comboModeType.SetCurSel(0);
  1709. }
  1710. return 0;
  1711. }
  1712. LRESULT CMobileDlg::OnBnClickedCheckViewPassword(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
  1713. {
  1714. CEdit edit = (CEdit)this->GetDlgItem(IDC_EDIT_PASSWORD);
  1715. if(IsDlgButtonChecked(IDC_CHECK_VIEW_PASSWORD)) {
  1716. edit.SetPasswordChar(0);
  1717. } else {
  1718. edit.SetPasswordChar('*');
  1719. }
  1720. edit.RedrawWindow();
  1721. return 0;
  1722. }
  1723. void CMobileDlg::OnSetFocus(HWND hWnd)
  1724. {
  1725. OpenVirtualKeyboard();
  1726. SetMsgHandled(FALSE);
  1727. }
  1728. void CMobileDlg::OnKillFocus(HWND hWnd)
  1729. {
  1730. SetMsgHandled(FALSE);
  1731. }
  1732. LRESULT CMobileDlg::OnEnSetfocusEdit(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& bHandled)
  1733. {
  1734. OpenVirtualKeyboard();
  1735. return 0;
  1736. }
  1737. LRESULT CMobileDlg::OnEnKillfocusEdit(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& bHandled)
  1738. {
  1739. return 0;
  1740. }
  1741. LRESULT CWlanConfigDlg::OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
  1742. {
  1743. int cx = GetSystemMetrics(SM_CXSCREEN);
  1744. RECT rcDlg;
  1745. ::GetWindowRect(m_hWnd, &rcDlg);
  1746. ::SetWindowPos(m_hWnd, NULL, (cx + rcDlg.left - rcDlg.right)/2, 40, -1, -1, SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
  1747. const MBBParams* originalParam = &m_pDlg->m_sMBBParam;
  1748. GetDlgItem(IDC_EDIT_MBB_LOGIN_USERNAME).SetWindowTextA(originalParam->loginParam.strUsername);
  1749. GetDlgItem(IDC_EDIT_MBB_LOGIN_PSW).SetWindowTextA(originalParam->loginParam.strPassword);
  1750. GetDlgItem(IDC_EDIT_MBB_WLAN_SSID).SetWindowTextA(originalParam->wlanConnectParam.strUsername);
  1751. GetDlgItem(IDC_EDIT_MBB_WLAN_PSW).SetWindowTextA(originalParam->wlanConnectParam.strPassword);
  1752. CheckDlgButton(IDC_CHECK_WLAN_HIDDEN, originalParam->wlanConnectParam.Flag);
  1753. if(originalParam->connectType == 1) {
  1754. GetDlgItem(IDC_EDIT_MBB_WLAN_SSID).EnableWindow(FALSE);
  1755. GetDlgItem(IDC_EDIT_MBB_WLAN_PSW).EnableWindow(FALSE);
  1756. GetDlgItem(IDC_CHECK_WLAN_HIDDEN).EnableWindow(FALSE);
  1757. }
  1758. CButton btnCheck = GetDlgItem(IDC_CHECK_WLAN_HIDDEN);
  1759. if(btnCheck.GetCheck() == 0) {
  1760. GetDlgItem(IDC_STATIC_HIDE_TIP).ShowWindow(SW_SHOW);
  1761. } else {
  1762. GetDlgItem(IDC_STATIC_HIDE_TIP).ShowWindow(SW_HIDE);
  1763. }
  1764. //CheckDlgButton(IDC_CHECK_WLAN_HIDDEN, FALSE);
  1765. //GetDlgItem(IDC_CHECK_WLAN_HIDDEN).EnableWindow(FALSE);
  1766. return TRUE;
  1767. }
  1768. BOOL CWlanConfigDlg::HasUpdated(BOOL refresh /*= TRUE*/)
  1769. {
  1770. if(refresh) {
  1771. UpdateValue();
  1772. }
  1773. BOOL changed = FALSE;
  1774. MBBParams* originalParam = &m_pDlg->m_sMBBParam;
  1775. if(originalParam->loginParam.strUsername.Compare((LPCTSTR)m_strLoginUsername) != 0) {
  1776. originalParam->loginParam.strUsername = (LPCTSTR)m_strLoginUsername;
  1777. changed = TRUE;
  1778. }
  1779. if(originalParam->loginParam.strPassword.Compare((LPCTSTR)m_strLoginPassword) != 0) {
  1780. originalParam->loginParam.strPassword = (LPCTSTR)m_strLoginPassword;
  1781. changed = TRUE;
  1782. }
  1783. if(originalParam->wlanConnectParam.strUsername.Compare((LPCTSTR)m_strWlanSSID) != 0) {
  1784. originalParam->wlanConnectParam.strUsername = (LPCTSTR)m_strWlanSSID;
  1785. changed = TRUE;
  1786. }
  1787. if(originalParam->wlanConnectParam.strPassword.Compare((LPCTSTR)m_strWlanPassword) != 0) {
  1788. originalParam->wlanConnectParam.strPassword = (LPCTSTR)m_strWlanPassword;
  1789. changed = TRUE;
  1790. }
  1791. if(originalParam->wlanConnectParam.Flag != m_fHidden) {
  1792. originalParam->wlanConnectParam.Flag = m_fHidden;
  1793. changed = TRUE;
  1794. }
  1795. return changed;
  1796. }
  1797. LRESULT CMobileDlg::OnBnSetfocusRadioMbbWlan(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
  1798. {
  1799. m_wlanClickedTimes = 0;
  1800. Dbg("OnBnSetfocusRadioMbbWlan: %d", m_wlanClickedTimes);
  1801. return 0;
  1802. }
  1803. LRESULT CMobileDlg::OnBnKillfocusRadioMbbWlan(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
  1804. {
  1805. m_wlanClickedTimes = 0;
  1806. Dbg("OnBnKillfocusRadioMbbWlan: %d", m_wlanClickedTimes);
  1807. return 0;
  1808. }
  1809. LRESULT CMobileDlg::OnBnClickedRadioMbbWlan(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
  1810. {
  1811. Dbg("OnBnClickedRadioMbbWlan: %d", m_wlanClickedTimes);
  1812. if(IsDlgButtonChecked(IDC_RADIO_MBB_WLAN) && IsDlgButtonChecked(IDC_RADIO_WEB)) {
  1813. if(++m_wlanClickedTimes >= 3) {
  1814. GetDlgItem(IDC_BUTTON_MBB_CONFIG).ShowWindow(TRUE);
  1815. m_wlanClickedTimes = 0;
  1816. }
  1817. } else {
  1818. m_wlanClickedTimes = 0;
  1819. }
  1820. return 0;
  1821. }
  1822. LRESULT CMobileDlg::OnBnDoubleclickedRadioMbbWlan(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
  1823. {
  1824. Dbg("OnBnDoubleclickedRadioMbbWlan: %d", m_wlanClickedTimes);
  1825. return 0;
  1826. }