Results 1 to 11 of 11

Thread: Textfield...

  1. #1

    Thread Starter
    Frenzied Member CyberCarsten's Avatar
    Join Date
    Sep 1999
    Location
    Aalborg Ø, Denmark
    Posts
    1,544

    Textfield...

    Let's say I have a textfield, a command button and a string.
    How would I transfer the value of the textfield to the string when the button is pressed????
    razor
    Software Engineer Student, Aalborg University, Denmark
    http://www.cs.auc.dk

    My email at AUC: will get a new email soon
    My website: http://www.razorsoftware.net


    Windows XP Pro/ Gentoo Linux (Laptop)
    Windows XP Pro (Home PC)

  2. #2
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Window or Dialogue?
    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

  3. #3
    Frenzied Member Vlatko's Avatar
    Join Date
    Aug 2000
    Location
    Skopje, Macedonia
    Posts
    1,409
    Code:
    long fl  =SendMessage(edithwnd,WM_GETTEXTLENGTH,0,0);
    TCHAR *ft = new TCHAR[++fl];
    SendMessage(edithwnd,WM_GETTEXT,fl,(LPARAM)ft);
    /*ft contains text*/
    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
    If you are using a dialogue then you can use the GetDlgItemText function.

    Also you can use the string class (much easier to manipulate with the string).
    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
    Megatron
    Guest
    Assuming you have the handle:
    Code:
    LPSTR sText;
    DWORD dwLength = GetWindowTextLength(handle);
    sText = (char*)GlobalAlloc(GPTR, dwLength + 1);
    GetWindowText(handle, sText, dwLength + 1);

  6. #6
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Megatron - your code isn't macro-safe You need to use TCHAR. Incidentally, why use GlobalAlloc when new[] gives you type-safety?
    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

  7. #7

    Thread Starter
    Frenzied Member CyberCarsten's Avatar
    Join Date
    Sep 1999
    Location
    Aalborg Ø, Denmark
    Posts
    1,544
    Hi guys!
    It's a dialog...

    I tried out the following code, but windows closed my program......did I do that.....

    Code:
    LPSTR strText;
    				GetDlgItemText(hDlg,Text1, strText, 40);
    				MessageBox(NULL, strText, "Test", MB_OK);
    razor
    Software Engineer Student, Aalborg University, Denmark
    http://www.cs.auc.dk

    My email at AUC: will get a new email soon
    My website: http://www.razorsoftware.net


    Windows XP Pro/ Gentoo Linux (Laptop)
    Windows XP Pro (Home PC)

  8. #8
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    It closed because you didn't allocate a buffer. You need to use TCHAR* and GetTextLength, as posted above. Then, just use:
    Code:
    basic_string<TCHAR> sText = pcBuf; // or whatever it's called
    delete[] pcBuf;
    I normally typedef basic_string<TCHAR> to tstring to make life easier.
    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

  9. #9

    Thread Starter
    Frenzied Member CyberCarsten's Avatar
    Join Date
    Sep 1999
    Location
    Aalborg Ø, Denmark
    Posts
    1,544
    I don't quite get it, parksie.....could you please put together a small example....
    razor
    Software Engineer Student, Aalborg University, Denmark
    http://www.cs.auc.dk

    My email at AUC: will get a new email soon
    My website: http://www.razorsoftware.net


    Windows XP Pro/ Gentoo Linux (Laptop)
    Windows XP Pro (Home PC)

  10. #10
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Catch the button's notification message (see the PSDK for details, look under BN_CLICK ). Then use Vlatko's code, posted above.
    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

  11. #11
    denniswrenn
    Guest
    Here's a DialogProc from a working program. replace IDC_TEXTBOXNAME and IDC_BUTTONNAME with the names of the textbox and the button.

    Code:
    BOOL CALLBACK DialogProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM)
    {
    	HWND edithwnd;
    	TCHAR *ft;
    	switch(uMsg) {
    	case WM_CLOSE:
    		EndDialog(hDlg, 0);
    		break;
    	
    	case WM_INITDIALOG:
    		
    		SetDlgItemText(hDlg, IDC_TEXTBOXNAME, "Text Goes Here");
    		break;
    		
    	case WM_COMMAND:
    		if(wParam == MAKEWPARAM(IDC_BUTTONNAME, BN_CLICKED))
    		{
    			
    			edithwnd = GetDlgItem(hDlg, IDC_TEXTBOXNAME);
    			long fl  =SendMessage(edithwnd,WM_GETTEXTLENGTH,0,0);
    			ft = new TCHAR[++fl];
    			SendMessage(edithwnd,WM_GETTEXT,fl,(LPARAM)ft);
    			MessageBox(hDlg, ft, "Textbox Says...", MB_OK);
    
    		}
    		break;
    		
    	default:
    		return FALSE;
    	}
    
    	return TRUE;
    }

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