gpt4 book ai didi

c++ - SendMessage 收不到短信

转载 作者:太空宇宙 更新时间:2023-11-04 13:57:11 25 4
gpt4 key购买 nike

不确定为什么 SendMessage 没有从我需要的类中获取文本。我以前做过,但它是 VisualBasic,我想将它移植到 C++。我没有在任何其他程序上尝试过此代码。我正在阅读一些关于它可能是 unicode 的内容,但我不确定如何实现它。

#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <iostream>
using namespace std;

void FindmIRC()
{
cout << "[mIRC]" << endl;

cout << "- find mIRC window" << endl;
HWND hwndmIRC = FindWindow(L"mIRC", NULL);

if (NULL != hwndmIRC)
{
cout << " + found mIRC window" << endl;
cout << "- find MDIClient window" << endl;
HWND hwndMDIClient = FindWindowEx(hwndmIRC, NULL, L"MDIClient", NULL);

if (NULL != hwndMDIClient)
{
cout << " + found MDIClient window" << endl;
cout << "- find mIRC_Channel window" << endl;
HWND hwndmIRC_Channel = FindWindowEx(hwndMDIClient, NULL, L"mIRC_Channel", NULL);

if (NULL != hwndmIRC_Channel)
{
cout << " + found mIRC_Channel window" << endl;
cout << "- find Static window" << endl;
HWND hwndStatic = FindWindowEx(hwndmIRC_Channel, NULL, L"Static", NULL);

if (NULL != hwndStatic)
{
cout << " + found Static window" << endl;

cout << "- get text length" << endl;
int textLen = (int)SendMessage(hwndStatic, WM_GETTEXTLENGTH, 0, 0);
if (0 < textLen)
{
cout << "- getting text" << endl;
const int bufferSize = 1024;
char textBuffer[bufferSize] = "";
SendMessage(hwndStatic, WM_GETTEXT, (WPARAM)bufferSize, (LPARAM)textBuffer);

cout << "[begin text]" << endl;
cout << textBuffer << endl;
cout << "[end text]" << endl;
}
else
{
cerr << "No text." << endl;
}

}
else
{
cerr << "Static not found." << endl;
}

}
else
{
cerr << "mIRC_Channel not found." << endl;
}
}
else
{
cerr << "MDIClient not found." << endl;
}

}
else
{
cerr << "mIRC not open." << endl;
}
}
int main()
{

FindmIRC();

return 0;
}

突出显示的类是有文本的: mIRC

该程序可以毫无问题地找到该类,并且不会报告未找到它,所以我看不出它不应该找到它的原因。任何帮助都很棒!

最佳答案

正如您在 spy++ 输出中看到的,突出显示的控件不包含任何文本。它应该出现在“”中静态的左侧。

关于c++ - SendMessage 收不到短信,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20925570/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com