⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fileexportdialog.cpp

📁 AliEditor_Source code
💻 CPP
字号:
//****************************************************************************
// N O L D U S   I N F O R M A T I O N   T E C H N O L O G Y   B . V .
//****************************************************************************
// Filename:      CFileExportDialog.cpp
// Project:       EthoVision
// Module:        Visualization
// Programmer:    Anneke Sicherer-Roetman
// Version:       1.00
// Revision Date: 22-03-1999
//****************************************************************************
// Description:   Definition of class CFileExportDialog
//                See CFileExportDialog.h
//****************************************************************************
// Revision history:
// 22-03-1999 - First implementation
//****************************************************************************
// Bugs: ........
//****************************************************************************
// @doc
//****************************************************************************

#include "stdafx.h"
#include <dlgs.h>
#include "FileExportDialog.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

// helper functions, defined at end
int Split(char *str,char *word[],int max,char c);
char *newdup(const char *str);

IMPLEMENT_DYNAMIC(CFileExportDialog, FILEEXPORTDIALOG_BASECLASS)

//****************************************************************************
// Function CFileExportDialog::CFileExportDialog
// @mfunc   constructor, creates dialog title and filter buffers
// @parm    const CString | &title      | dialog title
// @parm    const CString | &filter     | file filter<nl>
//          The filter MUST be of the form "Word File (*.doc)\|Text File (*.txt)"<nl>
//          .i.e one extension per format and the formats separated by pipes.
// @parm    const CString | &fileName   | initial filename (default "")<nl>
//          The initial filetype is determined from this filename if given.
// @xref    <c CFileExportDialog>
//****************************************************************************
// @prog 
// Anneke Sicherer-Roetman
// @revs 
// 22-03-1999 - First implementation
//****************************************************************************
// @todo 
//****************************************************************************
CFileExportDialog::CFileExportDialog(BOOL bOpenFileDialog, // TRUE for FileOpen, FALSE for FileSaveAs
		LPCTSTR lpszDefExt,
		LPCTSTR lpszFileName,
		DWORD dwFlags,
		LPCTSTR lpszFilter,
		CWnd* pParentWnd) :
		base(bOpenFileDialog, lpszDefExt, lpszFileName, dwFlags, lpszFilter, pParentWnd),
      // if filter is "" (not NULL), an extension is added automatically!
      m_pTitleBuffer(NULL),
      m_pFilterBuffer(NULL),
      m_pFileBuffer(NULL),
      m_CurrentFilterIndex(1)
{
  // set dialog title
 // m_pTitleBuffer = newdup(title);
 // m_ofn.lpstrTitle = m_pTitleBuffer;
  CString filter(lpszFilter);
  CString fileName(lpszFileName);

  // construct filter string for standard file open dialog
  char *tempBuffer = newdup(filter);
  char *word[40]; // maximum of 40 file types
  // split original filter string on pipes
  int n = Split(tempBuffer,word,20,'|');
  char **fptr = new char *[n]; // note: pointers into tempBuffer
  // create new filter string
  m_pFilterBuffer = new char[filter.GetLength()+n*8+1];
  m_pFilterBuffer[0]='\0';
  // fill new filter string
  for (int i = 0; i < n; ++i) {
    // copy format description and add pipe
    strcat(m_pFilterBuffer,word[i]);
    strcat(m_pFilterBuffer,"|");
    // extract filter from format description
    char *part1[2]; 
	int m = Split(word[i],part1,2,'(');
    ASSERT(m == 2);
    char *part2[2]; 
	m = Split(part1[1],part2,2,')');
    ASSERT((m == 1 || m == 2) && !strncmp(part2[0],"*.",2));
    // add filter and add pipe
    strcat(m_pFilterBuffer,part2[0]);
    strcat(m_pFilterBuffer,"|");
    // remember filter for later usage
    fptr[i] = part2[0]+1;
  }
  // replace pipes by nul characters
  int l = strlen(m_pFilterBuffer);
  for (i = 0; i < l; ++i)
    if (m_pFilterBuffer[i] == '|')
      m_pFilterBuffer[i] = '\0';
  // set filter string
  m_ofn.lpstrFilter = m_pFilterBuffer;

  // set default filename in dialog
  m_pFileBuffer = new char[256];
  m_ofn.lpstrFile = m_pFileBuffer;
  m_ofn.nMaxFile = 256;
  if (fileName.IsEmpty()) {
    sprintf(m_pFileBuffer, "*%s",fptr[0]);
  } else {
    strcpy(m_pFileBuffer, fileName);
  }

  // set filter index from default filename
  m_ofn.nFilterIndex = m_CurrentFilterIndex = 1;
  if (fileName.IsEmpty()) {

  } else {
    char *ext = strchr(LPCSTR(fileName),'.');
    if (ext) {
      for (int i = 0; i < n; ++i)
        if (!strcmp(ext, fptr[i])) {
          m_ofn.nFilterIndex = m_CurrentFilterIndex = i + 1; 
          break;
        }
    }
  }

  // free temporary buffers
  delete tempBuffer;
  delete [] fptr;
}

//****************************************************************************
// Function CFileExportDialog::~CFileExportDialog
// @mfunc   destructor, destroys dialog title and filter buffers
// @xref    <c CFileExportDialog>
//****************************************************************************
// @prog 
// Anneke Sicherer-Roetman
// @revs 
// 22-03-1999 - First implementation
//****************************************************************************
// @todo 
//****************************************************************************
CFileExportDialog::~CFileExportDialog()
{
  delete [] m_pTitleBuffer;
  delete [] m_pFilterBuffer;
  delete [] m_pFileBuffer;
}

//****************************************************************************
// Function CFileExportDialog::OnTypeChange
// @mfunc   called when user selects other filetype, changes filename extension
// @rdesc   nothing
// @xref    <c CFileExportDialog>
//****************************************************************************
// @prog 
// Anneke Sicherer-Roetman<nl>
// programmed after Christian Skovdal Andersen<nl>
// http://www.codeguru.com/dialog/cmdlg.shtml
// @revs 
// 22-03-1999 - First implementation
//****************************************************************************
// @todo 
//****************************************************************************
void CFileExportDialog::OnTypeChange()
{
  // get current filename
  CWnd *fileNameBox = GetParent()->GetDlgItem(edt1);
  ASSERT_VALID(fileNameBox);
  CString fileName; fileNameBox->GetWindowText(fileName);

  // get current extension
  CWnd *typeNameBox = GetParent()->GetDlgItem(cmb1);
  ASSERT_VALID(typeNameBox);
  CString typeName; typeNameBox->GetWindowText(typeName);
  char *tempBuffer = newdup(typeName);
  char *ptr[2];
  int n = Split(tempBuffer, ptr, 2, '*');
  ASSERT(n == 2);
  n = Split(ptr[1], ptr, 2, ')');

  ASSERT(n == 1);
  typeName = ptr[0];

  // add or substute new extension in current filename
  if (fileName.IsEmpty()) {
    fileName = "*" + typeName;
  } else {
    int index = fileName.Find('.');
    if (index == -1) {
      fileName = fileName + typeName;
    } else {
      fileName = fileName.Left(index) + typeName;
    }
  }
  fileNameBox->SetWindowText(fileName);

  // get current filter index
  m_CurrentFilterIndex = ((CComboBox *)typeNameBox)->GetCurSel() + 1;

  // free temporary buffer
  delete tempBuffer;
}

//****************************************************************************
// MessageMap:    CFileExportDialog
// Programmer:    Anneke Sicherer-Roetman
// Revision history:
// 22-03-1999 - First implementation
//****************************************************************************
BEGIN_MESSAGE_MAP(CFileExportDialog, base)
	//{{AFX_MSG_MAP(CFileExportDialog)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

//****************************************************************************
// Function Split
// @func    splits string on separators
// @rdesc   number of substrings found (int)
// @parm    char | *str    | source string
// @parm    char | *word[] | pointers to substrings
// @parm    int  | max     | maximum number of substrigs
// @parm    char | c       | separator character
//****************************************************************************
// @prog 
// Anneke Sicherer-Roetman
// @revs 
// 22-03-1999 - First implementation
//****************************************************************************
// @todo 
//****************************************************************************
static int Split(char *str,char *word[],int max,char c)
{
  int n=0; char quote='\0';

  if (!str) return n;
  for (;;) {
    while (*str==c) str++;
    if (!*str || n==max) return n;
    if (!quote && (*str=='"' || *str=='\'')) { quote=*str; str++; }
    word[n++]=str++;
    while (*str && (!quote && *str!=c || quote && *str!=quote)) str++;
    if (quote && *str==quote) { quote='\0'; *str='\0'; str++; }
    if (!*str) return n;
    if (n<max) *str++ ='\0';  /* last word no \0 !!*/
  }
}
//****************************************************************************
// Function newdup
// @func    strdup equivalent that uses new[]
// @rdesc   pointer to new string (char *)
// @parm    const char | *str | original string
//****************************************************************************
// @prog 
// Anneke Sicherer-Roetman
// @revs 
// 29-03-1999 - First implementation
//****************************************************************************
// @todo 
//****************************************************************************
static char *newdup(const char *str)
{
  char *ptr = new char[strlen(str) + 1];
  strcpy(ptr, str);
  return ptr;
}
//****************************************************************************

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -