C++ Builder XE EnumWindowsProc遍历所有窗口的名称

BOOL CALLBACK EnumWindowsProc(HWND hwnd, LPARAM lParam)
{
    // 这里可以添加你的处理逻辑
    // 例如,将句柄添加到列表中或者其他操作
    // 这里我们仅仅输出到调试窗口
    OutputDebugString(L"枚举窗口句柄: ");
    char windowHandle[10];
    sprintf(windowHandle, "%x", hwnd);

    OutputDebugStringA(windowHandle);
    OutputDebugStringA("\n");

    WideChar windowText[256];
    // 获取窗口标题
    GetWindowText(hwnd, windowText, sizeof(windowText));
    if(String(windowText).Length()>0)
       Form1->Memo1->Lines->Append(windowText);
    // 继续枚举其他窗口
    return TRUE;
}
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
    : TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
   EnumWindows(EnumWindowsProc, 0);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button2Click(TObject *Sender)
{
    HWND hWnd = FindWindow(L"123456", NULL);               //GetForegroundWindow();
    if (hWnd != NULL)
    {
        WideChar windowText[256];
        // 获取窗口标题
        GetWindowText(hWnd, windowText, sizeof(windowText));
        // 显示窗口标题
        ShowMessage(windowText);

        //const int messageID =0x0400+0; // 替换为正确的消息ID
        //SendMessage(hWnd, WM_COMMAND, messageID, 0);
    }
    else
    {
        ShowMessage("无活动窗口");
    }
}

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

lzksword

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值