HDC hdc = GetDC(m_hWnd)
m_hMemDC=CreateCompatibleDC(hdc) SelectObject m_hMemDC,m_hBKbitmap
m_hStretchedBitmap=CreateCompatibleBitmap(hdc,WndClintRect.right-WndClintRect.left,WndClintRect.bottom- WndClintRect.top)
m_hStretchedMem=CreateCompatibleDC(hdc)
SelectObject m_hStretchedMem,m_hStretchedBitmapReleaseDC m_hWnd, hdc
This is how you handle the sizing message WM_SIZE:
SelectObject m_hStretchedMem,m_hStretchedBitmapOld
DeleteObject m_hStretchedBitmap
HDC hdc = GetDC(m_hWnd) m_hStretchedBitmap=CreateCompatibleBitmap(hdc,WndClintRect.right- WndClintRect.left,WndClintRect.bottom- WndClintRect.top)
InvalidateRect m_hWnd,NULL,false
SelectObject m_hStretchedMem, m_hStretchedBitmap
ReleaseDC m_hWnd, hdc
before we draw the background we will pass the bitmap to the rich edit control so it would draw its background on the given bitmap. We will handle this in the background erasing of the main dialog
int SemiRichEditDlg::OnEraseBkgnd(WPARAM wParam, LPARAM lParam)
HDC hdc = (HDC)wParam
StretchBlt m_hStretchedMem, 0, 0, WndClintRect.right, WndClintRect.bottom, m_hMemDC, 0, 0, m_iBitmapWidth, m_iBitmapHight, SRCCOPY
m_semiricheditctrl.DrawBackGround(hdc, m_hStretchedMem); BitBlt(hdc, 0, 0, WndClintRect.right - WndClintRect.left, WndClintRect.bottom - WndClintRect.top, m_hStretchedMem, 0, 0, SRCCOPY) return 1
How Does the Rich Edit draw its Background (Rich Edit to Bitmap)?
Now that we are almost done all we need to draw the background of the rich edit control to a bitmap and then copy it to the main window background(the main bitmap). So we need to create a bitmap the size of the rich edit background
' Creating A DC
HDC hdcTransparent=CreateCompatibleDC(hdc)
'Creating a bitmap
hTransparentBitmap=CreateCompatibleBitmap(hdc,m_RichEditRect.right-m_RichEditRect.left,m_RichEditRect.bottom-m_RichEditRect.top)
'Selecting the bitmap in to the created DC SelectObject hdcTransparent, hTransparentBitmap
'Fill the bitmap with white colour FloodFill hdcTransparent,0,0,RGB(255,255,255)
AlphaBlend hStretchedMem, m_RichEditRect.left + 1, m_RichEditRect.top + 1, m_RichEditRect.right - m_RichEditRect.left, m_RichEditRect.bottom - m_RichEditRect.top, hdcTransparent, 0, 0, m_RichEditRect.right - m_RichEditRect.left, m_RichEditRect.bottom - m_RichEditRect.top, blend
'Finding the size in twips
nLogPixelsX =GetDeviceCaps(hdcTransparent, LOGPIXELSX)
nLogPixelsY =GetDeviceCaps(hdcTransparent, LOGPIXELSY)
rc.left=MulDiv(rc.left,1440, nLogPixelsX)
rc.top=MulDiv(rc.top,1440, nLogPixelsY)
rc.right=MulDiv(rc.right, 1440,nLogPixelsX)
rc.bottom=MulDiv(rc.bottom,1440, nLogPixelsY)
fr.hdc=hdcTransparent
fr.hdcTarget=hdcTransparent
fr.rc=rc
fr.rcPage=rc
fr.chrg.cpMin=SendMessage(m_hWnd, EM_CHARFROMPOS,(WPARAM) FALSE, <BR> (LPARAM) &point)
fr.chrg.cpMax=-1
'Requesting to draw on the DC
lResult=SendMessage(m_hWnd, EM_FORMATRANGE,(WPARAM) TRUE, <BR> (LPARAM) &fr)
lResult=SendMessage(m_hWnd, EM_FORMATRANGE,(WPARAM) FALSE, <BR> (LPARAM) NULL)
BitBlt hStretchedMem, m_RichEditRect.left + 1, m_RichEditRect.top + 1,<BR> m_RichEditRect.right - m_RichEditRect.left, <BR> m_RichEditRect.bottom - m_RichEditRect.top, hdcTransparent, 0, 0,SRCAND
EM_FORMATRANGE message
wParam
Specifies whether to render the text. If this parameter is not zero, the text is rendered. Otherwise, the text is just measured.
lParam
A FORMATRANGE structure containing information about the output device, or NULLto free information cached by the control.
Type FORMATRANGE
hdcTarget As Long
hdc As Long
rc As RECT
rcPage As RECT
chrg As CHARRANGE
End Type
Type CHARRANGE
cpMin As Long
cpMax As Long
End Type
Private Const EM_DISPLAYBAND=&H451
Private Const EM_EXLINEFROMCHAR=&H454
Private Const EM_FORMATRANGE=&H457
Private Const EM_SETBKGNDCOLOR=&H467
Private Const EM_SETZOOM=&H625
EM_DISPLAYBAND message
Displays a portion of the contents of a rich edit control, as previously formatted for a device using the EM_FORMATRANGE message
Parameters
wParam
This parameter is not used; it must be zero.
lParam
A RECT structure specifying the display area of the device.