c++ - 将 Visual C++ 代码转换为 Borland C++Builder

标签 c++ visual-c++ webbrowser-control c++builder vcl

我用 Visual C++ 编写了一个程序。但是现在我必须把我的代码放在一个用 Borland C++Builder 编码的程序中。我的表单上有一个 WebBrowser 项目。在 Visual C++ 中,我将数据写入文本框,从文本框中获取数据,然后使用以下代码单击 WebBrowser 上的按钮:

写入数据:

WebBrowser1->Document->GetElementById("okul_kod")->SetAttribute("value", TextBox2->Text);

获取数据:

textBox17->Text = WebBrowser1->Document->GetElementById("kay_cev")->GetAttribute("value");

按钮点击:

WebBrowser1->Document->GetElementById("panelden_kayit")->InvokeMember("click");

我尝试了很多东西,并在网上进行了搜索,但找不到如何将此代码转换为 Borland C++Builder。

你能给我一个线索或建议吗?

最佳答案

在 C++Builder 6 中,其 TCppWebBrowser VCL 组件是 Internet Explorer ActiveX 控件的包装器。它的 Document 属性返回一个 IDispatch,您可以使用它来直接访问 IE 的原始 DOM 接口(interface)(而 Visual C++ 似乎已经为您更好地包装了这些接口(interface)) .

尝试这样的事情:

#include <mshtml.h>
#include <utilcls.h>

// helpers for interface reference counting
// could alternatively use TComInterface instead of DelphiInterface
typedef DelphiInterface<IHTMLDocument3> _di_IHTMLDocument3;
typedef DelphiInterface<IHTMLElement> _di_IHTMLElement;

...

// Write Data:
_di_IHTMLDocument3 doc = CppWebBrowser1->Document;
_di_IHTMLElement elem;
OleCheck(doc->getElementById(WideString("okul_kod"), &elem));
if (elem) OleCheck(elem->setAttribute(WideString("value"), TVariant(Edit2->Text)));

// Get Data:
_di_IHTMLDocument3 doc = CppWebBrowser1->Document;
_di_IHTMLElement elem;
OleCheck(doc->getElementById(WideString("kay_cev"), &elem));
TVariant value;
if (elem) OleCheck(elem->getAttribute(WideString("value"), 2, &value));
Edit17->Text = value;

//Button Click:
_di_IHTMLDocument3 doc = CppWebBrowser1->Document;
_di_IHTMLElement elem;
OleCheck(doc->getElementById(WideString("panelden_kayit"), &elem));
if (elem) elem->click();

关于c++ - 将 Visual C++ 代码转换为 Borland C++Builder,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54895597/

相关文章:

c++ - fatal error c1083 "afxwin.h"

internet-explorer - 在 MSHTML IE8 中修改 DOM 时是否会触发一个事件?

c# - 在C#Windows应用程序中使用C++ DLL:获取错误 “Entry point not found”

c++ - 随机快速排序 [某些输入崩溃]

c++ - 共享 void 指针。为什么这行得通?

windows - Windows 10 上的 Visual Studio 2010 x64 编译器

c++ - 使用 unique_ptr 保护析构函数

c++ - 使用 ReadFile 和 WriteFile 时出现死锁

c# - 如何在 System.Windows.Forms.WebBrowser 中调用自定义 Javascript?

c# - Lync ContactList WPF 控制热键/快捷键从 WebBrowser 窃取按键