Advertisement

How to add button to an sdi MFC app?

Started by June 07, 2001 10:25 AM
6 comments, last by Zeke 23 years, 8 months ago
I cant believe i am having problems with this. In a dialog based app its simple you just place the button with the resource editor and then double click on it and set it up. But in my sdi app i have no dialog box to put the button on so I just dont know how to do it. I just want a button with the word "save" on the top of the window (next to the toolbar icons). Can someone please tell me how to do this? Thanks for any help
Just my thoughts take them as you will. "People spend too much time thinking about the past, whatever else it is, its gone"-Mel Gibson, Man Without A Face
Well there are a couple of ways to do it depending on what your needs are.

Probably the easiest way is to derive your primary view class from CFormView and then add a button to the dialog resource that is created for the formview. If you use the MSVC++ Project Wizard to create an SDI project, the last step (step 6) will allow you to change the base class that each of your MFC classes will be derived from. Just select your View class (C{ProjectName}View ) and then select CFormView from the drop-down box on the bottom.


Or you can manually create a CButton and make the view window its parent.

Unfortunately I was just shocked to realize that my MSDN is not installed so I can''t pull up the exact command syntax right now.

If you want to add it manually with code I will try and post an example a little later after I install msdn.

Advertisement
I''m confused: do you want a save button ON the toolbar, or on your view? Maybe a little ascii diagram would help?

The toolbar comes equipped with a save key anyway--why do you need an extra button? CFormview is the way to make your SDI view look like a dialog, letting you drop button & all that jazz, but that means you can ONLY use it as a dialog. I''m sure there''s a way to drop a button into a regular CView, though I haven''t done it personally; probably you just need to define where the button is (i.e. it''s client area), then call Create on a CButton.

Thanks for the replies guys.

Krippy2k> Ill have to add it manually as I the views are TreeView and ListViews and Im way too far into the app to start again with a formview.

Stoffel> I am only really using the word save as an example sort of, I should have explained it more. It shoukld really say Create Dat File or something similar (i chose save because the button will save all data and create a dat file). the reason I want it next to the buttons on the tool bar is there isnt really anywhere else to put it and if i put it inside the list view it will lokk odd.

Thanks again for the replies
Just my thoughts take them as you will. "People spend too much time thinking about the past, whatever else it is, its gone"-Mel Gibson, Man Without A Face
You can have multiple toolbars (like MSVC), don''t know if that would be a better solution but it''s an option. Good luck.
There is a way to do this feature, by creating a new menu bar above the standard, a "ReBar".

Haven''t got the time to explaine how-to, I come back ASP to tel you how to make a ReBar.


---------------------------
MasterBlaster(CodeFighters)
---------------------------
---------------------------MasterBlaster(CodeFighters)---------------------------
Advertisement
==========================================
MICROSOFT FOUNDATION CLASS LIBRARY : ReBar
==========================================

This is what I can remember:

Got to CMainFrame (or what you labeled it) add in the source two public member-variable:
  CReBar m_rebar;CButton m_button;  

Now go to the class MainFrame and open OnCreate and add this code under the other looklike code:
  if(!m_rebar.Create(this)){    TRACE0("Failed to create to create rebar\n");    return -1;}  

Now you have to add a controler to the project, go to view>Resource Symbols, choose new and use the name IDC_BUTTON.

Then add the follow code under the previous code in the class oncreate:
  if(!m_button.Create("Save", WS_CHILD|WS_VISIBLE, CRect(0,0,20,20), this, IDC_BUTTON){   TRACE0("Failed to create the button\n");   return -1;}m_rebar.AddBar(&m_button, "Options: ", NULL, RBBS_BREAK);  


Hope you know how to add a new messagemap handler for the button, otherwise do a new post....


---------------------------
MasterBlaster(CodeFighters)
---------------------------
---------------------------MasterBlaster(CodeFighters)---------------------------
Thanks guys
MasterBlaster cheers, Yeah i know ho to add the messagemap handler and Ive got it working now.
Thanks again
Just my thoughts take them as you will. "People spend too much time thinking about the past, whatever else it is, its gone"-Mel Gibson, Man Without A Face

This topic is closed to new replies.

Advertisement