我最近在做毕设,有一个例子是先打开图片的时候不显示图片,要再点击显示原图才可以.我现在要做的是把这两个过程合起来,也就是在打开的同时就显示图片.可不可以拜托你帮下忙,看看要怎么实现.
打开文件的代码是:
void CDSplitDoc::OnFileopen()
{
// TODO: Add your command handler code here
CFileDialog dlg(TRUE,_T("BMP"),_T("*.BMP"),OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT,_T("位图文件(*.BMP)|*.BMP|"));
if(IDOK==dlg.DoModal ())
filename.Format ("%s",dlg.GetPathName() );
CDib.LoadFile(filename);
CDibNew.LoadFile(filename);
statedoc=1;
}显示图片的代码是:
void CDSplitView::OnYuantu()
{
CDSplitDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
filename=pDoc->filename;
state1=1;
Invalidate();
}
或者你给我你QQ,我把整个工程打包传给你看看
打开文件的代码是:
void CDSplitDoc::OnFileopen()
{
// TODO: Add your command handler code here
CFileDialog dlg(TRUE,_T("BMP"),_T("*.BMP"),OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT,_T("位图文件(*.BMP)|*.BMP|"));
if(IDOK==dlg.DoModal ())
filename.Format ("%s",dlg.GetPathName() );
CDib.LoadFile(filename);
CDibNew.LoadFile(filename);
statedoc=1;
}显示图片的代码是:
void CDSplitView::OnYuantu()
{
CDSplitDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
filename=pDoc->filename;
state1=1;
Invalidate();
}
或者你给我你QQ,我把整个工程打包传给你看看
解决方案 »
- CTABCTRL中动态创建的控件如何实现TABSTOP
- 没有连接accept也能往下执行?
- ddraw剪裁器剪裁DrawTextW文字怎么实现啊
- 好消息
- 如何得到一个网页上所有URL的响应时间?
- 我想用 RunDLL32 来运行一个 DLL 里的函数,但里面有个参数是 PAnsiChar 的,我要如何写 bat 呢?
- 急啊!作了一个gina程序,但是登陆对话框不是xp风格,找到一个解决方法,不过不好使,麻烦大家看看
- afx_msg是个什么东西呀?
- 有没有什么简便的方法可以真正完全在内存中解析HTML?
- 如何修改一个对话框的属性,使其只能被上下拉伸但不能左右拉伸?
- msxml的replaceChild()为什么要提供三个参数?
- 怎样在VC2005 IDE的状态栏中显示CapsLock大写键状态?
{
// TODO: Add your command handler code here
CFileDialog dlg(TRUE,_T("BMP"),_T("*.BMP"),OFN_HIDEREADONLY ¦OFN_OVERWRITEPROMPT,_T("位图文件(*.BMP) ¦*.BMP ¦"));
if(IDOK==dlg.DoModal ())
filename = dlg.GetPathName();
CDib.LoadFile(filename);
CDibNew.LoadFile(filename);
//这里,把图画出来,并通知view更新
//UpdateAllViews
}
//UpdateAllViews
这两行是什么功能?VIEW怎么更新?我是菜鸟,所以可能要麻烦你说详细点.嘿嘿
{
CDSplitDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
filename=pDoc->filename;
state1=1;
Invalidate();
} 这里有用的代码就是文件名和刷新
在doc里,也可以通知view刷新,参考2楼的方法
关键在于这里:在OnDraw时候,判断当前state1的值是否为1,为1则显示,为0则不显示,代码可以这样来写:void CDSplitView::OnDraw(CDC* pDC)
{
CDSplitDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
if (!pDoc)
return;
if (!state)
return; // TODO: add draw code for native data here
if( strFilename != "" )
{
BITMAP bmpProperties; // Create a bitmap handle using the name of the file
HBITMAP bmpHandle = (HBITMAP)LoadImage(NULL,
strFilename,
IMAGE_BITMAP,
0,
0,
LR_LOADFROMFILE); CBitmap bmpPicture;
CDC mdcPicture; // Convert the Win32 bitmap handle into an MFC bitmap object
CBitmap *bmpFromHandle = bmpPicture.FromHandle(bmpHandle);
bmpPicture.Attach(bmpHandle); // Call the Win32 GetObject() function to get the properties
// of the bitmap and store them in a BITMAP structure
::GetObject(bmpPicture,
sizeof(bmpProperties),
&bmpProperties); // Create a compatible device context
mdcPicture.CreateCompatibleDC(pDC);
// Select the bitmap into the device context
CBitmap * bmpPrevious =
mdcPicture.SelectObject(bmpFromHandle); // Using the dimensions store in the BITMAP object,
// display the picture
pDC->BitBlt(0, 0,
bmpProperties.bmWidth, bmpProperties.bmHeight,
&mdcPicture, 0, 0, SRCCOPY); // Get the dimensions of the new picture
SIZE sizeTotal;
sizeTotal.cx = bmpProperties.bmWidth;
sizeTotal.cy = bmpProperties.bmHeight;
// Change the scrolling area/dimensions of the view
SetScrollSizes(MM_TEXT, sizeTotal); // Restore the bitmap
pDC->SelectObject(bmpPrevious);
// Delete the Win32 bitmap handle
DeleteObject(bmpHandle);
}
} 其中strFilename 变量为你程序的filename,代替即可。
http://www.functionx.com/visualc/views/DisplayBitmap.htm