Click here to Skip to main content
16,007,809 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Passing a object as a parameter to a OCX Pin
Ian Darling29-Oct-03 6:12
Ian Darling29-Oct-03 6:12 
GeneralGDI+ crashes - please help Pin
ARL:UT Student29-Oct-03 4:00
ARL:UT Student29-Oct-03 4:00 
Generaldb_param Binding problem Pin
TheMooseMan29-Oct-03 3:59
TheMooseMan29-Oct-03 3:59 
GeneralRegistry Snap Shot Pin
YaronNir29-Oct-03 3:28
YaronNir29-Oct-03 3:28 
GeneralRe: Registry Snap Shot Pin
David Crow29-Oct-03 4:14
David Crow29-Oct-03 4:14 
GeneralRe: Registry Snap Shot Pin
YaronNir29-Oct-03 4:31
YaronNir29-Oct-03 4:31 
GeneralWM_QUERYENDSESSION Windows session end causes Pin
Anonymous29-Oct-03 2:09
Anonymous29-Oct-03 2:09 
GeneralOwner Draw Button Pin
YaronNir29-Oct-03 1:23
YaronNir29-Oct-03 1:23 
Hi all,

I have a class CMyBtn inherites from CButton. i want to draw it myself....

I have 4 bitmaps for each state - normal/down/over/disabled

I've tried to place code in OnPaint as follows:

void CMyBtn::OnPaint() 
{
	CPaintDC dc(this); // device context for painting
	
	CRect rect;
	GetWindowRect(rect);

	
	BITMAP bmp;
	HBITMAP hBitmap = NULL;
	memset(&bmp,0,sizeof(bmp));
	switch (m_eBtnState)
	{
	case bsUndefined:
		
		ASSERT(FALSE);
		return;

	case bsNormal:
		
		hBitmap = (HBITMAP)m_bmpNormal.m_hObject;
		break;

	case bsDown:

		hBitmap = (HBITMAP)m_bmpDown.m_hObject;
		break;

	case bsOver:    

		hBitmap = (HBITMAP)m_bmpOver.m_hObject;
		break;

	case bsDisabled:

		hBitmap = (HBITMAP)m_bmpDisabled.m_hObject;
		break;

	default:

		ASSERT(FALSE);
		return ;
	}
	
	::GetObject(hBitmap,sizeof(bmp),&bmp);
	HDC compatibleDC = CreateCompatibleDC(dc.m_hDC);
	HBITMAP hSavedObj = (HBITMAP)::SelectObject(compatibleDC,hBitmap);

	ASSERT(NULL != m_pParentDlg);
	COLORREF transparentColor = m_pParentDlg->GetDialogTitleBKColor();

	ScreenToClient(rect);
	BOOL bRes = TransparentBlt(dc.m_hDC, 
				   rect.left,
				   rect.top,
				   rect.right,
				   rect.bottom,
				   compatibleDC,
				   0,
				   0,
				   bmp.bmWidth,
				   bmp.bmHeight,
				   transparentColor);

	::SelectObject(compatibleDC,hSavedObj);
	::DeleteDC(compatibleDC);
}


the button picture of the bitmap is round button. when i looked at the button on the dialog i saw the round button but with gray frame (the part that was outside the button) that made me believe it was a problem of erasing the backgroun so i've added the following code:

BOOL CMyBtn::OnEraseBkgnd(CDC* pDC) 
{
	// TODO: Add your message handler code here and/or call default
	
//	return CButton::OnEraseBkgnd(pDC);

	return TRUE;
}


now i saw the button really good.

problem is when i move the mouse or click it i don't see the pictures changing as they i want them to.....

what should i do?

thanks in advanced

Yaron

Ask not what your application can do for you,
Ask what you can do for your application
GeneralRe: Owner Draw Button Pin
KaЯl29-Oct-03 3:33
KaЯl29-Oct-03 3:33 
GeneralRe: Owner Draw Button Pin
YaronNir29-Oct-03 3:35
YaronNir29-Oct-03 3:35 
QuestionSet IP over modem ? Pin
29-Oct-03 1:03
suss29-Oct-03 1:03 
AnswerRe: Set IP over modem ? Pin
Alexander M.,29-Oct-03 3:25
Alexander M.,29-Oct-03 3:25 
GeneralMeeting trouble when reading traffic bandwidth from network adapter. Pin
George228-Oct-03 23:48
George228-Oct-03 23:48 
GeneralVisual C++ .NET Compiler Error ... Pin
SD328-Oct-03 23:42
SD328-Oct-03 23:42 
QuestionSysInternals FileMon - how? Pin
peterchen28-Oct-03 23:37
peterchen28-Oct-03 23:37 
AnswerRe: SysInternals FileMon - how? Pin
Alexander M.,28-Oct-03 23:40
Alexander M.,28-Oct-03 23:40 
AnswerRe: SysInternals FileMon - how? Pin
David Crow29-Oct-03 2:55
David Crow29-Oct-03 2:55 
GeneralRe: SysInternals FileMon - how? Pin
Alexander M.,29-Oct-03 3:28
Alexander M.,29-Oct-03 3:28 
GeneralRe: SysInternals FileMon - how? Pin
David Crow29-Oct-03 3:37
David Crow29-Oct-03 3:37 
GeneralOT Pin
peterchen29-Oct-03 3:39
peterchen29-Oct-03 3:39 
GeneralRe: OT Pin
Atlantys29-Oct-03 7:55
Atlantys29-Oct-03 7:55 
QuestionInternal memory management when using 'new'? Pin
Dominik Reichl28-Oct-03 22:38
Dominik Reichl28-Oct-03 22:38 
AnswerRe: Internal memory management when using 'new'? Pin
Alexander M.,28-Oct-03 23:38
Alexander M.,28-Oct-03 23:38 
AnswerRe: Internal memory management when using 'new'? Pin
peterchen29-Oct-03 0:20
peterchen29-Oct-03 0:20 
GeneralRe: Internal memory management when using 'new'? Pin
Dominik Reichl29-Oct-03 0:45
Dominik Reichl29-Oct-03 0:45 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.