C++ SendMessage无法获取文本

C++ SendMessage无法获取文本,c++,sendmessage,hwnd,C++,Sendmessage,Hwnd,不确定SendMessage为什么没有从我需要的类中获取文本。我以前做过这件事,但VisualBasic和我想把它移植到C++。我没有在任何其他程序上尝试过此代码。我读到一些关于它可能是unicode的东西,但我不确定如何实现它 #define WIN32_LEAN_AND_MEAN #include <windows.h> #include <iostream> using namespace std; void FindmIRC() { cout <&

不确定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;
}
#定义WIN32_LEAN_和_MEAN
#包括
#包括
使用名称空间std;
void FindmIRC()
{

cout正如您在spy++输出中看到的,高亮显示的控件不包含任何文本。它应该出现在.

你没有收到任何文本,还是调用失败了?这里返回的是什么?
GetLastError
刚刚实现了
GetLastError
,我得到的
GetProcessId在eror 6中失败了:句柄无效。
我看到了,但是当我用spy++按住ctrl+f键并拖动查找器时,它会突出显示聊天框,并告诉我它是静态类。mIRC确实使用这样的多窗口:我不确定这是否有区别。不确定要查询哪个窗口,如果是主窗口,那么我怀疑您是否能够使用简单的方法获取其内容,它肯定使用了一些高级的呈现方法。那么,如果它使用这种方法,是否不可能获取该文本方法?如果spy++没有显示此文本,那么我怀疑您是否能在代码中实现这一点。最好寻找mirc选项,使您能够做到这一点-这是一个非常高级的程序。从顶层来看,它看起来没有那么高级,但我想是的。我也在考虑尝试另一个irc客户端,这可能会奏效。不过,感谢您的回复!