It seems to be a fair amount of MFC
2015-02-24 22:26
162 查看
If one is dealing with an application that performs a lot of painting or drawing, the OnDraw function can spend a lot of time each time it is called by the framework. In this situation, if the user hides the application main window and brings it back again,
he will be punished with a long waiting period to recover the original aspect of the view.
This boring waiting time can be saved if the application recovers the last drawn CDC bitmap whenever no redrawing is necessary. And that works fine if one is able to find out what is the clipping region that has to be saved (normally using BitBlt) and lately
recovered.
It seems to be a fair amount of MFC and
API
functions that deal with this problem but no one seems to be able to provide the actual clipping region for a CDC and the visible region seems to be out of reach. We comment here some of them.
CWnd::GetUpdateRgn( CRgn* pRgn, BOOL bErase = FALSE ); Will give us the window update region, if it is invoked before beginpaint or before CDC is created. This region has to be intersected with the visible region of the window to obtain the really updated region.
APIs GetClipRgn(HDC hdc, HRGN hrgn ) and GetMetaRgn(HDC hdc, HRGN hrgn ); Those functions seem to be designed to fit our purposes but they are not given us the expected result.. In fact they are returning cero and they do not provide any useful info. After
carefully reading, one can notice that Microsoft documentation states that
An application-defined clipping region is a clipping region identified by the SelectClipRgn function. It is not a clipping region created when the application calls the BeginPaint function.
If the user does not define a clipping region by means of SelectClipRgn the function simply indicates that there is none. This seems to be our case.
After several working days spent on this item, we do not have any good idea to get the visible region for a window and we are about to give up and let our users bored watching long unneeded redraws.
Does anyone have any suggestion to deal with this subject.
Re: How to get the visible region of a window or CDC.
Posted by
AsmGuru62 on 17 Dec 2002 at 8:36 AM
: If one is dealing with an application that performs a lot of painting or drawing, the OnDraw function can spend a lot of time each time it is called by the framework. In this situation, if the user hides the application main window
and brings it back again, he will be punished with a long waiting period to recover the original aspect of the view.
:
: This boring waiting time can be saved if the application recovers the last drawn CDC bitmap whenever no redrawing is necessary. And that works fine if one is able to find out what is the clipping region that has to be saved (normally using BitBlt) and lately
recovered.
:
: It seems to be a fair amount of MFC and API functions that deal with this problem but no one seems to be able to provide the actual clipping region for a CDC and the visible region seems to be out of reach. We comment here some of them.
:
: CWnd::GetUpdateRgn( CRgn* pRgn, BOOL bErase = FALSE ); Will give us the window update region, if it is invoked before beginpaint or before CDC is created. This region has to be intersected with the visible region of the window to obtain the really updated
region.
:
: APIs GetClipRgn(HDC hdc, HRGN hrgn ) and GetMetaRgn(HDC hdc, HRGN hrgn ); Those functions seem to be designed to fit our purposes but they are not given us the expected result.. In fact they are returning cero and they do not provide any useful info. After
carefully reading, one can notice that Microsoft documentation states that
:
: An application-defined clipping region is a clipping region identified by the SelectClipRgn function. It is not a clipping region created when the application calls the BeginPaint function.
:
: If the user does not define a clipping region by means of SelectClipRgn the function simply indicates that there is none. This seems to be our case.
:
: After several working days spent on this item, we do not have any good idea to get the visible region for a window and we are about to give up and let our users bored watching long unneeded redraws.
:
: Does anyone have any suggestion to deal with this subject.
:
:
:
Good topic!
How many objects do you have on your document?
Also, what is a nature of your application?
I have a couple of things to say for improving drawing performance.
1. If you have complex little things you draw - try to compose them with a set of bitmaps from RC file. Do not draw pixels or polygons if it can be avoided. In most cases it can be done easy.
2. When the application comes from minimized state to a normal state - there is no clipping region - the whole client area will be painted.
3. Use CDC::RectVisible to detect areas which needs to be painted. Every object - whatever the real object form is - can be surrounded by a RECT, so you can detect with that function - does it really needs to be painted or not.
4. Use resource caching: if you have a 1000 lines drawn by a RED pen or whatever color it is, but it is the same color - do you do it every object:
HPEN hPen = CreatePen (...);
DrawObject (...);
DeleteObject (hPen);
do not do it 1000 times - do it once at the beginning of OnDraw() and use it 1000 times. Same goes for every GDI resource - BRUSH, FONT, etc. - all same things can be cached.
5. If you use a lot of bitmaps - cache them too - there is a lot involved in drawing a bitmap:
- create a memory DC,
- select bitmap into it,
- draw something,
- deselect bitmap,
- destroy memory DC.
Make a class for such memory DC - you will save 2 first steps and 2 last steps!
he will be punished with a long waiting period to recover the original aspect of the view.
This boring waiting time can be saved if the application recovers the last drawn CDC bitmap whenever no redrawing is necessary. And that works fine if one is able to find out what is the clipping region that has to be saved (normally using BitBlt) and lately
recovered.
It seems to be a fair amount of MFC and
API
functions that deal with this problem but no one seems to be able to provide the actual clipping region for a CDC and the visible region seems to be out of reach. We comment here some of them.
CWnd::GetUpdateRgn( CRgn* pRgn, BOOL bErase = FALSE ); Will give us the window update region, if it is invoked before beginpaint or before CDC is created. This region has to be intersected with the visible region of the window to obtain the really updated region.
APIs GetClipRgn(HDC hdc, HRGN hrgn ) and GetMetaRgn(HDC hdc, HRGN hrgn ); Those functions seem to be designed to fit our purposes but they are not given us the expected result.. In fact they are returning cero and they do not provide any useful info. After
carefully reading, one can notice that Microsoft documentation states that
An application-defined clipping region is a clipping region identified by the SelectClipRgn function. It is not a clipping region created when the application calls the BeginPaint function.
If the user does not define a clipping region by means of SelectClipRgn the function simply indicates that there is none. This seems to be our case.
After several working days spent on this item, we do not have any good idea to get the visible region for a window and we are about to give up and let our users bored watching long unneeded redraws.
Does anyone have any suggestion to deal with this subject.
Re: How to get the visible region of a window or CDC.
Posted by
AsmGuru62 on 17 Dec 2002 at 8:36 AM
: If one is dealing with an application that performs a lot of painting or drawing, the OnDraw function can spend a lot of time each time it is called by the framework. In this situation, if the user hides the application main window
and brings it back again, he will be punished with a long waiting period to recover the original aspect of the view.
:
: This boring waiting time can be saved if the application recovers the last drawn CDC bitmap whenever no redrawing is necessary. And that works fine if one is able to find out what is the clipping region that has to be saved (normally using BitBlt) and lately
recovered.
:
: It seems to be a fair amount of MFC and API functions that deal with this problem but no one seems to be able to provide the actual clipping region for a CDC and the visible region seems to be out of reach. We comment here some of them.
:
: CWnd::GetUpdateRgn( CRgn* pRgn, BOOL bErase = FALSE ); Will give us the window update region, if it is invoked before beginpaint or before CDC is created. This region has to be intersected with the visible region of the window to obtain the really updated
region.
:
: APIs GetClipRgn(HDC hdc, HRGN hrgn ) and GetMetaRgn(HDC hdc, HRGN hrgn ); Those functions seem to be designed to fit our purposes but they are not given us the expected result.. In fact they are returning cero and they do not provide any useful info. After
carefully reading, one can notice that Microsoft documentation states that
:
: An application-defined clipping region is a clipping region identified by the SelectClipRgn function. It is not a clipping region created when the application calls the BeginPaint function.
:
: If the user does not define a clipping region by means of SelectClipRgn the function simply indicates that there is none. This seems to be our case.
:
: After several working days spent on this item, we do not have any good idea to get the visible region for a window and we are about to give up and let our users bored watching long unneeded redraws.
:
: Does anyone have any suggestion to deal with this subject.
:
:
:
Good topic!
How many objects do you have on your document?
Also, what is a nature of your application?
I have a couple of things to say for improving drawing performance.
1. If you have complex little things you draw - try to compose them with a set of bitmaps from RC file. Do not draw pixels or polygons if it can be avoided. In most cases it can be done easy.
2. When the application comes from minimized state to a normal state - there is no clipping region - the whole client area will be painted.
3. Use CDC::RectVisible to detect areas which needs to be painted. Every object - whatever the real object form is - can be surrounded by a RECT, so you can detect with that function - does it really needs to be painted or not.
4. Use resource caching: if you have a 1000 lines drawn by a RED pen or whatever color it is, but it is the same color - do you do it every object:
HPEN hPen = CreatePen (...);
DrawObject (...);
DeleteObject (hPen);
do not do it 1000 times - do it once at the beginning of OnDraw() and use it 1000 times. Same goes for every GDI resource - BRUSH, FONT, etc. - all same things can be cached.
5. If you use a lot of bitmaps - cache them too - there is a lot involved in drawing a bitmap:
- create a memory DC,
- select bitmap into it,
- draw something,
- deselect bitmap,
- destroy memory DC.
Make a class for such memory DC - you will save 2 first steps and 2 last steps!
相关文章推荐
- 无法启动Hbase hbase-default.xml file seems to be for and old version of HBase
- Use MFC in a Static Library,This may be due to a corruption of the heap....
- The type of the expression must be an array type but it resolved to Point
- http://blogs.msdn.com/b/pranavwagh/archive/2007/03/03/word-2007-file-seems-to-be-deleted-when-you-open-and-save-it-using-dsoframer.aspx
- mm_The type of the expression must be an array type but it resolved to List
- hbase启动报错hbase-default.xml file seems to be for and old version of HBase
- 未来IT行业将缩减到三类职业(The future of IT will be reduced to three kinds of jobs)
- When it comes to two corresponding names,one of them will be forces \( \)
- "Loading a plug-in failed The plug-in or one of its prerequisite plug-ins may be missing or damaged and may need to be reinstalled"
- maven-compiler-plugin:3.5.2 or one of its dependencies could not be resolved: Failure to find org.ap
- This may be due to a corruption of the heap, which indicates a bug in *.exe or any of the DLLs it has loaded.
- The Behavior version of the Forest is 0 it must be 2 or greater to perform a domain rename: 该服务器不愿意处理该请求。 :8245
- this may be due to a corruption of the heap, which indicates a bug in ... or any of the DLLs it has
- HBase异常:hbase-default.xml file seems to be for and old version of HBase的解决方法
- What does it mean for an algorithm to be fair
- hbase-default.xml file seems to be for an older version of HBase ,this version is 1.2.0
- Details: To enable the details of this specific error message to be viewable on remote machines, please create a tag within a
- Error 1 Operator '+' cannot be applied to operands of type 'string' and 'method group'
- (Page 1 of 3 )A walking tour of JavaBeans What JavaBeans is, how it works, and why you want to use it
- How to be a friend of yourself