为了解决绘图闪烁问题,我想在内存中作图,再将作的图恢复到窗体上,有人试过吗?

wsdyqyj 2001-12-02 04:47:24
希望举个例子,不胜感激!!
怎样存和怎样恢复??
...全文
2451 71 打赏 收藏 举报
写回复
71 条回复
切换为时间正序
请发表友善的回复…
发表回复
WinterSeo 2001-12-09
  • 打赏
  • 举报
回复
求助,先给95分,如果答案详细的话,还可以再开几个贴子给300分!
请详细点回答!谢谢!(下面几个贴子是同一个问题,为了多给分才开多个的)
http://www.csdn.net/expert/topic/410/410427.shtm
http://www.csdn.net/expert/topic/410/410433.shtm
http://www.csdn.net/expert/topic/410/410493.shtm
city_tiger 2001-12-06
  • 打赏
  • 举报
回复
大大鱼,欠我的MM还给我!
BigBigFish 2001-12-06
  • 打赏
  • 举报
回复
创建内存DC的大小不是当前client区的大小,而是最大图的大小,注意滚动坐标的偏移
city_tiger 2001-12-05
  • 打赏
  • 举报
回复
我玩DirectX的时候你还没生出来呢。
wsdyqyj 2001-12-05
  • 打赏
  • 举报
回复
大大鱼:你说的光退出时释放可不行,当窗体大小改变时还需要重新按窗口创建一个内存绘
制空间啊,再说我的背景一直在动,就像2000的系统资源显示
对了,我的鼠标的作用是动态在窗体上绘制一个和窗体等宽等高的线条,用以标出横纵坐标
的值。
wsdyqyj 2001-12-05
  • 打赏
  • 举报
回复
大大鱼:你说的光退出时释放可不行,当窗体大小改变时还需要重新按窗口创建一个内存绘
制空间啊,再说我的背景一直在动,就像2000的系统资源显示
对了,我的鼠标的作用是动态在窗体上绘制一个和窗体等宽等高的线条,用以标出横纵坐标
的值。
BigBigFish 2001-12-05
  • 打赏
  • 举报
回复
都市老虎显然对DC了解不深.
偶们平时画DC之所以有闪烁,就是因为直接画DC,如果你写过DirectX,就知道,为什么要再建个背表面,而不直接载主表面上操作(直接操作的话会闪屏)
wsdyqyj 2001-12-05
  • 打赏
  • 举报
回复
请以上留言的几位到PB版块收分!!谢谢了
BigBigFish 2001-12-05
  • 打赏
  • 举报
回复
再重申一点,我并没有输,都市老虎并没有完成偶的要求.
BigBigFish 2001-12-05
  • 打赏
  • 举报
回复
关于蓝调的问题.偶有不明
你的鼠标是自己的图形,还是window的鼠标?
如果是自己的图.
先在OnInitialUpdate里建内存DC,大小和底图大小一致.底图贴一边
重载OnEraseBkgnd 直接return TRUE或FALSE
在OnDraw里写内存DC.bitblt到pDC.(SRCCOPY,- -b你以前用bitblt的时候不用这个参数?)
在OnMouseMove里先把当前client区域的底图重贴一边(不重画的话以前鼠标的就会残留),
其他要绘的的也在这里绘,如果用CScrollView的话要注意坐标偏移
然后绘制鼠标.最后调用InvalidateRect(rc,FALSE);更新当前client区(如果你想效率更高些,可以保留鼠标上一次的坐标,只重贴那部分的区域,不更新整个client,不过有点麻烦)
注意太大的内存dc,可能分配不了,
释放的话随便你搂,只要是在退出的时候(在OnInitialUpdate也要释放一下,因为用户新建文档了)
BigBigFish 2001-12-05
  • 打赏
  • 举报
回复
呵呵,此问题已经结束,向都市老虎道个歉.
至于PPMM偶当然自己留着了,啊哈哈哈哈
kingfire 2001-12-05
  • 打赏
  • 举报
回复

兄弟啊,你也太辛苦了!哪里神奇啊?

BOOL BitBlt(
HDC hdcDest, // handle to destination DC
int nXDest, // x-coord of destination upper-left corner
int nYDest, // y-coord of destination upper-left corner
int nWidth, // width of destination rectangle
int nHeight, // height of destination rectangle
HDC hdcSrc, // handle to source DC
int nXSrc, // x-coordinate of source upper-left corner
int nYSrc, // y-coordinate of source upper-left corner
DWORD dwRop // raster operation code/*你取的为0能不为黑块吗?*/
);
BitBlt(wl_Hdc,0,0,500,500,memHdc,0,0,0);

DWORD dwRop取值为:
BLACKNESS [Fills the destination rectangle using the color associated with index 0 in the physical palette. (This color is black for the default physical palette.)]
CAPTUREBLT
DSTINVERT
MERGECOPY
MERGEPAINT
NOMIRRORBITMAP
NOTSRCCOPY
NOTSRCERASE
PATCOPY
PATINVERT
PATPAINT
SRCAND
SRCCOPY /******一般我们用这个值*****/
SRCERASE
SRCINVERT
SRCPAINT
WHITENESS
BitBlt(wl_Hdc,0,0,500,500,memHdc,0,0,0)?????
------------------------------------------------------------------------
回复人: Hanson_bati_zhu(Hanson_bati_zhu) (2001-12-3 11:17:24) 得17分
试试啊

BitBlt(wl_Hdc,0,0,500,500,memHdc,0,0,0)
改成
BitBlt(wl_Hdc,0,0,500,500,memHdc,0,0,13369376)


回复人: wsdyqyj(蓝调) (2001-12-3 11:22:23) 得0分
Hanson_bati_zhu(Hanson_bati_zhu):
太神奇了,改了该参数就搞定了,但也许还有别的问题出现,我还得清教你们。
该参数在哪儿查???
我明天一定单开一个帖子来答谢,请帮过忙得兄弟留意!
该帖子我暂时不结,今天都三号了,晚一点不会影响你们月末打榜!
另外你们控制闪烁有什么高招吗?
----------------------------------------------------------------
梁小白 2001-12-05
  • 打赏
  • 举报
回复
哥们试试这,好使!!

//*******************************************************************************************************/
//* FileName: MemDC.h
//*
//* Contents: Definition and implementation for CMemDC
//*
//* Copyright You may freely use or modify this code provided this Copyright is included in all
//* Notice: derived versions.
//*
//* Author: Keith Rule
//*
//* Email: keithr@europa.com
//*
//* Copyright 1996-1997, Keith Rule
//*******************************************************************************************************/
//* 10/3/97 Keith Rule Fixed scrolling bug.
//* 10/3/97 Keith Rule Added print support.
//* 12.feb.98 Jan Vidar Berger Ported CMemDC into clPlot and added some comments.
//*******************************************************************************************************/
#ifndef _MEMDC_H_
#define _MEMDC_H_


//*******************************************************************************************************/
//* Class: CMemDC - memory DC
//*
//* Base Class: public CDC
//*
//* Description: This class implements a memory Device Context that enables flicker free drawing.
//*
//* Usage: Implemen CMemDC in your CMyWnd::OnPaint as following:
//* {
//* CPaintDC dc(pWnd);
//* CMemDC mDC(dc); // call CMemDC::CMemDC(CDC *dc)
//*
//* Draw(mDC); // draw on CMemDC rather than CDC directly.
//* } // call CMemDC::~CMemDC()
//*
//* Finally, add and modify WM_ERASEBKGND message in your project as following.
//*
//* BOOL CMyView::OnEraseBkgnd(CDC* pDC)
//* {
//* return FALSE;
//* }
//*
//* How it works: 1. The constructor will construct compatibledc and do the work required to enable
//* drawing on a memory dc.
//* 2. You can draw on the CMemDC as if it is a CDC.
//* 3. The destructor copies the memory dc into the real DC.
//*******************************************************************************************************/
class CMemDC : public CDC {
private:
CBitmap m_bitmap; // Offscreen bitmap
CBitmap* m_oldBitmap; // bitmap originally found in CMemDC
CDC* m_pDC; // Saves CDC passed in constructor
CRect m_rect; // Rectangle of drawing area.
BOOL m_bMemDC; // TRUE if CDC really is a Memory DC.
public:
CMemDC(CDC* pDC) : CDC(), m_oldBitmap(NULL), m_pDC(pDC)
{
ASSERT(m_pDC != NULL); // If you asserted here, you passed in a NULL CDC.

m_bMemDC = !pDC->IsPrinting();

if (m_bMemDC){
// Create a Memory DC
CreateCompatibleDC(pDC);
pDC->GetClipBox(&m_rect);
m_bitmap.CreateCompatibleBitmap(pDC, m_rect.Width(), m_rect.Height());
m_oldBitmap = SelectObject(&m_bitmap);
SetWindowOrg(m_rect.left, m_rect.top);
} else {
// Make a copy of the relevent parts of the current DC for printing
m_bPrinting = pDC->m_bPrinting;
m_hDC = pDC->m_hDC;
m_hAttribDC = pDC->m_hAttribDC;
}
}

~CMemDC()
{
if (m_bMemDC) {
// Copy the offscreen bitmap onto the screen.
m_pDC->BitBlt(m_rect.left, m_rect.top, m_rect.Width(), m_rect.Height(),
this, m_rect.left, m_rect.top, SRCCOPY);
//Swap back the original bitmap.
SelectObject(m_oldBitmap);
} else {
// All we need to do is replace the DC with an illegal value,
// this keeps us from accidently deleting the handles associated with
// the CDC that was passed to the constructor.
m_hDC = m_hAttribDC = NULL;
}
}

// Allow usage as a pointer
CMemDC* operator->() {return this;}

// Allow usage as a pointer
operator CMemDC*() {return this;}
};

#endif



//*******************************************************************************************************/
//* FileName: MemDC.h
//*
//* Contents: Definition and implementation for CMemDC
//*
//* Copyright You may freely use or modify this code provided this Copyright is included in all
//* Notice: derived versions.
//*
//* Author: Keith Rule
//*
//* Email: keithr@europa.com
//*
//* Copyright 1996-1997, Keith Rule
//*******************************************************************************************************/
//* 10/3/97 Keith Rule Fixed scrolling bug.
//* 10/3/97 Keith Rule Added print support.
//* 12.feb.98 Jan Vidar Berger Ported CMemDC into clPlot and added some comments.
//*******************************************************************************************************/
#ifndef _MEMDC_H_
#define _MEMDC_H_


//*******************************************************************************************************/
//* Class: CMemDC - memory DC
//*
//* Base Class: public CDC
//*
//* Description: This class implements a memory Device Context that enables flicker free drawing.
//*
//* Usage: Implemen CMemDC in your CMyWnd::OnPaint as following:
//* {
//* CPaintDC dc(pWnd);
//* CMemDC mDC(dc); // call CMemDC::CMemDC(CDC *dc)
//*
//* Draw(mDC); // draw on CMemDC rather than CDC directly.
//* } // call CMemDC::~CMemDC()
//*
//* Finally, add and modify WM_ERASEBKGND message in your project as following.
//*
//* BOOL CMyView::OnEraseBkgnd(CDC* pDC)
//* {
//* return FALSE;
//* }
//*
//* How it works: 1. The constructor will construct compatibledc and do the work required to enable
//* drawing on a memory dc.
//* 2. You can draw on the CMemDC as if it is a CDC.
//* 3. The destructor copies the memory dc into the real DC.
//*******************************************************************************************************/
class CMemDC : public CDC {
private:
CBitmap m_bitmap; // Offscreen bitmap
CBitmap* m_oldBitmap; // bitmap originally found in CMemDC
CDC* m_pDC; // Saves CDC passed in constructor
CRect m_rect; // Rectangle of drawing area.
BOOL m_bMemDC; // TRUE if CDC really is a Memory DC.
public:
CMemDC(CDC* pDC) : CDC(), m_oldBitmap(NULL), m_pDC(pDC)
{
ASSERT(m_pDC != NULL); // If you asserted here, you passed in a NULL CDC.

m_bMemDC = !pDC->IsPrinting();

if (m_bMemDC){
// Create a Memory DC
CreateCompatibleDC(pDC);
pDC->GetClipBox(&m_rect);
m_bitmap.CreateCompatibleBitmap(pDC, m_rect.Width(), m_rect.Height());
m_oldBitmap = SelectObject(&m_bitmap);
SetWindowOrg(m_rect.left, m_rect.top);
} else {
// Make a copy of the relevent parts of the current DC for printing
m_bPrinting = pDC->m_bPrinting;
m_hDC = pDC->m_hDC;
m_hAttribDC = pDC->m_hAttribDC;
}
}

~CMemDC()
{
if (m_bMemDC) {
// Copy the offscreen bitmap onto the screen.
m_pDC->BitBlt(m_rect.left, m_rect.top, m_rect.Width(), m_rect.Height(),
this, m_rect.left, m_rect.top, SRCCOPY);
//Swap back the original bitmap.
SelectObject(m_oldBitmap);
} else {
// All we need to do is replace the DC with an illegal value,
// this keeps us from accidently deleting the handles associated with
// the CDC that was passed to the constructor.
m_hDC = m_hAttribDC = NULL;
}
}

// Allow usage as a pointer
CMemDC* operator->() {return this;}

// Allow usage as a pointer
operator CMemDC*() {return this;}
};

#endif
wsdyqyj 2001-12-05
  • 打赏
  • 举报
回复
该图形也是每几秒钟实时变一次的,我还没测,我怕要是资源释放不完的话那程序
用不了两天系统资源就告急了。
还有请两位到http://www.csdn.net/expert/topic/403/403922.shtm去留个名,我好给
你们加分!^_^谢先了!
wsdyqyj 2001-12-05
  • 打赏
  • 举报
回复
没想到两位兄弟还干上了,我的闪屏现象已搞定,老实得像一幅桌面背景似的,既然你们还
关注该贴,我就再讨教一个问题:
由于我作原型图是存在内存中的,所以涉及到内存绘制释放的问题,请问各位在什么时候
释放最好?我的图上还有鼠标跟随显示,必须随时重绘,所以不能随便释放,难道只能在重
新创建内存绘制区域时释放以前的?我不能每次在内存中绘制完成、绘到窗口上后后就马上
释放。绘制的数据来自数据库,要不然鼠标随便动一下就要重检索数据库,那肯定不行。
city_tiger 2001-12-05
  • 打赏
  • 举报
回复
咱俩真是不打不相识呀!幸会,幸会。
你们那个什么机动战士联盟有点儿意思,要帮忙找我,我1个顶俩儿,没问题。
都是老程序员了,谁跟谁呀?是不?
明儿见。
(PPMM还是要的,别忘了答应我的事)
city_tiger 2001-12-05
  • 打赏
  • 举报
回复
这么晚不下班?干嘛呢?
愿赌服输嘛!快介绍PPMM给我,要不就帮我解释一下:
为什么叫PPMM,而不叫 PLMM 呢?(漂亮MM么)
BTW: 我那bmp显示程序经典吧?
BigBigFish 2001-12-05
  • 打赏
  • 举报
回复
偶照你的程序写了一份,不过把你的玉照稍稍改动了一下.
http://210.15.78.1/bigbigfish/joke.zip
BigBigFish 2001-12-05
  • 打赏
  • 举报
回复
2次以上都要用内存dc,难道你没用?
city_tiger 2001-12-05
  • 打赏
  • 举报
回复
忘了说了,“在OnDraw你绘制两次以上,一定会闪”,2次太少,我5次也没关系。
加载更多回复(51)
相关推荐
发帖
PowerBuilder

1028

社区成员

PowerBuilder 相关问题讨论
社区管理员
  • 基础类社区
  • WorldMobile
加入社区
帖子事件
创建了帖子
2001-12-02 04:47
社区公告
暂无公告