spy++是可以获取浏览器当前页面的标题的,并且可以根据“窗口标题”和“类名”实现对浏览器的显示和隐藏,
生活随笔
收集整理的這篇文章主要介紹了
spy++是可以获取浏览器当前页面的标题的,并且可以根据“窗口标题”和“类名”实现对浏览器的显示和隐藏,
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
目前測試Firefox和Chrome都是可以的
以下是例子
頭文件mainwindow.h
#ifndef MAINWINDOW_H #define MAINWINDOW_H#include <QMainWindow> #include <QProcess> #include <QWindow> #include <QDebug> #include <QStringList> #include <Windows.h> #include <windows.h> #include <WinUser.h> #include <QLibrary>namespace Ui { class MainWindow; }class MainWindow : public QMainWindow {Q_OBJECTpublic:explicit MainWindow(QWidget *parent = 0);~MainWindow();QProcess process;QString addrname;QString proname;QStringList argu;QString sortname;QString windname;bool whetherrun();void killprog();void programrun();void windshow();void windhide();bool frun;QLibrary *libdll;private slots:void on_pushButton_clicked();void on_pushButton_2_clicked();void on_pushButton_3_clicked();private:Ui::MainWindow *ui; };#endif // MAINWINDOW_Hcpp文件,MainWindow
#include "mainwindow.h" #include "ui_mainwindow.h" #include <QLibrary> #include <QMessageBox>MainWindow::MainWindow(QWidget *parent) :QMainWindow(parent),ui(new Ui::MainWindow) {ui->setupUi(this); // QProcess *p = new QProcess();// addrname ="D:\\hello\\quicknanobrowser\\debug\\quicknanobrowser.exe"; // proname ="quicknanobrowser.exe"; // argu << "http://www.baidu.com"; // sortname = "Qt5QWindowOwnDCIcon"; // windname = "quicknanobrowser"; // addrname ="D:\\hello\\build-qwer-Desktop_Qt_5_9_6_MinGW_32bit-Debug\\debug\\qwer.exe"; // proname ="qwer.exe"; // argu << "http://www.baidu.com"; // sortname = "Qt5QWindowIcon"; // windname = "MainWindow";// libdll = new QLibrary("NDde.dll"); //聲明所用到的dll文件 // if (libdll->load()) //判斷是否正確加載 // { // QMessageBox::information(NULL,"OK","DLL load is OK!");// }// addrname ="C:\\Program Files\\Mozilla Firefox\\firefox.exe"; // proname ="firefox.exe"; // argu << "http://www.baidu.com"; // sortname = "MozillaWindowClass"; // windname = "百度一下,你就知道 — Mozilla Firefox";addrname ="C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe";proname ="chrome.exe";argu << "http://www.baidu.com";sortname = "Chrome_WidgetWin_1";//這是在spy++里面看到的類名windname = "百度一下,你就知道 - Google Chrome";//窗口標題// DdeClient dde = new DdeClient("Firefox", "WWW_GetWindowInfo"); // dde.Connect(); // QString url = dde.Request("URL", int.MaxValue); // dde.Disconnect(); // MessageBox.Show(url); }MainWindow::~MainWindow() {delete ui; }void MainWindow::on_pushButton_clicked() { // p->start(addrname,argu); // qDebug()<<"創建cs"<<proname;programrun(); }void MainWindow::on_pushButton_2_clicked() { // QProcess proc; // QString strs = "tasklist"; // proc.start(strs); // proc.waitForFinished(); // QString st = proc.readAllStandardOutput(); // if(st.contains(proname)) // { // p->close(); // qDebug()<<"關閉"; // } // else // { // if(p->state() ==2) // { // p->close(); // qDebug()<<"all"; // } // }windhide();}bool MainWindow::whetherrun() {QProcess proc;QString strs = "tasklist";proc.start(strs);proc.waitForFinished();QString st = proc.readAllStandardOutput();if(st.contains(proname)){frun = true;return true;}else{if(process.state() ==2){process.close();}return false;} } void MainWindow::killprog() {QProcess pkill;QString commd = "taskkill /f /im "+proname;if(frun){pkill.execute(commd);pkill.close();qDebug()<<"sha si";} } void MainWindow::programrun() {if(whetherrun() && (process.state()==2)){qDebug()<<proname<<"已經運行";windshow();//打開的窗口再次在上面}else{//trr->start();//定時器開始工作process.start(addrname,argu);qDebug()<<"創建ca"<<proname;} } void MainWindow::windshow() {WId wid;if(windname == ""){wid = (WId)FindWindow((LPCWSTR)sortname.toStdWString().c_str(),nullptr);}elsewid = (WId)FindWindow((LPCWSTR)sortname.toStdWString().c_str(),(LPCWSTR)windname.toStdWString().c_str());QWindow *qwind = QWindow::fromWinId(wid);qDebug()<<"creation windshow pos:"<<qwind->position().y();if(qwind== NULL)return;ShowWindow((HWND)qwind->winId(),SW_MAXIMIZE);SetWindowPos((HWND)qwind->winId(),HWND_TOP,0,0,0,0,SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW);//讓已經打開的界面再顯示//bool rty = SetWindowPos((HWND)qwind->winId(),HWND_TOP,0,theheight,taskwidth,subheight,SWP_FRAMECHANGED);//qDebug()<<rty;delete qwind; }void MainWindow::windhide() {WId wid;if(windname == ""){wid = (WId)FindWindow((LPCWSTR)sortname.toStdWString().c_str(),nullptr);}elsewid = (WId)FindWindow((LPCWSTR)sortname.toStdWString().c_str(),(LPCWSTR)windname.toStdWString().c_str());QWindow *qwind = QWindow::fromWinId(wid);if(qwind== NULL)return;ShowWindow((HWND)qwind->winId(),SW_HIDE);delete qwind; }void MainWindow::on_pushButton_3_clicked() {windshow(); }還有一個問題是如何實時獲取****瀏覽器當前打開的頁面的標題,這個問題解決了就可以更好的控制瀏覽器頁面隱藏和顯示了。
這個問題解決了,參考https://xiuye.blog.csdn.net/article/details/117553029
功能已經實現,對瀏覽器的隱藏顯示
總結
以上是生活随笔為你收集整理的spy++是可以获取浏览器当前页面的标题的,并且可以根据“窗口标题”和“类名”实现对浏览器的显示和隐藏,的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 视频教程-JavaScript全套课程-
- 下一篇: 多线程学习(九)-可阻塞的队列