How can I change the title of a control of a menu item in app which is not mine using c++ win32 api?

Viewed 51

For example, if I'll want to change to "Copy" string under "edit" menu on notepad.

I am trying to do the following:

use enumWindowsProc (works well)


BOOL CALLBACK enumWindowsProc(
    __in  HWND hWnd,
    __in  LPARAM lParam
) {
    int length = ::GetWindowTextLength(hWnd);
    if (0 == length) return TRUE;

    TCHAR* buffer;
    buffer = new TCHAR[length + 1];
    memset(buffer, 0, (length + 1) * sizeof(TCHAR));

    GetWindowText(hWnd, buffer, length + 1);
    wcout << buffer << endl;
    wstring s2(buffer);
    wstring s3(L"Notepad");
    std::string::size_type found = s2.find(s3);
    if (found != std::string::npos)
    {
        EnumChildWindows(hWnd, EnumChildProc, 0);
    }
    delete[] buffer;
    return TRUE;
}

and than use EnumChildProc (does not give the required behavior. I hoped to get a tree of controls):

BOOL CALLBACK EnumChildProc(HWND hwnd, LPARAM lParam)
{
    
    int length = ::GetWindowTextLength(hwnd);
    if (0 == length) return TRUE;

    TCHAR* buffer;
    buffer = new TCHAR[length + 1];
    memset(buffer, 0, (length + 1) * sizeof(TCHAR));

    GetWindowText(hwnd, buffer, length + 1);
    OutputDebugString(buffer);
    OutputDebugString(L"\n");
    
    EnumChildWindows(hwnd, EnumChildProc, 0);

    delete[] buffer;
    return TRUE;
    
}
0 Answers
Related