-
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
-
GetWindowText
You really should search more, I am 100% sure this has been asked many times before, laziness.
-
Still, taking that into consideration, I don't see how that would help me.
-
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.
-
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.
-
Use GetDlgItemText to get the text of an edit box easily.