c++winapiconcatenationwchar

How do you combine two char_t* strings?


What I am trying to do is get a list of processes in an edit child window. I originally was gonna use a series of buttons with a scroll bar but I don't know how to do that (if you have a solution for that) and found no resources how to.

I tried wchar.h functions, and type casting.

HWND listProc = CreateWindow(L"Edit", L"", WS_VISIBLE | WS_CHILD | WS_VSCROLL | WS_HSCROLL,
            0, 0, 100, 300, process, NULL, NULL, NULL);
        LPWSTR procList = L'';
        Process32First(procSnap, &procEntry);
        while (Process32Next(procSnap, &procEntry))
        {
            wcsncat(procList, procEntry.szExeFile, MAX_PATH);
            wcsncat(procList, L"\n", 1);
        }
        SetWindowText(listProc, procList);
        CloseHandle(procSnap);

Solution

    1. As @jkb metioned, usestd::wstring;
    2. use std::stringstream.(or any other stream class)

    In addition, there are other problems in your sample. If you don't want your output text to be one line and hard to read, you need to add the Exstyle of ES_MULTILINE | ES_AUTOVSCROLL to your edit control, and use "\r\n" to connect strings to Wrap text.

    1). Sample:

       HWND listProc = CreateWindowEx(0, L"Edit", L"", WS_VISIBLE | WS_CHILD | WS_VSCROLL | WS_HSCROLL| ES_LEFT | ES_MULTILINE | ES_AUTOVSCROLL,
           0, 0, 100, 300, hWnd, NULL, NULL, NULL);
    
       HANDLE procSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
    
       std::wstring procList;
       PROCESSENTRY32 procEntry;
       procEntry.dwSize = sizeof(PROCESSENTRY32);
       Process32First(procSnap, &procEntry);
       procList += procEntry.szExeFile;
       procList += L"\r\n";
       while (Process32Next(procSnap, &procEntry))
       {
           procList += procEntry.szExeFile;
           procList += L"\r\n";
       }
       SetWindowText(listProc, procList.c_str());
       CloseHandle(procSnap);
    

    2). Sample:

       HWND listProc = CreateWindowEx(0, L"Edit", L"", WS_VISIBLE | WS_CHILD | WS_VSCROLL | WS_HSCROLL| ES_LEFT | ES_MULTILINE | ES_AUTOVSCROLL,
           0, 0, 100, 300, process, NULL, NULL, NULL);
    
       HANDLE procSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
    
       std::wstringstream procList;
       PROCESSENTRY32 procEntry;
       procEntry.dwSize = sizeof(PROCESSENTRY32);
       Process32First(procSnap, &procEntry);
       procList += procEntry.szExeFile;
       procList += L"\r\n";
       while (Process32Next(procSnap, &procEntry))
       {
           procList << procEntry.szExeFile;
           procList << L"\r\n";
       }
    
       SetWindowText(listProc, procList.str().c_str());
       CloseHandle(procSnap);