Use the MFC dialog to do a flashing picture redraw

zhaozj2021-02-16  57

Use the application wizard into a dialog-based application

Set the Border of the dialog styles to Resizing and hook the minimize box with the Maximize Box check button.

Now we import a bitmap for resources and then we add four private variables for programs: int Height; int width; cbitmap mybitmap; bitmap BM;

Then add the WM Size message with the class wizard to enter the following code: width = cx; height = cy; invalidate ();

Then add the following code to add the WM_PAINT message: CDC * PDC = New CDC; CPAINTDC DC (this); // CclientDC DC (NULL); PDC-> CreateCompatibleDC (& DC); PDC-> SelectObject (MyBitmap); / / Stretch the picture into our setting size. Dc.stretchBLT (0, 0, Width, Height, PDC, 0, 0, Bm.Bmwidth, BM.Bmheight, Srcopy); // If you are not ready to scale, you can use Bitblt. //Dc.bitblt (0, 5, cm.bmwidth ,bm.bmheight, pdc ,0,0,4rccopy);

DELETE PDC;

Then do the last step to import our pictures when the program is initialized and let the dialogue are the same as the picture.

Add the following code in the last iNitDialog function:

// Todo: add extra initialization hebitmap.loadbitmap (idb_bitmap1); MybitMap.GetObject (Sizeof (Bitmap), & BM)

Ok, we have made a dialog that can be displayed and the picture size will change when the conversation changes, but this program has a shortcoming, it is to flash, there is a flashing, the performance is not good,

Now we press the steps to do a dialog, import bitmap,

Add the following variables: public: csize m_sizebuffer; cbitmap m_BmpBackBuffer; cbitmap * m_pbmpppattern;

Add the following code in the OnInitDialog function

M_PBMPPATTERN = CBitmap :: fromHandle ((hbitmap) :: loadimage (AfxgetResourceHandle (), makeintResource (idb_backround), image_bitmap, 0,0, lr_shared);

Override onpaint function

IF (isiconic ()) {cPaintDC DC (this); // device context for Painting

SendMessage (WM_ICONERASEBKGND, (WPARAM) dc.getsafehdc (), 0);

// Center icon in client rectangle int cxIcon = GetSystemMetrics (SM_CXICON); int cyIcon = GetSystemMetrics (SM_CYICON); CRect rect; GetClientRect (& rect); int x = (rect.Width () - cxIcon 1) / 2; int y = (Rect.height () - Cyicon 1) / 2;

// Draw the icon dc.DrawIcon (x, y, m_hIcon);} else {CPaintDC dc (this); CDC dcBackBuffer; dcBackBuffer.CreateCompatibleDC (& dc); // recalculate the area of ​​CRect rectClient; GetClientRect (rectClient); if (m_sizeBuffer = rectClient.Size ()!) {m_sizeBuffer = rectClient.Size (); if (m_bmpBackBuffer.GetSafeHandle () = NULL!) m_bmpBackBuffer.DeleteObject (); m_bmpBackBuffer.CreateCompatibleBitmap (& dc, m_sizeBuffer.cx, m_sizeBuffer.cy) ;} CBitmap * pOldBmp = dcBackBuffer.SelectObject (& m_bmpBackBuffer); // Videos background if (NULL == m_pbmpPattern) {dcBackBuffer.FillSolidRect (rectClient, RGB (255,0,255));} else {CDC dcPat; dcPat.CreateCompatibleDC (& dcBackBuffer ); CBitmap * pbmpOld = dcPat.SelectObject (m_pbmpPattern); BITMAP bitmap; if (m_pbmpPattern-> GetBitmap (& bitmap) && bitmap.bmWidth> 0 && bitmap.bmHeight> 0) {BOOL m_bTilePattern; m_bTilePattern = TRUE; if (m_bTilePattern) {For (int y = 0; y

转载请注明原文地址:https://www.9cbs.com/read-22874.html

New Post(0)