Highlighted text

I need to get highlighted text out of a window. How do I get it to pass.

edit- its my own window, just need to get it at an event trigger.
Last edited on
Ok, I am new to windows so help me out on this one; I want to get the text thats highlighted and send it to an internal manipulator and then replace the highlighted section with the manipulated string.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
switch(LOWORD(wParam))
        {
            case ID_FILE_EXIT:
                PostMessage(hwnd, WM_CLOSE, 0, 0);
            break;
            case ID_STUFF_GO: //this is the menu item that cause the string pass
            try{
                HWND hEdit; //Identifying the window handle
                const wchar_t * input; 
                long start,finish;
                //need message to place highlighted section into input
                std::wstring compstring=Functions::fullstringcomputation(input); //internal manip
                const wchar_t * bob= compstring.c_str(); 
                SendMessage(hEdit, WM_SETTEXT, 0, (LPARAM) bob); //replacing string
            }
            catch(std::wstring error){
                const wchar_t * use = error.c_str();
                MessageBox(hwnd, use, L"Error: ",MB_OK | MB_ICONINFORMATION);
            }
            break;
        }
Last edited on
Hi toothkiller I'am a newbie also and i want to try this one also..thanks for posting this...
I haven't done Windows programming without a framework in over 15 years, so don't try to compile this, but I'd imagine the code would go something like this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
    {
        // Get selection range
        DWORD dwBegin. dwEnd;
        SendMessage(hEdit, EM_GETSEL, (WPARAM)&dwBegin, (LPARAM)&dwEnd);

        // Get text
        int iMaxTextLen = 4096; // some number
        char* pszText = new char[iMaxTextLen];
        SendMessage(hEdit, WM_GETTEXT, (WPARAM)iMaxTextLen, (LPARAM)pszText);

        std::string sOldString(pszText + dwBegin, dwEnd - dwBegin);
        std::string sNewString = DetermineNewString(sOldString); // apply your change
        delete [] pszText, pszText = 0;

        // Replace text
        DWORD dwCanUndo = 1;
        SendMessage(hEdit, EM_REPLACESEL, (WPARAM)dwCanUndo, (LPARAM)sNewString.c_str());
    }
Last edited on
char* pszText = new char[iMaxTextLen];

Why are you dynamically allocating it like this when it has a set max val or is this supposed to a variable and you are just using a place holder?
Topic archived. No new replies allowed.