www.pudn.com > CEimage.zip > imageDlg.cpp


// imageDlg.cpp : implementation file 
// 
 
// 
// Created by Douglas H Williams. 
// Waterloo, Ontario, Canada 
// 
 
#include "stdafx.h" 
#include "image.h" 
#include "imageDlg.h" 
#include "voimage.h" 
// #include "WinBase.h" 
 
#ifdef _DEBUG 
#define new DEBUG_NEW 
#undef THIS_FILE 
static char THIS_FILE[] = __FILE__; 
#endif 
 
///////////////////////////////////////////////////////////////////////////// 
// CImageDlg dialog 
 
CImageDlg::CImageDlg(CWnd* pParent /*=NULL*/) 
	: CDialog(CImageDlg::IDD, pParent) 
{ 
	//{{AFX_DATA_INIT(CImageDlg) 
	//}}AFX_DATA_INIT 
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32 
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); 
} 
 
void CImageDlg::DoDataExchange(CDataExchange* pDX) 
{ 
	CDialog::DoDataExchange(pDX); 
	//{{AFX_DATA_MAP(CImageDlg) 
	DDX_Control(pDX, IDC_CURRENT_SCALE, m_edit_scale); 
	DDX_Control(pDX, IDC_SLIDER1, m_scale); 
	DDX_Control(pDX, IDC_PICTURE, m_picture_window); 
	DDX_Control(pDX, IDC_COMBO1, m_combo1); 
	DDX_Control(pDX, IDC_CHECK_STRETCH, m_stretch_image); 
	DDX_Control(pDX, IDC_LIST1, m_people_list); 
	//}}AFX_DATA_MAP 
} 
 
BEGIN_MESSAGE_MAP(CImageDlg, CDialog) 
	//{{AFX_MSG_MAP(CImageDlg) 
	ON_BN_CLICKED(IDC_BUTTON1, OnButton1) 
	ON_WM_VSCROLL() 
	ON_CBN_SELCHANGE(IDC_COMBO1, OnSelchangeCombo1) 
	ON_WM_KEYUP() 
	ON_BN_CLICKED(IDC_CHECK_STRETCH, OnCheckStretch) 
	ON_WM_HSCROLL() 
	//}}AFX_MSG_MAP 
END_MESSAGE_MAP() 
 
///////////////////////////////////////////////////////////////////////////// 
// CImageDlg message handlers 
 
BOOL CImageDlg::OnInitDialog() 
{ 
	CDialog::OnInitDialog(); 
 
	// Set the icon for this dialog.  The framework does this automatically 
	//  when the application's main window is not a dialog 
	SetIcon(m_hIcon, TRUE);			// Set big icon 
	SetIcon(m_hIcon, FALSE);		// Set small icon 
	 
	CenterWindow(GetDesktopWindow());	// center to the hpc screen 
 
	CVOImage image; 
   RECT pic_rect; 
   m_picture_window.GetWindowRect(&pic_rect); 
    
    
   _WIN32_FIND_DATAW *FindFileDataStruct = new _WIN32_FIND_DATAW; 
 
   HDC picDC = ::GetDC(m_picture_window.m_hWnd ); 
 
   // 
   // find all the files in '\My Documents\album\' and put them in the list 
   // 
    
   HANDLE search_handle = ::FindFirstFile((LPCTSTR)_T("\\My Documents\\album\\*.*"), FindFileDataStruct);  
   if( search_handle == INVALID_HANDLE_VALUE ) 
   { 
      m_combo1.AddString( (LPCTSTR) _T("No Files Found"));   
   }else{ 
      m_combo1.AddString( (LPCTSTR) FindFileDataStruct->cFileName); 
   } 
       
   while ( ::FindNextFile (search_handle, FindFileDataStruct)  != 0 ) 
   { 
	   m_combo1.AddString( (LPCTSTR) FindFileDataStruct->cFileName); 
   } 
    
   // 
   // Show first in list 
   // 
 
   m_combo1.SetCurSel(0); 
 
   // 
   // close the search handle and clean up 
   // 
 
   ::FindClose ( search_handle); 
   delete FindFileDataStruct; 
 
   // 
   // Set the slider range 
   // 
 
   m_scale.SetRange(1,10); 
   m_scale.SetPos(10); 
 
   	 
	return TRUE;  // return TRUE  unless you set the focus to a control 
} 
 
 
 
void CImageDlg::OnButton1()  
{ 
 
} 
 
 
void CImageDlg::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)  
{ 
 
	CDialog::OnVScroll(nSBCode, nPos, pScrollBar); 
} 
 
 
void CImageDlg::OnSelchangeCombo1()  
{ 
  
   CVOImage image; 
   RECT pic_rect; 
   m_picture_window.GetWindowRect(&pic_rect); 
   HDC picDC = ::GetDC(m_picture_window.m_hWnd ); 
 
   // 
   // Show the selected picture 
   // 
    
   CString path = _T("\\My Documents\\album\\");  
   CString image_name = ""; 
   m_combo1.GetLBText( m_combo1.GetCurSel(), image_name); 
    
   CString path_fname = path + image_name; 
 
   //  
   // Load the image 
   // 
 
   image.Load (picDC ,path_fname );    
 
   if( this->m_stretch_image.GetCheck() == BST_CHECKED) 
   { 
      // 
      // If you want to maintain the aspect ratio then modify this ! 
      // 
 
      image.Draw (picDC ,10,10, pic_rect.bottom -  pic_rect.top, pic_rect.right - pic_rect.left - 10);  
 
   }else{ 
 
      image.Draw (picDC ,10,10 );  
   } 
  
   // 
	// Releae the DC; 
   // 
 
   ::ReleaseDC( m_picture_window.m_hWnd, picDC); 
	 
} 
 
void CImageDlg::OnKeyUp(UINT nChar, UINT nRepCnt, UINT nFlags)  
{	 
	CDialog::OnKeyUp(nChar, nRepCnt, nFlags); 
} 
 
BOOL CImageDlg::OnCommand(WPARAM wParam, LPARAM lParam)  
{ 
 
	return CDialog::OnCommand(wParam, lParam); 
} 
 
void CImageDlg::OnCheckStretch()  
{ 
   CVOImage image; 
   RECT pic_rect; 
   m_picture_window.GetWindowRect(&pic_rect); 
   HDC picDC = ::GetDC(m_picture_window.m_hWnd ); 
 
   // 
   // Show the selected picture 
   // 
    
   CString path = _T("\\My Documents\\album\\");  
   CString image_name = ""; 
   m_combo1.GetLBText( m_combo1.GetCurSel(), image_name); 
    
   CString path_fname = path + image_name; 
 
   // m_picture_window.SetWindowText(image_name); 
    
   image.Load (picDC ,path_fname );    
 
   if( this->m_stretch_image.GetCheck() == BST_CHECKED) 
   { 
      image.Draw (picDC ,10,10, pic_rect.bottom -  pic_rect.top, pic_rect.right - pic_rect.left - 10 );  
   }else{ 
      image.Draw (picDC ,10,10 );  
   } 
  
   // 
	// Releae the DC; 
   // 
 
   ::ReleaseDC( m_picture_window.m_hWnd, picDC);	 
} 
 
void CImageDlg::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)  
{ 
 
   // 
   // Set the scale and re display the picture.  
   // 
      
   if( pScrollBar->m_hWnd == this->m_scale.m_hWnd) // Ensure the correct scroll bar 
   { 
 
      int curpos = this->m_scale.GetPos(); 
      int cur_scale = (int) curpos * 10; 
 
      // 
      // Made CVOImage::g_iScale public -> I should keep private and create set\get (limited time). 
      // Set the scale on  
 
      CVOImage::g_iScale = cur_scale; 
      char s_scale[16]; 
 
      sprintf(s_scale, "%d", cur_scale); 
      m_edit_scale.SetWindowText((CString)s_scale); 
 
      CVOImage image; 
      RECT pic_rect; 
       
      // 
      // The display window RECT 
      // 
 
      m_picture_window.GetWindowRect(&pic_rect); 
 
      // 
      // The HDC of the display window 
      // 
 
      HDC picDC = ::GetDC(m_picture_window.m_hWnd ); 
 
      // 
      // Show the selected picture 
      // 
 
      CString path = _T("\\My Documents\\album\\");  
      CString image_name = ""; 
      m_combo1.GetLBText( m_combo1.GetCurSel(), image_name); 
 
      CString path_fname = path + image_name; 
 
      image.Load (picDC ,path_fname );    
 
      if( this->m_stretch_image.GetCheck() == BST_CHECKED) 
      { 
         image.Draw (picDC ,10,10, pic_rect.bottom -  pic_rect.top, pic_rect.right - pic_rect.left - 10);  
      }else{ 
         image.Draw (picDC ,10,10 );  
      } 
 
      // 
      // Releae the DC; 
      // 
 
      ::ReleaseDC( m_picture_window.m_hWnd, picDC);	 
   } 
 
	CDialog::OnHScroll(nSBCode, nPos, pScrollBar); 
}