1

我正在尝试将 wchar_t 发送到另一个窗口上的文本框,但我无法弄清楚为什么当我打印到控制台时它会正确显示,但是当我发送到文本框时,它会附加“????????” 在最后。

// MyTest.h 中的函数

    static HWND GetEditWindow()
    {
        HWND winmx = WinMX::GetWinMXWindow();
        if(winmx == NULL) return NULL;

        // Check for inner window
        HWND inner = FindWindowEx(winmx, NULL, NULL, NULL);
        while(inner != NULL)
        {
            TCHAR title[100];
            GetWindowText(inner, title, 100);

            if(wcsstr(title, L"WinMX Peer Network") != NULL && wcsstr(title, L"on WinMX Peer Network") == NULL)
                return inner;

            inner = FindWindowEx(winmx, inner, NULL, NULL);
        }


        // Check for floating window
        HWND channels = FindWindowEx(NULL, NULL, NULL, NULL);
        while(channels != NULL)
        {
            TCHAR title[100];
            GetWindowText(channels, title, 100);

            if(wmemcmp(title, L"WinMX Peer Network", 18) == 0) 
                return channels;

            channels = FindWindowEx(NULL, channels, NULL, NULL);
        }

        // Failed
        return NULL;
    }

    static map<wchar_t*, HWND> GetOpenWindows()
    {
        map<wchar_t*, HWND> results;
        HWND winmx = WinMX::GetWinMXWindow();
        if (winmx == NULL) return results;

        // Check for inner chat windows.
        HWND inner = FindWindowEx(winmx, NULL, NULL, NULL);
        while(inner != NULL)
        {
            TCHAR title[100];
            GetWindowText(inner, title, 100);

            if(wcsstr(title, L" on WinMX Peer Network") != NULL)
            {
                wchar_t* newtitle = new wchar_t[wcslen(title) - 22];
                wmemcpy(newtitle, title, wcslen(title) - 22);

                results.insert(pair<wchar_t*,HWND>(newtitle, inner));
            }

            inner = FindWindowEx(winmx, inner, NULL, NULL);
        }


        // Check for floating chat windows.
        HWND top = FindWindowEx(NULL, NULL, NULL, NULL);
        while(top != NULL)
        {
            TCHAR title[100];
            GetWindowText(top, title, 100);

            if(wcsstr(title, L"on WinMX Peer Network") != NULL)
            {
                wchar_t* newtitle = new wchar_t[wcslen(title) - 22];
                wmemcpy(newtitle, title, wcslen(title) - 22);

                results.insert(pair<wchar_t*,HWND>(newtitle, top));
            }

            top = FindWindowEx(NULL, top, NULL, NULL);
        }

        return results;
    }

// Main.cpp

#include <stdio.h>
#include "MyTest.h"

using namespace std;

void main()
{
    map<wchar_t*, HWND> Wins = Api::GetOpenWindows();
    HWND editwindow = Api::GetEditWindow();
    HWND filterbar = FindWindowEx(editwindow, NULL, L"edit", NULL);

    for(map<wchar_t*, HWND>::iterator it = Wins.begin(); it != Wins.end(); ++it)
    {
        wcout << it->first << "\n";
        SendMessage(filterbar, WM_SETTEXT, NULL, (LPARAM)it->first);
    }

    getchar();
}

// Output:
//     WindowNameHere_334334

// TextBox SetText OutPut:
//     WindowNameHere_334334????????
4

0 回答 0