Click here to Skip to main content
15,879,095 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionDatabase path Pin
MsmVc5-Jul-09 22:28
MsmVc5-Jul-09 22:28 
AnswerRe: Database path Pin
Stuart Dootson6-Jul-09 0:13
professionalStuart Dootson6-Jul-09 0:13 
Question[Message Deleted] [modified] Pin
rajapp5-Jul-09 21:24
rajapp5-Jul-09 21:24 
AnswerRe: how to add button control to a drawing Pin
Hamid_RT5-Jul-09 22:18
Hamid_RT5-Jul-09 22:18 
GeneralRe: how to add button control to a drawing Pin
rajapp6-Jul-09 0:30
rajapp6-Jul-09 0:30 
GeneralRe: how to add button control to a drawing Pin
Hamid_RT6-Jul-09 0:42
Hamid_RT6-Jul-09 0:42 
GeneralRe: how to add button control to a drawing Pin
chandu0046-Jul-09 1:56
chandu0046-Jul-09 1:56 
AnswerRe: how to add button control to a drawing Pin
Adam Roderick J6-Jul-09 6:01
Adam Roderick J6-Jul-09 6:01 
Create a customized Button
say as below and add a resource button with owner draw and now instead of you button change the CButton with ButtonEx Smile | :) :-
// Color settings.
const COLORREF CLR_FILL_NORMAL = RGB( 255, 250, 192 );
const COLORREF CLR_FILL_HOT = RGB( 255, 255, 225 );
const COLORREF CLR_FILL_PUSHED = RGB( 240, 225, 164 );
const COLORREF CLR_FILL_DISABLED = RGB( 225, 225, 225 );

const COLORREF CLR_BORDER_NORMAL = RGB( 230, 215, 128 );
const COLORREF CLR_BORDER_HOT = RGB( 0, 64, 255 );
const COLORREF CLR_BORDER_PUSHED = RGB( 64, 192, 255 );
const COLORREF CLR_BORDER_DISABLED = RGB( 192, 192, 192 );

const COLORREF CLR_TEXT_NORMAL = RGB( 0, 0, 0 );
const COLORREF CLR_TEXT_HOT = RGB( 0, 0, 192 );
const COLORREF CLR_TEXT_PUSHED = RGB( 0, 0, 0 );
const COLORREF CLR_TEXT_DISABLED = RGB( 128, 128, 128 );

ButtonEx::ButtonEx() : m_bMouseInside( false )
{
}

BEGIN_MESSAGE_MAP(ButtonEx, CButton)
//{{AFX_MSG_MAP(ButtonEx)
ON_WM_MOUSEMOVE()
ON_WM_LBUTTONDBLCLK()
//}}AFX_MSG_MAP
ON_MESSAGE( WM_MOUSELEAVE, OnMouseLeave )
END_MESSAGE_MAP()

// This function set the owner draw style to the button when it is sub-classed.
void ButtonEx::PreSubclassWindow()
{
ModifyStyle( 0, BS_OWNERDRAW );
CButton::PreSubclassWindow();
}

void ButtonEx::DrawItem( LPDRAWITEMSTRUCT lpDrawItemStruct )
{
// Get the dc as CDC object.
CDC dc;
dc.Attach( lpDrawItemStruct->hDC );

// Get the button rectangle as CRect object.
CRect rect( lpDrawItemStruct->rcItem );

// Get the button caption.
CString csCaption;
GetWindowText( csCaption );

// Variables for keeping the drawing colors.
COLORREF clrFill, clrBorder, clrText;

// Check the state of the button.
// First of all we have to check the enable/disable state.
if( ODS_DISABLED == ( lpDrawItemStruct->itemState & ODS_DISABLED ))
{
// Disabled state.
clrFill = CLR_FILL_DISABLED;
clrBorder = CLR_BORDER_DISABLED;
clrText = CLR_TEXT_DISABLED;
}
else
{
// Enabled state.
if( ODS_SELECTED == ( lpDrawItemStruct->itemState & ODS_SELECTED ))
{
// Button is pushed/pressed.
clrFill = CLR_FILL_PUSHED;
clrBorder = CLR_BORDER_PUSHED;
clrText = CLR_TEXT_PUSHED;
}
else
{
// If the mouse is inside the button area then show the hot colors.
if( m_bMouseInside )
{
clrFill = CLR_FILL_HOT;
clrBorder = CLR_BORDER_HOT;
clrText = CLR_TEXT_HOT;
}
else
{
clrFill = CLR_FILL_NORMAL;
clrBorder = CLR_BORDER_NORMAL;
clrText = CLR_TEXT_NORMAL;
}
}
}

// Fill the background.
dc.FillSolidRect( &rect, clrFill );
// Draw the border.
dc.Draw3dRect( &rect, clrBorder, clrBorder );
rect.DeflateRect( 1, 1 );
dc.Draw3dRect( &rect, clrBorder, clrBorder );
// Draw the caption.
dc.SetTextColor( clrText );
dc.SetBkMode( TRANSPARENT );
dc.DrawText( csCaption, &rect, DT_VCENTER | DT_CENTER | DT_SINGLELINE );

// Detach the dc from CDC object.
dc.Detach();
}

// This function will track the mouse movement and handle the mouse enter and mouse leave.
void ButtonEx::OnMouseMove(UINT nFlags, CPoint point)
{
// If the mouse was outside then the mouse is just entered the button area.
if( !m_bMouseInside )
{
// Set the flag.
m_bMouseInside = true;

// Update the display to reflect the hot state.
Invalidate( FALSE );

// Register the mouse-track to get the mouse leave message.
TRACKMOUSEEVENT stTME = { 0 };
stTME.cbSize = sizeof( stTME );
stTME.dwFlags = TME_LEAVE;
stTME.hwndTrack = m_hWnd;
_TrackMouseEvent( &stTME );
}

// Nothing to do special if the mouse is already inside the button area.

CButton::OnMouseMove(nFlags, point);
}

// This function will handle the mouse leave from the button area.
LRESULT ButtonEx::OnMouseLeave( WPARAM, LPARAM )
{
// Reset the flag.
m_bMouseInside = false;

// Update the display to reflect the hot state.
Invalidate( FALSE );

return 0; // Not used.
}

// This function will make the double click event to single click.
void ButtonEx::OnLButtonDblClk( UINT nFlags, CPoint point )
{
const MSG* pstMSG = GetCurrentMessage();
DefWindowProc( WM_LBUTTONDOWN, pstMSG->wParam, pstMSG->lParam );
}


Hope you are looking for this.
Answer[solved]adding button inside View class of MFC Pin
rajapp14-Jul-09 21:52
rajapp14-Jul-09 21:52 
QuestionPlease help me for sending Service Message! Pin
Le@rner5-Jul-09 21:00
Le@rner5-Jul-09 21:00 
Questionminimal coverage Pin
Hamed_sm20025-Jul-09 20:38
Hamed_sm20025-Jul-09 20:38 
AnswerRe: minimal coverage Pin
Cedric Moonen5-Jul-09 20:44
Cedric Moonen5-Jul-09 20:44 
GeneralRe: minimal coverage Pin
Hamed_sm20025-Jul-09 20:56
Hamed_sm20025-Jul-09 20:56 
GeneralRe: minimal coverage Pin
Cedric Moonen5-Jul-09 21:02
Cedric Moonen5-Jul-09 21:02 
GeneralRe: minimal coverage Pin
CPallini5-Jul-09 21:03
mveCPallini5-Jul-09 21:03 
GeneralRe: minimal coverage Pin
Hamed_sm20025-Jul-09 21:07
Hamed_sm20025-Jul-09 21:07 
GeneralRe: minimal coverage Pin
CPallini5-Jul-09 21:14
mveCPallini5-Jul-09 21:14 
GeneralRe: minimal coverage Pin
Chandrasekharan P5-Jul-09 21:37
Chandrasekharan P5-Jul-09 21:37 
GeneralRe: minimal coverage Pin
Hamed_sm20025-Jul-09 21:42
Hamed_sm20025-Jul-09 21:42 
GeneralRe: minimal coverage Pin
Chandrasekharan P5-Jul-09 21:51
Chandrasekharan P5-Jul-09 21:51 
GeneralRe: minimal coverage Pin
Hamid_RT6-Jul-09 1:01
Hamid_RT6-Jul-09 1:01 
QuestionRe: minimal coverage Pin
CPallini5-Jul-09 21:54
mveCPallini5-Jul-09 21:54 
AnswerRe: minimal coverage Pin
TheGreatAndPowerfulOz6-Jul-09 10:53
TheGreatAndPowerfulOz6-Jul-09 10:53 
QuestionGet CultureInfo Use VC Pin
jeansea5-Jul-09 20:21
jeansea5-Jul-09 20:21 
AnswerRe: Get CultureInfo Use VC Pin
jeansea5-Jul-09 20:58
jeansea5-Jul-09 20:58 

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.