|
how to Add button inside view class in MFC
modified on Wednesday, July 15, 2009 3:49 AM
|
|
|
|
|
Do you need to Ownerdraw for your button?
Of one Essence is the human race
thus has Creation put the base
One Limb impacted is sufficient
For all Others to feel the Mace
(Saadi )
|
|
|
|
|
i will explain wht i did. i uploaded a bit map and inthat bit map i draw a rectangle in view OnDraw function.
pDC->Rectangle(x, y, x1, y1);
now wht i want is that whn i click on the rectangle i want another window to b opened.
|
|
|
|
|
You can use of CreateWindow/ShowWindow or DoModal for show other dialogs.
Of one Essence is the human race
thus has Creation put the base
One Limb impacted is sufficient
For all Others to feel the Mace
(Saadi )
|
|
|
|
|
sounds simple,
just take the onclick event on the view, it will give you, the point,(x,y), clicked.
then use ptinrect(...) function to verify, weather user has clicked on the desired rectangle or not.
hope this should be clear for you.
--------------------------------------------
Suggestion to the members:
Please prefix your main thread subject with [SOLVED] if it is solved.
thanks.
chandu.
|
|
|
|
|
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 :-
// 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.
|
|
|
|
|
|
Hi all,
i want to send service message to recipient i m using Mapi for sending msg but its not send service msg,
service msg means its open on recipient mobile screen and delete when user exit the mobile screen.
i think
MESSAGEFIELDS or IMessageFormHostEx,or IFormProviderEx api's can be use for this.
i dont know how can i use it please help me how can i use it.
if possible please provide me any sample code.
thanks in advance.
To accomplish great things, we must not only act, but also dream;
not only plan, but also believe.
|
|
|
|
|
i need minimal coverage code by c++.
plz send to hhn1364@gmail.com.
tnx
|
|
|
|
|
Hamed_sm2002 wrote: i need minimal coverage code by c++.
Would you like some fries with it ?
|
|
|
|
|
|
If you want to receive help, I suggest you first read the posting guidelines ("How to receive an answer to your question").
|
|
|
|
|
It looks like homework and it looks like you didn't read forum guidelines [^].
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
i want only the algorithm. plz help me to do my job
|
|
|
|
|
That make me think you haven't read forum guidelines yet. I strongly advice you to do it.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
|
|
Ask you teacher or your manager( if you are working) to do that for you. They wont mind a kiss from you.
|
|
|
|
|
I read it but I cant find any answer yet?
Of one Essence is the human race
thus has Creation put the base
One Limb impacted is sufficient
For all Others to feel the Mace
(Saadi )
|
|
|
|
|
Why don't you just try? It doesn't look a daunting task and you're a developer, aren't you?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
please send me your bank account information so that I may deduct fee for stupid question
|
|
|
|
|
hi everybody
Today i build MFC to get CultureInfo include Culture Name and Culture
Identifier
like :
en 0x0009 English
en-AU 0x0C09 English - Australia
en-BZ 0x2809 English - Belize
en-CA 0x1009 English - Canada
en-CB 0x2409 English - Caribbean
en-IE 0x1809 English - Ireland
en-JM 0x2009 English - Jamaica
en-NZ 0x1409 English - New Zealand
en-PH 0x3409 English - Philippines
en-ZA 0x1C09 English - South Africa
en-TT 0x2C09 English - Trinidad and Tobago
en-GB 0x0809 English - United Kingdom
but i don't know how to implement it?
thank you
|
|
|
|
|
anybody understand what i say? could help me
|
|
|
|
|
|
Chandru080 wrote: No
means No methods or NOT understand what i say?
|
|
|
|