Results 1 to 17 of 17

Thread: textbox -> string

  1. #1

    Thread Starter
    Addicted Member cwm's Avatar
    Join Date
    Mar 2000
    Posts
    133

    textbox -> string

    man,vc++ is no fun =(

    how do i take the text from an 'edit box' and put it into a string?

    i'm basically trying to copy the contents of a text box to the clipboard...

    please tell me everything i'll need to do including the include files

  2. #2
    Frenzied Member Vlatko's Avatar
    Join Date
    Aug 2000
    Location
    Skopje, Macedonia
    Posts
    1,409
    If you are using a dialog then:
    Code:
    char *buffer = new char[255];
    GetDlgItemText(hwndofdialog,IDI_EDIT1,buffer,255];
    if you are not using a dialog:
    Code:
    char *buffer = new char[255];
    GetWindowText(hwndofedit,buffer,255);
    You can also send the WM_GETTEXT message (it also retrieves asteriks (passswords)).
    I am become death, the destroyer of worlds.
    mail:[email protected]

    • Visual Basic 6.0 & .NET
    • Visual C++ 6.0 & .NET
    • ASP
    • LISP
    • PROLOG
    • C
    • Pascal

  3. #3
    Frenzied Member Vlatko's Avatar
    Join Date
    Aug 2000
    Location
    Skopje, Macedonia
    Posts
    1,409
    To place the text to the clipboard use the
    Code:
    SetClipboardData
    The SetClipboardData function places data on the clipboard in a specified clipboard format. The window must be the current clipboard owner, and the application must have called the OpenClipboard function. (When responding to the WM_RENDERFORMAT and WM_RENDERALLFORMATS messages, the clipboard owner must not call OpenClipboard before calling SetClipboardData.) 
    
    HANDLE SetClipboardData(
      UINT uFormat, // clipboard format
      HANDLE hMem   // data handle
    );
     
    Parameters
    uFormat 
    Specifies a clipboard format. This parameter can be a registered format or any of the standard clipboard formats. For more information, see Registered Clipboard Formats and Standard Clipboard Formats. 
    hMem 
    Handle to the data in the specified format. This parameter can be NULL, indicating that the window provides data in the specified clipboard format (renders the format) upon request. If a window delays rendering, it must process the WM_RENDERFORMAT and WM_RENDERALLFORMATS messages. 
    After SetClipboardData is called, the system owns the object identified by the hMem parameter. The application can read the data, but must not free the handle or leave it locked. If the hMem parameter identifies a memory object, the object must have been allocated using the GlobalAlloc function with the GMEM_MOVEABLE and GMEM_DDESHARE flags. 
    
    Return Values
    If the function succeeds, the return value is the handle of the data.
    
    If the function fails, the return value is NULL. To get extended error information, call GetLastError. 
    
    Remarks
    The uFormat parameter can identify a registered clipboard format, or it can be one of the standard clipboard formats. For more information, see Registered Clipboard Formats and Standard Clipboard Formats. 
    
    The system performs implicit data format conversions between certain clipboard formats when an application calls the GetClipboardData function. For example, if the CF_OEMTEXT format is on the clipboard, a window can retrieve data in the CF_TEXT format. The format on the clipboard is converted to the requested format on demand. For more information, see Synthesized Clipboard Formats. 
    
    Windows CE: The data to be set into the clipboard should be allocated using the LocalAlloc function. 
    
    Windows CE does not support the following uFormat values: 
    
    CF_GDIOBJFIRST through CF_GDIOBJLAST 
    
    CF_DSPBITMAP 
    
    CF_DSPENHMETAFILE 
    
    CF_DSPMETAFILEPICT 
    
    CF_DSPTEXT 
    
    CF_HDROP 
    
    CF_LOCALE 
    
    CF_OWNERDISPLAY 
    
    CF_PRIVATEFIRST through CF_PRIVATELAST
    I am become death, the destroyer of worlds.
    mail:[email protected]

    • Visual Basic 6.0 & .NET
    • Visual C++ 6.0 & .NET
    • ASP
    • LISP
    • PROLOG
    • C
    • Pascal

  4. #4
    Frenzied Member Vlatko's Avatar
    Join Date
    Aug 2000
    Location
    Skopje, Macedonia
    Posts
    1,409
    No, the limit cna be other than 255. To get the whole text use:
    Code:
    long textlen = SendMessage(edithwnd,WM_GETTEXTLENGTH,0,0);
    TCHAR *buffer = new TCHAR[textlen+1];
    SendMessage(edithwnd,WM_GETTEXT,textlen,(LPARAM)buffer);
    //now buffer contains the whole text that is in the edit box
    I am become death, the destroyer of worlds.
    mail:[email protected]

    • Visual Basic 6.0 & .NET
    • Visual C++ 6.0 & .NET
    • ASP
    • LISP
    • PROLOG
    • C
    • Pascal

  5. #5

    Thread Starter
    Addicted Member cwm's Avatar
    Join Date
    Mar 2000
    Posts
    133
    hmm
    error C2065: 'edithwnd' : undeclared identifier
    Generic vb 5

    Private Sub WakeMyAssUp( As Boolean)
    If Then : = False
    End Sub

  6. #6

    Thread Starter
    Addicted Member cwm's Avatar
    Join Date
    Mar 2000
    Posts
    133
    looks like you use hwnds a lot up there but you don't tell me how to get them

  7. #7
    Frenzied Member Technocrat's Avatar
    Join Date
    Jan 2000
    Location
    I live in the 1s and 0s of everyones data streams
    Posts
    1,024
    If you make the editbox yourself with APIs, your CreateWindow, or CreateWindowEX will return the hWnd for the edit box.
    MSVS 6, .NET & .NET 2003 Pro
    I HATE MSDN with .NET & .NET 2003!!!

    Check out my sites:
    http://www.filthyhands.com
    http://www.techno-coding.com


  8. #8

    Thread Starter
    Addicted Member cwm's Avatar
    Join Date
    Mar 2000
    Posts
    133
    k, so how do i make it myself with apis

  9. #9
    Frenzied Member Technocrat's Avatar
    Join Date
    Jan 2000
    Location
    I live in the 1s and 0s of everyones data streams
    Posts
    1,024
    You can do it with Dialogs also. How do you have it right now? Some code would help.
    MSVS 6, .NET & .NET 2003 Pro
    I HATE MSDN with .NET & .NET 2003!!!

    Check out my sites:
    http://www.filthyhands.com
    http://www.techno-coding.com


  10. #10

    Thread Starter
    Addicted Member cwm's Avatar
    Join Date
    Mar 2000
    Posts
    133
    ya, some code would help, care to offer some?

    i just have an edit box, clicked the lil edit box thing, then drew it,
    the end
    can you zip a sample project that just has an edit box and
    changes the contents then puts the contents into a string then
    displays the string in a message box?

    sucks going from being able to code vb in my sleep, to being
    more lost than i was when i first taught myself qbasic =\
    Generic vb 5

    Private Sub WakeMyAssUp( As Boolean)
    If Then : = False
    End Sub

  11. #11
    Frenzied Member Technocrat's Avatar
    Join Date
    Jan 2000
    Location
    I live in the 1s and 0s of everyones data streams
    Posts
    1,024
    I meant code from you would help

    I am guessing by your response you are trying to apply VB ideas to a VC++ project and you cant really do that.

    First thing first, how familure are you just plan C/C++?
    If your answer is your not then you need to learn that stuff first. Becuase your are going to drown in the Visual side if you dont understand classess, pointers, and other basic C/C++ functions. You need to start with console (DOS) apps first then move up.

    If you are familure with C/C++ then you should try to break yourself from using the Dialog creation tools and MFC until you learn how to do that stuff using API and manualy doing everything by hand. Its a pain at first but you learn how everything works a lot better that way. Then you can move on to MFC and using the Dialog creation tools.

    If you are lucky Vlatko or parksie will come a long and give you their links (You might try the FAQ) to their info

    If you have done all the above and you just needed info on how to get info from an edit box on a Dialog box I can help you, if thats what you need.

    Get used to being slapped down by VC++. I used to be a GOD when it came to VB, then I move to VC++ an now I feel like a bug. Its hard work to learn VC++, and no where close to as easy as VB.
    MSVS 6, .NET & .NET 2003 Pro
    I HATE MSDN with .NET & .NET 2003!!!

    Check out my sites:
    http://www.filthyhands.com
    http://www.techno-coding.com


  12. #12

    Thread Starter
    Addicted Member cwm's Avatar
    Join Date
    Mar 2000
    Posts
    133
    blablabla, can you zip a sample project that does the things i
    asked for above or no?
    all i want to do is make one program, i have no books and no
    classes teach it here, i'd rather learn it like i've learned all the
    other languages i know

  13. #13
    Frenzied Member Technocrat's Avatar
    Join Date
    Jan 2000
    Location
    I live in the 1s and 0s of everyones data streams
    Posts
    1,024
    Fine be that way. Dont say I did not warn you.
    No I dont have anything I can give you.
    MSVS 6, .NET & .NET 2003 Pro
    I HATE MSDN with .NET & .NET 2003!!!

    Check out my sites:
    http://www.filthyhands.com
    http://www.techno-coding.com


  14. #14
    Frenzied Member Vlatko's Avatar
    Join Date
    Aug 2000
    Location
    Skopje, Macedonia
    Posts
    1,409
    [code]
    cwm i see that you are asking how to make an edit box with API. How did you make this one. I assume you are using MFC.(did you draw the edit box on the form). When using MFC you assign a variable to each control. (in the classwizard). In that case to get the text just use the variable (m_eVar (variable) contains the text).

    For your other question to get the hwnd use the FindWindow API.
    Code:
    HWND handle = FindWindow(classname,caption)
    Here is an example of MFC:
    I am become death, the destroyer of worlds.
    mail:[email protected]

    • Visual Basic 6.0 & .NET
    • Visual C++ 6.0 & .NET
    • ASP
    • LISP
    • PROLOG
    • C
    • Pascal

  15. #15
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    People, play nicely. I assume that if he wants to learn he's not going to use MFC

    http://www.parksie.net/Raw.zip
    http://www.parksie.net/RawDlg.zip

    Those assume the Platform SDK headers are installed, so otherwise change LONG_PTR to LRESULT, and INT_PTR to int.
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  16. #16

    Thread Starter
    Addicted Member cwm's Avatar
    Join Date
    Mar 2000
    Posts
    133
    o_O

    is it me or did neither of those two zips you just posted even have a text box?

  17. #17
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Bugger it, you're right. Ooops...I think they're a different version to the one I had before, probably because someone complained it was too complicated/useful (despite excessive comments).

    Okay, originally when you pressed the button it displayed the editbox's contents in a message box.
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width