Thread: Saving EditBox text

  1. #1
    Registered User Queatrix's Avatar
    Join Date
    Apr 2005
    Posts
    1,342

    Exclamation Saving EditBox text

    Okay, I have this script:
    Code:
    HFONT hfDefault;
    HWND hEdit;   
    hEdit = CreateWindowEx(WS_EX_CLIENTEDGE, "EDIT", " ", 
    WS_CHILD | WS_VISIBLE | WS_VSCROLL | ES_MULTILINE | ES_AUTOVSCROLL, 2, 2, 285, 196, hwnd, (HMENU)IDC_MAIN_EDIT, GetModuleHandle(NULL), NULL);
    if(hEdit == NULL)
    MessageBox(hwnd, "EditBox Creation Failed.", "Error", MB_OK | MB_ICONERROR);
    And this:
    Code:
     HANDLE hFile1=CreateFile("data.txt", GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
    DWORD dwBytes1;
    if (hFile1!=INVALID_HANDLE_VALUE)
    {
       WriteFile(hFile1, "blabla", 6, &dwBytes1, NULL);
       CloseHandle(hFile1);
    }
    else {
       MessageBox(NULL, "File Saveing Failed.", "Title", MB_OK | MB_ICONERROR); }
    Is there a way that can use these scripts to save the data that a user typed in the EditBox to data.txt file?

    Thanks, August

  2. #2
    Registered User r1ck0r's Avatar
    Join Date
    Apr 2005
    Location
    UK
    Posts
    30
    GetWindowText

    You really should search more, I am 100% sure this has been asked many times before, laziness.
    Last edited by r1ck0r; 04-25-2005 at 11:00 AM.

  3. #3
    Registered User Queatrix's Avatar
    Join Date
    Apr 2005
    Posts
    1,342
    Still, taking that into consideration, I don't see how that would help me.

  4. #4
    Registered User
    Join Date
    Aug 2004
    Location
    San Diego, CA
    Posts
    313
    Code:
    OPENFILENAME ofn;
    	ZeroMemory(&ofn, sizeof(ofn));
    	
    	ofn.lStructSize = sizeof(ofn);
    	ofn.hwndOwner = hWnd;
    	ofn.lpstrFilter = "HTML Files (*.html)\0*.html\0C++ Files (*.cpp)\0*.cpp\0All Files (*.*)\0*.*\0"; // A mask for .html, .cpp, and then all possible files.
    	ofn.lpstrFile = FileName;
    	ofn.nMaxFile = MAX_PATH;
    	ofn.Flags = OFN_EXPLORER | OFN_PATHMUSTEXIST | OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT;
    	ofn.lpstrDefExt = "html"; // Default extention is .html.
    
    if(GetSaveFileName(&ofn))
    {
    	DWORD Written;
    	HANDLE hFile;
    	hFile = CreateFile(FileName, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
    	
    	int length = GetWindowTextLength(GetDlgItem(hWnd, ID_EDIT));
    	char *temp = new char[length+1];
    	
    	GetDlgItemText(hWnd, ID_EDIT, temp, length+1);
    	
    	WriteFile(hFile, temp, length, &Written, NULL);
    	
    	CloseHandle(hFile);
    	
    	delete [] temp;
    }
    That's how I save files from an edit box. Replace ID_EDIT and such with your own identifiers, and set the mask to whatever files you want (by default) to be available.

  5. #5
    Work in Progress..... Jaken Veina's Avatar
    Join Date
    Mar 2005
    Location
    Missouri. Go Imos Pizza!
    Posts
    256
    If you still don't get it, look around a bit at www.winprog.org/tutorial and a tutorial doing this exact thing. It explains the process very well.

  6. #6
    Yah. Morgul's Avatar
    Join Date
    Feb 2005
    Posts
    109
    Use GetDlgItemText to get the text of an edit box easily.
    Sic vis pacum para bellum. If you want peace, prepare for war.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Highlighting text in an EditBox
    By @nthony in forum Windows Programming
    Replies: 5
    Last Post: 01-17-2007, 10:16 PM
  2. Replies: 3
    Last Post: 05-25-2005, 01:50 PM
  3. Removing text between /* */ in a file
    By 0rion in forum C Programming
    Replies: 2
    Last Post: 04-05-2004, 08:54 AM
  4. Ok, Structs, I need help I am not familiar with them
    By incognito in forum C++ Programming
    Replies: 7
    Last Post: 06-29-2002, 09:45 PM
  5. Saving and Importing text files
    By ColdFire in forum Windows Programming
    Replies: 4
    Last Post: 06-17-2002, 08:32 AM