ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

export.c
Go to the documentation of this file.
00001 /*
00002  * PROJECT:     ReactOS Services
00003  * LICENSE:     GPL - See COPYING in the top level directory
00004  * FILE:        base/system/servman/export.c
00005  * PURPOSE:     Save services to a file
00006  * COPYRIGHT:   Copyright 2006 Ged Murphy <gedmurphy@gmail.com>
00007  *
00008  */
00009 
00010 #include "precomp.h"
00011 
00012 static DWORD
00013 GetTextFromListView(PMAIN_WND_INFO Info,
00014                     TCHAR Text[500],
00015                     INT row,
00016                     INT col)
00017 {
00018     LVITEM item;
00019     DWORD NumChars;
00020 
00021     ZeroMemory(&item, sizeof(item));
00022     item.mask = LVIF_TEXT;
00023     item.iSubItem = col;
00024     item.pszText = Text;
00025     item.cchTextMax = 500;
00026     NumChars = (INT)SendMessage(Info->hListView,
00027                                 LVM_GETITEMTEXT,
00028                                 row,
00029                                 (LPARAM)&item);
00030 
00031     return NumChars;
00032 }
00033 
00034 
00035 static BOOL
00036 SaveServicesToFile(PMAIN_WND_INFO Info,
00037                    LPCTSTR pszFileName)
00038 {
00039     HANDLE hFile;
00040     BOOL bSuccess = FALSE;
00041 
00042     hFile = CreateFile(pszFileName,
00043                        GENERIC_WRITE,
00044                        0,
00045                        NULL,
00046                        CREATE_ALWAYS,
00047                        FILE_ATTRIBUTE_NORMAL,
00048                        NULL);
00049 
00050     if(hFile != INVALID_HANDLE_VALUE)
00051     {
00052         TCHAR LVText[500];
00053         TCHAR newl = _T('\n');
00054         TCHAR tab = _T('\t');
00055         DWORD dwTextLength, dwWritten;
00056         INT NumListedServ = 0;
00057         INT i, k;
00058 
00059         NumListedServ = ListView_GetItemCount(Info->hListView);
00060 
00061         for (i=0; i < NumListedServ; i++)
00062         {
00063             for (k=0; k<5; k++)
00064             {
00065                 dwTextLength = GetTextFromListView(Info,
00066                                                    LVText,
00067                                                    i,
00068                                                    k);
00069                 if (LVText != NULL)
00070                 {
00071                     WriteFile(hFile,
00072                               LVText,
00073                               sizeof(TCHAR) * dwTextLength,
00074                               &dwWritten,
00075                               NULL);
00076 
00077                     WriteFile(hFile,
00078                               &tab,
00079                               sizeof(TCHAR),
00080                               &dwWritten,
00081                               NULL);
00082                 }
00083             }
00084             WriteFile(hFile,
00085                       &newl,
00086                       sizeof(TCHAR),
00087                       &dwWritten,
00088                       NULL);
00089         }
00090 
00091         CloseHandle(hFile);
00092         bSuccess = TRUE;
00093     }
00094 
00095     return bSuccess;
00096 }
00097 
00098 
00099 VOID ExportFile(PMAIN_WND_INFO Info)
00100 {
00101     OPENFILENAME ofn;
00102     TCHAR szFileName[MAX_PATH] = _T("");
00103 
00104     ZeroMemory(&ofn, sizeof(ofn));
00105 
00106     ofn.lStructSize = sizeof(OPENFILENAME);
00107     ofn.hwndOwner = Info->hMainWnd;
00108     ofn.lpstrFilter = _T("Text (Tab Delimited)(*.txt)\0*.txt\0Text (Comma Delimited)(*.csv)\0*.csv\0");
00109     ofn.lpstrFile = szFileName;
00110     ofn.nMaxFile = MAX_PATH;
00111     ofn.lpstrDefExt = _T("txt");
00112     ofn.Flags = OFN_EXPLORER | OFN_PATHMUSTEXIST | OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT;
00113 
00114     if(GetSaveFileName(&ofn))
00115     {
00116         if (SaveServicesToFile(Info, szFileName))
00117             return;
00118     }
00119 
00120     if (CommDlgExtendedError() != CDERR_GENERALCODES)
00121         MessageBox(NULL, _T("Export to file failed"), NULL, 0);
00122 }

Generated on Sat May 26 2012 04:15:54 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.