سؤال

I have done something like this before in visual basic but it was a long time ago and it was for Wolfenstein ET. I know that I will have to use SendMessage or WM_GETTEXT so all I would need is the code the would constantly get the text from the chat window. Now hexchat is opensource but I do not know how to go about and get the ID that is needed to specify. I would rather not use a handle since I would have to recompile it every time. I know this is asking for a lot but I have been trying to figure this out for the past couple of days with no success. Any help is greatly appreciated! Thanks!

Oops also forgot to mention that since HexChat is open-source should we be able to use GetDlgItem()?

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

void FindHexChat()

{

HWND hwndNotepad = FindWindow(L"gdkWindowToplevel", NULL);

if (NULL != hwndNotepad)
{

    HWND hwndEdit = FindWindowEx(hwndNotepad, NULL, L"Chat", NULL);

    if (NULL != hwndEdit)
    {
        int textLen = (int)SendMessage(hwndEdit, WM_GETTEXTLENGTH, 0, 0);

        if (0 < textLen)
        {

            const int bufferSize = 1024;
            char textBuffer[bufferSize] = "";
            SendMessage(hwndEdit, WM_GETTEXT, (WPARAM)bufferSize, (LPARAM)textBuffer);

 << cout << textBuffer << endl;



}
            else
            {

            }
        }
        else
        {

        }
    }
    else
    {
 endl;
    }

}

int main()
{
    FindHexChat();

    return 0;
}
هل كانت مفيدة؟

المحلول

The ID of the window you are looking for can be determined from the source code or with Spy++. Every child window HWND is returned by EnumChildWindows. For each of those HWNDs you can call GetWindowLong(hwnd, GWL_ID) to get that child window's ID. When it matches the target ID you have found the HWND that can be used with WM_GETTEXT to read the window's text.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top