DlgFileOpen.cpp 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. /*************************************************************************************************\
  2. DlgFileOpen.cpp : Implementation of the DlgFileOpen component.
  3. //---------------------------------------------------------------------------//
  4. // Copyright (C) Microsoft Corporation. All rights reserved. //
  5. //===========================================================================//
  6. \*************************************************************************************************/
  7. #include "stdafx.h"
  8. #include "DlgFileOpen.h"
  9. #ifndef TOOLOS_HPP
  10. #include "ToolOs.hpp"
  11. #endif
  12. #include "resource.h"
  13. #include <stdlib.h>
  14. #include <string.h>
  15. BEGIN_MESSAGE_MAP(DlgFileOpen,CDialog )
  16. //{{AFX_MSG_MAP(DlgFileOpen)
  17. ON_LBN_SELCHANGE(IDC_FILEOPEN_FILELIST, OnSelchangeFileopenFilelist)
  18. //}}AFX_MSG_MAP
  19. END_MESSAGE_MAP()
  20. //-------------------------------------------------------------------------------------------------
  21. DlgFileOpen::DlgFileOpen( const char* directory, const char* dlgExtension, bool bsave ):CDialog(IDD_FILEOPEN)
  22. {
  23. strcpy(m_directory, directory);
  24. strcpy(fileName, directory);
  25. if (dlgExtension)
  26. {
  27. strcpy(extension, dlgExtension);
  28. }
  29. else
  30. {
  31. strcpy(extension, "");
  32. }
  33. m_bSave = bsave;
  34. }
  35. void DlgFileOpen::Init()
  36. {
  37. CListBox* m_pList = (CListBox *)GetDlgItem(IDC_FILEOPEN_FILELIST);
  38. //Not Used.
  39. //CEdit* m_pEntry = (CEdit*)GetDlgItem(IDC_FILEOPEN_EDITBOX);
  40. char dirBuffer[1024];
  41. strcpy( dirBuffer, m_directory );
  42. strcat( dirBuffer, "*." );
  43. strcat( dirBuffer, extension );
  44. char* pFileFirst = gos_FindFiles( dirBuffer );
  45. while( pFileFirst )
  46. {
  47. m_pList->AddString(pFileFirst);
  48. pFileFirst = gos_FindFilesNext();
  49. }
  50. strcpy( fileName, m_directory );
  51. }
  52. void DlgFileOpen::OnCancel()
  53. {
  54. //EndDialog(IDCANCEL);
  55. EndDialog(IDCANCEL);
  56. }
  57. void DlgFileOpen::OnOK()
  58. {
  59. CEdit* m_pEntry = (CEdit*)GetDlgItem(IDC_FILEOPEN_EDITBOX);
  60. char pszEntryString[1024/*MAX_STRING_LENGTH*/];
  61. m_pEntry->GetWindowText(pszEntryString, 1024/*MAX_STRING_LENGTH*/);
  62. strcat(fileName, pszEntryString);
  63. char tmpExtension[32];
  64. tmpExtension[0] = '.';
  65. tmpExtension[1] = 0;
  66. strcat( tmpExtension, extension );
  67. if ( !fileName || (strlen( fileName ) < 4 ||
  68. 0 != stricmp( tmpExtension, fileName + strlen( fileName ) - 4 )) )
  69. {
  70. strcat( fileName, "." );
  71. strcat( fileName, extension );
  72. }
  73. CDialog::OnOK();
  74. }
  75. //-------------------------------------------------------------------------------------------------
  76. DlgFileOpen::~DlgFileOpen()
  77. {
  78. }
  79. //*************************************************************************************************
  80. // end of file ( DlgFileOpen.cpp )
  81. BOOL DlgFileOpen::OnInitDialog()
  82. {
  83. CDialog ::OnInitDialog();
  84. Init();
  85. return TRUE; // return TRUE unless you set the focus to a control
  86. // EXCEPTION: OCX Property Pages should return FALSE
  87. }
  88. void DlgFileOpen::OnSelchangeFileopenFilelist()
  89. {
  90. CListBox* m_pList = (CListBox *)GetDlgItem(IDC_FILEOPEN_FILELIST);
  91. gosASSERT( m_pList );
  92. int nSelectionIndex = m_pList->GetCurSel();
  93. int nStringLength = m_pList->GetTextLen(nSelectionIndex);
  94. if (0 < nStringLength)
  95. {
  96. char *pszSelectionString = new char[nStringLength + 1];
  97. m_pList->GetText(nSelectionIndex, pszSelectionString);
  98. CEdit* m_pEntry = (CEdit*)GetDlgItem(IDC_FILEOPEN_EDITBOX);
  99. m_pEntry->SetWindowText(pszSelectionString);
  100. delete pszSelectionString;
  101. }
  102. }