在对话框中应用CScrollView显示图像

news/2024/9/19 6:17:29

1、用vs2008创建一个基于对话框的工程DialogView;
2、添加一个新类CMyDocument,基类为CDocument;
3、添加一个新类CMyView,基类为CScrollView;
4、修改CMyDocument的头文件:
#pragma once

// CMyDocument document
class CDialogView;

class CMyDocument : public CDocument
{
 //DECLARE_DYNCREATE(CMyDocument)
 friend class CDialogView;

public:
 CMyDocument();
 DECLARE_DYNCREATE(CMyDocument)
public:
 virtual ~CMyDocument();
#ifndef _WIN32_WCE
 virtual void Serialize(CArchive& ar);   // overridden for document i/o
#endif
#ifdef _DEBUG
 virtual void AssertValid() const;
#ifndef _WIN32_WCE
 virtual void Dump(CDumpContext& dc) const;
#endif
#endif

protected:
 virtual BOOL OnNewDocument();

 DECLARE_MESSAGE_MAP()
};

5、修改CMyView的头文件:
#pragma once

 

// CMyView view
class CDialogView;

class CMyView : public CScrollView
{
 //DECLARE_DYNCREATE(CMyView)
 friend class CDialogView;
protected:
 CMyView();           // protected constructor used by dynamic creation
 DECLARE_DYNCREATE(CMyView)
 virtual ~CMyView();

public:
#ifdef _DEBUG
 virtual void AssertValid() const;
#ifndef _WIN32_WCE
 virtual void Dump(CDumpContext& dc) const;
#endif
#endif

protected:
 virtual void OnDraw(CDC* pDC);      // overridden to draw this view
 virtual void OnInitialUpdate();     // first time after construct

 DECLARE_MESSAGE_MAP()
};
6、修改DialogView执行文件:
 在文件中加入 #include "MyScroll.h"
              #include "MyDocument.h"

BOOL CDialogView::OnInitDialog()
{
 CDialog::OnInitDialog();

 // Add "About..." menu item to system menu.

 // IDM_ABOUTBOX must be in the system command range.
 ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
 ASSERT(IDM_ABOUTBOX < 0xF000);

 CMenu* pSysMenu = GetSystemMenu(FALSE);
 if (pSysMenu != NULL)
 {
  CString strAboutMenu;
  strAboutMenu.LoadString(IDS_ABOUTBOX);
  if (!strAboutMenu.IsEmpty())
  {
   pSysMenu->AppendMenu(MF_SEPARATOR);
   pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
  }
 }

 // 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

 // TODO: Add extra initialization here
 CCreateContext pContext;
 CWnd* pFrameWnd = this;
 pContext.m_pCurrentDoc = new CMyDocument;
 pContext.m_pNewViewClass = RUNTIME_CLASS(CMyView);
 CMyView* pView = (CMyView *)((CFrameWnd*)pFrameWnd)->CreateView(&pContext);
 ASSERT(pView);
 pView->m_nMapMode = MM_TEXT;
 pView->ShowWindow(SW_NORMAL);
 CRect rectWindow;
 GetWindowRect(rectWindow);
 rectWindow.right -= 30;
 rectWindow.bottom   -= 100;
 pView->MoveWindow(rectWindow);

 return TRUE;  // return TRUE  unless you set the focus to a control
}

7、在CMyView的OnDraw函数中添加代码:
void CMyView::OnDraw(CDC* pDC)
{
 //CDocument* pDoc = GetDocument();
 // TODO: add draw code here
 CBitmap BK;
 BK.LoadBitmap(IDB_BITMAP1);//需要添加一位图用于显示
 CDC MemDC;
 MemDC.CreateCompatibleDC(pDC);
 MemDC.SelectObject(&BK);
 BITMAP bm;
 BK.GetBitmap(&bm);

 pDC->BitBlt(0, 0, bm.bmWidth, bm.bmHeight, &MemDC, 0, 0, SRCCOPY);

 CRect m_Rect;
 GetClientRect(&m_Rect);
 m_Rect.bottom += 100;
 CSize sizeTotal;
 // TODO: calculate the total size of this view
 sizeTotal.cx = bm.bmWidth;
 sizeTotal.cy = bm.bmHeight;
 SetScrollSizes(MM_TEXT, sizeTotal);
}

 参考:http://download.csdn.net/down/610747/jia_xiaoxin
            http://www.codeguru.com/Cpp/W-D/dislog/article.php/c5009/


http://lihuaxi.xjx100.cn/news/226074.html

相关文章

升级Jekyll 3.0

每一次的升级都得又一次折腾一次&#xff0c;jekyll也不例外 从jekyll 2.5.2 升级为jekyll 3.0.1 错误一: jekyll 3.0.1 | Error: Permission denied - bind(2) for 127.0.0.1:4000 端口被占有&#xff0c;打开_config.yml 在最后加上一行 port: 5001 (其它也可)问题解决 错误…

java 跨年 周计算公式_如何跨年计算 两日期之间相隔的周数 with java8 time API

2016年9月版 分割线之前版本的我太simple了...最近再去研究了一下Java8的新时间API&#xff0c;发现更有简单的方式去处理LocalDate localDate1 LocalDate.parse("2015-12-01");LocalDate localDate2 LocalDate.parse("2016-01-15");System.out.println(…

DataGrid基于Access的快速分页法

DataGrid基于Access的快速分页法撰文/ 黎波DataGrid是一个功能非常强大的ASP.NET Web服务器端控件&#xff0c;它除了能够方便地按各种方式格式化显示表格中的数据&#xff0c;还可以对表格中的数据进行动态的排序、编辑和分页。使Web开发人员从繁琐的代码中解放。实现DataGrid…

vs2008中,在OCX控件中应用doc/view基本步骤

1、利用向导创建一个MFC ActiveX Control控件CMyOCX&#xff1b; 2、在工程中加入ActivDoc头文件和执行文件&#xff1b; class CActiveXDocTemplate : public CSingleDocTemplate { enum { IDR_NOTUSED 0x7FFF }; CWnd* m_pParentWnd; CFrameWnd* m_pFrameWnd; C…

学习dubbo框架的问题

InputStream &#xff1a; 是所有字节输入流的超类&#xff0c;一般使用它的子类&#xff1a;FileInputStream等&#xff0c;它能输出字节流&#xff1b;InputStreamReader &#xff1a; 是字节流与字符流之间的桥梁&#xff0c;能将字节流输出为字符流&#xff0c;并且能为字节…

lua java 性能比较_Lua coroutine vs Java wait/notify

在上文Lua coroutine 不一样的多线程编程思路中想到coroutine的运行机制跟Java中的wait/notify很相似&#xff0c;所以写了一个简单程序比较一下。源代码Lua codeco coroutine.create(function(loops)for i 1, loops docoroutine.yield()endend)local x os.clock()local loo…

DataGrid连接Access的快速分页法(1)——需求与现状

作者&#xff1a;黎波一、需求分析 DataGrid是一个功能强大的ASP.NET Web服务器端控件&#xff0c;它除了能够按各种方式格式化显示数据&#xff0c;还可以对数据进行动态的排序、编辑和分页。大大减轻了广大Web程序员的工作量。实现DataGrid的分页功能一直是很多入门者感到棘手…

java在己有的类创子类怎么创_如何使用Java创建自己的异常子类

Java不知道学了多少课时了&#xff0c;你知道如何使用Java创建自己的异常子类吗&#xff0c;Java的内置异常处理有哪些常见的错误呢&#xff0c;今天IT培训网小编就来给大家详细介绍下吧&#xff1a;尽管Java的内置异常处理大多数常见错误&#xff0c;你也许希望建立你自己的异…