--- trunk/reactos/base/system/servman/export.c 2006-01-31 19:25:52 UTC (rev 67)
+++ trunk/reactos/base/system/servman/export.c 2006-01-31 20:43:06 UTC (rev 68)
@@ -3,24 +3,64 @@
* LICENSE: GPL - See COPYING in the top level directory
* FILE: base/system/servman/export.c
* PURPOSE: Save services to a file
- * COPYRIGHT: Copyright 2005 Ged Murphy <gedmurphy@gmail.com>
+ * COPYRIGHT: Copyright 2006 Ged Murphy <gedmurphy@gmail.com>
*
*/
#include "servman.h"
+extern HWND hListView;
-BOOL SaveServicesToFile(HWND hListView, LPCTSTR pszFileName)
+
+DWORD GetTextFromListView(TCHAR Text[500], INT row, INT col)
{
+ LVITEM item;
+ DWORD NumChars;
+
+ ZeroMemory(&item, sizeof(item));
+ item.mask = LVIF_TEXT;
+ item.iSubItem = col;
+ item.pszText = Text;
+ item.cchTextMax = 500;
+ NumChars = (INT)SendMessage(hListView, LVM_GETITEMTEXT, row, (LPARAM)&item);
+
+ return NumChars;
+}
+
+
+BOOL SaveServicesToFile(LPCTSTR pszFileName)
+{
HANDLE hFile;
BOOL bSuccess = FALSE;
hFile = CreateFile(pszFileName, GENERIC_WRITE, 0, NULL,
- CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
+ CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
if(hFile != INVALID_HANDLE_VALUE)
{
+ TCHAR LVText[500];
+ TCHAR newl = _T('\n');
+ TCHAR tab = _T('\t');
+ DWORD dwTextLength, dwWritten;
+ INT NumListedServ = 0;
+ INT i, k;
+ NumListedServ = ListView_GetItemCount(hListView);
+
+ for (i=0; i < NumListedServ; i++)
+ {
+ for (k=0; k<5; k++)
+ {
+ dwTextLength = GetTextFromListView(LVText, i, k);
+ if (LVText != NULL)
+ {
+ WriteFile(hFile, LVText, dwTextLength, &dwWritten, NULL);
+ WriteFile(hFile, &tab, 1, &dwWritten, NULL);
+ }
+ }
+ WriteFile(hFile, &newl, 1, &dwWritten, NULL);
+ }
CloseHandle(hFile);
+ bSuccess = TRUE;
}
return bSuccess;
}
@@ -35,7 +75,7 @@
ofn.lStructSize = sizeof(OPENFILENAME);
ofn.hwndOwner = hwnd;
- ofn.lpstrFilter = _T("Text Files (*.txt)\0*.txt\0All Files (*.*)\0*.*\0");
+ ofn.lpstrFilter = _T("Text (Tab Delimited)(*.txt)\0*.txt\0Text (Comma Delimited)(*.csv)\0*.csv\0");
ofn.lpstrFile = szFileName;
ofn.nMaxFile = MAX_PATH;
ofn.lpstrDefExt = _T("txt");
@@ -43,8 +83,11 @@
if(GetSaveFileName(&ofn))
{
- SaveServicesToFile(hwnd, szFileName);
+ if (SaveServicesToFile(szFileName))
+ return;
}
+
+ MessageBox(NULL, _T("Export to file failed"), NULL, 0);
}