| |

VerySource

 Forgot password?
 Register
Search
View: 737|Reply: 5

Memory DC problem? Everyone, please help ...

[Copy link]

2

Threads

8

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

Post time: 2020-3-22 23:00:02
| Show all posts |Read mode
I made a drawing program, using memory DC, the original code is as follows: (in the OnDraw (CDC * pDC) function of C * View) ----- but after running, the entire View area is black?

CDC dc;
CDC * pDrawDC = pDC;
CBitmap bitmap;
CBitmap * pOldBitmap;

CRect rect;
GetClientRect (&rect);
// ==================================================== =========
if (dc.CreateCompatibleDC (pDC))
{
if (bitmap.CreateCompatibleBitmap (pDC,
rect.Width (),
rect.Height ()))
{
OnPrepareDC (&dc, NULL);
pDrawDC =&dc;
pOldBitmap = dc.SelectObject (&bitmap);
}
}
// ==================================================== =========
pDoc-> Draw (pDrawDC, ViewID);
pDrawDC-> TextOut (1,1, * str);
dc.DPtoLP (&rect);
// ==================================================== =========
if (pDrawDC! = pDC)
{
pDC-> BitBlt (0, 0, rect.Width (), rect.Height (),
&dc, 0, 0, SRCCOPY);
dc.SelectObject (pOldBitmap);
bitmap.DeleteObject ();
}
Please help me, what is the problem?
Reply

Use magic Report

1

Threads

9

Posts

7.00

Credits

Newbie

Rank: 1

Credits
7.00

 China

Post time: 2020-7-3 12:00:01
| Show all posts
The original bitmap created with CreateCompatibleBitmap is black and white
The bitmap file should be loaded directly by loadimage, then
selectobject memory dc is enough
Reply

Use magic Report

0

Threads

14

Posts

10.00

Credits

Newbie

Rank: 1

Credits
10.00

 China

Post time: 2020-7-3 14:45:01
| Show all posts
The bitmap created by CreateCompatibleBitmap is black by default. Before drawing up, you must paint it with the background color you want, such as white.
Reply

Use magic Report

0

Threads

8

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

Post time: 2020-7-5 20:30:01
| Show all posts
S upstairs is right!
Use CreateCompatibleBitmap to create the original bitmap, the default is black and white
Reply

Use magic Report

2

Threads

8

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

 Author| Post time: 2020-7-8 12:30:01
| Show all posts
Let’s ask a more vegetable question: how to paint the background color of the bitmap to white?
Reply

Use magic Report

2

Threads

8

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

 Author| Post time: 2020-7-27 09:00:01
| Show all posts
The reason is that I have a SetMapMode(MM_TWIPS) statement in OnPrepareDC(); when I comment out this statement, normal results can be obtained. Why?
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list