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

📄 alphatoolbar.cpp

📁 用户管理系统
💻 CPP
字号:
/*********************************************************
* Simple IE-like Menu And Toolbar
* Version: 1.3
* Date: Semptember 1, 2003
* Autor: Michal Mecinski
* E-mail: mimec@mimec.w.pl
* WWW: http://www.mimec.w.pl
*
* Copyright (C) 2002-03 by Michal Mecinski
*********************************************************/

#include "stdafx.h"
#include "AlphaToolBar.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#endif


CAlphaToolBar::CAlphaToolBar()
{
}

CAlphaToolBar::~CAlphaToolBar()
{
}

BEGIN_MESSAGE_MAP(CAlphaToolBar, CToolBar)
END_MESSAGE_MAP()


BOOL CAlphaToolBar::Create(CWnd* pParentWnd, UINT nID)
{
	// create flat transparent toolbar for use in a rebar control
	return CToolBar::CreateEx(pParentWnd, TBSTYLE_FLAT | TBSTYLE_TRANSPARENT,
		CBRS_SIZE_DYNAMIC|WS_CHILD | WS_VISIBLE | CBRS_ALIGN_TOP | CBRS_TOOLTIPS | CBRS_FLYBY,
		CRect(0,0,0,0), nID);
}

/*
BOOL CAlphaToolBar::LoadToolBar(UINT nID, int nStyle)
{
	HINSTANCE hInst = AfxFindResourceHandle(MAKEINTRESOURCE(nID), RT_TOOLBAR);
	HRSRC hRsrc = ::FindResource(hInst, MAKEINTRESOURCE(nID), RT_TOOLBAR);
	if (hRsrc == NULL)
		return FALSE;

	HGLOBAL hGlobal = LoadResource(hInst, hRsrc);
	if (hGlobal == NULL)
		return FALSE;

	struct TBDATA
	{
		WORD wVersion;
		WORD wWidth;
		WORD wHeight;
		WORD wItemCount;
		WORD aItems[1];
	};

	// get the toolbar data
	TBDATA* pData = (TBDATA*)LockResource(hGlobal);
	if (pData == NULL)
		return FALSE;
	ASSERT(pData->wVersion == 1);

	// create toolbar buttons
	UINT* pItems = new UINT[pData->wItemCount];
	//UINT* pTexts = new UINT[pData->wItemCount];
	LPTSTR pTexts[256];
	LPTSTR pText, pDest;
	char szBuff[256];
	BOOL bFoundText = FALSE;
	CString strName;
	UINT id;
	int nSize;
	for (int i = 0; i < pData->wItemCount; i++)
	{
		pItems[i] = pData->aItems[i];
		pTexts[i] = NULL;
	}
	BOOL bResult = SetButtons(pItems, pData->wItemCount);
	delete[] pItems;
	UnlockResource(hGlobal);
	FreeResource(hGlobal);
    if(bResult)
	{
	 for ( i = 0; i < pData->wItemCount; i++)
	 {
		//取出字符串
	    id = GetItemID(i);
        LoadString(hInst, id, szBuff, sizeof(szBuff)-1);
		pText = strchr(szBuff, '\n'); //跳过第1段
		if(!pText)  continue;
		pText++;
		if(!pText)  continue;
		pText = strchr(pText, '\n');  //跳过第2段
		if(!pText) continue;
		pText++;
		if(!pText) continue;
	    nSize = strlen(pText)+1; //取出第3段
		pDest = new char [nSize];
		//pTexts[i] = (UINT)&pDest;
 		pTexts[i] = pDest;
        memcpy(pDest, pText, nSize);
		pDest[nSize-1] = NULL;
		bFoundText = TRUE;
	 }
	}//
	CSize sizeButton;
	if (bResult)
	{
		CSize sizeImage(pData->wWidth, pData->wHeight);
		if(bFoundText)
		   sizeButton=CSize(pData->wWidth + 8, pData->wHeight + 23);
		else
		   sizeButton=CSize(pData->wWidth + 8, pData->wHeight + 7);
		SetSizes(sizeButton, sizeImage);

		// load images from bitmap resource
		if (m_ImgList.Create(pData->wWidth, pData->wHeight, nStyle,
			pData->wItemCount))
		{
			bResult = m_ImgList.AddBitmap(nID);
		}
		else
			bResult = FALSE;
	}

    TBBUTTONINFOA tb;
	if (bResult)	// let the toolbar use our image lists
	{
		SendMessage(TB_SETIMAGELIST, 0, (LPARAM)m_ImgList.GetImageList(AIL_NORMAL));
		SendMessage(TB_SETHOTIMAGELIST, 0, (LPARAM)m_ImgList.GetImageList(AIL_HOT));
		SendMessage(TB_SETDISABLEDIMAGELIST, 0, (LPARAM)m_ImgList.GetImageList(AIL_DISABLED));
	    //SendMessage(TB_SETBUTTONINFO, ID_FILE_NEW, (LPARAM)(LPTBBUTTONINFO)&tb);
        //导入字符串
	    tb.cbSize = sizeof(TBBUTTONINFOA);
	    tb.dwMask = TBIF_TEXT;
		if(bFoundText)
		{
	      for (int i = 0; i < pData->wItemCount; i++)
		  {
           pText = pTexts[i];
	       if (!pText) continue;
		   id = GetItemID(i);
           tb.pszText = pText;
	       tb.cchText = strlen(pText);
	       id = GetItemID(i);
	       tb.idCommand = id;
	       SendMessage(TB_SETBUTTONINFO, id, (LPARAM)(LPTBBUTTONINFO)&tb);
		   delete pText;
		  }//end for
        }//end if
	}//end if
//    delete pTexts;
	return bResult;
}
*/


BOOL CAlphaToolBar::LoadToolBar(UINT nID, int nStyle)
{
	HINSTANCE hInst = AfxFindResourceHandle(MAKEINTRESOURCE(nID), RT_TOOLBAR);
	HRSRC hRsrc = ::FindResource(hInst, MAKEINTRESOURCE(nID), RT_TOOLBAR);
	if (hRsrc == NULL)
		return FALSE;

	HGLOBAL hGlobal = LoadResource(hInst, hRsrc);
	if (hGlobal == NULL)
		return FALSE;

	struct TBDATA
	{
		WORD wVersion;
		WORD wWidth;
		WORD wHeight;
		WORD wItemCount;
		WORD aItems[1];
	};

	// get the toolbar data
	TBDATA* pData = (TBDATA*)LockResource(hGlobal);
	if (pData == NULL)
		return FALSE;
	ASSERT(pData->wVersion == 1);

	// create toolbar buttons
	UINT* pItems = new UINT[pData->wItemCount];
	//UINT* pTexts = new UINT[pData->wItemCount];
	LPTSTR pTexts[256];
	LPTSTR pText, pDest;
	char szBuff[256];
	BOOL bFoundText = FALSE;
	CString strName;
	UINT id;
	int nSize;
	for (int i = 0; i < pData->wItemCount; i++)
	{
		pItems[i] = pData->aItems[i];
		pTexts[i] = NULL;
	}
	BOOL bResult = SetButtons(pItems, pData->wItemCount);
	delete[] pItems;
	UnlockResource(hGlobal);
	FreeResource(hGlobal);
    if(bResult)
	{
	 for ( i = 0; i < pData->wItemCount; i++)
	 {
		//取出字符串
	    id = GetItemID(i);
        LoadString(hInst, id, szBuff, sizeof(szBuff)-1);
		pText = strchr(szBuff, '\n'); //跳过第1段
		if(!pText)  continue;
		pText++;
		if(!pText)  continue;
		pText = strchr(pText, '\n');  //跳过第2段
		if(!pText) continue;
		pText++;
		if(!pText) continue;
	    nSize = strlen(pText)+1; //取出第3段
		pDest = new char [nSize];
		//pTexts[i] = (UINT)&pDest;
 		pTexts[i] = pDest;
        memcpy(pDest, pText, nSize);
		bFoundText = TRUE;
	 }
	}//
	CSize sizeButton;
	if (bResult)
	{
		CSize sizeImage(pData->wWidth, pData->wHeight);
		if(bFoundText)
		   sizeButton=CSize(pData->wWidth + 8, pData->wHeight + 23);
		else
		   sizeButton=CSize(pData->wWidth + 8, pData->wHeight + 7);
		SetSizes(sizeButton, sizeImage);

		// load images from bitmap resource
		if (m_ImgList.Create(pData->wWidth, pData->wHeight, nStyle,
			pData->wItemCount))
		{
			bResult = m_ImgList.AddBitmap(nID);
		}
		else
			bResult = FALSE;
	}

    TBBUTTONINFOA tb;
	if (bResult)	// let the toolbar use our image lists
	{
		SendMessage(TB_SETIMAGELIST, 0, (LPARAM)m_ImgList.GetImageList(AIL_NORMAL));
		SendMessage(TB_SETHOTIMAGELIST, 0, (LPARAM)m_ImgList.GetImageList(AIL_HOT));
		SendMessage(TB_SETDISABLEDIMAGELIST, 0, (LPARAM)m_ImgList.GetImageList(AIL_DISABLED));
	    //SendMessage(TB_SETBUTTONINFO, ID_FILE_NEW, (LPARAM)(LPTBBUTTONINFO)&tb);
        //导入字符串
		if(bFoundText)
		{
	      for (int i = 0; i < pData->wItemCount; i++)
		  {
		   if(pTexts[i])
		   {
		     SetButtonText(i, pTexts[i]);
		     delete pTexts[i];
		   }
		  }//end for
        }//end if
	}//end if
//    delete pTexts;
	return bResult;
}

⌨️ 快捷键说明

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