CBitmapButton?
Hi,
Today when i made an application using CBitmapButton?
i met this notification:
uses undefined class 'CBitmapButton'
Visual studio 2005 for pocket pc 2005 isn't supported this class.
What is the purpose of it?
JT
Hi,
Today when i made an application using CBitmapButton?
i met this notification:
uses undefined class 'CBitmapButton'
Visual studio 2005 for pocket pc 2005 isn't supported this class.
What is the purpose of it?
JT
I tried to make a source code for CBitmapButton like below:
I tested, it run and can paste the Bitmap on the button, can
you test and fix the bug ( i test OK with LoadBitmaps )?
// this is file: x.h
#ifndef
#define _CBitmapButton_H#include "windows.h"
#include
"stdlib.h"#include
"stdio.h"#include
"afxext.h"class
CBitmapButton; // Bitmap button (self-draw)/////////////////////////////////////////////////////////////////////////////
// Simple bitmap button
// CBitmapButton - push-button with 1->4 bitmap images
class
CBitmapButton : public CButton{
//DECLARE_DYNAMIC(CBitmapButton)public
:// Construction
/* JT */ //CBitmapButton();BOOL LoadBitmaps(LPCTSTR lpszBitmapResource,
LPCTSTR lpszBitmapResourceSel = NULL,
LPCTSTR lpszBitmapResourceFocus = NULL,
LPCTSTR lpszBitmapResourceDisabled = NULL);
BOOL LoadBitmaps(UINT nIDBitmapResource,
UINT nIDBitmapResourceSel = 0,
UINT nIDBitmapResourceFocus = 0,
UINT nIDBitmapResourceDisabled = 0);
BOOL AutoLoad(UINT nID, CWnd* pParent);
// Operations
void SizeToContent();// Implementation:
public
:#ifdef
_DEBUG// virtual void AssertValid() const;
// virtual void Dump(CDumpContext& dc) const;
#endif
protected
: // all bitmaps must be the same sizeCBitmap m_bitmap;
// normal image (REQUIRED)CBitmap m_bitmapSel;
// selected image (OPTIONAL)CBitmap m_bitmapFocus;
// focused but not selected (OPTIONAL)CBitmap m_bitmapDisabled;
// disabled bitmap (OPTIONAL) virtual void DrawItem(LPDRAWITEMSTRUCT lpDIS);};
#endif
// this is file x.c
#include "x.h"
//#include "afx.h"
/////////////////////////////////////////////////////////////////////////////
// CBitmapButton
// LoadBitmaps will load in one, two, three or all four bitmaps
// returns TRUE if all specified images are loaded
BOOL CBitmapButton::LoadBitmaps(LPCTSTR lpszBitmapResource,
LPCTSTR lpszBitmapResourceSel, LPCTSTR lpszBitmapResourceFocus,
LPCTSTR lpszBitmapResourceDisabled)
{
// delete old bitmaps (if present)m_bitmap.DeleteObject();
m_bitmapSel.DeleteObject();
m_bitmapFocus.DeleteObject();
m_bitmapDisabled.DeleteObject();
if (!m_bitmap.LoadBitmap(lpszBitmapResource)){
// TRACE(traceAppMsg, 0, "Failed to load bitmap for normal image.\n");
return FALSE; // need this one image}
BOOL bAllLoaded = TRUE;
if (lpszBitmapResourceSel != NULL){
if (!m_bitmapSel.LoadBitmap(lpszBitmapResourceSel)){
// TRACE(traceAppMsg, 0, "Failed to load bitmap for selected image.\n");bAllLoaded = FALSE;
}
}
if (lpszBitmapResourceFocus != NULL){
if (!m_bitmapFocus.LoadBitmap(lpszBitmapResourceFocus))bAllLoaded = FALSE;
}
if (lpszBitmapResourceDisabled != NULL){
if (!m_bitmapDisabled.LoadBitmap(lpszBitmapResourceDisabled))bAllLoaded = FALSE;
}
return bAllLoaded;}
/* JT */
// LoadBitmaps will load in one, two, three or all four bitmaps
// returns TRUE if all specified images are loaded
BOOL CBitmapButton::LoadBitmaps(UINT nIDBitmapResource,
UINT nIDBitmapResourceSel,
UINT nIDBitmapResourceFocus,
UINT nIDBitmapResourceDisabled)
{
// delete old bitmaps (if present)m_bitmap.DeleteObject();
m_bitmapSel.DeleteObject();
m_bitmapFocus.DeleteObject();
m_bitmapDisabled.DeleteObject();
if (!m_bitmap.LoadBitmap(nIDBitmapResource)){
// TRACE(traceAppMsg, 0, "Failed to load bitmap for normal image.\n");
return FALSE; // need this one image}
BOOL bAllLoaded = TRUE;
if (nIDBitmapResourceSel != NULL){
if (!m_bitmapSel.LoadBitmap(nIDBitmapResourceSel)){
// TRACE(traceAppMsg, 0, "Failed to load bitmap for selected image.\n");bAllLoaded = FALSE;
}
}
if (nIDBitmapResourceFocus != NULL){
if (!m_bitmapFocus.LoadBitmap(nIDBitmapResourceFocus))bAllLoaded = FALSE;
}
if (nIDBitmapResourceDisabled != NULL){
if (!m_bitmapDisabled.LoadBitmap(nIDBitmapResourceDisabled))bAllLoaded = FALSE;
}
return bAllLoaded;}
// SizeToContent will resize the button to the size of the bitmap
void
CBitmapButton::SizeToContent(){
ASSERT(m_bitmap.m_hObject != NULL);
CSize bitmapSize;
BITMAP bmInfo;
VERIFY(m_bitmap.GetObject(
sizeof(bmInfo), &bmInfo) == sizeof(bmInfo));VERIFY(SetWindowPos(NULL, -1, -1, bmInfo.bmWidth, bmInfo.bmHeight,
SWP_NOMOVE|SWP_NOZORDER|SWP_NOREDRAW|SWP_NOACTIVATE));
}
// Autoload will load the bitmap resources based on the text of
// the button
// Using suffices "U", "D", "F" and "X" for up/down/focus/disabled
BOOL CBitmapButton::AutoLoad(UINT nID, CWnd* pParent)
{
// first attach the CBitmapButton to the dialog control if (!SubclassDlgItem(nID, pParent)) return FALSE;CString buttonName;
GetWindowText(buttonName);
ASSERT(!buttonName.IsEmpty());
// must provide a titleLoadBitmaps(buttonName + _T(
"U"), buttonName + _T("D"),buttonName + _T(
"F"), buttonName + _T("X")); // we need at least the primary if (m_bitmap.m_hObject == NULL) return FALSE; // size to contentSizeToContent();
return TRUE;}
// Draw the appropriate bitmap
void
CBitmapButton::DrawItem(LPDRAWITEMSTRUCT lpDIS){
ASSERT(lpDIS != NULL);
// must have at least the first bitmap loaded before calling DrawItemASSERT(m_bitmap.m_hObject != NULL);
// required // use the main bitmap for up, the selected bitmap for downCBitmap* pBitmap = &m_bitmap;
UINT state = lpDIS->itemState;
if ((state & ODS_SELECTED) && m_bitmapSel.m_hObject != NULL)pBitmap = &m_bitmapSel;
else if ((state & ODS_FOCUS) && m_bitmapFocus.m_hObject != NULL)pBitmap = &m_bitmapFocus;
// third image for focused else if ((state & ODS_DISABLED) && m_bitmapDisabled.m_hObject != NULL)pBitmap = &m_bitmapDisabled;
// last image for disabled // draw the whole buttonCDC* pDC = CDC::FromHandle(lpDIS->hDC);
CDC memDC;
memDC.CreateCompatibleDC(pDC);
CBitmap* pOld = memDC.SelectObject(pBitmap);
if (pOld == NULL) return; // destructors will clean upCRect rect;
rect.CopyRect(&lpDIS->rcItem);
pDC->BitBlt(rect.left, rect.top, rect.Width(), rect.Height(),
&memDC, 0, 0, SRCCOPY);
memDC.SelectObject(pOld);
}
/////////////////////////////////////////////////////////////////////////////
// CBitmapButton diagnostics
#ifdef
_DEBUG#if
0void CBitmapButton::AssertValid() const
{
CButton::AssertValid();
m_bitmap.AssertValid();
m_bitmapSel.AssertValid();
m_bitmapFocus.AssertValid();
m_bitmapDisabled.AssertValid();
}
#endif
#if
0void CBitmapButton::Dump(CDumpContext& dc) const
{
CButton::Dump(dc);
dc << "m_bitmap = " << (void*)m_bitmap.m_hObject;
dc << "\nm_bitmapSel = " << (void*)m_bitmapSel.m_hObject;
dc << "\nm_bitmapFocus = " << (void*)m_bitmapFocus.m_hObject;
dc << "\nm_bitmapDisabled = " << (void*)m_bitmapDisabled.m_hObject;
dc << "\n";
}
#endif
#endif
//IMPLEMENT_DYNAMIC(CBitmapButton, CButton)
/////////////////////////////////////////////////////////////////////////////