Dialog Layout Manager in MFC

Uwaga! Informacje na tej stronie mają ponad 3 lata. Nadal je udostępniam, ale prawdopodobnie nie odzwierciedlają one mojej aktualnej wiedzy ani przekonań.

21:08
Sat
08
Aug 2009

Dialog Layout Manager in MFC

Sometimes I write some tools using C++ and MFC. In the Linux world it is common that GUI windows are resizeable. In Windows its not the case, but sometimes it would be nice to be able to resize a dialog window to see more information, like more rows and colums in a list. After repositioning and resizing controls in a window with my custom code I've decided to automate this task.

There are many possible approaches to this problem. WinAPI (and thus MFC) does not provide by itself any solution to automatically align controls inside a resizeable window. Each control has just its fixed rectangle (left, top, width, height) inside parent window. Delphi VCL uses Align property to snap selected controls (like Panel containing child controls) to left, right, top or bottom edge of the window. Qt encourages to design all windows with Layouts. For example, Vertical Layout splits the window into rows and automatically adjusts controls inside, one under the other.

But the solution of my choice is the one based on .NET. Controls in Windows Forms have a property called Anchor so they can be anchored to any of four possible window edges: left, top, right and bottom. If a controls is anchored only to left and top edges, it just doesn't change its position or size. If the control is anchored to right and bottom edges (for example: a button), it changes its position as window is resized so it preserves its distance to right and bottom edge of the window. If the control is anchored to all four possible window edges, it is resized to preserve distance to all window edges same as designed (for example: a list occupying central part of the window).

I've written a class which I called DialogLayoutManager. It's very easy to use and automates control resizing and repositioning inside an MFC window. All you need to do at the beginning is to create an object of this class, register your controls with selected anchors and call Save method:

m_LayoutManager->SetControl(GetDlgItem(ID_BTN_CANCEL),
  DialogLayoutManager::ANCHOR_RIGHT | DialogLayoutManager::ANCHOR_BOTTOM);
m_LayoutManager->SetControl(GetDlgItem(ID_BTN_OK),
  DialogLayoutManager::ANCHOR_RIGHT | DialogLayoutManager::ANCHOR_BOTTOM);
m_LayoutManager->Save(this);

Layout manager remembers positions and sizes of registered controls together with starting window size. Now all you need to do when the window is resized is to call Restore method. Layout manager will adjust registered controls according to new window size and specified anchors. For example, two buttons showed above will stay in bottom-right corner of the window.

void CDialog01::OnSize(UINT nType, int cx, int cy)
{
  ...
  if (LayoutManager && LayoutManager->IsSaved())
    m_LayoutManager->Restore(this);
}

Here is the code of my DialogLayoutManager class and usage example: DialogLayoutManager.cpp. It's easy to translate this code to pure WinAPI.

Comments (1) | Tags: gui mfc winapi | Author: Adam Sawicki | Share

Comments

wxm
2016-03-29 09:33:12
beautiful www.pradaoutlet.com.co things www.christianlouboutinoutlet.net.co to www.nikemercurial.in.net read www.rosherun.org.uk more, look www.babyliss-pro.us.com for www.pumaonline-shop.de a www.cheap-nike-shoes.net long www.adidas-schuhe-online.de time, www.longchampoutlet.com.co I www.kate-spade.in.net felt airmax.misblackfriday.com closer www.raybans-sunglassesoutlet.in.net to www.nikestore.com.de reality www.adidas--canada.ca very www.louis-vuitton-australia.com.au far away, www.nike-rosherun.nl life www.michael-kors-canada-outlet.ca is www.uggboots.com.de short, if www.toms-shoes.net.co put www.nike-roshe-run.com.es too www.rolex-watch.me.uk much www.ghdhair-straighteners.co.uk time is www.rayban.org.es spent www.michaelkorsbags.us.org on www.coco-chanel.com.de practical www.mmoncler-outlet.com things, really www.chiflatiron.net.co is www.coachblackfriday.com a waste www.ralph-laurenoutlet.ca of www.prada-shoes.com.co life, www.lululemon-australia.com.au but www.rayban.com.de some www.toms--outlet.com.co things, but if www.louisvuitton.so the www.swarovski-crystal.us.com raw www.oakley-sunglasses.mex.com flavor, www.tomsshoes-outlet.us.com leisure www.coach-factoryoutlet.net.co goods www.converse-shoesoutlet.com for gossip, www.cheapjerseys.com.co so www.cheapmichaelkors.us.org I www.tiffany-und-co.de love www.adidasshoes.top romantic www.coach-purseoutlet.net dreamer, www.abercrombie-kids.us.com but supra.shoesoutlet.us.com I www.coach-factory.in.net love www.michael-kors-outlet.us.org real life.Day www.maccosmetics.gr.com in www.rolex-watches.us.com a www.katespadeoutlet.gb.net hurry, www.lauren-ralph.co.uk took www.chanel-bags.com.co all the www.ray-banocchiali.it joy www.nike-shoesoutlet.us.com and sadness, www.mizuno-running.net a www.swarovski-online-shop.de lot www.timberlandshoes.net.co of www.airmax-90.org things, www.mcm-handbags.org not www.mcmsworldwide.com enough time www.uggs-onsale.net to www.chi-flatiron.us.com recall, www.cheapuggboots.us.com Chaoyang July, www.michael-kors-australia.com.au early www.pandora-charms-canada.ca June www.juicycouture.com.co already covered uggaustralia.misblackfriday.com confused. www.beats-headphone.com.co Season removed, www.polos-ralphlauren.us.com landscape www.mkoutletonline.us.com transformation, www.tommy-hilfiger-online-shop.de the www.michaelkorsoutletonline-sale.us.com so-called www.canadagooses-2016.com forever www.the-north-face.ca always www.burberryoutlet2016.us.com far-fetched, www.ralphlaurenoutletonline.us.org time, www.hermesbags.jp.net not www.coachoutletstore-online.com.co to be www.ferragamoshoes.in.net squandered, www.nike-air-max.ca the www.nike-maxfr.com true www.michaelkors.com.se meaning www.swarovski--uk.me.uk of www.cheaprayban.com.co life www.nikefree-run.org.uk is www.asics-outlet.us.com to www.guccishoes.com.co enjoy www.converse.com.de the good www.guccihandbags.net.co in the www.bcbg-dresses.com flat, www.abercrombie-hollister.nl I www.airjordans.us Dimei www.tiffanyandco-canada.ca fireworks, www.michael-kors-outlet-online.us.org also read www.omega-watches.us.com the www.bottegaveneta-bagsoutlet.com leisure, www.ralphlaurenepolo.com with www.omegarelojes.es a touch www.adidas-superstar.nl of www.replicarolex-watches.us.com ink, www.ralphlaurenpolos.in.net painting www.handbagsoutlet.net.co a www.replica-watches.com.co thin www.kate-spade.gb.net clear www.northfaceoutlet.com.co Huan, www.valentino-shoesoutlet.us.com look lush www.converse-shoes.net green, www.adidas.com.se covered with www.oakleyoutlet-online.us.com mottled www.abercrombie-and-fitch.us.com wall. www.michaelkorsoutlet-online.ar.com This www.burberry2016.co.uk July, www.montres-pascher.fr I kept www.mcm-bags.in.net the www.louisvuitton.jp.net book's www.nike-tnrequinpascher.fr swoosh; www.hogan.com.de this www.michaelkors.so July, I www.retro-jordans.com dream www.rayban-wayfarer.in.net in www.mcmhandbags.com.co Lijiang; www.louis-vuittonoutletcanada.ca this www.jordanrelease-dates.us.com July, www.tory-burchshoesoutlet.net and www.coco-chanels.us.com has www.nike-schuhe.com.de been www.michael-kors.com.co well, www.canada-goosesjackets.us.com not www.marc-jacobs.us.com made sad.If www.truereligion-outlet.us.org you www.hermesbirkin-bag.net can www.thomas-sabo.com.de do www.pandorajewellery.com.au if www.instylers.us.com a www.maccosmetics.net.co light www.weddingdressesuk.org.uk breeze www.polo-ralph-lauren.de right www.moncler-outlet.us.org woman, placed www.pumashoes.in.net in www.nike-air-max.com.au the www.toryburchoutlet-sale.us.com text www.tiffany-andco.com.au soul, airhuarache.shoesoutlet.us.com written imprint www.cheap-baseballbats.net of www.nikeair-max.es life, www.eyeglassesonline.us.com write www.oakleys-sunglasses.us.com thin cool and www.new-balance-schuhe.de clear www.nikeshoesoutlet.org.uk Huan, www.rayban.co.nl occasionally www.tomsoutlet-online.com write www.thenorth-faces.co.uk love, www.nike-air-force.de but www.nike-air-max.com.se never give www.longchamps.us.com love, www.vans-schuhe.com.de keep www.salvatoreferragamo.in.net a www.louis-vuittonblackfriday.com clear www.salomon-schuhe.com.de gel www.tiffany-jewelry.net Bay, look www.jordan-shoes.com.co for www.pandora.com.de a www.tnf-jackets.us.com parts of www.woolrich-clearance.com the peace, www.bcbg-max-azria.ca the www.tocoachoutlet.com joy www.thenorthfacejackets.net.co and www.louboutin.jp.net sorrow www.vans-shoes.net of www.coachoutletstore.net.co all www.oakleysunglasses-cheap.in.net his www.burberry-outlet.net.co writings, www.polo-outlets.com.co and www.coach-outletonline.net.co text www.ugg-boots.us.org only www.oakley-sunglasses-canada.ca affair www.airhuarache.co.uk has nothing to www.air-max.com.de do www.ralphlauren-polos.co.uk with www.christianlouboutin.org.uk the www.cheap-jordans.net other.Morning www.chanelhandbags.net.in time, www.iphone-cases.net.co with www.ralphlaurenoutlet.us.com a www.christianlouboutinshoesoutlet.org tranquil www.thejoreseproject.com and www.hollister.us.org contented www.ralphs-lauren.co.uk Zen www.ralphlaurenoutletonline.in.net cloud www.nikefree-run.net water, www.uggsoutlet.com.co eyes closed, www.bebeclothing.in.net the www.newbalance.com.es heart www.pandorajewelry.top distant www.levisjeans.com.co exile, www.new-balance.ca Wind www.designerhandbagsoutlet.net.co and www.beatsbydrdre.co.com Smoke www.prada-handbags.com.co curl www.michael-kors-handbags.us.com in www.scarpe-hoganoutlets.it the www.yoga-pants.ca mountains, www.toryburch-sandals.in.net such www.toms-shoesoutlet.net as www.true-religion.com.co Dai, www.rolexwatches-canada.ca ups www.nikefactory.org and www.basketballshoes.com.co downs, www.mk-outlet.us.com indeed, www.uhren-shop.com.de like airmax.shoesoutlet.us.com a www.the-northface.net.co thread, www.tommy-hilfiger.com.de the ups www.ghd-hairstraightener.net and downs www.horloges-rolex.nl of www.cheap-oakleyglasses.us.com life, www.oakley.com.de with www.ugg-bootsclearance.com long www.burberry-handbagsoutlet.com.co Qingyuan . www.nike-air-max.us Flowers www.insanity-workout.us.com followed www.lululemonoutlet.gb.net the www.nike.org.es road, www.yoga-pants.net.co facing www.tommy-hilfigeroutlet.com the www.ralph-lauren.com.au sun www.ralphlaurenoutlet-online.us.com slowly www.vans-shoes.co.uk forward, www.adidas.org.es then the www.ugg-boots-australia.com.au mind www.hollisterclothingstore.org is www.guccishoes-uk.co.uk calm, www.louis--vuitton.org.uk quiet www.pandora-charms.org.uk as www.air-huarache.co.uk the www.nike-huarache.nl lake, www.ray-ban-outlet.us.com the www.swarovskijewelry.com.co water www.ralphslauren-outlet.co.uk peach, www.giuseppezanotti.com.co flower www.gucci-outletstore.com with www.michael-korshandbags.org.uk water, www.newoutletonlinemall.com just www.giuseppe-zanotti.net like www.jordanretro.org the fate www.nike-skor.com.se of www.abercrombie-fitchsale.com this world, www.newbalance-outlet.org do www.celine-bags.org not www.outlet-burberry.net.co ask www.rayban-sunglasses.us.org why, www.abercrombieand-fitch.ca regardless www.oakley.org.es of www.converse.net.co come and go, www.longchamp.com.co only www.gucci-shoes.net flowers www.oakleys-glasses.us.com need www.toryburchsale.com.co to www.supra-shoes.org remember www.ugg-australia.com.de Lu www.coachhandbags2016.us.com Qing, www.hollister-clothing.in.net Yue www.rayban-sunglassesoutlet.co.uk possessor of the www.uggsaustralia.com.co green www.tommy-hilfiger.co.nl heart, cool count. www.cheapshoes.com.co Sunlight www.rosheruns.us penetration www.nike-schoenen.co.nl mist, www.ugg-uggboots.net alluding www.airmax-2015.org on www.michael-kors-taschen.com.de the www.polooutlets-store.com lake, the water www.soccer-shoes.us.com green, www.tiffanyand-co.net.co clear, sparkling, www.guccishoes.in.net on www.tommyhilfigeroutlet.in.net the www.bottega-veneta.us.com beach, www.louisvuitton-outlets.us there www.harrods-london.co.uk are www.truereligionjeans.net.co birds flying www.nike-shoes-canada.ca over www.truereligion-outlet.com.co from www.michael-kors.com.es time www.nikeair--max.fr to www.uggboots.net.co time, www.swarovski-australia.com.au the www.burberrys-outlet2016.com sky www.fashionclothes.us.com blue www.gucci-taschen-outlet.de and www.raybans.us.org empty, www.thomas-sabos.org.uk with www.rolexwatchesforsale.us.com a www.louisvuitton-outlet.com.co quiet www.nikefree5.net life www.beatsbydre.com.co after ups www.oakley--sunglasses.com.au and www.longchamphandbagsoutlet.net downs, www.longchamp-bags.us.com this time www.burberry-outletstore.net the www.the-northface.com.co heart www.lululemoncanada.ca is www.abercrombie-fitchs.us.com close www.burberryoutlet-canada.ca to www.newbalance-shoes.org nature, www.burberrys-outlet.co.uk without www.pulseras-pandora.com.es the www.coachoutlet-online.com.co slightest www.toms-outlets.us.com ripples, www.uggs.in.net content www.zxcoachoutlet.com with www.marcjacobs.us.com this www.nikerosherun.us quiet and www.louisvuittons.com.co peaceful. www.nike-free-run.de An end, www.oakleysunglass-outlet.net wins www.cheap-michaelkors.com the www.timberlandbootsoutlet.us.com snow www.tommy-hilfiger-canada.ca lotus, www.christianlouboutinshoes.jp.net world www.p90xworkout.us.com clarity, www.hollisters-canada.ca years www.the-northfacejackets.us.com of www.michael--kors.us.com silence, www.hollisteronlineshop.com.de the heart www.nike--freerun.co.uk is www.cheap-raybans.com also www.wedding--dresses.ca safe.Time, www.cheapoakley-sunglasses.com very www.nikeskos.dk long. www.cheapjerseys.us.org I www.nikestore.us know, www.christian-louboutinshoes.com.co I www.soccer-shoesoutlet.com can www.michaelkors-uk.org.uk stay www.ray-bansunglasses.net in my www.hermes-outlet.com.co mind www.oakleyoutlet.ar.com there www.reebok.com.de are www.louis-vuitton-taschen.com.de limitations, www.calvin-kleins.us.com not the www.nike-air-max.com.de majority, www.michaelkors-outlet-online.com.co can www.replica-handbags.net.co only www.burberrybags-outlet.com rely www.michaeljordan.com.de on nike.shoesoutlet.us.com these www.pradahandbags.net.co words www.juicycoutureoutlet.net.co to www.nfl-jersey.us.com memory.Time, www.coach-factoryyoutletonline.net is www.tomsoutletonline.net very www.beats-by-dre.com.co short. www.longchamp.com.de I www.christian-louboutin-shoes.ca understand, www.burberry-handbags2016.in.net you www.edhardy.us.org can www.ralphlauren-polos.com.co never www.eyeglassframes.in.net forget www.jimmy-choos.com so www.adidas-superstar.de little, www.jimmy-chooshoes.com so www.christian--louboutin.in.net I www.uggs.co.nl was www.michaelkors.co.nl in www.guccioutlet-sale.in.net such www.cheapoakley-sunglasses.in.net a www.prada.com.de manner so www.nike-roshe-run.de as www.longchamp-handbagsoutlet.us.com to leave www.burberryoutlet-sale.in.net some more.Youth, is very www.toms-shoes.com.co long. www.barbour-factory.com In www.swarovskicanada.ca life, www.burberry-outletonlinesale.in.net shiny www.montblanc--pens.in.net people, www.michaelkorsoutlet.ar.com in www.ugg-boots.ca fact, www.nike-airmaxinc.co.uk that www.tommyhilfiger.net.co a www.designer-handbagsoutlet.us.com figure, www.asicsgels.de how www.ralph-laurens.org.uk the passage of www.mcmbags.net time, www.tiffany-andco.us.com or www.ralphlaurenonlineshop.de the www.barbour-jacketsoutlet.com whole www.poloralphlaurenoutlet.net.co dazzling www.hollister-abercrombie.com.se Love.Youth, is www.ray--ban.ca very www.burberryonlineshop.de short. www.michael-kors.net.co In www.oakley-outletstore.in.net life, www.ferragamo.com.co flickering www.thenorthface.com.de days www.timberlands-paschere.fr

www.soft-ballbats.com

Post comment

Nick *
Your name or nickname
E-mail
Your contact information (optional, will not be shown)
Text *
Content of your comment
Calculate *
(* - required field)
STAT NO AD [Stat] [Admin] [STAT NO AD] [pub] [Mirror] Copyright © 2004-2016 Adam Sawicki
Copyright © 2004-2016 Adam Sawicki