c#语言翻译成c++的(实现百度翻译API)
问题如题。。请教
内容:
在MFC对话框中添加一个WebBrows控件,两个编辑框
调用百度翻译的网页实现从第一个编辑框中输入需要翻译的内容,从第二个编辑框中获取到翻译后的内容
下面是C#实现的。。。能运行,请教高手翻译成c++的(MFC)
如果用百度翻译API实现最好
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace nettest
{
public partial class Form1 : Form
{
private int num = 0;
private bool fanyi = false;
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
webBrowser1.Navigate("http://fanyi.baidu.com/translate#kor/zh/" + textBox1.Text);
button1.Text = "翻译中...";
button1.Enabled = false;
fanyi = true;
}
private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
HtmlElementCollection hes = webBrowser1.Document.GetElementsByTagName("p");
if (fanyi==false)
{
return;
}
num++;
if (num>=2)
{
string content="";
foreach(HtmlElement he in hes[2].All)
{
content += he.InnerHtml;
}
textBox2.Text = content;
button1.Text = "翻译";
button1.Enabled = true;
fanyi = false;
num = 0;
webBrowser1.Navigate("about:Tabs");
}
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
}
private void textBox2_TextChanged(object sender, EventArgs e)
{
}
}
}
更多 0 分享到: