C++技巧(枚舉出當(dāng)前系統(tǒng)所有窗體句柄)

字號:

有時(shí)需要一個(gè)軟件在一定時(shí)間執(zhí)行一件時(shí)情,而軟件本身又不提供相關(guān)接口,更不用說可編程性了,考試大提示:只能寫個(gè)程序來自動控制它。
    首先第一步,找出相關(guān)程序的句柄,
    在此列出枚舉出系統(tǒng)句柄的程序:
    #include "stdafx.h"
    //#include
    #include
    int Leavel = 0;
    void ShowWindowHandle(HWND parent )
    {
    Leavel ++;
    //find the child
    HWND _FirstChild = NULL;
    do
    {
    _FirstChild = FindWindowEx(parent, _FirstChild, NULL, NULL);
    if(_FirstChild!=NULL)
    {
    for(int i=0;i    printf(" ");
    printf("%x\n",_FirstChild);
    ShowWindowHandle(_FirstChild);
    }
    } while (_FirstChild!=NULL);
    Leavel--;
    }
    int _tmain(int argc, _TCHAR* argv[])
    {
    ShowWindowHandle(NULL);
    return 0;
    }
    找到句柄后下一步就是做我們自己想做的事情,比如給他sendMessage