MFC程序重绘问题
MFC程序运行过程中,如果切换到别的程序,在程序面前来回拖动,那么MFC程序不能够实现及时的重绘。这是为什么??
MFC程序中加载了一张整个程序的背景图片,还有一个picture控件,picture控件在程序中加载了一张位图。onpaint中代码:
CPaintDC dc(this); // 用于绘制的设备上下文
CRect rect1;
GetClientRect(rect1);
CDC dcMem;
dcMem.CreateCompatibleDC(&dc);
CBitmap bkbitmap;
bkbitmap.LoadBitmapA(IDB_BITMAP4);
BITMAP bitmap;
bkbitmap.GetBitmap(&bitmap);
CBitmap* cbitmapOld = dcMem.SelectObject(&bkbitmap);
dc.StretchBlt(0, 0, rect1.Width(), rect1.Height(), &dcMem, 0, 0, bitmap.bmWidth, bitmap.bmHeight, SRCCOPY);
dcMem.DeleteDC();
onpaint中加载了背景图片,picture控件中位图加载在代码中实现。 MFC onpaint 重绘
[解决办法]
OnPaint中每次都加载图片?这设计效率太低了吧,加载一次,在OnPaint中直接画嘛。不能实现重绘?来回拖动 这个应该会自动重绘吧
[解决办法]
repaint is needed, but reload is not.
[解决办法]
搜索下载安装MSDN98
然后老老实实按照MSDN里面的步骤一步一步学习SAMPLES\VC98\MFC\TUTORIAL\SCRIBBLE\STEP1~7
SCRIBBLE: Illustrates Use of Foundation Class Libraries
Click to open or copy STEP1
Click to open or copy STEP2
Click to open or copy STEP3
Click to open or copy STEP4
Click to open or copy STEP5
Click to open or copy STEP6
Click to open or copy STEP7
SCRIBBLE is the tutorial sample application discussed in Visual C++? Tutorials. The SCRIBBLE sample directory has seven subdirectories that correspond to different steps in the tutorial. Each subdirectory contains the complete sources for a given step.
SCRIBBLE provides simple illustrations of a wide breadth of MFC features. Step 1 through Step 6 of theScribble Tutorial give the best introduction to the following framework features.
Application objects
Documents, views, and document templates
Commands, message maps, and command user interface updating
MDI (multiple document interface) frame and child windows
Toolbars and status bars
Update hints from documents to views
Dialogs, data exchange, and validation
Scroll view
Splitter window
Printing and print preview
Context-sensitive Help
Refer to other samples for illustrations of advanced use of the above features, and for illustrations of many other features not covered in the tutorial.
Step 7,Creating an OLE Server, of the Scribble Tutorial adds another step to the development of the SCRIBBLE application by introducing OLE Visual Editing server functionality.
……