1.添加头文件:#include <Windows.h>
2.添加库:LIBS +=User32.LIB
3.添加相关代码:
QString ClassName( "YodaoWordBookClass" );
QString AppName( tr("有道单词本" ));
LPCWSTR App = reinterpret_cast <LPCWSTR>(ClassName.data());
LPCWSTR AppCaption = reinterpret_cast <LPCWSTR>(AppName.data());
//亦可不用上面两名,直接转换即可,ClassName.utf16(), AppName.utf16())
if(AppWnd=::FindWindow(App,AppCaption))
{
::ShowWindow(AppWnd,SW_SHOWNORMAL);
}
else
{
ui->youDaoTitle_lineEdit->setText(tr("单词本打开失败"));
}