class CBigImageDlg : public CDialog
{
public:
	CBigImageDlg(CWnd* pParent /*=NULL*/);
	virtual ~CBigImageDlg();

// 对话框数据
	enum { IDD = IDD_BIG_IMAGE_DLG };

protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV 支持
	DECLARE_MESSAGE_MAP()
public:
	afx_msg void OnPaint();
	afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
	afx_msg void OnLButtonUp(UINT nFlags, CPoint point);
	afx_msg void OnMouseMove(UINT nFlags, CPoint point);
	afx_msg void OnRButtonDown(UINT nFlags, CPoint point);
	afx_msg void OnRButtonUp(UINT nFlags, CPoint point);
	afx_msg void OnLButtonDblClk(UINT nFlags, CPoint point);
	afx_msg void PostNcDestroy();
	afx_msg void PreSubclassWindow();
	afx_msg BOOL PreCreateWindow(CREATESTRUCT& cs);

private:
	// 将视图类的变量转化为此类的
	CMainFrame* pframe;
	CMDIChildWnd* pChildWnd;
	CBsqViewView* pView;

	float AverageGrey[240];
	int Bands;
	int Width;
	int Height;
	CString m_pathname;
	int HBig;

	int workmode;
	BOOL m_ldraw;
	BOOL m_rdraw;
	BOOL firstmouse_l;
	BOOL firstmouse_r;
	int Areas;
	BOOL AreasBool[40];
	BOOL bChooseAreas;
	BOOL bOpenProfileDlg;
	BOOL m_display;

	CPoint* AreaPoint1;
	int AreaPoints1;

	// 新增加的一个变量
	int OriginBoderPoint[100000][100];
	int BoderPoints[100000];
	COLORREF Color[40];
};

// CBigImageDlg 的构造函数

CBigImageDlg::CBigImageDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CBigImageDlg::IDD, pParent)
{
	//将视图类的变量转化为此类的
	pframe = (CMainFrame *)AfxGetApp()->GetMainWnd();
	pChildWnd = pframe->MDIGetActive();
	pView = (CBsqViewView *) pChildWnd->GetActiveView();
	
    memset(AverageGrey,0x00,sizeof(float)*240);
	//定义初始值
	Bands=pView->Bands;
	Width=pView->Width;
	Height=pView->Height;
	m_pathname=pView->m_pathname;
	HBig=pView->HBig;
	
	workmode=CommonMode;
	m_ldraw=FALSE;
	m_rdraw=FALSE;
	firstmouse_l=TRUE;
	firstmouse_r=TRUE;
	Areas=0;  
	
	//新增加的一个变量
	
	for(int i=1;i<40;i++)
	{
		AreasBool[i]=true;
	}
	
	bChooseAreas = false;
	bOpenProfileDlg = FALSE;
	m_display=true;
	
	//定义存放所有点坐标
	AreaPoint1= new CPoint[200000];
	//定义所有区域点的个数
	AreaPoints1=0;

}

// 用于从对话框数据交换
void CBigImageDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CBigImageDlg)
		// NOTE: ClassWizard 会在此添加 DDX 和 DDV 调用
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CBigImageDlg, CDialog)
	//{{AFX_MSG_MAP(CBigImageDlg)
	ON_WM_PAINT()
	ON_WM_LBUTTONDOWN()
	ON_WM_LBUTTONUP()
	ON_WM_MOUSEMOVE()
	ON_WM_RBUTTONDOWN()
	ON_WM_RBUTTONUP()
	ON_WM_LBUTTONDBLCLK()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CBigImageDlg 消息处理程序

void CBigImageDlg::OnPaint()//自己激发的函数 
{
	CPaintDC dc(this); // 设备上下文用于绘画
	

	// TODO: 在此处添加消息处理程序代码
	CWnd *pWnd = GetDlgItem(IDC_BIG_IMAGE);
	CDC *pDC = pWnd->GetDC();
	CRect conRect;

	//获得该控件的矩形区域
	::GetClientRect(pWnd->m_hWnd,conRect);

	pDC->SetViewportOrg(conRect.left,conRect.top);//设置窗口原点

	pWnd->Invalidate();
	pWnd->UpdateWindow();	
  
    CMainFrame* pframe = (CMainFrame *)AfxGetApp()->GetMainWnd();
    CMDIChildWnd* pChildWnd = pframe->MDIGetActive();
    CBsqViewView* pView = (CBsqViewView *) pChildWnd->GetActiveView();
	
	pView->pBigPiData=(LPSTR)(pView->lpbigshowbuf);
   
	//该函数使用 DIB 位图和颜色数据对与目标设备环境相关的设备上的指定矩形中的像素进行设置
	::SetDIBitsToDevice(pDC->m_hDC,0,0,pView->bgbi.biWidth,pView->bgbi.biHeight,0,0,
             0,pView->bgbi.biHeight,pView->pBigPiData,(BITMAPINFO *)&(pView->bgbi),DIB_RGB_COLORS);
	
	if(bChooseAreas)
	{
	   
		for(int i=1;i<=Areas;i++)
		{
		   
			if(AreasBool[i]==true)
			{
				CBrush brush(Color[i]);
			    CRgn Area;
			    Area.CreatePolygonRgn(OriginBoderPoint[i],BoderPoints[i],ALTERNATE);
		    	pDC->FillRgn(&Area,&brush);
			
			}
		}
	
	}

}



void CBigImageDlg::PostNcDestroy() 
{
	// TODO: 在此处添加您专用的代码或调用基类
	delete this;
	CDialog::PostNcDestroy();
}

void CBigImageDlg::PreSubclassWindow() 
{
	// TODO: 在此处添加您专用的代码或调用基类
	
	CDialog::PreSubclassWindow();
}

BOOL CBigImageDlg::PreCreateWindow(CREATESTRUCT& cs) 
{
	// TODO: 在此处添加您专用的代码或调用基类
	
	return CDialog::PreCreateWindow(cs);
}

解释内容:这段代码是 MFC 中的一个对话框类的实现,用于显示一张大图像。在构造函数中,初始化了一些变量并将视图类中的变量转化为此类的变量。在 OnPaint 函数中,使用双缓冲技术和 SetDIBitsToDevice 函数将图像绘制在界面上。同时,在选择区域的情况下,使用 CreatePolygonRgn 函数和 FillRgn 函数将区域用不同的颜色填充。其他函数和消息映射用于处理用户的鼠标操作和界面的初始化等。

CBigImageDlg 类: MFC 对话框用于显示大图像

原文地址: https://www.cveoy.top/t/topic/oacO 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录