天天看點

TCppWebBrowser控件的一些用法

?

  1. 娴?瑙??ㄧ??琛ㄧ?闆艦寮?涓闆??锛???搴???浣跨?ㄨ?戒嬌???㈠??蹭?灏?锛?浠?缁?涓?涓?CB6涓?TCppWebBrowser?т歡??涓?浜??ㄦ?
  2. ??寮?璇存??杈?楹葷???浠?浠ュ????宸ョ????句?涓?涓?瀹??寸?椤佃創杩???/li>
  3. 缃?椤碉?
  4. <!DOCTYPE?HTML?PUBLIC?"-//W3C//DTD?HTML?4.01?Transitional//EN">
  5. <html>
  6. <head>
  7. <meta?http-equiv="Content-Type"?content="text/html;?charset=gb2312">
  8. <title>??璐歸??姝?</title>
  9. <style?type="text/css">
  10. input?{border:1px?solid?#000000}
  11. <!--
  12. -->
  13. </style>
  14. <script?language="JavaScript"?type="text/JavaScript">
  15. <!--
  16. function?MM_preloadImages()?{?//v3.0
  17. ??var?d=document;?if(d.images){?if(!d.MM_p)?d.MM_p=new?Array();
  18. ????var?i,j=d.MM_p.length,a=MM_preloadImages.arguments;?for(i=0;?i<a.length;?i++)
  19. ????if?(a[i].indexOf("#")!=0){?d.MM_p[j]=new?Image;?d.MM_p[j++].src=a[i];}}
  20. }
  21. function?MM_swapImgRestore()?{?//v3.0
  22. ??var?i,x,a=document.MM_sr;?for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++)?x.src=x.oSrc;
  23. }
  24. function?MM_findObj(n,?d)?{?//v4.01
  25. ??var?p,i,x;??if(!d)?d=document;?if((p=n.indexOf("?"))>0&&parent.frames.length)?{
  26. ????d=parent.frames[n.substring(p+1)].document;?n=n.substring(0,p);}
  27. ??if(!(x=d[n])&&d.all)?x=d.all[n];?for?(i=0;!x&&i<d.forms.length;i++)?x=d.forms[i][n];
  28. ??for(i=0;!x&&d.layers&&i<d.layers.length;i++)?x=MM_findObj(n,d.layers[i].document);
  29. ??if(!x?&&?d.getElementById)?x=d.getElementById(n);?return?x;
  30. }
  31. function?MM_swapImage()?{?//v3.0
  32. ??var?i,j=0,x,a=MM_swapImage.arguments;?document.MM_sr=new?Array;?for(i=0;i<(a.length-2);i+=3)
  33. ???if?((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x;?if(!x.oSrc)?x.oSrc=x.src;?x.src=a[i+2];}
  34. }
  35. //-->
  36. </script>
  37. <style?type="text/css">
  38. <!--
  39. td?{
  40. ?font-family:?"Arial";
  41. ?font-size:?12px;
  42. ?color:?#990000;
  43. ?cursor:?default;
  44. }
  45. .jiben?{
  46. ?font-family:?"Arial";
  47. ?font-size:?12px;
  48. ?font-weight:?bold;
  49. ?color:?#990000;
  50. ?cursor:?default;
  51. }
  52. -->
  53. </style>
  54. </head>
  55. <body?leftmargin="0"?topmargin="0"?onLoad="MM_preloadImages('image/K-17a.jpg','image/K-11a.jpg')">
  56. <table?width="315"?height="144"?string">"0"?cellpadding="0"?cellspacing="0">
  57. ??<tr>
  58. ????<td?height="22"><table?width="314"?string">"0"?cellspacing="0"?cellpadding="0">
  59. ????????<tr>?
  60. ??????????<td?width="6"><img?src="image/F-1.jpg"?width="4"?height="25"></td>
  61. ??????????<td>?<div?align="left">
  62. ??????????????<table?width="310"?string">"0"?align="right"?cellpadding="0"?cellspacing="0"?background="image/14A.jpg"?id="moveform">
  63. ????????????????<tr>?
  64. ??????????????????<td?valign="middle"?4>8751??璐圭?規???婚??</td>
  65. ??????????????????<td?width="195"><div?align="right">?
  66. ??????????????????????<table?width="64"?string">"0"?cellspacing="0"?cellpadding="0">
  67. ????????????????????????<tr>?
  68. ??????????????????????????<td?width="29%"><div?align="right"><img?src="image/A1.jpg"?alt="??灏???"?name="minform"?width="20"?height="25"?id="Image1"?onMouseOver="MM_swapImage('Image1',','image/1A.jpg',1)"?onMouseOut="MM_swapImgRestore()"></div></td>
  69. ??????????????????????????<td?width="32%"><div?align="right"><img?src="image/A2.jpg"?width="20"?height="25"></div></td>
  70. ??????????????????????????<td?width="27%"><div?align="right"><img?src="image/A3.jpg"?alt="?抽??"?name="closeform"?width="19"?height="25"?id="Image2"?onMouseOver="MM_swapImage('Image2',','image/3A.jpg',1)"?onMouseOut="MM_swapImgRestore()"></div></td>
  71. ??????????????????????????<td?width="12%"><div?align="right"></div></td>
  72. ????????????????????????</tr>
  73. ??????????????????????</table>
  74. ????????????????????</div></td>
  75. ????????????????</tr>
  76. ??????????????</table>
  77. ????????????</div></td>
  78. ????????</tr>
  79. ??????</table></td>
  80. ??</tr>
  81. ??<tr>
  82. ????<td?valign="top"><table?width="315"?string">"0"?cellspacing="0"?cellpadding="0">
  83. ????????<tr>
  84. ??????????<td?width="10"><img?src="image/L-1.jpg"?width="4"?height="198"></td>
  85. ??????????<td?width="260"?valign="top"><table?width="304"?string">"0"?cellpadding="0"?cellspacing="0"?background="image/K-9.jpg">
  86. ??????????????<tr>?
  87. ????????????????<td?colspan="4"><table?width="305"?height="141"?string">"0"?cellpadding="0"?cellspacing="0">
  88. ????????????????????<tr>?
  89. ??????????????????????<td?height="141"?valign="top">?<table?width="201"?height="132"?string">"0"?align="center"?cellpadding="0"?cellspacing="0">
  90. ??????????????????????????<tr>?
  91. ????????????????????????????<td?height="16"?colspan="2">?</td>
  92. ??????????????????????????</tr>
  93. ??????????????????????????<tr>?
  94. ????????????????????????????<td?colspan="2"?><div?align="center"?class="jiben">?郝?
  95. ???????????????????????????????????淇÷???</div></td>
  96. ??????????????????????????</tr>
  97. ??????????????????????????<tr?>?
  98. ????????????????????????????<td?width="81">???哄?風??锛?</td>
  99. ????????????????????????????<td?width="120">?<input?name="MbNum"?type="text"?id="MbNum"?size="15"></td>
  100. ??????????????????????????</tr>
  101. ??????????????????????????<tr?>?
  102. ????????????????????????????<td>濮???锛?</td>
  103. ????????????????????????????<td>?<input?name="Name"?type="text"?id="Name"?size="15"></td>
  104. ??????????????????????????</tr>
  105. ??????????????????????????<tr?>?
  106. ????????????????????????????<td>8751ID锛?</td>
  107. ????????????????????????????<td>?<input?name="ID"?type="text"?id="ID"?size="15"></td>
  108. ??????????????????????????</tr>
  109. ??????????????????????????<tr?>?
  110. ????????????????????????????<td>澶?娉ㄤ俊??锛?</td>
  111. ????????????????????????????<td>?<input?name="MemTextArea"?type="text"?id="MemTextArea"?size="15"></td>
  112. ??????????????????????????</tr>
  113. ????????????????????????</table></td>
  114. ????????????????????</tr>
  115. ??????????????????</table></td>
  116. ??????????????</tr>
  117. ??????????????<tr>?
  118. ????????????????<td?width="83"?height="38">?</td>
  119. ????????????????<td?width="84"><a?href="#"><img?src="image/K-17.jpg"?name="Ok"?width="55"?height="19"?string">"0"?id="Ok"?onMouseOver="MM_swapImage('Ok',','image/K-17a.jpg',1)"?onMouseOut="MM_swapImgRestore()"></a></td>
  120. ????????????????<td?width="79">?<div?align="center"><a?href="#"><img?src="image/K-11.jpg"?name="Cancel"?width="55"?height="19"?string">"0"?id="Cancel"?onMouseOver="MM_swapImage('Cancel',','image/K-11a.jpg',1)"?onMouseOut="MM_swapImgRestore()"></a></div></td>
  121. ????????????????<td?width="59">?<div?align="left"></div></td>
  122. ??????????????</tr>
  123. ??????????????<tr>?
  124. ????????????????<td?colspan="4">?</td>
  125. ??????????????</tr>
  126. ??????????????<tr>?
  127. ????????????????<td?height="4"?colspan="4"><img?src="image/K-8.jpg"?width="306"?height="4"></td>
  128. ??????????????</tr>
  129. ????????????</table></td>
  130. ??????????<td?width="45"><img?src="image/K-7.jpg"?width="4"?height="198"></td>
  131. ????????</tr>
  132. ??????</table></td>
  133. ??</tr>
  134. </table>
  135. <div?align="right"></div>
  136. </body>
  137. </html>
  138. .h
  139. #ifndef?AddFriendFormH
  140. #define?AddFriendFormH
  141. //---------------------------------------------------------------------------
  142. #include?<Classes.hpp>
  143. #include?<Controls.hpp>
  144. #include?<StdCtrls.hpp>
  145. #include?<Forms.hpp>
  146. #include?"SHDocVw_OCX.h"
  147. #include?<OleCtrls.hpp>
  148. //---------------------------------------------------------------------------
  149. class?TfrmAddFriend?:?public?TForm
  150. {
  151. __published:?//?IDE-managed?Components
  152. ????????TCppWebBrowser?*CppWebBrowserAddFriend;
  153. ????????void?__fastcall?FormCreate(TObject?*Sender);
  154. ????????void?__fastcall?CppWebBrowserAddFriendDocumentComplete(TObject?*Sender,
  155. ??????????LPDISPATCH?pDisp,?Variant?*URL);
  156. ????????void?__fastcall?FormDestroy(TObject?*Sender);
  157. private:
  158. ????????void?MoveFormEvt(DISPID?id,?VARIANT*?pVarResult);
  159. ????????void?MoveForm(void);
  160. ????????void?MaskEvt(DISPID?id,?VARIANT*?pVarResult);
  161. ????????void?SetBrowserStyle(void);
  162. ????????void?CancelEvt(void);
  163. ????????void?ReleaseHook(void);
  164. ????????void?AddFriendOnClick(DISPID?id,?VARIANT*?pVarResult);
  165. ????????AnsiString?GetInputValue(AnsiString?itemname);
  166. ????????void?OnKeyPressEvt(DISPID?id,?VARIANT*?pVarResult);
  167. ????????void?SetFocusInput(AnsiString?itemname);
  168. ????????void?PutInputValue(AnsiString?itemname,?AnsiString?value);?//?User?declarations
  169. public:??//?User?declarations
  170. ????????AnsiString?MbNum;
  171. ????????AnsiString?FriendName;
  172. ????????AnsiString?ID8751;
  173. ????????AnsiString?Info;
  174. ????????__fastcall?TfrmAddFriend(TComponent*?Owner);
  175. };
  176. //---------------------------------------------------------------------------
  177. extern?PACKAGE?TfrmAddFriend?*frmAddFriend;
  178. //---------------------------------------------------------------------------
  179. #endif
  180. .cpp
  181. //---------------------------------------------------------------------------
  182. #include?<vcl.h>
  183. #pragma?hdrstop
  184. #include?"AddFriendForm.h"
  185. #include?"GlobalFunc.h"
  186. #include?"GlobalVar.h"
  187. //---------------------------------------------------------------------------
  188. #pragma?package(smart_init)
  189. #pragma?link?"SHDocVw_OCX"
  190. #pragma?resource?"*.dfm"
  191. TfrmAddFriend?*frmAddFriend;
  192. //---------------------------------------------------------------------------
  193. __fastcall?TfrmAddFriend::TfrmAddFriend(TComponent*?Owner)
  194. ????????:?TForm(Owner)
  195. {
  196. }
  197. //---------------------------------------------------------------------------
  198. void?__fastcall?TfrmAddFriend::FormCreate(TObject?*Sender)
  199. {
  200. ????????this->CppWebBrowserAddFriend->HandleNeeded();
  201. ????????this->CppWebBrowserAddFriend->Navigate(WideString(GetResPath("AddFriends.htm")),NULL,NULL,NULL,NULL);
  202. ????????CutFormRgn(Handle,316,225);
  203. }
  204. //---------------------------------------------------------------------------
  205. void?TfrmAddFriend::MoveFormEvt(DISPID?id,?VARIANT*?pVarResult)?
  206. {
  207. ????????//TODO:?Add?your?source?code?here
  208. ????????_di_IDispatch?disp;
  209. ????????System::DelphiInterface<IHTMLDocument2>?htmldoc2;
  210. ????????System::DelphiInterface<IHTMLWindow2>?htmlwnd2;
  211. ????????System::DelphiInterface<IHTMLEventObj>?htmlevt;
  212. ????????System::DelphiInterface<IHTMLElement>?htmlelem;
  213. ????????disp?=?this->CppWebBrowserAddFriend->Document;
  214. ????????if(!disp)
  215. ????????????????return;
  216. ????????htmldoc2?=?disp;
  217. ????????htmldoc2->get_parentWindow(&htmlwnd2);
  218. ????????htmlwnd2->get_event(&htmlevt);
  219. ????????htmlevt->get_srcElement(&htmlelem);
  220. ????????WideString?_tag;
  221. ????????htmlelem->get_tagName(&_tag);
  222. ????????long?btn,_x,_y;
  223. ????????htmlevt->get_button(&btn);
  224. ????????htmlevt->get_screenX(&_x);
  225. ????????htmlevt->get_screenY(&_y);
  226. ????????if(_tag?==?WideString("TD")?&&?btn?==?1)
  227. ????????{
  228. ????????????????::ReleaseCapture();
  229. ????????????????::SendMessage(Handle,WM_NCLBUTTONDOWN,HTCAPTION,MAKELPARAM(_x,_y));
  230. ????????}
  231. ????????pVarResult->vt?=?VT_BOOL;
  232. ????????pVarResult->boolVal?=?FALSE;
  233. }
  234. void?TfrmAddFriend::MoveForm(void)
  235. {
  236. ????????//TODO:?Add?your?source?code?here
  237. ????????_di_IDispatch?disp;
  238. ????????System::DelphiInterface<IHTMLDocument2>?htmldoc2;
  239. ????????System::DelphiInterface<IHTMLElementCollection>?htmlelemcoll;
  240. ????????System::DelphiInterface<IHTMLElement>?htmlelem;
  241. ????????disp?=?this->CppWebBrowserAddFriend->Document;
  242. ????????if(!disp)
  243. ????????????????return;
  244. ????????htmldoc2?=?disp;
  245. ????????htmldoc2->get_all(&htmlelemcoll);
  246. ????????htmlelemcoll->item(TVariant("moveform"),TVariant(0),&disp);
  247. ????????htmlelem?=?disp;
  248. ????????TVariant?OnfrmMosuseDown;
  249. ????????OnfrmMosuseDown?=?CFunctionObject<TfrmAddFriend>::CreateEventFunctionObject(this,&TfrmAddFriend::MoveFormEvt,0);
  250. ????????htmlelem->put_onmousedown(OnfrmMosuseDown);
  251. }
  252. void?TfrmAddFriend::MaskEvt(DISPID?id,?VARIANT*?pVarResult)
  253. {
  254. ????????//TODO:?Add?your?source?code?here
  255. ????????_di_IDispatch?disp;
  256. ????????System::DelphiInterface<IHTMLDocument2>?htmldoc2;
  257. ????????System::DelphiInterface<IHTMLWindow2>?htmlwnd2;
  258. ????????System::DelphiInterface<IHTMLEventObj>?htmlevt;
  259. ????????System::DelphiInterface<IHTMLElement>?htmlelem;
  260. ????????disp?=?this->CppWebBrowserAddFriend->Document;
  261. ????????
  262. ????????if(!disp)
  263. ????????????????return;
  264. ????????htmldoc2?=?disp;
  265. ????????htmldoc2->get_parentWindow(&htmlwnd2);
  266. ????????htmlwnd2->get_event(&htmlevt);
  267. ????????htmlevt->get_srcElement(&htmlelem);
  268. ????????WideString?_tag;
  269. ????????htmlelem->get_tagName(&_tag);
  270. ????????if(_tag?==?WideString("INPUT"))
  271. ????????????????return;
  272. ????????pVarResult->vt?=?VT_BOOL;
  273. ????????pVarResult->boolVal?=?FALSE;
  274. }
  275. void?TfrmAddFriend::CancelEvt(void)
  276. {
  277. ????????//TODO:?Add?your?source?code?here
  278. ????????_di_IDispatch?disp;
  279. ????????System::DelphiInterface<IHTMLDocument2>?htmldoc2;
  280. ????????System::DelphiInterface<IHTMLElement>?htmlelem;
  281. ????????System::DelphiInterface<IHTMLElement2>?htmlelem2;
  282. ????????disp?=?this->CppWebBrowserAddFriend->Document;
  283. ????????if(!disp)
  284. ????????????????return;
  285. ????????htmldoc2?=?disp;
  286. ????????htmldoc2->get_body(&htmlelem);
  287. ????????htmlelem2?=?htmlelem;
  288. ????????TVariant?vt;
  289. ????????vt?=?CFunctionObject<TfrmAddFriend>::CreateEventFunctionObject(this,&TfrmAddFriend::MaskEvt,0);
  290. ????????htmlelem->put_onselectstart(vt);
  291. ????????htmlelem2->put_oncontextmenu(vt);
  292. }
  293. void?TfrmAddFriend::SetBrowserStyle(void)
  294. {
  295. ????????//TODO:?Add?your?source?code?here
  296. ????????_di_IDispatch?disp;
  297. ????????System::DelphiInterface<IHTMLDocument2>?htmldoc2;
  298. ????????System::DelphiInterface<IHTMLElement>?htmlelem;
  299. ????????System::DelphiInterface<IHTMLBodyElement>?htmlbody;
  300. ????????System::DelphiInterface<IHTMLStyle>?htmlsty;
  301. ????????disp?=?this->CppWebBrowserAddFriend->Document;
  302. ????????if(!disp)
  303. ????????????????return;
  304. ????????htmldoc2?=?disp;
  305. ????????htmldoc2->get_body(&htmlelem);
  306. ????????htmlbody?=?htmlelem;
  307. ????????htmlbody->put_scroll(WideString("no"));
  308. ????????htmlelem->get_style(&htmlsty);
  309. ????????htmlsty->put_border(WideString("none"));
  310. }
  311. void?TfrmAddFriend::ReleaseHook(void)
  312. {
  313. ????????//TODO:?Add?your?source?code?here
  314. ????????_di_IDispatch?disp;
  315. ????????System::DelphiInterface<IHTMLDocument2>?htmldoc2;
  316. ????????System::DelphiInterface<IHTMLElementCollection>?htmlelemcoll;
  317. ????????System::DelphiInterface<IHTMLElement>?htmlelem;
  318. ????????System::DelphiInterface<IHTMLElement2>?htmlelem2;
  319. ????????disp?=?this->CppWebBrowserAddFriend->Document;
  320. ????????if(!disp)
  321. ????????????????return;
  322. ????????htmldoc2?=?disp;
  323. ????????htmldoc2->get_all(&htmlelemcoll);
  324. ????????htmlelemcoll->item(TVariant("moveform"),TVariant(0),&disp);
  325. ????????htmlelem?=?disp;
  326. ????????VARIANT?varNull;
  327. ????????varNull.vt?=?VT_NULL;
  328. ????????htmlelem->put_onmousedown(varNull);
  329. ????????htmldoc2->get_body(&htmlelem);
  330. ????????htmlelem->put_onselectstart(varNull);
  331. ????????htmlelem->put_onclick(varNull);
  332. ????????htmlelem->put_onkeypress(varNull);
  333. ????????htmlelem2?=?htmlelem;
  334. ????????htmlelem2->put_oncontextmenu(varNull);
  335. }
  336. AnsiString?TfrmAddFriend::GetInputValue(AnsiString?itemname)
  337. {
  338. ????????//TODO:?Add?your?source?code?here
  339. ????????AnsiString?rtn?=?"";
  340. ????????_di_IDispatch?disp;
  341. ????????System::DelphiInterface<IHTMLDocument2>?htmldoc2;
  342. ????????System::DelphiInterface<IHTMLElement>?htmlelem;
  343. ????????System::DelphiInterface<IHTMLElementCollection>?htmlelemcoll;
  344. ????????disp?=?this->CppWebBrowserAddFriend->Document;
  345. ????????if(!disp)
  346. ????????????????return?rtn;
  347. ????????htmldoc2?=?disp;
  348. ????????htmldoc2->get_all(&htmlelemcoll);
  349. ????????htmlelemcoll->item(TVariant(itemname),TVariant(0),&disp);
  350. ????????htmlelem?=?disp;
  351. ????????TVariant?val;
  352. ????????htmlelem->getAttribute(WideString("value"),0,&val);
  353. ????????rtn?=?val.bstrVal;
  354. ????????return?rtn;
  355. }
  356. void?TfrmAddFriend::PutInputValue(AnsiString?itemname,?AnsiString?value)
  357. {
  358. ????????//TODO:?Add?your?source?code?here
  359. ????????_di_IDispatch?disp;
  360. ????????System::DelphiInterface<IHTMLDocument2>?htmldoc2;
  361. ????????System::DelphiInterface<IHTMLElement>?htmlelem;
  362. ????????System::DelphiInterface<IHTMLElementCollection>?htmlelemcoll;
  363. ????????disp?=?this->CppWebBrowserAddFriend->Document;
  364. ????????if(!disp)
  365. ????????????????return;
  366. ????????htmldoc2?=?disp;
  367. ????????htmldoc2->get_all(&htmlelemcoll);
  368. ????????htmlelemcoll->item(TVariant(itemname),TVariant(0),&disp);
  369. ????????htmlelem?=?disp;
  370. ????????htmlelem->setAttribute(WideString("value"),TVariant(value),0);
  371. }
  372. void?TfrmAddFriend::AddFriendOnClick(DISPID?id,?VARIANT*?pVarResult)
  373. {
  374. ????????//TODO:?Add?your?source?code?here
  375. ????????_di_IDispatch?disp;
  376. ????????System::DelphiInterface<IHTMLDocument2>?htmldoc2;
  377. ????????System::DelphiInterface<IHTMLWindow2>?htmlwnd2;
  378. ????????System::DelphiInterface<IHTMLEventObj>?htmlevt;
  379. ????????System::DelphiInterface<IHTMLElement>?htmlelem;
  380. ????????disp?=?this->CppWebBrowserAddFriend->Document;
  381. ????????if(!disp)
  382. ????????????????return;
  383. ????????htmldoc2?=?disp;
  384. ????????htmldoc2->get_parentWindow(&htmlwnd2);
  385. ????????htmlwnd2->get_event(&htmlevt);
  386. ????????htmlevt->get_srcElement(&htmlelem);
  387. ????????WideString?ws;
  388. ????????bool?flag;
  389. ????????ws.SetLength(64);
  390. ????????htmlelem->get_tagName(&ws);
  391. ????????if(ws?==?WideString("IMG"))
  392. ????????{
  393. ????????????????TVariant?val;
  394. ????????????????htmlelem->getAttribute(WideString("name"),0,&val);
  395. ????????????????AnsiString?str;
  396. ????????????????str?=?val.bstrVal;
  397. ????????????????if(str?==?WideString("closeform"))
  398. ????????????????{
  399. ????????????????????????this->Close();
  400. ????????????????}
  401. ????????????????else?if(str?==?WideString("minform"))
  402. ????????????????{
  403. ????????????????????????this->WindowState?=?wsMinimized?;
  404. ????????????????}
  405. ????????????????else?if(str?==?WideString("Ok"))
  406. ????????????????{
  407. ????????????????????????this->MbNum?=?this->GetInputValue("MbNum");
  408. ????????????????????????this->FriendName?=?this->GetInputValue("Name");
  409. ????????????????????????this->ID8751?=?this->GetInputValue("ID");
  410. ????????????????????????this->Info?=?this->GetInputValue("MemTextArea");
  411. ????????????????????????this->ModalResult?=?mrOk;
  412. ????????????????????????this->Close();
  413. ????????????????}
  414. ????????????????else?if(str?==?WideString("Cancel"))
  415. ????????????????{
  416. ????????????????????????this->ModalResult?=?mrCancel;
  417. ????????????????????????this->Close();
  418. ????????????????}
  419. ????????}
  420. ????????pVarResult->vt?=?VT_BOOL;
  421. ????????pVarResult->boolVal?=?FALSE;
  422. }
  423. //---------------------------------------------------------------------------
  424. void?__fastcall?TfrmAddFriend::CppWebBrowserAddFriendDocumentComplete(
  425. ??????TObject?*Sender,?LPDISPATCH?pDisp,?Variant?*URL)
  426. {
  427. ????????this->CancelEvt();
  428. ????????this->SetBrowserStyle();
  429. ????????this->MoveForm();
  430. ????????_di_IDispatch?disp;
  431. ????????System::DelphiInterface<IHTMLDocument2>?htmldoc2;
  432. ????????System::DelphiInterface<IHTMLElement>?htmlelem;
  433. ????????disp?=?this->CppWebBrowserAddFriend->Document;
  434. ????????if(!disp)
  435. ????????????????return;
  436. ????????htmldoc2?=?disp;
  437. ????????htmldoc2->get_body(&htmlelem);
  438. ????????TVariant?vt;
  439. ????????vt?=?CFunctionObject<TfrmAddFriend>::CreateEventFunctionObject(this,&TfrmAddFriend::AddFriendOnClick,0);
  440. ????????htmlelem->put_onclick(vt);
  441. ????????vt?=?CFunctionObject<TfrmAddFriend>::CreateEventFunctionObject(this,&TfrmAddFriend::OnKeyPressEvt,0);
  442. ????????htmlelem->put_onkeypress(vt);
  443. ????????this->SetFocusInput("MbNum");
  444. }
  445. //---------------------------------------------------------------------------
  446. void?TfrmAddFriend::OnKeyPressEvt(DISPID?id,?VARIANT*?pVarResult)
  447. {
  448. ????????//TODO:?Add?your?source?code?here
  449. ????????_di_IDispatch?disp;
  450. ????????System::DelphiInterface<IHTMLDocument2>?htmldoc2;
  451. ????????System::DelphiInterface<IHTMLWindow2>?htmlwnd2;
  452. ????????System::DelphiInterface<IHTMLEventObj>?htmlevt;
  453. ????????disp?=?this->CppWebBrowserAddFriend->Document;
  454. ????????if(!disp)
  455. ????????????????return;
  456. ????????????????
  457. ????????htmldoc2?=?disp;
  458. ????????htmldoc2->get_parentWindow(&htmlwnd2);
  459. ????????htmlwnd2->get_event(&htmlevt);
  460. ????????long?key;
  461. ????????htmlevt->get_keyCode(&key);
  462. ????????if(int(key)?==?13)
  463. ????????{
  464. ????????????????this->MbNum?=?this->GetInputValue("MbNum");
  465. ????????????????this->FriendName?=?this->GetInputValue("Name");
  466. ????????????????this->ID8751?=?this->GetInputValue("ID");
  467. ????????????????this->Info?=?this->GetInputValue("MemTextArea");
  468. ????????????????this->ModalResult?=?mrOk;
  469. ????????????????this->Close();
  470. ????????????????pVarResult->vt?=?VT_BOOL;
  471. ????????????????pVarResult->boolVal?=?FALSE;
  472. ????????}
  473. ????????if(int(key)?==?27)
  474. ????????{
  475. ????????????????this->Close();
  476. ????????????????pVarResult->vt?=?VT_BOOL;
  477. ????????????????pVarResult->boolVal?=?FALSE;
  478. ????????}
  479. }
  480. void?TfrmAddFriend::SetFocusInput(AnsiString?itemname)
  481. {
  482. ????????//TODO:?Add?your?source?code?here
  483. ????????_di_IDispatch?disp;
  484. ????????System::DelphiInterface<IHTMLDocument2>?htmldoc2;
  485. ????????System::DelphiInterface<IHTMLElementCollection>?htmlelemcoll;
  486. ????????System::DelphiInterface<IHTMLElement2>?htmlelem2;
  487. ????????disp?=?this->CppWebBrowserAddFriend->Document;
  488. ????????if(!disp)
  489. ????????????????return;
  490. ????????htmldoc2?=?disp;
  491. ????????htmldoc2->get_all(&htmlelemcoll);
  492. ????????htmlelemcoll->item(TVariant(itemname),TVariant(0),&disp);
  493. ????????if(!disp)
  494. ????????????????return;
  495. ????????htmlelem2?=?disp;
  496. ????????htmlelem2->focus();
  497. }
  498. void?__fastcall?TfrmAddFriend::FormDestroy(TObject?*Sender)
  499. {
  500. ????????this->ReleaseHook();????????
  501. }

繼續閱讀