abcdefgqwerty2

Im a pretty big new person to mfc and i do this in my program:

[code]
RECT rec;
playback->GetClientRect(&rec);

CWnd *w=CWnd::FromHandle(playback->GetSafeHwnd());


CBitmapButton *upbtn = new CBitmapButton();
upbtn->Create(NULL,WS_CHILD|WS_VISIBLE|BS_OWNERDRAW,CRect(rec.right-200,rec.top+30,rec.right-200+40,rec.top+70),w,BUTTONUP);
upbtn->LoadBitmaps(IDB_BUTTONUP,IDB_BUTTONUP,IDB_BUTTONUP2);


CBitmapButton *downbtn = new CBitmapButton();
downbtn->Create(NULL,WS_CHILD|WS_VISIBLE|BS_OWNERDRAW,CRect(rec.right-200,rec.top+150,rec.right-200+40,rec.top+190),w,BUTTONDOWN);
downbtn->LoadBitmaps(IDB_BUTTONDOWN,IDB_BUTTONDOWN,IDB_BUTTONDOWN2);

CBitmapButton *leftbtn = new CBitmapButton();
leftbtn->Create(NULL,WS_CHILD|WS_VISIBLE|BS_OWNERDRAW,CRect(rec.right-260,rec.top+90,rec.right-260+40,rec.top+130),w,BUTTONLEFT);
leftbtn->LoadBitmaps(IDB_BUTTONLEFT,IDB_BUTTONLEFT,IDB_BUTTONLEFT2);

CBitmapButton *rightbtn = new CBitmapButton();
rightbtn->Create(NULL,WS_CHILD|WS_VISIBLE|BS_OWNERDRAW,CRect(rec.right-140,rec.top+90,rec.right-140+40,rec.top+140),w,BUTTONRIGHT);
rightbtn->LoadBitmaps(IDB_BUTTONRIGHT,IDB_BUTTONRIGHT,IDB_BUTTONRIGHT2);
[/code]


Now the problem is I have nothing else. The form is CDialogmfcDlg(). My problem is I have no idea how I wire up these 4 buttons. I need the leftmousebuttonclick event but im not sure how to do this. Normally you click the control in the designer and add the event. How do I do this manually myself MFC is pretty confusing at first as is windows programming in general. what happened to DOS
Im a pretty big new person to mfc and i do this in my program:

[code]
RECT rec;
playback->GetClientRect(&rec);

CWnd *w=CWnd::FromHandle(playback->GetSafeHwnd());


CBitmapButton *upbtn = new CBitmapButton();
upbtn->Create(NULL,WS_CHILD|WS_VISIBLE|BS_OWNERDRAW,CRect(rec.right-200,rec.top+30,rec.right-200+40,rec.top+70),w,BUTTONUP);
upbtn->LoadBitmaps(IDB_BUTTONUP,IDB_BUTTONUP,IDB_BUTTONUP2);


CBitmapButton *downbtn = new CBitmapButton();
downbtn->Create(NULL,WS_CHILD|WS_VISIBLE|BS_OWNERDRAW,CRect(rec.right-200,rec.top+150,rec.right-200+40,rec.top+190),w,BUTTONDOWN);
downbtn->LoadBitmaps(IDB_BUTTONDOWN,IDB_BUTTONDOWN,IDB_BUTTONDOWN2);

CBitmapButton *leftbtn = new CBitmapButton();
leftbtn->Create(NULL,WS_CHILD|WS_VISIBLE|BS_OWNERDRAW,CRect(rec.right-260,rec.top+90,rec.right-260+40,rec.top+130),w,BUTTONLEFT);
leftbtn->LoadBitmaps(IDB_BUTTONLEFT,IDB_BUTTONLEFT,IDB_BUTTONLEFT2);

CBitmapButton *rightbtn = new CBitmapButton();
rightbtn->Create(NULL,WS_CHILD|WS_VISIBLE|BS_OWNERDRAW,CRect(rec.right-140,rec.top+90,rec.right-140+40,rec.top+140),w,BUTTONRIGHT);
rightbtn->LoadBitmaps(IDB_BUTTONRIGHT,IDB_BUTTONRIGHT,IDB_BUTTONRIGHT2);
[/code]


Now the problem is I have nothing else. The form is CDialogmfcDlg(). My problem is I have no idea how I wire up these 4 buttons. I need the leftmousebuttonclick event but im not sure how to do this. Normally you click the control in the designer and add the event. How do I do this manually myself MFC is pretty confusing at first as is windows programming in general. what happened to DOS


Re: Visual C++ General Help on dynamic control and wiring click event for buttons

Pintu Shukla

Have a Look In MSDN for ON_COMMAND().and ON_COMMAND_RANGE() and ON_BN_CLICKED().

Thanx






Re: Visual C++ General Help on dynamic control and wiring click event for buttons

Simple Samples

abcdefgqwerty2 wrote:
what happened to DOS

I must be missing something here, because I am not aware of buttons being a DOS thing or having any value whatsoever for buttons. Perhaps DOS means something different than what I am familiar with, so if the answer depends on whatever DOS is, then you might need to define what that means. If however someone else understands what you mean by DOS or if the answer does not depend on DOS, then you can ignore this except I might be able to help if I understood.






Re: Visual C++ General Help on dynamic control and wiring click event for buttons

abcdefgqwerty2

Im not sure why I brought up DOS operating system. I guess I was just mad at windows programming in general. Just ignore that. The On_command() event sounds maybe like what I need to get messages sent to my buttons.




Re: Visual C++ General Help on dynamic control and wiring click event for buttons

Simple Samples

Oh now I see. You are creating the buttons dynamically, so of course you can't create message handlers the normal way.

My experience with MFC is a little fuzzy but I think you need to derive a class from CBitmapButton and then add a handler for processing the button click event. If you want to use one derived class for multiple buttons then you need a way for the derived class to know which button is being handled. My Deriving from Control Classes might help but it was written for VC 6.

You will then want to allocate instances of your derived class instead of instances of CBitmapButton.






Re: Visual C++ General Help on dynamic control and wiring click event for buttons

abcdefgqwerty2

Ah I see. I think thats what I need to do is derive from the bitmapbutton and try it that way. Im sure the On_Command() could be used somehow but I cant figure out how to do it that way. Im very new to mfc so its all pretty confusing still.
That link you gave describes the steps using a class wizar. I added a class that derives from bitmapbutton using an mfc wizard. I made a class called MyBitmapButton and click it in the class view but when i click messages it gives me nothing. I would think I could add message handlers for all the messages in a bitmapbutton since it derives from that but I guess not.




Re: Visual C++ General Help on dynamic control and wiring click event for buttons

Simple Samples

Yes the class wizard is not called a wizard. As I said, I wrote that article when VC 6 was the latest version of VC.

In my opinion, most Microsoft wizards are not smart enough to qualify as wizards. Microsoft has a tendency to be trendy in the sense of making use of whatever they have chosen as the current trend. One trend in VS 2005 is to use properties. There is so much in VS 2005 that are called properties that it is confusing.

To do what you need to do, go to the Class View. Then right-click on the class (your derived class) and choose properties. At the top of the properties are a few icons. Find the icon that allows you to add handlers for the common messages or overrides of members or something like that.






Re: Visual C++ General Help on dynamic control and wiring click event for buttons

abcdefgqwerty2

Thanks for all your help. I have this to get the button click event
afx_msg void MyFunc();

and then this to the message handler
ON_BN_CLICKED(BUTTONUP,&CPLAYBACK::MyFunc)

and then just putting in that function into the class.

I realized after I got that to work that I need to know if its buttonup or buttondown mouse click event. so now I have this.

[code]
// MyBitmapButton

class MyBitmapButton : public CBitmapButton
{
DECLARE_DYNAMIC(MyBitmapButton)

public:
MyBitmapButton();
virtual ~MyBitmapButton();
afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
afx_msg void OnLButtonUp (UINT nFlags, CPoint point);

protected:
DECLARE_MESSAGE_MAP()
};

[/code]

I have this function now, but I have 4 bitmapbutton controls. How do I distinguish between the controls I need some way to know what control is sending me these messages since I have 4 different ones. Neither of these parameters tells me what control is sending the message.

MyBitmapButton:SurprisenLButtonDown(UINT nFlags, CPoint point)
{
}






Re: Visual C++ General Help on dynamic control and wiring click event for buttons

Pintu Shukla

Dude Answer is Simple you have Four Button . and each Button is Assiciate with a ButtonID . SO with the help of ButtonID you can distinguish between Buttons.and think now you are able to make a try.

Thanx






Re: Visual C++ General Help on dynamic control and wiring click event for buttons

Simple Samples

You can use the control id as suggested but C++ and MFC enable us to be more object-oriented. You can pass parameters in the class constructor and then each instance can do what it needs to do without any dependencies on any other instances. The details of what parameters to pass depend entirely on your requirements.






Re: Visual C++ General Help on dynamic control and wiring click event for buttons

abcdefgqwerty2

I got the left button clicks and thought I was done but much to suprise the bitmap doesnt switch to the down bitmap when i handle the left mouse button down event. if I dont handle the mouse button down event then it works fine. I derived my control from the CBitmapButton control to get the messages but I guess it messes up how the control switches pictures somehow. How do I fix this or what is even the problem

i figured out how to sort them by ids too i cant believe i didnt think of that, but for some stupid reason these controls dont animate when i handle the mousedown message its like it interferes with how control knows when to switch from the up picture to the mousedown one




Re: Visual C++ General Help on dynamic control and wiring click event for buttons

abcdefgqwerty2

I figured it out finally.

I forgot this
CBitmapButton:SurprisenLButtonDown(nFlags, point);
had to pass the message on to base class.
Thanks for the help