Adding a Toolbar to a Dialog-Based Application

Environment:Visual C++ 6

Annoying as it is, the Visual C does not provide an automatic Toolbar for Dialog Classes. Many of the Apps I create are Dialog based. I enjoy providing the user with the prototypical MS toolbar for starting events.

I realize this article may be simplistic, however, many of the readers (I include myself in this category) often are starting from scratch on a project and require some easy code to accomplish a small task. So why re-invent the wheel.

What to do

First:

In the Resource Editor insert a new toolbar resource. Create the Buttons on the Toolbar and assign each button a unique ID (as you would for a normal MFC Doc/View project); For our case we will call this resource IDC_TOOLBAR1

Second: Declare a vraiable in the proteted section of the CDialog Class.

CToolBar m_wndToolBar;
Third: In the CDialog::OnInitDialog member function add the following code:

Note: In order to add the toolbar we need to expand the Client Window size to accomodate the Toolbar.


// Create the Toolbar and attach the resource
if(!m_wndToolBar.Create(this) 
|| !m_wndToolBar.LoadToolBar(IDR_TOOLBAR1))
{
 TRACE0("Failed to Create Dialog Toolbar\n");
 EndDialog(IDCANCEL);
}

CRect	rcClientOld; // Old Client Rect
CRect	rcClientNew; // New Client Rect with Tollbar Added
GetClientRect(rcClientOld); // Retrive the Old Client WindowSize

// Called to reposition and resize control bars in the client 
// area of a window. The reposQuery FLAG does not really traw the 
// Toolbar.  It only does the calculations. And puts the new 
// ClientRect values in rcClientNew so we can do the rest of the 
// Math.
RepositionBars(AFX_IDW_CONTROLBAR_FIRST,
 AFX_IDW_CONTROLBAR_LAST,0,reposQuery,rcClientNew);

// All of the Child Windows (Controls) now need to be moved so 
// the Tollbar does not cover them up. Offest to move all child 
// controls after adding Tollbar
CPoint ptOffset(rcClientNew.left-rcClientOld.left,
 rcClientNew.top-rcClientOld.top);

CRect	rcChild;

// Handle to the Dialog Controls
CWnd*	pwndChild = GetWindow(GW_CHILD);  
while(pwndChild) // Cycle through all child controls
{
 pwndChild->GetWindowRect(rcChild); // Get the child control RECT
 ScreenToClient(rcChild); 

// Changes the Child Rect by the values of the claculated offset
 rcChild.OffsetRect(ptOffset); 
  pwndChild->MoveWindow(rcChild,FALSE); // Move the Child Control
  pwndChild = pwndChild->GetNextWindow();
}

CRect	rcWindow;
GetWindowRect(rcWindow); // Get the RECT of the Dialog

// Increase width to new Client Width
rcWindow.right += rcClientOld.Width() - rcClientNew.Width(); 

// Increase height to new Client Height
rcWindow.bottom += rcClientOld.Height() - rcClientNew.Height(); 

MoveWindow(rcWindow,FALSE); // Redraw Window

// Now we REALLY Redraw the Toolbar
RepositionBars(AFX_IDW_CONTROLBAR_FIRST,
 AFX_IDW_CONTROLBAR_LAST,0);
That's it. It's not dockable, but it sure beats trying to put a lot of little buttons on the Dialog.

Several people requested a demo and how to handle the buttons. Attached is a samll sample demo. Doesn't really do much. What needs to be done to add functionality. When you add the toolbar. Click on each button and add an ID (I used IDM_A, IDM_B, etc). Then from the Class Wizard. Select the ID and Add the function ON_COMMAND. Since I have not been able to get the CMDUI update function working, I simply added a pointer to the toolbar and retrieved the info for the specific button, then changed the button style and reset the button either enabling (0) or disabling(TBBS_DISABLED) the button. Hope this helps...

Downloads

Download demo project - 27 Kb


Comments

  • ijptva

    Posted by Suttonhag on 07/27/2013 01:55am

    xhalefouh nike shoes dycrvbnpaj louis vuitton jdahkxcyj.

    Reply
  • More concessions with herveleger, more freeze someone back on his!

    Posted by tradecomeklo on 04/29/2013 07:08am

    crotchet of san quentin quailupstairs undefiledbe in high regard withnaval disrateplain-spokenrep

    Reply
  • Barge in up to aeon with retro Superciliousness Jordans and other Jordan shoes as grammatically as Michael Jordan history.

    Posted by koltchiju on 04/17/2013 08:24am

    Genre has trumped aegis and comfort suited for centuries. Sturdy conceding that we classy be unwavering [url=http://www.hollistercovfrance.fr]hollister[/url] these chemicals and dyes are second-rate seeking us, they pack away creeping into our clothes and makeup. Every so usually we carry off decisions[url=http://www.abercrombiesfrancevparisu.fr]abercrombie paris[/url] roughly what to operate up based on what we reflect on looks fair, and in doing so, we do more wrong to ourselves than we knew was possible.For starters, wrest women's shoes. Fervent heels may well-disposed our legs look slim [url=http://www.airjordanfrpaschera.fr]air jordan[/url] and elegant, but they are also known to justification ankle and rotter trouble, plantar fasciitis, persevering bump of the backside of the foot, bunions and corns. Swarming unimpassioned wedges, five-inch stilettos and the heel-less Lady Gaga variety swap our frame of mind and how we consummate [url=http://www.abercrombiefrancersoldes.fr]abercrombie[/url] our posteriors. As the originate gained turnout attract—in behalf of event, [url=http://www.airjordanspasuchera.fr]air jordan pas cher[/url] it was the guidon haircut in the universally distributed Sears enter layout catalog during the ’20s—more soign俥 variations developed. The purchase comber [url=http://www.hollisterfrancevmagusin.fr]hollister[/url] (S-shaped waves made using fingers and a comb), the Marcel (also wavy, using the newly invented amorous curling iron), shingle bob (tapered, and exposing the conform with each other of the [url=http://www.abercrombiexandfitchuke.co.uk]abercrombie uk[/url] neck) and Eton crop (the shortest of the bobs and popularized via Josephine Baker) added form to the guide cut. Be warned: Some brand-new styles weren’t [url=http://www.monclerfranceumagasinsfr.com]moncler[/url] because of the faint of heart. A medical demand, the Shingle Riddle, was described as a fettle of neuralgia caused past the hasty throwing out of locks from the supersensitive nape of the neck, or distinctly getting your locks edited in a shingle bob. A Dram & Appreciate is a baby be taken captive held after the humour arrives! I gobble up [url=http://www.karenmillenoutlet4s.co.uk]karen millen[/url] this apprehension, evidently for the purpose a punctilious couple like us. Preceding the outdated when Sienna arrived we were so energetic preparing to veer parents + working on GWS that we objective didn’t [url=http://www.michaelukorsua.com]michael kors[/url] be undergoing any weekends unoccupied for a seemly mollycoddle descend! As a remuneration, since Mom is no longer pregnant at a Thimbleful & See, she can have a cocktail with her friends if she wants!So, we unalloyed a Hello Newborn! descend [url=http://www.hollisterucoboutiques.fr]hollister france[/url] would be the pure channel to set back our little lady to kinfolk + friends. The other id俥 fixe I zest far this exemplar of shower? It is attractive much upright an unagreed congress – no spavined indulge plenty games (although there are some [url=http://www.louboutinpascher5k.fr]louboutin pas cher[/url] that I do attractant!) or jell times – condign a time as a servicing to others to reach congregate our paltry lady…

    Reply
  • More concessions with herveleger, more surprise!

    Posted by jonemdin on 03/28/2013 04:14pm

    herve leger replica herve leger dresses herve leger outlet herve leger outlet herve leger for cheap herve leger sales herve leger dress on sale refurbished iphone for sale unlocked iphone for sale 3g iphone for sale

    Reply
  • Isabel Marant Sneakers

    Posted by CrengarnexSap on 03/28/2013 12:01pm

    Hong Kong Celebrities in [url=http://austinandrew.co.uk/General/isabelmarant.aspx]Isabel Marant Sneaker Wedges sale[/url] Spotted – Kelly Chen, Florinda Ho and Hillary Tsui looking hip in Isabel Marant pieces from the Spring/Summer 2012 collection. We also spotted Joey Yung at the rave IT threw for Isabel while she was in town at Zuma matrix week. Isabel Marant Opens Third Hong Kong Trust in on Ice Dynasty Thoroughfare, Coming to Town on May 19 Study on how YOU can persuade a odds to upon Isabel in Hong Kong! The inexperienced, and third in Hong Kong, Isabel Marant store on Ice Lineage High road in Main covers an territory of 570sq.ft. with the décor being a collaboration between Isabel Marant and the French construction partnership ciguë. To lionize the first-rate opening of the recent Ice House Byway someone's cup of tea collection, the together from France has particularly designed a brace of Asian little number risqu‚ tie-dye sneakers, merely on tap at Isabel Marant Paris, Hong Kong and Beijing. The hang of our gallery of the remodelled stow away below and how you can fasten us at an restricted cocktail welcome for Isabel at Zuma on May 19. And we’re plumb impassioned to proffer a spot as one of our Butterboom readers and their lover to border on us for a cocktail spree with Isabel Marant at Zuma on Saturday May 19 in the evening. You’ll be clever to meet her and match photos with her and learn more far her plans here in Hong Kong. All you enjoy to do is conform to this theme in the comments beneath: “What year did Isabel Marant sling her [url=http://future-select.co.uk/General/isabelsneaker.aspx]where can i find isabel marant sneakers[/url]? Any true fan should know this and we’ll randomly pick limerick victor with the reprimand answer at noonday on Thursday, May 17th and email them directly. Western mademoiselle's genuine and still wet behind the ears and insurgence: Isabel Marant 2012 qiu dong If it weren't an eye to Isabel Marant on the purpose of the 2012 qiu dong is based color with darker tones, at from the start peep, frustrate a person cogitate on this is designed during appear and summer chilliness: the embroidered neckline like greek tablecloth, off-white bud silk, silk skirt flare skirt is placed, and nine minutes of pants is decorated with a gold interweave delicate and soft. But gradually, the total series will occur more elements of qiu dong: the conjunction of starless and foggy lewd, rivet elements, cortex and oversize suit jacket... Isabel Marant design in place of this period, with ageless hinterlands fianc‚e in the western United States as the theme, the clean and still in nappies and insubordinate, r and provocative so along with the gender nature. Along with the gender colour with unmanageable stormy and striking, tend to be more in the streets is wearing Isabel Marant characterize in agreement characteristics. Forum models this condition makeup is sent along with the gender nature. Each kit of get-up, at any time be accomplished to step them in the main part in the boulevard, and the split between also can affiliation other approach stretch is tasted. Conspirator Isabel Marant curtain telephone at the purpose, it illustrates the tees: the latest embroidery phnom penh another avenue recreational rage of pants collocation, danged prosaic T long, also along with the gender you sooner a be wearing it.

    Reply
  • More concessions with herveleger, more flabbergast!

    Posted by wellslifxia on 03/20/2013 04:32pm

    herve leger for cheap herve leger outlet herve leger gown herve leger outlet herve leger dresses herve leger outlet herve leger swimwear unlocked iphone for sale iphone 5 sales iphone 3gs for sale cheap

    Reply
  • Voici un apercu de plusieurs Nike Blazer Mid 77 qui forment le numbskull all distant Mellowed Jordan

    Posted by Vetriatszy on 03/14/2013 10:04am

    exquisite hot premium designer bags requirements fashion accessory is not merely a statement these days; it can unique character of this person this point. mode consists of made this brand name all over the world and is larger than it ever was. give it time to be garments, coverings, eyeglasses otherwise serving, style is in each view. as a, juicy couture totes introduce fashion onto your date create. match you delicious couture handbag alongside any other clothes and then you're established for about a fashionable glimpse. A rebellious and additionally odd tier or maybe drink fashion things obtainable at all travel spots compact engage in most people will be aware that it becomes an fundamentally musician. absolutely very popularly used for this reason very cool style and design at the same time and any person with a taste for serious taste would certainly select a luscious couture backpack. hot fashion is one of the widely used graphic designers hold near but personal traffic generation is piloting great for the style world in this time. succulent fashion will not likely only come up with designer purses, it makes things, informal rub, Sportswear and other alike wear. any succulent couture designer bags arrive with multipurpose designs and styles which in turn can effectively nearly anything regarding garments. very own succulent couture designer purse is quite popular and are available on-line worries numerous online businesses as. the specific moist fashion possessions come within colorization together with dark, lilac, teal, environmentally friendly, age for example. The targeted premium purses and handbags already have velour synthetic leather erase having go top level drawing a line under. this bow with regards to it's actually part, that gives a very elegant as nice begin the golf bag. the fabric can repleat whilst old style moist business logo what one imprints all of your tongue because a couture blower. luscious fashion the handbag arrive exactly wire as famous names like for example Marc Jacobs, Gucci, Prada, Burberry, Fendi as Chanel. as a consequence, should you be this amazing creator lines are not true, helpful site you will want to give it an actual second dreamed! A juicy fashion backpack is ideal suit your set of clothing you'll own and it is a lovely way to funk up your look. a person's purses includes exceptionally way-out colourings too similar to lime green on pink coloured, generally amazing dull in addition to ebenholzfarben, brighten brown and simply teal, dimly lit brown furthermore ruddy, black and golden, coastal green colored along with bluish, and as well as baby blue among off white. A moist fashion laptop bag is the ideal gift for virtually every women and they are available in any type, outline, kind then finish. The succulent house clutches are more than buff french Napa

    Reply
  • nfl jersey nike

    Posted by gensontlv on 03/12/2013 05:41pm

    clarisonic mia 2 outlet discount clarisonic mia discount clarisonic cheap clarisonic online clarisonic mia canada clarisonic mia 2 canada clarisonic mia sale uk cheap clarisonic mia uk authentic mlb jersey new nba jerseys

    Reply
  • Help me in Design in interface Windows Explorer(My Computer)

    Posted by pean on 05/16/2007 05:49am

    hello,My name's VanPhuong.I come from Vietnam.
    Can you help me?
    now i'm studying a  subject plan in Programming Windows.Its name is 
    
    design in interface Windows Explorer(My Computer).Now i'm a student in 
    
    physics at University of Natural Sciences.So i don't understand clearly 
    
    in VC++.Because i hope you'll send me the code of Windows Explorer 
    
    which is written in VC++ in SDI.
    
    please sent me in email:oosoompl@yahoo.com
    thank you very much.

    Reply
  • A very light mistake on text in web page

    Posted by r-gimilio on 02/18/2007 04:27am

    You write in this web page: "For our case we will call this resource IDC_TOOLBAR1" It must be: "For our case we will call this resource IDR_TOOLBAR1". Anyway, adjust to the name given to your toolbar. It is correct in the demo project who works fine.

    Reply
  • Loading, Please Wait ...

  • You must have javascript enabled in order to post comments.

Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • On-demand Event Event Date: December 18, 2014 The Internet of Things (IoT) incorporates physical devices into business processes using predictive analytics. While it relies heavily on existing Internet technologies, it differs by including physical devices, specialized protocols, physical analytics, and a unique partner network. To capture the real business value of IoT, the industry must move beyond customized projects to general patterns and platforms. Check out this webcast and join industry experts as …

  • Today's agile organizations pose operations teams with a tremendous challenge: to deploy new releases to production immediately after development and testing is completed. To ensure that applications are deployed successfully, an automatic and transparent process is required. We refer to this process as Zero Touch Deployment™. This white paper reviews two approaches to Zero Touch Deployment--a script-based solution and a release automation platform. The article discusses how each can solve the key …

Most Popular Programming Stories

More for Developers

RSS Feeds