Home > Software engineering >  Who help me science the beginning the following code?
Who help me science the beginning the following code?

Time:09-27

To draw the interface of what don't understand, dc CompatibleDC CompatibleBitmap what of chaos, the following is a project code for comments, thank you

Void CMainDlg: : OnPaint ()
{
CPaintDC dc (this);
CDC memDC;
CBitmap memBitmap;
MemDC. CreateCompatibleDC (& amp; Dc);//draw interface is to get the current dc and then create a compatible dc? What's the relationship between cpaintdc CDC: why do you want to have two?
MemBitmap. CreateCompatibleBitmap (& amp; Dc, m_nWidth m_nHeight);//this is going to put a bitmap into the dc, notice the width height? Why not memDC?
MemDC. SelectObject (& amp; MemBitmap);//here in dc (CPaintDC) is that ok?
MemDC. SetBkMode (TRANSPARENT);/behind/no TransparentBlt set transparent? What's the point? MemDC behind when drawtext use, said this is only part of the other part of the reserved word transparent?
HDC HDC=memDC. M_hDC;//
//-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
If (: : GetProp (m_hWnd, _T (" CacheDC "))) {///why do you want to keep m_hOldCacheBitmap alone? Already a member variable, in other places with the hWnd to obtain and use?
: : SelectObject (m_hCacheDC m_hOldCacheBitmap);///this is why?
: : DeleteObject ((HGDIOBJ) m_hCacheBitmap);
} else {
: : SetProp (m_hWnd, _T (" CacheDC "), (HANDLE) m_hCacheDC);//the main window has added a attribute cacheDC
}
M_hCacheBitmap=CreateCompatibleBitmap (dc) m_hDC, m_nWidth m_nWidth);//in front of a bitmap why still make a cachebitmap
M_hOldCacheBitmap=(HBITMAP) : : SelectObject (m_hCacheDC m_hCacheBitmap);
//-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
: : FillRect (hDC, m_ClientRc m_hbrBack);//it's like with the default color is the meaning of all the clientrect fill
: : StretchBlt (hDC, 0,0,3, m_nHeight, g_SkinDC, 0,47,3,1, SRCCOPY);//these are duplicate the image content, good understand
.
: : StretchBlt (hDC, m_nWidth - 3,0,3 m_nHeight, g_SkinDC, 57,47,3,1, SRCCOPY);

M_MainBtn. The Draw (hDC);
.
M_MinBtn. The Draw (hDC);

//-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
///can't directly to output text on hDC, can only get a memDC membitmap specified width height into the bitmap first output (drawtext) and then copy the content to the dc?
Cstrings STR.
GetWindowText (STR);
MemDC. DrawText (STR, m_TitleRc DT_VCENTER | DT_SINGLELINE | DT_END_ELLIPSIS | DT_HIDEPREFIX);
//-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
: : BitBlt (m_hCacheDC, 0, 0, m_nWidth m_nHeight, hDC, 0, 0, SRCCOPY);//cachedc output text before the interface is preserved?
//GetProp above the two lines of code of success is what function?
Dc. BitBlt (0, 0, m_nWidth m_nHeight, & amp; MemDC, 0, 0, SRCCOPY);//here: : BitBlt is the same?
}

CodePudding user response:

 
Void CCustomCtrlDlg: : MyPaint ()
{
CPaintDC dc (this);//screen DC
CDC memDC;//memory DC, construct a DC
CBitmap memBitmap;//constructs a BMP object
//a memory dc compatible with, it is double buffer drawing method, to draw to a memory dc
MemDC. CreateCompatibleDC (& amp; Dc);
//create a BMP object, m_nWidth m_nHeight is size
MemBitmap. CreateCompatibleBitmap (& amp; Dc, m_nWidth m_nHeight);
//put the BMP in the memory dc, cannot use dc screen
MemDC. SelectObject (& amp; MemBitmap);
//let the text background is transparent
MemDC. SetBkMode (TRANSPARENT);
HDC HDC=memDC. M_hDC;//
//remove CacheDC
If (: : GetProp (m_hWnd, _T (" CacheDC ")))//there
{//the original cached BMP into m_hCacheDC, delete the last created m_hCacheBitmap
: : SelectObject (m_hCacheDC m_hOldCacheBitmap);
: : DeleteObject ((HGDIOBJ) m_hCacheBitmap);
}
The else//there is no
{//save m_hCacheDC in the main window
: : SetProp (m_hWnd, _T (" CacheDC "), (HANDLE) m_hCacheDC);
}
//create a Cached Bitmap, use screen DC, DC. The m_hDC
M_hCacheBitmap=CreateCompatibleBitmap (dc) m_hDC, m_nWidth m_nWidth);
//put the m_hCacheBitmap m_hCacheDC
M_hOldCacheBitmap=(HBITMAP) : : SelectObject (m_hCacheDC m_hCacheBitmap);
//hDC corresponding memory dc memDC, fill the memory dc
: : FillRect (hDC, m_ClientRc m_hbrBack);
//use g_SkinDC, to map the memory DC
: : StretchBlt (hDC, 0,0,3, m_nHeight, g_SkinDC, 0,47,3,1, SRCCOPY);
: : StretchBlt (hDC, m_nWidth - 3,0,3 m_nHeight, g_SkinDC, 57,47,3,1, SRCCOPY);
///can't directly to output text on hDC, can only get a memDC membitmap specified width height into the bitmap first output (drawtext) and then copy the content to the dc?
Cstrings STR.
GetWindowText (STR);
//write the word memory DC
MemDC. DrawText (STR, m_TitleRc DT_VCENTER | DT_SINGLELINE | DT_END_ELLIPSIS | DT_HIDEPREFIX);
//copy all the contents of a memory dc to the m_hCacheDC
: : BitBlt (m_hCacheDC, 0, 0, m_nWidth m_nHeight, hDC, 0, 0, SRCCOPY);
//the last copy the contents of a memory dc to dc screen, you can use the: : GetProp BitBlt//above the two lines of code of success is what function?
Dc. BitBlt (0, 0, m_nWidth m_nHeight, & amp; MemDC, 0, 0, SRCCOPY);
}

CodePudding user response:

This is a memory map code,
See, this code is not very good,
But you can study,

CodePudding user response:

Gdi + memory map, adopting the object-oriented class CDC

You can also use HDC win32 gdi

CodePudding user response:

Thank you for your reply soon very detailed,
There is confusion:
 
//dc here every time with the actual drawing dc? Can pass memdc cachedc? With SelectObject with dc, bitmap needs to have a corresponding relationship? Or can casually with?
M_hCacheBitmap=CreateCompatibleBitmap (dc) m_hDC, m_nWidth m_nWidth);
M_hOldCacheBitmap=(HBITMAP) : : SelectObject (m_hCacheDC m_hCacheBitmap);


In addition, I look at the next cachedc create, is simple in dialog. When the create execution:
 
HDC hSrcDC=: : GetDC (0);
G_SkinDC=: : CreateCompatibleDC (hSrcDC);
M_hCacheDC=: : CreateCompatibleDC (hSrcDC);

Already have m_hCacheDC above at the time of paint and necessary memDC? Directly use the m_hCacheDC not line?
In the onpaint
M_hCacheBitmap=CreateCompatibleBitmap (dc) m_hDC, m_nWidth m_nWidth);
M_hOldCacheBitmap=(HBITMAP) : : SelectObject (m_hCacheDC m_hCacheBitmap);//here with memDC also can

nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related