class CBigImageDlg : public CDialog
{
public:
    CBigImageDlg(CWnd* pParent /*=NULL*/);
    //{{AFX_DATA(CBigImageDlg)
    // NOTE: the ClassWizard will add data members here
    //}}AFX_DATA

    // ClassWizard generated virtual function overrides
    //{{AFX_VIRTUAL(CBigImageDlg)
    protected:
    virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
    //}}AFX_VIRTUAL

    // Implementation
protected:
    // Generated message map functions
    //{{AFX_MSG(CBigImageDlg)
    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
    DECLARE_MESSAGE_MAP()

private:
    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 m_display;
};

CBigImageDlg::CBigImageDlg(CWnd* pParent /*=NULL*/) : CDialog(CBigImageDlg::IDD, pParent)
{
    //{{AFX_DATA_INIT(CBigImageDlg)
    // NOTE: the ClassWizard will add member initialization here
    //}}AFX_DATA_INIT

    // 将视图类的变量转化为此类的
    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;
    
    m_display = true;
    
}


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 message handlers

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);
    
    // 显示设备无关图到指定的坐标
    ::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);
    
}


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);
}



void CBigImageDlg::OnMouseMove(UINT nFlags, CPoint point)
{
    // TODO: Add your message handler code here and/or call default
    CString str;
    CMainFrame* pFrame = (CMainFrame*)AfxGetApp()->m_pMainWnd;
    CStatusBar* pStatus = &pFrame->m_wndStatusBar;
    if (pStatus)
    {
        str.Format("X=%d", point.x);
        pStatus->SetPaneText(1, str);
        str.Format("Y=%d", point.y);
        pStatus->SetPaneText(2, str);
    }
    CDialog::OnMouseMove(nFlags, point);
}

解释:

  • 构造函数:

    • 从活动视图类 CBsqViewView 中获取图像数据,包括 BandsWidthHeightm_pathnameHBig
    • 初始化其他成员变量,如 AverageGreyworkmodem_ldrawm_rdrawfirstmouse_lfirstmouse_rAreasAreasBoolbChooseAreas
  • OnPaint() 函数:

    • 获取 IDC_BIG_IMAGE 控件的设备上下文 pDC
    • 使用 SetDIBitsToDevice() 函数将 CBsqViewView 的图像数据显示在对话框中。
  • OnMouseMove() 函数:

    • 获取鼠标位置 point
    • 在状态栏上显示鼠标的 X 和 Y 坐标。

说明:

  • 该代码使用了 MFC 框架和 GDI+ 函数来显示图像。
  • 代码中包含了一些未被使用的函数,如 OnLButtonDown()OnLButtonUp() 等,可能用于其他功能。
  • 代码中没有对 CommonMode 的定义,需要根据上下文进行推断。
  • 代码中可能存在一些缺失的代码,例如 CBsqViewView 的定义,以及 SetDIBitsToDevice() 的使用细节。

其他信息:

  • CBsqViewView 可能是 CView 的派生类,用于显示图像。
  • IDC_BIG_IMAGE 是对话框中的一个控件,用于显示图像。
  • CMainFrame 是主框架窗口类。
  • CMDIChildWnd 是多文档界面 (MDI) 子窗口类。
  • CStatusBar 是状态栏窗口类。

建议:

  • 补充完整代码,包括 CBsqViewView 的定义和相关代码。
  • 研究 SetDIBitsToDevice() 函数的用法,确保图像显示正确。
  • 添加注释,解释代码的功能和逻辑。
  • 使用合适的命名规范,提高代码可读性。
CBigImageDlg 类:显示大图像的 MFC 对话框

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

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