1.添加头文件:#include <Windows.h>
2.添加库:LIBS +=User32.LIB
win32 {
LIBS += -luser32
}
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(HWND AppWnd=::FindWindow(App,AppCaption))
{
::ShowWindow(AppWnd,SW_SHOWNORMAL);
}
else
{
ui->youDaoTitle_lineEdit->setText(tr("单词本打开失败"));
}
LRESULT CALLBACK WindowProc(
HWND hwnd, // handle to window
UINT uMsg, // message identifier
WPARAM wParam, // first message parameter
LPARAM lParam // second message parameter
)
{
if( uMsg == 10000)
{
int kk = 0;
}
return DefWindowProc( hwnd, uMsg, wParam, lParam );
}
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
{
ui->setupUi(this);
WNDCLASS wc;
memset(&wc, 0, sizeof(wc));
wc.style = 0;
wc.lpfnWndProc = &WindowProc;
wc.cbClsExtra = wc.cbWndExtra = 0;
wc.hInstance = NULL;
wc.hIcon = NULL;
wc.hCursor = NULL;
wc.hbrBackground = NULL;
wc.lpszMenuName = NULL;
wc.lpszClassName = L"xfs Notify Window";
RegisterClass(&wc);
m_hWnd = CreateWindow(wc.lpszClassName, L"WWWWWWWWWWWW",
WS_DISABLED, 0, 0, 0, 0, NULL, NULL, wc.hInstance, NULL);
SendMessage(m_hWnd, 10000, 0, NULL);
int ok=0;
}