www.pudn.com > hongmoyuan.rar > GUIYIHUA.cpp


// GUIYIHUA.cpp : implementation file 
// 
 
#include "stdafx.h" 
#include "hongmo.h" 
#include "GUIYIHUA.h" 
#include "Cdib.h" 
 
#ifdef _DEBUG 
#define new DEBUG_NEW 
#undef THIS_FILE 
static char THIS_FILE[] = __FILE__; 
#endif 
 
///////////////////////////////////////////////////////////////////////////// 
// GUIYIHUA dialog 
 
 
GUIYIHUA::GUIYIHUA(CWnd* pParent /*=NULL*/,CDib* pDibShow) 
	: CDialog(GUIYIHUA::IDD, pParent) 
{ 
	//{{AFX_DATA_INIT(GUIYIHUA) 
		// NOTE: the ClassWizard will add member initialization here 
	//}}AFX_DATA_INIT 
	m_pDib = pDibShow; 
	m_bCalImgLoc =	FALSE; 
} 
 
 
void GUIYIHUA::DoDataExchange(CDataExchange* pDX) 
{ 
	CDialog::DoDataExchange(pDX); 
	//{{AFX_DATA_MAP(GUIYIHUA) 
		// NOTE: the ClassWizard will add DDX and DDV calls here 
	//}}AFX_DATA_MAP 
} 
 
 
BEGIN_MESSAGE_MAP(GUIYIHUA, CDialog) 
	//{{AFX_MSG_MAP(GUIYIHUA) 
	ON_WM_PAINT() 
	ON_WM_RBUTTONDBLCLK() 
	//}}AFX_MSG_MAP 
END_MESSAGE_MAP() 
 
///////////////////////////////////////////////////////////////////////////// 
// GUIYIHUA message handlers 
 
void GUIYIHUA::OnPaint()  
{ 
	CPaintDC dc(this); // device context for painting 
	 
	// TODO: Add your message handler code here 
    if(!m_bCalImgLoc) 
	{ 
		CalImgLocation(); 
	} 
	CSize sizeDisplay; 
	CPoint pointDisplay; 
	if(m_pDib != NULL) 
	{ 
		if(!m_pDib->IsEmpty()) 
		{ 
			sizeDisplay.cx=m_pDib->m_lpBMIH->biWidth; 
			sizeDisplay.cy=m_pDib->m_lpBMIH->biHeight; 
			pointDisplay.x = m_rectImage.left; 
			pointDisplay.y = m_rectImage.top; 
			m_pDib->Draw(&dc,pointDisplay,sizeDisplay);	 
		} 
	}	 
	// Do not call CDialog::OnPaint() for painting messages 
} 
 
/************************************************************************* 
 *   函数名称: 
 *   CalImgLocation() 
 *   说明: 
 *   该函数设置对话框中的控件位置和大小,并设置显示图象的位置。默认的图象大 
 *   小为1024×128,如果图象小于此大小,则控件大小设置为1024×128,并将图象 
 *   放置在控件中间。 
 **************************************************************************/ 
void GUIYIHUA::CalImgLocation() 
{ 
	// 获得控件IDC_EDITimg的句柄,并获得控件的初始位置信息 
	CWnd* pWnd=GetDlgItem(IDC_EDITimg); 
	WINDOWPLACEMENT *winPlacement; 
	winPlacement=new WINDOWPLACEMENT; 
	pWnd->GetWindowPlacement(winPlacement); 
 
	// 图象宽度 
	int nImageWidth = 0;	 
	// 图象高度 
	int nImageHeight = 0; 
 
	if(m_pDib != NULL) 
	{ 
		nImageWidth = m_pDib->m_lpBMIH->biWidth; 
		nImageHeight = m_pDib->m_lpBMIH->biHeight; 
	}	 
	// 调整控件IDC_NormalizImg的大小位置 
	if(nImageHeight > 128) 
	{		 
		winPlacement->rcNormalPosition.bottom = winPlacement->rcNormalPosition.top + nImageHeight;	 
		m_rectImage.bottom = winPlacement->rcNormalPosition.bottom; 
		m_rectImage.top    = winPlacement->rcNormalPosition.top;		 
	} 
	else 
	{ 
		winPlacement->rcNormalPosition.bottom = winPlacement->rcNormalPosition.top + 128; 
		m_rectImage.bottom = winPlacement->rcNormalPosition.top + 64 + nImageHeight/2; 
		m_rectImage.top    = winPlacement->rcNormalPosition.top + 64 - nImageHeight/2; 
	} 
	if(nImageWidth > 1024) 
	{ 
		winPlacement->rcNormalPosition.right = winPlacement->rcNormalPosition.left + nImageWidth; 
		m_rectImage.right = winPlacement->rcNormalPosition.right; 
		m_rectImage.left  = winPlacement->rcNormalPosition.left;			 
	} 
	else 
	{ 
		winPlacement->rcNormalPosition.right = winPlacement->rcNormalPosition.left + 1024; 
		m_rectImage.right = winPlacement->rcNormalPosition.left + 512 + nImageWidth/2; 
		m_rectImage.left  = winPlacement->rcNormalPosition.left + 512 - nImageWidth/2; 
	}	 
	// 设置IDC_NormalizImg控件的大小位置 
	pWnd->SetWindowPlacement(winPlacement); 
	 
	m_bCalImgLoc = TRUE; 
	 
	// 释放已分配内存 
	delete winPlacement;	 
} 
 
void GUIYIHUA::OnRButtonDblClk(UINT nFlags, CPoint point)  
{ 
	// TODO: Add your message handler code here and/or call default 
	 
	CDialog::OnRButtonDblClk(nFlags, point); 
}