代码改变世界

Qt引用Windows API方法

2012-07-21 16:51  owenyang  阅读(1015)  评论(0)    收藏  举报

1.添加头文件:#include<Windows.h>

2.添加库LIBS+=User32.LIB   

3.添加相关代码:

 

QStringClassName("YodaoWordBookClass");
QStringAppName(tr("有道单词本"));

LPCWSTRApp=reinterpret_cast<LPCWSTR>(ClassName.data());
LPCWSTRAppCaption=reinterpret_cast<LPCWSTR>(AppName.data());
//亦可不用上面两名,直接转换即可,ClassName.utf16(),AppName.utf16())
if(AppWnd=::FindWindow(App,AppCaption))
{
::ShowWindow(AppWnd,SW_SHOWNORMAL);
}
else
{
ui->youDaoTitle_lineEdit->setText(tr("单词本打开失败"));
}