CBigImageDlg 类:MFC 大图像显示对话框
// CBigImageDlg.cpp : 实现文件
//
#include "stdafx.h"
#include "BSQView.h"
#include "BigImageDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
// CBigImageDlg 对话框
CBigImageDlg::CBigImageDlg(CWnd* pParent /*=NULL*/) : CDialog(CBigImageDlg::IDD, pParent)
{
//将视图类的变量转化为此类的
CMainFrame* pframe = (CMainFrame *)AfxGetApp()->GetMainWnd();
CMDIChildWnd* pChildWnd = pframe->MDIGetActive();
CBsqViewView* 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: the ClassWizard will add DDX and DDV calls here
//}}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); // device context for painting
// TODO: Add your message handler code here
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: Add your specialized code here and/or call the base class
delete this;
CDialog::PostNcDestroy();
}
void CBigImageDlg::PreSubclassWindow()
{
// TODO: Add your specialized code here and/or call the base class
CDialog::PreSubclassWindow();
}
BOOL CBigImageDlg::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Add your specialized code here and/or call the base class
return CDialog::PreCreateWindow(cs);
}
解释内容:这是一个 MFC 中的对话框类,用于显示大图像。在构造函数中,将视图类的变量转换为此类的变量,并初始化一些变量。在消息映射函数中,处理鼠标事件和绘图事件。在绘图事件中,使用双缓冲技术绘制图像,并在需要时绘制区域。在析构函数中,释放一些资源。其他函数和消息映射函数都是一些未使用的默认函数或空函数。
原文地址: https://www.cveoy.top/t/topic/oacJ 著作权归作者所有。请勿转载和采集!