c++ - SendMessage 收不到短信

标签 c++ sendmessage hwnd

不确定为什么 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/

相关文章:

c++ - 不明白return *this "as a whole"的用法

c++ - 如何让 C++ 按下空格键?

wpf - 我想禁用特定空气动力学窗口的阴影效果

c++ - Qt本地化

c++ - 无法声明静态 constexpr char []

c++ - 使用 boost::is_any_of 拆分会混淆定界符 ",,"和 ","

vb.net - VB 2010发送消息: sending binary data to another app

java - 在 Activity 类中找不到方法 sendMessage(View)

c - 如何在编辑控件中垂直居中文本?

C++ 在运行时更改 HWND 窗口过程