Thread: Adding Text to an Edit

  1. #1
    Registered User
    Join Date
    Mar 2004
    Posts
    10

    Adding Text to an Edit

    I searched the forums and found what code to use.... but im not sure about how to use it....

    Code:
    lResult = SendMessage(      // returns LRESULT in lResult
    (HWND) hWndControl,      // handle to destination control
    (UINT) WM_SETTEXT,      // message ID
    (WPARAM) wParam,      // = (WPARAM) () wParam;    
    (LPARAM) lParam      // = (LPARAM) () lParam; );
    So what I'm tryig to do is when I click a button it takes the text from hPopURL and puts it in hLink along with some extra prewritten text after it clears any text that may be in there... Can someone please explain to me how this peice of code works? Thanks alot... I'm just learning how to program in windows, please be patient with me...

  2. #2
    * Death to Visual Basic * Devil Panther's Avatar
    Join Date
    Aug 2001
    Posts
    768
    first you should get msdn, and read about the function and the message it sends.

    you can find an on-line version of msdn here: http://msdn.microsoft.com
    An application sends a WM_SETTEXT message to set the text of a window.


    WM_SETTEXT
    wParam = 0; // not used; must be zero
    lParam = (LPARAM)(LPCTSTR)lpsz; // address of window-text string


    but anyway, you can simply use:

    Code:
    SetDlgItemText(hDlg, ID_EDITBOX_CONTROL, "hello");
    The SetDlgItemText writes the "hello" string to the editbox, named: ID_EDITBOX_CONTROL, which is part of the window/dialog box, and it's handle is: hDlg.
    Last edited by Devil Panther; 03-16-2004 at 01:52 PM.
    "I don't suffer from insanity but enjoy every minute of it" - Edgar Allen Poe

    http://www.Bloodware.net - Developing free software for the community.

  3. #3
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,981
    >> I'm just learning how to program in windows...
    A big part of that will be learning to use available documentation: WM_SETTEXT.

    gg

  4. #4
    Registered User
    Join Date
    Mar 2004
    Posts
    10
    thanks alot guys!

  5. #5
    Registered User
    Join Date
    Mar 2004
    Posts
    10
    ok, so i need help...

    to add text from another text box also...

    UINT GetDlgItemText(

    HWND hDlg, // handle of dialog box
    int nIDDlgItem, // identifier of control
    LPTSTR lpString, // address of buffer for text
    int nMaxCount // maximum size of string
    );

  6. #6
    Registered User
    Join Date
    Mar 2004
    Posts
    10
    so what am i doing wrong here?

    Code:
                   popUrl = GetDlgItemText(hwnd, IDE_MAIN_POPURL, 0, 0);
                    SetDlgItemText(hwnd, IDE_MAIN_LINK, "URL: " + popUrl);
    i r n00b

  7. #7
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,981
    >> I'm just learning how to program in windows...

    Do you know how to program in C? If not, I would start there first....

    gg

  8. #8
    Registered User
    Join Date
    Mar 2004
    Posts
    10
    yes, i've made some simple dos programs in C before.. and also have had experiance in other languages...


    I've got my problem just about figured out... but i need to know one thing... how can i convert a char to a string and then back again?

    Code:
                char popUrl[256];
                string finLink1;
                finLink1 = "<a href=";
                string finLink2;
                finLink2 = ">click me</a>";
    
                   GetDlgItemText(hwnd, IDE_MAIN_POPURL, popUrl, 256);
                   finLink1 += popUrl;
                   finLink1 += finLink2;
                   SetDlgItemText(hwnd, IDE_MAIN_LINK, finLink1);
    i r n00b

  9. #9
    * Death to Visual Basic * Devil Panther's Avatar
    Join Date
    Aug 2001
    Posts
    768
    I think codeplug is right, you should... not wait, you must start from the basic C (ansi), before you can you start with windows programming.


    And about the GetDlgItemText()... it should be:

    Code:
    GetDlgItemText(hwnd, IDE_MAIN_POPURL, popUrl, BUFFER_SIZE);
                
    sprintf(total_string, "Url: %s", popUrl);
    SetDlgItemText(hwnd, IDE_MAIN_LINK, total_string);

    Forget what I said and go learn C.
    "I don't suffer from insanity but enjoy every minute of it" - Edgar Allen Poe

    http://www.Bloodware.net - Developing free software for the community.

  10. #10
    * Death to Visual Basic * Devil Panther's Avatar
    Join Date
    Aug 2001
    Posts
    768
    dude you can't just add strings with a plus... either you write your own function to do that, or use ready ones from the given libs... strcat(), sprintf()... etc.

    you're mixing c with other languages.


    and what the hell is string finLink2; ?
    "I don't suffer from insanity but enjoy every minute of it" - Edgar Allen Poe

    http://www.Bloodware.net - Developing free software for the community.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. (Multiline) Edit Control Limit
    By P4R4N01D in forum Windows Programming
    Replies: 9
    Last Post: 05-17-2008, 11:56 AM
  2. need to edit text from within my application.
    By spiroth10 in forum C++ Programming
    Replies: 2
    Last Post: 12-15-2006, 03:15 PM
  3. A bunch of Linker Errors...
    By Junior89 in forum Windows Programming
    Replies: 4
    Last Post: 01-06-2006, 02:59 PM
  4. Edit Text color for specific lines
    By JaWiB in forum Windows Programming
    Replies: 7
    Last Post: 07-08-2004, 03:03 PM
  5. Adding text to a disabled edit box
    By osal in forum Windows Programming
    Replies: 1
    Last Post: 06-16-2004, 01:23 PM