API func to select the text in an edit control?

This is a discussion on API func to select the text in an edit control? within the Windows Programming forums, part of the Platform Specific Boards category; ...suppose the thread title sums it up!...

  1. #1
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708

    API func to select the text in an edit control?

    ...suppose the thread title sums it up!
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  2. #2
    Registered User
    Join Date
    Jun 2002
    Posts
    14
    Code:
    GetWindowText(
      HWND hWnd,        // handle to window or control
      LPTSTR lpString,  // text buffer
      int nMaxCount     // maximum number of characters to copy
    );
    & or
    Code:
    GetDlgItemText(
      HWND hDlg,       // handle to dialog box
      int nIDDlgItem,  // control identifier
      LPTSTR lpString, // pointer to buffer for text
      int nMaxCount    // maximum size of string
    );
    Last edited by polo; 06-25-2002 at 02:43 PM.

  3. #3
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    Actually, what I meant is how to highlight the text. As if the user had dragged the mouse over the text while holding down the left mouse button...BTW: thanks for the quick response though!
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  4. #4
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,789
    Hmm.....have a try at..

    Code:
    SendMessage(hEdit, EM_SETSEL,
    (WPARAM)nFirstChar,(LPARAM) nLastChar);

  5. #5
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    Hmm...interesting. That didn't work but you gave me a great starting point! Your suggestion led me directly to the windowsx.h header. What an interesting file! I will be back with a definite...thanks Rob...
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  6. #6
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,789
    Hmm didnt work huh?.....It should do.....it will highlight the selected range within an edit........I assume that's what you want right?

    BTW, there are loads of EM_ messages you can send to an edit......have a look at the SDK docs for more info...

  7. #7
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    Ahh, well that file was a bum one. Just a bunch of cheap macros! Anyhow, I believe you gave the correct code. I am just overlooking something. I will figure it out. Oh and BTW: I am assuming the last two params are pointers to the first and last cells of the buffer that got the window text?
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  8. #8
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,789
    Originally posted by Sebastiani
    Ahh, well that file was a bum one. Just a bunch of cheap macros! Anyhow, I believe you gave the correct code. I am just overlooking something. I will figure it out. Oh and BTW: I am assuming the last two params are pointers to the first and last cells of the buffer that got the window text?
    This function simply highlights text in an edit just like dragging a mouse over the text with the left button down...that is what you want right?

    The last 2 params are the start and end positions of the text you want highlighted.........simply send ints, but cast them to WPARAM & LPARAM for the purposes of the function...

    Oh....and you may need to give the edit input focus before doing this.....

  9. #9
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    Yes to highlight text.

    Here is what I was trying:

    eTicker.Focus();

    SendMessage(eTicker.hwnd, EM_SETSEL, (WPARAM)buff[0], (LPARAM)buff[strlen(buff) - 1]);

    ...and even the hard-coded:

    eTicker.Focus();

    SendMessage(eTicker.hwnd, EM_SETSEL, (WPARAM)'a', (LPARAM)'c');

    //...the contents of the edit in that case being "abc"...
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  10. #10
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,789
    No sorry...you need the numerical index positions....
    Code:
    int nFirstChar = 1,nLastChar = 3;
    
    
    //.......................
    
    eTicker.Focus();
    
    SendMessage(eTicker.hwnd, EM_SETSEL, (WPARAM)nFirstChar, (LPARAM)nLastChar );
    You dont even need to know the contents of an edit to set selections....

  11. #11
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    Geez I'm a goober. Anyhow, now the effect is that the text is completely erased! Well I will work on that after more important aspects of the program are finished. But I thank you kindly, sir. Let me know if I can be of any assistance to you...
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  12. #12
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,856
    Try this

    SendMessage(hWnd, EM_SETSEL, 0, MAKELONG(0,0xffff) );
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. edit control text buffer
    By scurvydog in forum Windows Programming
    Replies: 4
    Last Post: 12-11-2008, 09:13 AM
  2. How to use FTP?
    By maxorator in forum C++ Programming
    Replies: 8
    Last Post: 11-04-2005, 02:17 PM
  3. struct question
    By caduardo21 in forum Windows Programming
    Replies: 5
    Last Post: 01-31-2005, 03:49 PM
  4. adding text to an edit control
    By steve_i83 in forum Windows Programming
    Replies: 2
    Last Post: 10-26-2001, 06:40 AM
  5. Rich edit control example Win API
    By Echidna in forum Windows Programming
    Replies: 1
    Last Post: 09-17-2001, 02:12 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21