阅读背景:

【QT】使用Windows API枚举窗口_可爱的小黑土土博客_枚举窗口相关的api

来源:互联网 
#include <windows.h>
#pragma comment(lib, "user32.lib")

BOOL CALLBACK EnumWindowsProc( HWND hwnd, LPARAM lParam)
{
    char buff[250]= {0};//全部填充为0
    ::GetWindowTextA(hwnd,(LPSTR)buff,sizeof(buff));//获取windows窗口标题
    qDebug()<<"buff================="<<buff;
    if(strstr(buff,".ppt"))
    {
        ::SetWindowPos(hwnd,nullptr,0,0,100,100,SWP_NOMOVE|SWP_NOSIZE);
        return FALSE;
       // break;
    }

    return TRUE;//如果返回FALSE的话,则回调函数会停止
}

void MainWindow::on_pushButton_clicked()
{
    ::EnumWindows(EnumWindowsProc,0);
          //  SetForegroundWindow
    /*
    HWND h = ::GetWindow(::GetDesktopWindow(),GW_CHILD);//
    while(h!=NULL)
    {
        char buff[250]= {0};//全部填充为0
        ::GetWindowTextA(h,(LPSTR)buff,sizeof(buff));

        qDebug()<<"buff=============="<<buff;


        qDebug()<<"strstr=========="<<strstr(buff,".ppt");

        if(strstr(buff,".ppt"))
        {
            ::SetWindowPos(h,nullptr,0,0,100,100,SWP_NOMOVE|SWP_NOSIZE);
            break;
        }


        h = ::GetWindow(h,GW_HWNDNEXT);//GW_HWNDNEXT  获取他的下一个,也就是邻居,就是他的下一个窗口的句柄
    }
    */

}#include <windows.h>
#pragma comment(lib, "user



你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: