CBkDialogST::CBkDialogST(CWnd* pParent )
{
Init();
}
CBkDialogST::CBkDialogST(UINT uResourceID, CWnd* pParent)
: CDialog(uResourceID, pParent)
{
Init();
}
CBkDialogST::CBkDialogST(LPCTSTR pszResourceID, CWnd* pParent)
: CDialog(pszResourceID, pParent)
{
Init();
}
CBkDialogST::~CBkDialogST()
{
FreeResources();
}
CBkDialogST::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
}
BEGIN_MESSAGE_MAP(CBkDialogST, CDialog)
ON_WM_ERASEBKGND()
ON_WM_SIZE()
ON_WM_LBUTTONDOWN()
END_MESSAGE_MAP()
CBkDialogST::Init()
{
FreeResources(FALSE);
m_byMode BKDLGST_MODE_TILE;
m_bEasyMoveMode TRUE;
}
CBkDialogST::FreeResources(BOOL bCheckForNULL)
{
(bCheckForNULL TRUE)
{
(m_hBitmap) ::DeleteObject(m_hBitmap);
}
m_hBitmap NULL;
m_dwWidth ;
m_dwHeight ;
}
CBkDialogST::OnLButtonDown(UINT nFlags, CPoint point)
{
(m_bEasyMoveMode TRUE)
PostMessage(WM_NCLBUTTONDOWN, HTCAPTION, MAKELPARAM(point.x, point.y));
CDialog::OnLButtonDown(nFlags, point);
}
DWORD CBkDialogST::ActivateEasyMoveMode(BOOL bActivate)
{
m_bEasyMoveMode bActivate;
BKDLGST_OK;
}
DWORD CBkDialogST::SetBitmap( nBitmap)
{
HBITMAP hBitmap NULL;
HINSTANCE hInstResource NULL;
hInstResource AfxFindResourceHandle(MAKEINTRESOURCE(nBitmap), RT_BITMAP);
hBitmap (HBITMAP)::LoadImage(hInstResource, MAKEINTRESOURCE(nBitmap), IMAGE_BITMAP, , , );
SetBitmap(hBitmap);
}
DWORD CBkDialogST::SetBitmap(HBITMAP hBitmap)
{
nRetValue;
BITMAP csBitmapSize;
FreeResources();
(hBitmap)
{
m_hBitmap hBitmap;
nRetValue ::GetObject(hBitmap, (csBitmapSize), &csBitmapSize);
(nRetValue )
{
FreeResources();
BKDLGST_INVALIDRESOURCE;
}
m_dwWidth (DWORD)csBitmapSize.bmWidth;
m_dwHeight (DWORD)csBitmapSize.bmHeight;
}
Invalidate();
BKDLGST_OK;
}
DWORD CBkDialogST::SetMode(BYTE byMode, BOOL bRepaint)
{
(byMode > BKDLGST_MAX_MODES) BKDLGST_INVALIDMODE;
m_byMode byMode;
(bRepaint TRUE) Invalidate();
BKDLGST_OK;
}
DWORD CBkDialogST::ShrinkToFit(BOOL bRepaint)
{
CRect rWnd;
CRect rClient;
DWORD dwDiffCX;
DWORD dwDiffCY;
::GetWindowRect(m_hWnd, &rWnd);
::GetClientRect(m_hWnd, &rClient);
dwDiffCX rWnd.Width() rClient.Width();
dwDiffCY rWnd.Height() rClient.Height();
m_byMode BKDLGST_MODE_CENTER;
MoveWindow(rWnd.left, rWnd.top, dwDiffCX m_dwWidth, dwDiffCY m_dwHeight, bRepaint);
BKDLGST_OK;
}
CBkDialogST::OnSize(UINT nType, cx, cy)
{
CDialog::OnSize(nType, cx, cy);
(m_hBitmap NULL)
{
Invalidate();
}
}
CBkDialogST::OnPostEraseBkgnd(CDC* pDC)
{
}
BOOL CBkDialogST::OnEraseBkgnd(CDC* pDC)
{
CRect rWnd;
nX ;
nY ;
BOOL bRetValue CDialog::OnEraseBkgnd(pDC);
(m_hBitmap)
{
GetClientRect(rWnd);
CDC dcMemoryDC;
CBitmap bmpMemoryBitmap;
CBitmap* pbmpOldMemoryBitmap NULL;
dcMemoryDC.CreateCompatibleDC(pDC);
bmpMemoryBitmap.CreateCompatibleBitmap(pDC, rWnd.Width(), rWnd.Height());
pbmpOldMemoryBitmap (CBitmap*)dcMemoryDC.SelectObject(&bmpMemoryBitmap);
dcMemoryDC.FillSolidRect(rWnd, pDC>GetBkColor());
CDC dcTempDC;
HBITMAP hbmpOldTempBitmap NULL;
dcTempDC.CreateCompatibleDC(pDC);
hbmpOldTempBitmap (HBITMAP)::SelectObject(dcTempDC.m_hDC, m_hBitmap);
(m_byMode)
{
// 平铺位图
(nY < rWnd.Height())
{
(nX < rWnd.Width())
{
dcMemoryDC.BitBlt(nX, nY, m_dwWidth, m_dwHeight, &dcTempDC, , , SRCCOPY);
nX m_dwWidth;
}
nX ;
nY m_dwHeight;
}
;
nX ((rWnd.Width() m_dwWidth)/);
nY ((rWnd.Height() m_dwHeight)/);
dcMemoryDC.BitBlt(nX, nY, m_dwWidth, m_dwHeight, &dcTempDC, , , SRCCOPY);
;
// 拉伸位图
dcMemoryDC.StretchBlt(, , rWnd.Width(), rWnd.Height(), &dcTempDC, , , m_dwWidth, m_dwHeight, SRCCOPY);
;
(nX < rWnd.Width())
{
dcMemoryDC.BitBlt(nX, , m_dwWidth, m_dwHeight, &dcTempDC, , , SRCCOPY);
nX m_dwWidth;
}
;
(nX < rWnd.Width())
{
dcMemoryDC.BitBlt(nX, rWnd.bottom m_dwHeight, m_dwWidth, m_dwHeight, &dcTempDC, , , SRCCOPY);
nX m_dwWidth;
}
;
(nY < rWnd.Height())
{
dcMemoryDC.BitBlt(, nY, m_dwWidth, m_dwHeight, &dcTempDC, , , SRCCOPY);
nY m_dwHeight;
}
;
(nY < rWnd.Height())
{
dcMemoryDC.BitBlt(rWnd.right m_dwWidth, nY, m_dwWidth, m_dwHeight, &dcTempDC, , , SRCCOPY);
nY m_dwHeight;
}
;
dcMemoryDC.BitBlt(, , m_dwWidth, m_dwHeight, &dcTempDC, , , SRCCOPY);
;
dcMemoryDC.BitBlt(rWnd.right m_dwWidth, , m_dwWidth, m_dwHeight, &dcTempDC, , , SRCCOPY);
;
nX ((rWnd.Width() m_dwWidth)/);
dcMemoryDC.BitBlt(nX, , m_dwWidth, m_dwHeight, &dcTempDC, , , SRCCOPY);
;
dcMemoryDC.BitBlt(, rWnd.bottom m_dwHeight, m_dwWidth, m_dwHeight, &dcTempDC, , , SRCCOPY);
;
dcMemoryDC.BitBlt(rWnd.right m_dwWidth, rWnd.bottom m_dwHeight, m_dwWidth, m_dwHeight, &dcTempDC, , , SRCCOPY);
;
nX ((rWnd.Width() m_dwWidth)/);
dcMemoryDC.BitBlt(nX, rWnd.bottom m_dwHeight, m_dwWidth, m_dwHeight, &dcTempDC, , , SRCCOPY);
;
}
pDC>BitBlt(, , rWnd.Width(), rWnd.Height(), &dcMemoryDC, , , SRCCOPY);
OnPostEraseBkgnd(&dcMemoryDC);
::SelectObject(dcTempDC.m_hDC, hbmpOldTempBitmap);
dcMemoryDC.SelectObject(pbmpOldMemoryBitmap);
}
bRetValue;
}