⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jnbitmapwnd.cpp

📁 此次上传的使linux下的文件传输协议
💻 CPP
字号:
// JnBitmapWnd.cpp : implementation file
//

#include "stdafx.h"
#include "Prog.h"
#include "JnBitmapWnd.h"


#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// JnBitmapWnd

IMPLEMENT_DYNCREATE(JnBitmapWnd, CWnd)

void AFXAPI DDX_BmpControl(CDataExchange* pDX, int nIDC, JnBitmapWnd& rControl)
{
    if (rControl.GetSafeHwnd() == NULL)    // not subclassed yet
    {
        ASSERT(!pDX->m_bSaveAndValidate);
        HWND hWndCtrl = pDX->PrepareCtrl(nIDC);
        if (!rControl.SubclassWindow(hWndCtrl))
        {
            ASSERT(FALSE);      // possibly trying to subclass twice?
            AfxThrowNotSupportedException();
        }
#ifndef _AFX_NO_OCC_SUPPORT
        else
        {
            if (pDX->m_pDlgWnd->GetSafeHwnd() != ::GetParent(rControl.GetSafeHwnd()))
                rControl.AttachControlSite(pDX->m_pDlgWnd);
        }
#endif //!_AFX_NO_OCC_SUPPORT
    }
}

JnBitmapWnd::JnBitmapWnd()
{
	CommonConstruct();
    RegisterWindowClass();
	m_sFilePath="";
	m_bCopy=FALSE;
}

JnBitmapWnd::~JnBitmapWnd()
{
}

BOOL JnBitmapWnd::RegisterWindowClass()
{
    WNDCLASS wndcls;
    HINSTANCE hInst = AfxGetResourceHandle();
    if (!(::GetClassInfo(hInst, JNBITMAPWND_CLASSNAME, &wndcls)))
    {
        wndcls.style            = CS_DBLCLKS | CS_HREDRAW | CS_VREDRAW;
        wndcls.lpfnWndProc      = ::DefWindowProc;
        wndcls.cbClsExtra       = wndcls.cbWndExtra = 0;
        wndcls.hInstance        = hInst;
        wndcls.hIcon            = NULL;
        wndcls.hCursor          = NULL;
        wndcls.hbrBackground    = (HBRUSH) (COLOR_3DFACE + 1);
        wndcls.lpszMenuName     = NULL;
        wndcls.lpszClassName    = JNBITMAPWND_CLASSNAME;
        if (!AfxRegisterClass(&wndcls)) 
		{
            AfxThrowResourceException();
            return FALSE;
        }
    }
    return TRUE;
}

BOOL JnBitmapWnd::Create(const RECT& rect, CWnd* pParentWnd, UINT nID, DWORD dwStyle)
{
    ASSERT(pParentWnd->GetSafeHwnd());
    if (!CWnd::Create(JNBITMAPWND_CLASSNAME, NULL, dwStyle, rect, pParentWnd, nID)) 
        return FALSE;
    return TRUE;
}

void JnBitmapWnd::CommonConstruct()
{
	m_pBmpBackground=NULL;
	m_nType = BITMAP_TILE;
	VERIFY(m_HollowBrush.CreateStockObject(HOLLOW_BRUSH));
	//{{AFX_DATA_INIT(JnBitmapWnd)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
}

BEGIN_MESSAGE_MAP(JnBitmapWnd, CWnd)
	//{{AFX_MSG_MAP(JnBitmapWnd)
	ON_WM_ERASEBKGND()
	ON_WM_CTLCOLOR()
	ON_WM_PALETTECHANGED()
	ON_WM_QUERYNEWPALETTE()
	ON_WM_SIZE()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()


/////////////////////////////////////////////////////////////////////////////
// JnBitmapWnd message handlers

BOOL JnBitmapWnd::OnEraseBkgnd(CDC* pDC) 
{
	if(!m_pBmpBackground)
	{
		return CWnd::OnEraseBkgnd(pDC);
	}
	if(m_pBmpBackground->m_bImage) 
	{
		ASSERT(m_nType == BITMAP_TILE || m_nType == BITMAP_STRETCH || m_nType == BITMAP_CENTER);
		CRect rc;
		GetClientRect(rc);
		int x = 0, y = 0;
		switch(m_nType) 
		{
		case BITMAP_CENTER:
			// center the bitmap
			CWnd::OnEraseBkgnd(pDC);
			x = (rc.Width() - m_pBmpBackground->GetWidth()) / 2;
			y = (rc.Height() - m_pBmpBackground->GetHeight()) / 2;
			m_pBmpBackground->DrawDIB(pDC, x, y);
			break;
		case BITMAP_STRETCH:
			// stretch bitmap so it will best fit to the dialog
			m_pBmpBackground->DrawDIB(pDC, 0, 0, rc.Width(), rc.Height());
			break;
		default:
			// tile the bitmap
			while(y < rc.Height()) 
			{
				while(x < rc.Width()) 
				{
					m_pBmpBackground->DrawDIB(pDC, x, y);
					x += m_pBmpBackground->GetWidth();
				}
				x = 0;
				y += m_pBmpBackground->GetHeight();
			}
			break;
		}
	}
	else
		return CWnd::OnEraseBkgnd(pDC);
	return TRUE;
}

HBRUSH JnBitmapWnd::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) 
{
	if(!m_pBmpBackground)
	{
		return CWnd::OnCtlColor(pDC, pWnd, nCtlColor);
	}
	if(m_pBmpBackground->m_bImage) 
	{
		switch(nCtlColor)
		{
		case CTLCOLOR_STATIC:
			TCHAR lpszClassName[255];
			GetClassName(pWnd->m_hWnd, lpszClassName, 255);
			if(_tcscmp(lpszClassName, TRACKBAR_CLASS) == 0)
				return CWnd::OnCtlColor(pDC, pWnd, nCtlColor);
		case CTLCOLOR_BTN:
			pDC->SetBkMode(TRANSPARENT);
			return HBRUSH(m_HollowBrush);
		default:
			break;
		}
	}
	return CWnd::OnCtlColor(pDC, pWnd, nCtlColor);
}

void JnBitmapWnd::OnPaletteChanged(CWnd* pFocusWnd) 
{
	CWnd::OnPaletteChanged(pFocusWnd);
}

BOOL JnBitmapWnd::OnQueryNewPalette() 
{
	return CWnd::OnQueryNewPalette();
}

BOOL JnBitmapWnd :: SetBitmap(UINT uResource, int nType /*BITMAP_TILE*/)
{
	Remove();
	m_nType = nType;
	ASSERT(m_nType == BITMAP_TILE || m_nType == BITMAP_STRETCH || m_nType == BITMAP_CENTER);
	m_pBmpBackground=new CDIBitmap;
	return m_pBmpBackground->Load(uResource);
}

BOOL JnBitmapWnd::SetBitmap(CString sPath, int nType)
{
	Remove();
	m_sFilePath=sPath;
	m_nType = nType;
	ASSERT(m_nType == BITMAP_TILE || m_nType == BITMAP_STRETCH || m_nType == BITMAP_CENTER);

	m_pBmpBackground=new CDIBitmap;
	return m_pBmpBackground->Load(sPath);
}

void JnBitmapWnd::OnSize(UINT nType, int cx, int cy) 
{
	CWnd::OnSize(nType, cx, cy);
	Invalidate();
}

void JnBitmapWnd::Remove()
{
	m_sFilePath="";
	if(m_pBmpBackground && !m_bCopy)
	{
		m_bCopy=FALSE;
		m_pBmpBackground->Free();
	}
	m_pBmpBackground=NULL;
	m_bCopy=FALSE;
}

void JnBitmapWnd::Copy(CDIBitmap *pBmp, int nType)
{
	Remove();
	m_nType=nType;
	m_pBmpBackground=pBmp;
	m_bCopy=TRUE;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -