SelFile.cpp 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. // SelFile.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "ylgl.h"
  5. #include "SelFile.h"
  6. #include "ShowPhoto.h"
  7. #ifdef _DEBUG
  8. #define new DEBUG_NEW
  9. #undef THIS_FILE
  10. static char THIS_FILE[] = __FILE__;
  11. #endif
  12. /////////////////////////////////////////////////////////////////////////////
  13. // SelFile dialog
  14. SelFile::SelFile(CWnd* pParent /*=NULL*/)
  15. : CDialog(SelFile::IDD, pParent)
  16. {
  17. //{{AFX_DATA_INIT(SelFile)
  18. // NOTE: the ClassWizard will add member initialization here
  19. //}}AFX_DATA_INIT
  20. }
  21. void SelFile::DoDataExchange(CDataExchange* pDX)
  22. {
  23. CDialog::DoDataExchange(pDX);
  24. //{{AFX_DATA_MAP(SelFile)
  25. DDX_Control(pDX, IDC_LIST1, m_List1);
  26. //}}AFX_DATA_MAP
  27. }
  28. BEGIN_MESSAGE_MAP(SelFile, CDialog)
  29. //{{AFX_MSG_MAP(SelFile)
  30. ON_LBN_DBLCLK(IDC_LIST1, OnDblclkList1)
  31. //}}AFX_MSG_MAP
  32. END_MESSAGE_MAP()
  33. /////////////////////////////////////////////////////////////////////////////
  34. // SelFile message handlers
  35. BOOL SelFile::OnInitDialog()
  36. {
  37. CDialog::OnInitDialog();
  38. // TODO: Add extra initialization here
  39. CString str;
  40. for(int i=0; i<m_pArray->GetSize (); i++)
  41. {
  42. str=m_pArray->ElementAt (i);
  43. str=str.Right(str.GetLength()-str.ReverseFind('\\')-1);
  44. if(m_List1.GetCount()%2)
  45. m_List1.AddEntry( str , g_gridcol1, m_List1.GetCount());
  46. else
  47. m_List1.AddEntry( str , g_gridcol2, m_List1.GetCount());
  48. }
  49. m_List1.Invalidate ();
  50. return TRUE; // return TRUE unless you set the focus to a control
  51. // EXCEPTION: OCX Property Pages should return FALSE
  52. }
  53. void SelFile::OnOK()
  54. {
  55. // TODO: Add extra validation here
  56. int pos=m_List1.GetCurSel();
  57. if(pos==-1)
  58. {
  59. AfxMessageBox("请先选中您要查看的附件!");return;
  60. }
  61. CString str=m_pArray->ElementAt(pos);
  62. CString ext;
  63. if(str.Find(".")!=-1)
  64. ext=str.Right(str.GetLength()-str.ReverseFind('.')-1);
  65. ext.MakeLower ();
  66. if(0)//ext=="jpg" || ext=="jpeg" || ext=="png" || ext=="gif"|| ext=="bmp")
  67. {
  68. Image *m_pImg=NULL;
  69. ::LoadImageFromBuf (&m_pImg, str);
  70. if(m_pImg==NULL)
  71. {
  72. AfxMessageBox("无效图片文件!");return;
  73. }
  74. ShowPhoto dlg;
  75. dlg.m_pImg=m_pImg;
  76. dlg.DoModal();
  77. delete m_pImg;
  78. }
  79. else
  80. {
  81. ShellExecute(NULL, _T("open"), str, NULL, NULL, SW_SHOWMAXIMIZED);
  82. }
  83. }
  84. void SelFile::OnDblclkList1()
  85. {
  86. // TODO: Add your control notification handler code here
  87. OnOK() ;
  88. }