Example #1
0
// Hinzufügen einer Bitmap zur Toolbar, liefert Index des ersten Buttons der 
// Bitmap
HRESULT CTRiASToolBar::AddBitmap (HINSTANCE hInst, UINT uiRsc, int nNumButtons, int *piOffset)
{
	AFX_MANAGE_STATE(AfxGetModuleState());
    ASSERT_VALID(this);
    ASSERT(::IsWindow(m_hWnd));

	if (NULL != piOffset) *piOffset = -1;	// für alle Fälle

#if !defined(_USE_SEC_CLASSES)
// Größen für das Control ausrechnen
HBITMAP hBmp = NULL;

	if (NULL == hInst)
		hBmp = (HBITMAP)uiRsc;
	else {
	HRSRC hRsrcImageWell = ::FindResource(hInst, (LPCSTR)uiRsc, RT_BITMAP);
	
		if (hRsrcImageWell == NULL)
			return E_FAIL;		// Bitmap not found

		hBmp = AfxLoadSysColorBitmap(hInst, hRsrcImageWell);
	}
	if (NULL == hBmp) return E_FAIL;

// need complete bitmap size to determine size of images
BITMAP bitmap;

	VERIFY(::GetObject(hBmp, sizeof(BITMAP), &bitmap));

int iWidth = bitmap.bmWidth / nNumButtons;
int iHeight = bitmap.bmHeight;

CSize sizeImage(iWidth, iHeight+1);
CSize sizeButton(iWidth + 7, iHeight + 7);

	SetSizes(sizeButton, sizeImage);

// Bitmap zu Control hinzufügen
TBADDBITMAP tbab;

	tbab.hInst = NULL;
	tbab.nID = (UINT)hBmp;

int iOffset = (int) DefWindowProc(TB_ADDBITMAP, (WPARAM)nNumButtons, (LPARAM)&tbab);

	if (NULL != piOffset) *piOffset = iOffset;

	return NOERROR;
#else
// einfach weiterreichen
	return m_pMainFrm -> AddBitmap (hInst, uiRsc, nNumButtons, piOffset);
#endif // _USE_SEC_CLASSES
}
Example #2
0
BOOL CRulerItem::LoadMaskedBitmap(LPCTSTR lpszResourceName)
{
    ASSERT(lpszResourceName != NULL);

    if (m_hbm != NULL)
        ::DeleteObject(m_hbm);

    HINSTANCE hInst = AfxFindResourceHandle(lpszResourceName, RT_BITMAP);
    HRSRC hRsrc = ::FindResource(hInst, lpszResourceName, RT_BITMAP);
    if (hRsrc == NULL)
        return FALSE;

    m_hbm = AfxLoadSysColorBitmap(hInst, hRsrc);
    return (m_hbm != NULL);
}
Example #3
0
BOOL CModControlBar::Init(UINT nId)
//---------------------------------
{
    HINSTANCE hInstance = AfxGetInstanceHandle();
    TBADDBITMAP tbab;

    SetButtonStructSize(sizeof(TBBUTTON));
    SetBitmapSize(CSize(16, 15));
    SetButtonSize(CSize(27, 24));
    // Add bitmaps
    m_hBarBmp = AfxLoadSysColorBitmap(
                    hInstance,
                    ::FindResource(hInstance, MAKEINTRESOURCE(nId), RT_BITMAP));
    tbab.hInst = NULL;
    tbab.nID = (UINT)m_hBarBmp;
    ::SendMessage(m_hWnd, TB_ADDBITMAP, 16, (LPARAM)&tbab);
    UpdateStyle();
    return TRUE;
}