逆向 | 查窗口名代码

逆向 | 查窗口名代码

存一份,有时候窗口名FindWindow找不到可能是少了空格之类的

#include <iostream>
#include <Windows.h>

using namespace std;

BOOL CALLBACK EnumChildProc( HWND   hwnd,  LPARAM lParam)
{
    char szTitle[MAX_PATH] = {0};
    char szClass[MAX_PATH] = {0};
    int nMaxCount = MAX_PATH;

    LPSTR lpClassName = szClass;
    LPSTR lpWindowName = szTitle;

    GetWindowTextA(hwnd, lpWindowName, nMaxCount);
    GetClassNameA(hwnd, lpClassName, nMaxCount);
    cout << "[Child window] window handle: " << hwnd << " window name: `" 
        << lpWindowName << "` class name " << lpClassName << endl; 

    return TRUE;
}


BOOL CALLBACK EnumWindowsProc(HWND hwnd, LPARAM lParam)
{

    /*
     * Remarks
        The EnumWindows function does not enumerate child windows, 
        with the exception of a few top-level windows owned by the 
        system that have the WS_CHILD style.
     */
    char szTitle[MAX_PATH] = {0};
    char szClass[MAX_PATH] = {0};
    int nMaxCount = MAX_PATH;

    LPSTR lpClassName = szClass;
    LPSTR lpWindowName = szTitle;

    GetWindowTextA(hwnd, lpWindowName, nMaxCount);
    GetClassNameA(hwnd, lpClassName, nMaxCount);
    cout << "[Parent window] window handle: " << hwnd << " window name: `" 
        << lpWindowName << "` class name " << lpClassName << endl; 

    //EnumChildWindows(hwnd, EnumChildProc, lParam);

    return TRUE;
}


int main(int argc, char *argv[])
{
    EnumWindows(EnumWindowsProc, 0);
	system("pause");
    return 0;
} 

posted @ 2024-07-06 16:00  Mz1  阅读(8)  评论(0编辑  收藏  举报