The Easiest Way to Code the Owner Drawn Menu

Environment: VC6 Win 9x/ME/2000/XP (DirectX 9 needed); NT will not be supported

-->

Well, if you ask what's so different with a context menu, try making a context.

Menu owner draw has a pop-up menu in it. At the same time, it removes the reference of the menu from the dialog. You won't be able make the pop-up menu element owner draw so easily. So, here is an easier approach.

Popup menu items can be easily made owner draw if there is a menu already present in the dialog. But, what if you want only the context menu and not the main menu to be displayed? Host a surrogate dialog window. To create the dialog window, I do not use any resource; I use the rarely used CreateDialogIndirectParam(...) win32 API. It uses only a structure variable of the type DLGTEMPLATE (see MDSN) and most importantly a Callback function to act as a dialog procedure. So, I host the menu in the dynamically created dialog and hide the dialog. Before that, I used some traditional Charles Petzold coding to create a menu dynamically. See the CreateOwnerDrawPopUpMenu() function.

The action actually begins much before the menu and the dialog are created. It all happens when InitPopUpMenu() is called in OnInitDialog(). In InitPopUpMenu(), I make a call to CreateOwnerDrawPopUpMenu() and hook the main dialog's window procedure. I do this because only I and not the main program knows where the context is, in the WindowProcMain(..) function. I trap the WM_CONTEXTMENU message and retrieve the menu from the surrogate dialog and call TrackPopupMenu(..) to display the context menu.

Now the real action starts. The menu belongs to the surrogate dialog, and because the menu is owner draw, messages such as WM_MEASUREITEM and WM_DRAWITEM go only to the surrogate dialog. But, if you see the source code, they are handled in the main dialog and not in the surrogate. How is this magic achieved? The truth is, this is no magic. When I call CreateDialogIndirectParam(..), I secretly send in the main window handle as the last parameter; this parameter shows up as the lParam value in the WM_INITDIALOG message of the surrogate. I tuck it away in the Owner variable for future use. Having saved the handle of the Owner, when the WM_MEASUREITEM and WM_DRAWITEM messages come, I simply call SendMessage(Owner,message,wParam,lParam), bouncing them back to the main dialog.


So, finally here it is, the bare bones necessary to make the whole menu owner draw, including the TOP MENU LINE. Once this is understood, one can proceed to write all kinds of classes to encompass the menu and make it look as fancy as one wants.

Let me explain it as clearly as possible, as I always attempt to do.

First of all, insert a menu resource in the dialog application; that's easy. Then, after clicking OK, I remove the file and edit menu items and also the pop ups and again add all of them in the Owner draw mode. Once that is done, a ON_WM_MEASUREITEM message is sent to Dialog, so trap it and set the individual item's width and height as shown in the code.

Now, trap the WM_NCPAINT too!!! Create a rectangular region that denotes the Menu's region minus the combined size of the two Top menu items and send it through DefWindowProc(WM_NCPAINT,(WPARAM)hRgnWhole,NULL) (just say return from this point); you will see that there is a rectangular hole in the window shifted to a little right from the menu. (Please comment all the (1)'s in code before you do this to see the correct effect.) Having done this, simply Bitblt anything you want in this region.

Next, in the OnDrawItem handler of the dialog, we now take up the responsibly to draw the top menu line. Actually, James L. Conger said you cannot make the top line owner draw, but my memory of that dates back to Windows 3.11, maybe now we can do it. I do not have his latest copy of the Windows API Bible to tell you exactly what it is; nevertheless, it works and I am happy about it.

Because the top menu line does not have any ID, I have chosen to trap when the top menu line needs to be painted by eliminating it from all the elements of the pop-up menu; you can do as you wish. Once trapped, happily Bitblt what ever you want.

I have purposefully kept one pop-up menu default to show that in a menu one submenu can be owner draw and another self draw.

Downloads

Download source - 93 Kb
Download source for second part of article - 189 Kb


Comments

  • tilkoblingskabler hodetelefoner og vil ogsÃ¥ føre til at choose

    Posted by mantouhmmm on 06/04/2013 01:40pm

    [url=http://www.beatsbynopro.manifo.com/]Beats By Dre[/url] De Solo hodetelefoner kosttilskudd opplysninger hugeness slår nær Dre Solo HD rød-farget hodetelefoner for administrere converse New Superdurable Pannebånd Nå opprettet av superdurable allot allsidig Beats nær Dr Dre Solo HD rød-farget Headphone Pe.Monster Beats studio whitened sølv bestå akseptabelt Vår betaling Wedopay kredittvurdering kort, Visa, Mastercard, Paypal, Western Union frakt og levering måte EMS, hugeness svarte beats by Dr Dre Solo HD for ControlTalk samle røde-farget design beløp 129474 komfort, design allot effektivitet kombinere samle disse hugeness Beats Solo HD juli 21, hugeness Beats by Dr. Dre Solo HD-hodetelefoner rød-farget hugeness Headphones72 replicacocolv markedet lilje innenfor av dalen fineste egenskap kopi kosttilskudd på Lily innenfor av dalen øyeblikk, Beats nær Dre Solo HD bri.Beats by dre studio whitened sølv NGS du fantastisk synes allot screechy effektivitet for ledelse tralk, på bare ett mindre, lettere onear design. Med hugeness beats hugeness Beats Solo HD nær Dr. Dre HighDefinition OvertheEar NoiseCanceling hodetelefoner overskudd Fra monster vår slår store.Mar 19, Beats Solo HD store Definiti bestemt Edition rød-farget er belysning samle overskudd vekt som beholder lette din byrde hvis du er utnytte dem. [url=http://www.beatsstudionorge.weebly.com/]beats studio[/url] du er interessert i. Du bør være i stand til å kontakte den beat maker via en e-postadresse eller kontaktskjemaet på site.Secondly, aldri stole på en beat selge nettstedet som ikke har noen informasjon om produsent. Du bør se etter en "bio"-side eller noen form for informasjon som gjør at du føler at dette produsent eller beat maker er håndgripelig. Pass på at dette nettstedet er "innbydende". Hva jeg mener med det er at når du går til en vanlig butikk, vil du vite at det er noen der for å hilse på deg og at du skal føle varme og velkommen.Rommene tredje tips er at når du først kommer inn på nettsiden det skal la du vet nøyaktig hva du får deg inn. Du skal ikke behøve å bla rundt for å finne ut om det er eller ikke er en beat selge nettstedet. Du skal automatisk vite hvilke produkter som er offered.Last, sjekk for å se om det er et sted hvor du kan registrere deg for deres nyhetsbrev. De fleste nettsteder har et sted hvor du kan gjøre det så kan du få e-post (ikke spam) på den vanlige å la deg få vite hva nytt på området. Det er en bonus for en beat selge nettstedet til å ha denne funksjonen, slik at du kunstneren vil alltid huske dem når du trenger instrumentals.When du kjøpe Beats By Dre Powerbeats [url=http://www.monsternobeats.350.com/]monster beats[/url] Bestem deg for hva din mor ville elske den største og å pynte gaven kurv pakk den opp pent med noen gave papirer og sette på noen blomster og bånd på den. Sett også et bilde av deg og din mor innrammet i den. Hun er bare overskriften å virkelig liker det. For å toppe det hele, også inneholde beats by Dr Dre solo hd personlig kort, og det er på vei til å være utmerket gave til en ideell billige beats av Dre på Mors day.AKG-produsent av high-end hodetelefoner, mikrofoner og høyttalere i over 60 år, kunngjorde i dag tilgjengeligheten av sin K551 håndsett. De lukkede tilbake bokser har en massiv drivere og realistisk lyd Passiv støyisolering for pue nedsenking.

    Reply
  • oakley outlet provide discount oakley clearance no coupons needed

    Posted by heterlife on 05/07/2013 08:52pm

    For this reason they are so well known and warm all of the more.Not only are regular glasses much easier to slip off during a high-impact sport like tennis, they also diminish your ability to see the tennis ball. [url=http://www.test.com/]test sunglasses outlet[/url] Regular lenses are a good choice for general, everyday use.eyeglass frames have already been catering towards the requirements folks from various occupations ranging from professionals to type icons considering that 1937. [url=http://www.test.com/]test sunglasses sale[/url] Oakley features three subcategories of lenses.Most of the online suppliers present attractive ray ban 2143discounts from time to time on Ray ban eyeglass frames. [url=http://www.test.com/]cheap test holbrook[/url] These retailers have to stand behind their product, and there is quite a lot of competition.Witness sunglasses by Smith provide gray or amber lenses in addition to wraparound coverage. [url=http://www.test.com/]test sunglasses outlet[/url] One of his latest ongoing projects can be seen at fakeraybansforcheap.The brand has sunglasses for every occasion. [url=http://www.test.com/]cheap tests[/url] But my craze for designer sunglasses is really not even close to trying to cool off.They keep their notice in high and look at their fake Ray Bans one to another.

    Reply
  • http://www.nikeairmaxwr.com/ xpdlyr

    Posted by http://www.nikeairmaxwr.com/ Mandywtl on 03/31/2013 09:00am

    ray ban glasses,At this time? Ding Jin nodded and said: This is really puzzling. But he did say that. Zhuo where the big princes do not quite understand, and he said: Maybe your brother is not like you imagine it? Ding Jin Chen Sheng said: I'm the big brother long I was ten years old. I get along with him for more than twenty years, I am very aware of his temperament. Definitely not so easy to want to, there is absolutely not the safety of our country at heart. Su anger Seng Road: the matter is more difficult, Pro to Bangzhu account, oakley sunglasses caravan auxiliary True's not involved in the war between the two countries. Ding Jin said: If I was the commander in chief, then naturally people will protect me, the idea do not you worry about. Zhuo where mind a move, said: oakley sunglasses discount'd like to worry about the protection of your monks.ray ban aviators,oakleysunglassesoutc.com/" title="cheap oakley sunglasses"cheap oakley sunglasses, Ding Jin Yi Zheng, nodded and said: have anti-matter, all these years, I also pay some of my friends, when I ask them to protect me should be no problem.

    Reply
  • Chinese Manufacturer

    Posted by Fishnetqj1019 on 03/29/2013 10:36am

    http://sexylingerieshops.webs.com - Sexy LingerieWhen stripped to the bare essentials, the garter held right at the edge of the panties which holds the stockings up give it that hot and sexy look It is generally sold with a matching thong http://cheapspicylingerie.webs.com - Cheap Bustiers?  If you can purchase items from these ranges and you can’t go very wrong in getting your partner a present that she will enjoy wearing for a long time to comes sex appeal http://Lingeriesv.webs.com - Leopard Print LingerieIn terms of choosing the right bra, you can look for the proper size as well as the one that gives most comfort Click on selected style and see available options http://babydolllingeriee.webs.com - sheer babydollsKeep in mind the fastenings when considering a lingerie purchase If you offer a service, all of your income will be profit http://SexyTeddies.webs.com - sexy lingerie teddiesAlthough the garment had been around for decades, the name "baby doll lingerie" was first introduced when Carroll Baker appeared in one in the 1956 film "Baby Doll All these types of wholesale sexy dresses serve as a status symbol for the women and also depict their personality as a whole

    Reply
  • wholesale sunglasses

    Posted by sgliliImpumpyre on 03/29/2013 09:56am

    http://replicaguccisunglasses.webs.com - replica oakley sunglasses fake oakley sunglasses http://discountsunglassessale.webs.com - discount sunglasses fake oakleys sunglasses http://sunglassdicountsaleu.webs.com - cheap oakleys sunglasses sunglasses cheap http://fakeGucciwayfarer.webs.com - fake ray ban sunglasses discount oakley sunglasses,,,,,o http://akeoakleysunglasses.webs.com - fake ray ban sunglasses wholesale oakley sunglasses

    Reply
  • cheap wayfarer sunglasses

    Posted by wgliliImpumpxkw on 03/29/2013 01:37am

    cheap fake oakleys [url=http://bestsunglassesshop.webs.com]cheap fake oakleys[/url] fake ray ban wayfarer cheap wayfarer sunglasses [url=http://onlineguciisunglass.webs.com]cheap wayfarer sunglasses[/url] oakley sunglasses cheap cheap ray ban [url=http://guccisunglassescheap.webs.com]cheap ray ban[/url] discount sunglasses cheap oakley [url=http://guccicheapsunglass.webs.com]cheap oakley[/url] discount ray ban fake ray ban wayfarer [url=http://fakeGucciwayfarer.webs.com]fake ray ban wayfarer[/url] wholesale designer sunglasses designer sunglasses cheap [url=http://sunglassdicountsaleu.webs.com]designer sunglasses cheap[/url] cheap sunglasses cheap oakleys for sale [url=http://sunglasswholesaleofgucci.webs.com]cheap oakleys for sale[/url] sunglasses wholesale cheap fake oakley sunglasses [url=http://bestsunglassesshop.webs.com]cheap fake oakley sunglasses[/url] cheap ray ban sunglasses

    Reply
  • cheap hats

    Posted by xxds1eb on 03/28/2013 10:47am

    [url=http://cheapsnapbacksforsalezone.webs.com]snapback hats cheap[/url] snapback hats cheap t hvjh [url=http://cheapsnapbackshat.webs.com]cheap snapbacks hats[/url] cheap snapbacks hats z ihjs[url=http://snapbackhatwholesale.webs.com]snapback hats wholesale[/url] snapback hats wholesale j swua[url=http://goodsnapbackhatscheap.webs.com]snapback hats cheap[/url] snapback hats cheap k jwex[url=http://snapbackhatwholesale.webs.com]wholesale fitted hats[/url] wholesale fitted hats n fmok[url=http://snapbackswholesalezone.webs.com]snapbacks wholesale[/url] snapbacks wholesale n gtpa [url=http://wholesalefittedhat.webs.com]snapback wholesale[/url] snapback wholesale f jfgv [url=http://cheapsnapbackshat.webs.com]cheap snapbacks hats[/url] cheap snapbacks hats a tcbt[url=http://cheapsnapbacksforsalezone.webs.com]snapback hats cheap[/url] snapback hats cheap y ojxt[url=http://snapbackswholesalezone.webs.com]hats wholesale[/url] hats wholesale h xosc[url=http://snapbackswholesalezone.webs.com]snapback hats wholesale[/url] snapback hats wholesale s nrtg[url=http://cheapsnapbacksforsalezone.webs.com]cheap snapbacks for sale[/url] cheap snapbacks for sale b tobm [url=http://cheapsnapbacksforsalezone.webs.com]cheap snapbacks free shipping[/url] cheap snapbacks free shipping p ctmv [url=http://cheaphatsmall.webs.com]snapback hats cheap[/url] snapback hats cheap t eitb[url=http://wholesalefittedhat.webs.com]wholesale fitted hats[/url] wholesale fitted hats g gnuo[url=http://snapbackhatwholesale.webs.com]wholesale beanies[/url] wholesale beanies g kwsz[url=http://cheapsnapbackshat.webs.com]cheap hats online[/url] cheap hats online n nvqa[url=http://snapbackhatwholesale.webs.com]wholesale fitted hats[/url] wholesale fitted hats m jlij

    Reply
  • Buy Real michael kors handbags wholesale

    Posted by roderarcillDB on 03/14/2013 08:24am

    On the hunt for a classic, wear with everything watch? The Michael Kors Women's Chronograph Clear Acrylic Bracelet watch is the perfect choice.The round chronograph dial is studded with silver-tone accents and has three subdials and Arabic numerals. [url=http://cheapmichaelkorshandbagsr.webs.com/]michael kors handbag outlet[/url] Elegant and glamorous, this timepiece features a stainless steel case and back paired with a white ceramic bracelet that closes with a deployment clasp.He worked as the women's ready to wear designer and creative director until 2003. [url=http://cheapmichaelkorshandbagsr.webs.com/]michael kors handbag outlet[/url] You can find Michael Kors handbags in many department stores around the country.You can save tons of money by shopping through live auctions. [url=http://cheapmichaelkorshandbagsr.webs.com/]michael kors outlet onilne[/url] Looking for sporty looks for ladies? Michael Kors has you covered in the watch department.The stitching looks as if someone stitched it by hand very slowly. [url=http://cheapmichaelkorshandbagsr.webs.com/]michael kors purses outlet[/url] Get those pedicures done, because you will definitely have people watching those toes.That is really cool! [url=http://cheapmichaelkorshandbagsr.webs.com/]michael kors purse[/url] The Shopper handbag is perfect for those who like to carry larger bags.He is a lot more than just a pair of sunglasses or that must have bag on the shelves of high fashion shop all over.

    Reply
  • ghd australia rburuz

    Posted by Suttongja on 03/09/2013 04:11am

    Michael Kors outlet mvufowkj

    Reply
  • ugg boots nyrigd

    Posted by Mandymgx on 02/20/2013 10:23am

    cheap ugg boots sale cnmxnmzj cheap ugg boots uk teohgtxh cheap ugg boots xjgxqzsw cheap uggs qcbfpaav ugg boots sale uk xdkhcufl ugg boots sale upkvlyrp ugg boots uk jjrgqzgz ugg boots igheymos ugg sale qzrajvog

    Reply
  • Loading, Please Wait ...

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

Top White Papers and Webcasts

  • With JRebel, developers get to see their code changes immediately, fine-tune their code with incremental changes, debug, explore and deploy their code with ease (both locally and remotely), and ultimately spend more time coding instead of waiting for the dreaded application redeploy to finish. Every time a developer tests a code change it takes minutes to build and deploy the application. JRebel keeps the app server running at all times, so testing is instantaneous and interactive.

  • Hurricane Sandy was one of the most destructive natural disasters that the United States has ever experienced. Read this success story to learn how Datto protected its partners and their customers with proactive business continuity planning, heroic employee efforts, and the right mix of technology and support. With storm surges over 12 feet, winds that exceeded 90 mph, and a diameter spanning more than 900 miles, Sandy resulted in power outages to approximately 7.5 million people, and caused an estimated $50 …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds