BitmapPage.cpp 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. // CBitmapPage.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "resource.h"
  5. #include "bitmappage.h"
  6. #ifdef _DEBUG
  7. #define new DEBUG_NEW
  8. #undef THIS_FILE
  9. static char THIS_FILE[] = __FILE__;
  10. #endif
  11. /////////////////////////////////////////////////////////////////////////////
  12. // CBitmapPage property page
  13. IMPLEMENT_DYNCREATE(CBitmapPage, CPropertyPage)
  14. CBitmapPage::CBitmapPage() : CPropertyPage(CBitmapPage::IDD)
  15. {
  16. //{{AFX_DATA_INIT(CBitmapPage)
  17. m_strDynFile = _T("");
  18. m_strStaticFile = _T("");
  19. m_bStretch = FALSE;
  20. m_bDyn = FALSE;
  21. m_strDynCondition = _T("");
  22. //}}AFX_DATA_INIT
  23. }
  24. CBitmapPage::~CBitmapPage()
  25. {
  26. }
  27. void CBitmapPage::DoDataExchange(CDataExchange* pDX)
  28. {
  29. CPropertyPage::DoDataExchange(pDX);
  30. //{{AFX_DATA_MAP(CBitmapPage)
  31. DDX_Text(pDX, ID_DYNPIC, m_strDynFile);
  32. DDX_Text(pDX, ID_STATICPIC, m_strStaticFile);
  33. DDX_Check(pDX, ID_STRETCH, m_bStretch);
  34. DDX_Check(pDX, IDC_DYNAMIC, m_bDyn);
  35. DDX_Text(pDX, IDC_DYNCONDITION, m_strDynCondition);
  36. //}}AFX_DATA_MAP
  37. }
  38. BEGIN_MESSAGE_MAP(CBitmapPage, CPropertyPage)
  39. //{{AFX_MSG_MAP(CBitmapPage)
  40. ON_BN_CLICKED(ID_SELSTATIC, OnSelstatic)
  41. ON_BN_CLICKED(ID_SELDYN, OnSeldyn)
  42. //}}AFX_MSG_MAP
  43. END_MESSAGE_MAP()
  44. /////////////////////////////////////////////////////////////////////////////
  45. // CBitmapPage message handlers
  46. BOOL CBitmapPage::OnInitDialog()
  47. {
  48. CPropertyPage::OnInitDialog();
  49. // TODO: Add extra initialization here
  50. UpdateData(FALSE);
  51. return TRUE; // return TRUE unless you set the focus to a control
  52. // EXCEPTION: OCX Property Pages should return FALSE
  53. }
  54. void CBitmapPage::SelectFile(CString& strFileName)
  55. {
  56. UpdateData(TRUE);
  57. DWORD dwFlags = OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT;
  58. if(strFileName.IsEmpty()) strFileName = "bitmap\\home.bmp";
  59. LPSTR lpszFile = (char*)(const char*)strFileName;
  60. LPSTR lpszFilter = (char *)(LPCTSTR)g_strPictureFile1;
  61. //LPSTR lpszFilter = "BMP files (*.bmp)|*.bmp|PNG Files (*.png)|*.png|JPG Files (*.jpg)|*.jpg|GIF Files (*.gif)|*.gif||";
  62. //"BMP file (*.bmp)|*.bmp|PNG Files (*.png)|*.png|JPG Files (*.jpg)|*.jpg)||";
  63. //"Picture file(*.png;*.bmp)|*.png;*.bmp|BMP(*.BMP)|*.BMP||"
  64. int INDEX=0;
  65. CString sTemp1=strFileName;
  66. sTemp1 = sTemp1.MakeLower();
  67. if( -1!=sTemp1.Find( ".bmp" ) )
  68. INDEX = 1;
  69. else if( -1!=sTemp1.Find( ".png" ) )
  70. INDEX = 2;
  71. else if( -1!=sTemp1.Find( ".gif" ) )
  72. INDEX = 4;
  73. else if( -1!=sTemp1.Find( ".jpg" ) )
  74. INDEX = 3;
  75. CFileDialog dlg(TRUE,NULL,lpszFile,dwFlags,lpszFilter);
  76. dlg.m_pOFN->nFilterIndex = INDEX;
  77. if(dlg.DoModal()==IDOK)
  78. {
  79. strFileName = dlg.GetFileName();
  80. UpdateData(FALSE);
  81. }
  82. }
  83. void CBitmapPage::OnSelstatic()
  84. {
  85. SelectFile(m_strStaticFile);
  86. }
  87. void CBitmapPage::OnSeldyn()
  88. {
  89. SelectFile(m_strDynFile);
  90. }