PreviewFileDlg.cpp
上传用户:alisonmail
上传日期:2013-02-28
资源大小:500k
文件大小:3k
源码类别:

图片显示

开发平台:

Visual C++

  1. /////////////////////////////////////////////////////////////////////////////
  2. // Copyright (C) 1998 by Jorge Lodos
  3. // All rights reserved
  4. //
  5. // Distribute and use freely, except:
  6. // 1. Don't alter or remove this notice.
  7. // 2. Mark the changes you made
  8. //
  9. // Send bug reports, bug fixes, enhancements, requests, etc. to:
  10. //    lodos@cigb.edu.cu
  11. /////////////////////////////////////////////////////////////////////////////
  12. // PreviewFileDlg.cpp : implementation file
  13. //
  14. #include "stdafx.h"
  15. #include "resource.h"
  16. #include "Dib.h"
  17. #include "DibStatic.h"
  18. #include "PreviewFileDlg.h"
  19. #include <dlgs.h>
  20. #ifdef _DEBUG
  21. #define new DEBUG_NEW
  22. #undef THIS_FILE
  23. static char THIS_FILE[] = __FILE__;
  24. #endif
  25. /////////////////////////////////////////////////////////////////////////////
  26. // CPreviewFileDlg
  27. IMPLEMENT_DYNAMIC(CPreviewFileDlg, CFileDialog)
  28. CPreviewFileDlg::CPreviewFileDlg(BOOL bOpenFileDialog, LPCTSTR lpszDefExt, LPCTSTR lpszFileName,
  29. DWORD dwFlags, LPCTSTR lpszFilter, CWnd* pParentWnd) :
  30. CFileDialog(bOpenFileDialog, lpszDefExt, lpszFileName, dwFlags, lpszFilter, pParentWnd)
  31. {
  32. m_ofn.Flags |= (OFN_EXPLORER | OFN_ENABLETEMPLATE);
  33. m_ofn.lpTemplateName = MAKEINTRESOURCE(IDD_FILEOPENPREVIEW);
  34.   m_bPreview = TRUE;
  35. }
  36. BEGIN_MESSAGE_MAP(CPreviewFileDlg, CFileDialog)
  37. //{{AFX_MSG_MAP(CPreviewFileDlg)
  38. ON_BN_CLICKED(IDC_PREVIEW, OnPreview)
  39. ON_WM_QUERYNEWPALETTE()
  40. ON_WM_PALETTECHANGED()
  41. ON_WM_SETFOCUS()
  42. //}}AFX_MSG_MAP
  43. END_MESSAGE_MAP()
  44. BOOL CPreviewFileDlg::OnInitDialog() 
  45. {
  46. CFileDialog::OnInitDialog();
  47. m_DIBStaticCtrl.SubclassDlgItem(IDC_IMAGE, this);
  48. GetDlgItem(IDC_PREVIEW)->SendMessage(BM_SETCHECK, (m_bPreview) ? 1 : 0);
  49. return TRUE;  // return TRUE unless you set the focus to a control
  50.               // EXCEPTION: OCX Property Pages should return FALSE
  51. }
  52. void CPreviewFileDlg::OnFileNameChange() 
  53. {
  54. CFileDialog::OnFileNameChange();
  55. if (m_bPreview)
  56. m_DIBStaticCtrl.LoadDib(GetPathName()); // the control will handle errors
  57. }
  58. void CPreviewFileDlg::OnFolderChange() 
  59. {
  60. CFileDialog::OnFolderChange();
  61. m_DIBStaticCtrl.RemoveDib();
  62. }
  63. void CPreviewFileDlg::OnPreview() 
  64. {
  65. m_bPreview = !m_bPreview;
  66. if (!m_bPreview)
  67. m_DIBStaticCtrl.RemoveDib(); // no preview
  68. else
  69. m_DIBStaticCtrl.LoadDib(GetPathName()); // the control will handle errors
  70. }
  71. BOOL CPreviewFileDlg::OnQueryNewPalette() 
  72. {
  73. m_DIBStaticCtrl.SendMessage(WM_QUERYNEWPALETTE); // redo the palette if necessary
  74. return CFileDialog::OnQueryNewPalette();
  75. }
  76. void CPreviewFileDlg::OnPaletteChanged(CWnd* pFocusWnd) 
  77. {
  78. CFileDialog::OnPaletteChanged(pFocusWnd);
  79. m_DIBStaticCtrl.SendMessage(WM_PALETTECHANGED, (WPARAM)pFocusWnd->GetSafeHwnd()); // redo the palette if necessary
  80. }
  81. void CPreviewFileDlg::OnSetFocus(CWnd* pOldWnd) 
  82. {
  83. CFileDialog::OnSetFocus(pOldWnd);
  84. m_DIBStaticCtrl.SendMessage(WM_QUERYNEWPALETTE); // redo the palette if necessary
  85. }
  86. #ifdef _DEBUG
  87. void CPreviewFileDlg::Dump(CDumpContext& dc) const
  88. {
  89. CFileDialog::Dump(dc);
  90. if (m_bPreview)
  91. dc << "preview is enabledn";
  92. else
  93. dc << "preview is disabledn";
  94. }
  95. #endif //_DEBUG