atlctrlw.h 111 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997
  1. // Windows Template Library - WTL version 10.0
  2. // Copyright (C) Microsoft Corporation, WTL Team. All rights reserved.
  3. //
  4. // This file is a part of the Windows Template Library.
  5. // The use and distribution terms for this software are covered by the
  6. // Microsoft Public License (http://opensource.org/licenses/MS-PL)
  7. // which can be found in the file MS-PL.txt at the root folder.
  8. #ifndef __ATLCTRLW_H__
  9. #define __ATLCTRLW_H__
  10. #pragma once
  11. #ifndef __ATLAPP_H__
  12. #error atlctrlw.h requires atlapp.h to be included first
  13. #endif
  14. #ifndef __ATLCTRLS_H__
  15. #error atlctrlw.h requires atlctrls.h to be included first
  16. #endif
  17. // Define _WTL_CMDBAR_VISTA_MENUS as 0 to exclude Vista menus support
  18. #ifndef _WTL_CMDBAR_VISTA_MENUS
  19. #define _WTL_CMDBAR_VISTA_MENUS 1
  20. #endif
  21. // Note: Define _WTL_CMDBAR_VISTA_STD_MENUBAR to use Vista standard menubar look with Vista menus
  22. ///////////////////////////////////////////////////////////////////////////////
  23. // Classes in this file:
  24. //
  25. // CCommandBarCtrlImpl<T, TBase, TWinTraits>
  26. // CCommandBarCtrl
  27. // CMDICommandBarCtrlImpl<T, TBase, TWinTraits>
  28. // CMDICommandBarCtrl
  29. namespace WTL
  30. {
  31. ///////////////////////////////////////////////////////////////////////////////
  32. // Command Bars
  33. // Window Styles:
  34. #define CBRWS_TOP CCS_TOP
  35. #define CBRWS_BOTTOM CCS_BOTTOM
  36. #define CBRWS_NORESIZE CCS_NORESIZE
  37. #define CBRWS_NOPARENTALIGN CCS_NOPARENTALIGN
  38. #define CBRWS_NODIVIDER CCS_NODIVIDER
  39. // Extended styles
  40. #define CBR_EX_TRANSPARENT 0x00000001L
  41. #define CBR_EX_SHAREMENU 0x00000002L
  42. #define CBR_EX_ALTFOCUSMODE 0x00000004L
  43. #define CBR_EX_TRACKALWAYS 0x00000008L
  44. #define CBR_EX_NOVISTAMENUS 0x00000010L
  45. // standard command bar styles
  46. #define ATL_SIMPLE_CMDBAR_PANE_STYLE \
  47. (WS_CHILD | WS_VISIBLE | WS_CLIPCHILDREN | WS_CLIPSIBLINGS | CBRWS_NODIVIDER | CBRWS_NORESIZE | CBRWS_NOPARENTALIGN)
  48. // Messages - support chevrons for frame windows
  49. #define CBRM_GETCMDBAR (WM_USER + 301) // returns command bar HWND
  50. #define CBRM_GETMENU (WM_USER + 302) // returns loaded or attached menu
  51. #define CBRM_TRACKPOPUPMENU (WM_USER + 303) // displays a popup menu
  52. typedef struct tagCBRPOPUPMENU
  53. {
  54. int cbSize;
  55. HMENU hMenu; // popup menu do display
  56. UINT uFlags; // TPM_* flags for ::TrackPopupMenuEx
  57. int x;
  58. int y;
  59. LPTPMPARAMS lptpm; // ptr to TPMPARAMS for ::TrackPopupMenuEx
  60. } CBRPOPUPMENU, *LPCBRPOPUPMENU;
  61. // helper class
  62. template <class T>
  63. class CSimpleStack : public ATL::CSimpleArray< T >
  64. {
  65. public:
  66. BOOL Push(T t)
  67. {
  68. #ifdef _CMDBAR_EXTRA_TRACE
  69. ATLTRACE2(atlTraceUI, 0, _T("CmdBar - STACK-PUSH (%8.8X) size = %i\n"), t, GetSize());
  70. #endif
  71. return this->Add(t);
  72. }
  73. T Pop()
  74. {
  75. int nLast = this->GetSize() - 1;
  76. if(nLast < 0)
  77. return NULL; // must be able to convert to NULL
  78. T t = this->m_aT[nLast];
  79. #ifdef _CMDBAR_EXTRA_TRACE
  80. ATLTRACE2(atlTraceUI, 0, _T("CmdBar - STACK-POP (%8.8X) size = %i\n"), t, GetSize());
  81. #endif
  82. if(!this->RemoveAt(nLast))
  83. return NULL;
  84. return t;
  85. }
  86. T GetCurrent()
  87. {
  88. int nLast = this->GetSize() - 1;
  89. if(nLast < 0)
  90. return NULL; // must be able to convert to NULL
  91. return this->m_aT[nLast];
  92. }
  93. };
  94. ///////////////////////////////////////////////////////////////////////////////
  95. // CCommandBarCtrlBase - base class for the Command Bar implementation
  96. class CCommandBarCtrlBase : public CToolBarCtrl
  97. {
  98. public:
  99. struct _MsgHookData
  100. {
  101. HHOOK hMsgHook;
  102. DWORD dwUsage;
  103. _MsgHookData() : hMsgHook(NULL), dwUsage(0)
  104. { }
  105. };
  106. typedef ATL::CSimpleMap<DWORD, _MsgHookData*> CMsgHookMap;
  107. static CMsgHookMap* s_pmapMsgHook;
  108. static HHOOK s_hCreateHook;
  109. static CCommandBarCtrlBase* s_pCurrentBar;
  110. static bool s_bStaticInit;
  111. CSimpleStack<HWND> m_stackMenuWnd;
  112. CSimpleStack<HMENU> m_stackMenuHandle;
  113. HWND m_hWndHook;
  114. DWORD m_dwMagic;
  115. CCommandBarCtrlBase() : m_hWndHook(NULL), m_dwMagic(1314)
  116. {
  117. // init static variables
  118. if(!s_bStaticInit)
  119. {
  120. CStaticDataInitCriticalSectionLock lock;
  121. if(FAILED(lock.Lock()))
  122. {
  123. ATLTRACE2(atlTraceUI, 0, _T("ERROR : Unable to lock critical section in CCommandBarCtrlBase::CCommandBarCtrlBase.\n"));
  124. ATLASSERT(FALSE);
  125. return;
  126. }
  127. if(!s_bStaticInit)
  128. {
  129. // Just in case...
  130. AtlInitCommonControls(ICC_COOL_CLASSES | ICC_BAR_CLASSES);
  131. // done
  132. s_bStaticInit = true;
  133. }
  134. lock.Unlock();
  135. }
  136. }
  137. bool IsCommandBarBase() const { return m_dwMagic == 1314; }
  138. };
  139. __declspec(selectany) CCommandBarCtrlBase::CMsgHookMap* CCommandBarCtrlBase::s_pmapMsgHook = NULL;
  140. __declspec(selectany) HHOOK CCommandBarCtrlBase::s_hCreateHook = NULL;
  141. __declspec(selectany) CCommandBarCtrlBase* CCommandBarCtrlBase::s_pCurrentBar = NULL;
  142. __declspec(selectany) bool CCommandBarCtrlBase::s_bStaticInit = false;
  143. ///////////////////////////////////////////////////////////////////////////////
  144. // CCommandBarCtrl - ATL implementation of Command Bars
  145. template <class T, class TBase = CCommandBarCtrlBase, class TWinTraits = ATL::CControlWinTraits>
  146. class ATL_NO_VTABLE CCommandBarCtrlImpl : public ATL::CWindowImpl< T, TBase, TWinTraits >
  147. {
  148. public:
  149. DECLARE_WND_SUPERCLASS2(NULL, T, TBase::GetWndClassName())
  150. // Declarations
  151. struct _MenuItemData // menu item data
  152. {
  153. DWORD dwMagic;
  154. LPTSTR lpstrText;
  155. UINT fType;
  156. UINT fState;
  157. int iButton;
  158. _MenuItemData() : dwMagic(0x1313), lpstrText(NULL), fType(0U), fState(0U), iButton(0)
  159. { }
  160. bool IsCmdBarMenuItem() { return (dwMagic == 0x1313); }
  161. };
  162. struct _ToolBarData // toolbar resource data
  163. {
  164. WORD wVersion;
  165. WORD wWidth;
  166. WORD wHeight;
  167. WORD wItemCount;
  168. //WORD aItems[wItemCount]
  169. WORD* items()
  170. { return (WORD*)(this+1); }
  171. };
  172. // Constants
  173. enum _CmdBarDrawConstants
  174. {
  175. s_kcxGap = 1,
  176. s_kcxTextMargin = 2,
  177. s_kcxButtonMargin = 3,
  178. s_kcyButtonMargin = 3
  179. };
  180. enum
  181. {
  182. _nMaxMenuItemTextLength = 100,
  183. _chChevronShortcut = _T('/')
  184. };
  185. // Data members
  186. HMENU m_hMenu;
  187. HIMAGELIST m_hImageList;
  188. ATL::CSimpleValArray<WORD> m_arrCommand;
  189. DWORD m_dwExtendedStyle; // Command Bar specific extended styles
  190. ATL::CContainedWindow m_wndParent;
  191. bool m_bMenuActive:1;
  192. bool m_bAttachedMenu:1;
  193. bool m_bImagesVisible:1;
  194. bool m_bPopupItem:1;
  195. bool m_bContextMenu:1;
  196. bool m_bEscapePressed:1;
  197. bool m_bSkipMsg:1;
  198. bool m_bParentActive:1;
  199. bool m_bFlatMenus:1;
  200. bool m_bUseKeyboardCues:1;
  201. bool m_bShowKeyboardCues:1;
  202. bool m_bAllowKeyboardCues:1;
  203. bool m_bKeyboardInput:1;
  204. bool m_bAlphaImages:1;
  205. bool m_bLayoutRTL:1;
  206. bool m_bSkipPostDown:1;
  207. bool m_bVistaMenus:1;
  208. int m_nPopBtn;
  209. int m_nNextPopBtn;
  210. SIZE m_szBitmap;
  211. SIZE m_szButton;
  212. COLORREF m_clrMask;
  213. CFont m_fontMenu; // used internally, only to measure text
  214. UINT m_uSysKey;
  215. HWND m_hWndFocus; // Alternate focus mode
  216. int m_cxExtraSpacing;
  217. #if _WTL_CMDBAR_VISTA_MENUS
  218. ATL::CSimpleValArray<HBITMAP> m_arrVistaBitmap; // Bitmaps for Vista menus
  219. #endif // _WTL_CMDBAR_VISTA_MENUS
  220. // Constructor/destructor
  221. CCommandBarCtrlImpl() :
  222. m_hMenu(NULL),
  223. m_hImageList(NULL),
  224. m_dwExtendedStyle(CBR_EX_TRANSPARENT | CBR_EX_SHAREMENU | CBR_EX_TRACKALWAYS),
  225. m_wndParent(this, 1),
  226. m_bMenuActive(false),
  227. m_bAttachedMenu(false),
  228. m_bImagesVisible(true),
  229. m_bPopupItem(false),
  230. m_bContextMenu(false),
  231. m_bEscapePressed(false),
  232. m_bSkipMsg(false),
  233. m_bParentActive(true),
  234. m_bFlatMenus(false),
  235. m_bUseKeyboardCues(false),
  236. m_bShowKeyboardCues(false),
  237. m_bAllowKeyboardCues(true),
  238. m_bKeyboardInput(false),
  239. m_bAlphaImages(false),
  240. m_bLayoutRTL(false),
  241. m_bSkipPostDown(false),
  242. m_bVistaMenus(false),
  243. m_nPopBtn(-1),
  244. m_nNextPopBtn(-1),
  245. m_clrMask(RGB(192, 192, 192)),
  246. m_uSysKey(0),
  247. m_hWndFocus(NULL),
  248. m_cxExtraSpacing(0)
  249. {
  250. SetImageSize(16, 15); // default
  251. }
  252. ~CCommandBarCtrlImpl()
  253. {
  254. if(m_wndParent.IsWindow())
  255. /*scary!*/ m_wndParent.UnsubclassWindow();
  256. if((m_hMenu != NULL) && ((m_dwExtendedStyle & CBR_EX_SHAREMENU) == 0))
  257. ::DestroyMenu(m_hMenu);
  258. if(m_hImageList != NULL)
  259. ::ImageList_Destroy(m_hImageList);
  260. }
  261. // Attributes
  262. DWORD GetCommandBarExtendedStyle() const
  263. {
  264. return m_dwExtendedStyle;
  265. }
  266. DWORD SetCommandBarExtendedStyle(DWORD dwExtendedStyle, DWORD dwMask = 0)
  267. {
  268. DWORD dwPrevStyle = m_dwExtendedStyle;
  269. if(dwMask == 0)
  270. m_dwExtendedStyle = dwExtendedStyle;
  271. else
  272. m_dwExtendedStyle = (m_dwExtendedStyle & ~dwMask) | (dwExtendedStyle & dwMask);
  273. return dwPrevStyle;
  274. }
  275. CMenuHandle GetMenu() const
  276. {
  277. ATLASSERT(::IsWindow(this->m_hWnd));
  278. return m_hMenu;
  279. }
  280. COLORREF GetImageMaskColor() const
  281. {
  282. return m_clrMask;
  283. }
  284. COLORREF SetImageMaskColor(COLORREF clrMask)
  285. {
  286. COLORREF clrOld = m_clrMask;
  287. m_clrMask = clrMask;
  288. return clrOld;
  289. }
  290. bool GetImagesVisible() const
  291. {
  292. return m_bImagesVisible;
  293. }
  294. bool SetImagesVisible(bool bVisible)
  295. {
  296. bool bOld = m_bImagesVisible;
  297. m_bImagesVisible = bVisible;
  298. return bOld;
  299. }
  300. void GetImageSize(SIZE& size) const
  301. {
  302. size = m_szBitmap;
  303. }
  304. bool SetImageSize(SIZE& size)
  305. {
  306. return SetImageSize(size.cx, size.cy);
  307. }
  308. bool SetImageSize(int cx, int cy)
  309. {
  310. if(m_hImageList != NULL)
  311. {
  312. if(::ImageList_GetImageCount(m_hImageList) == 0) // empty
  313. {
  314. ::ImageList_Destroy(m_hImageList);
  315. m_hImageList = NULL;
  316. }
  317. else
  318. {
  319. return false; // can't set, image list exists
  320. }
  321. }
  322. if((cx == 0) || (cy == 0))
  323. return false;
  324. m_szBitmap.cx = cx;
  325. m_szBitmap.cy = cy;
  326. m_szButton.cx = m_szBitmap.cx + 2 * s_kcxButtonMargin;
  327. m_szButton.cy = m_szBitmap.cy + 2 * s_kcyButtonMargin;
  328. return true;
  329. }
  330. bool GetAlphaImages() const
  331. {
  332. return m_bAlphaImages;
  333. }
  334. bool SetAlphaImages(bool bAlphaImages)
  335. {
  336. if(m_hImageList != NULL)
  337. {
  338. if(::ImageList_GetImageCount(m_hImageList) == 0) // empty
  339. {
  340. ::ImageList_Destroy(m_hImageList);
  341. m_hImageList = NULL;
  342. }
  343. else
  344. {
  345. return false; // can't set, image list exists
  346. }
  347. }
  348. m_bAlphaImages = bAlphaImages;
  349. return true;
  350. }
  351. HWND GetCmdBar() const
  352. {
  353. ATLASSERT(::IsWindow(this->m_hWnd));
  354. return (HWND)::SendMessage(this->m_hWnd, CBRM_GETCMDBAR, 0, 0L);
  355. }
  356. // Methods
  357. HWND Create(HWND hWndParent, RECT& rcPos, LPCTSTR szWindowName = NULL,
  358. DWORD dwStyle = 0, DWORD dwExStyle = 0,
  359. UINT nID = 0, LPVOID lpCreateParam = NULL)
  360. {
  361. // These styles are required for command bars
  362. dwStyle |= TBSTYLE_LIST | TBSTYLE_FLAT;
  363. return ATL::CWindowImpl< T, TBase, TWinTraits >::Create(hWndParent, rcPos, szWindowName, dwStyle, dwExStyle, nID, lpCreateParam);
  364. }
  365. BOOL AttachToWindow(HWND hWnd)
  366. {
  367. ATLASSERT(this->m_hWnd == NULL);
  368. ATLASSERT(::IsWindow(hWnd));
  369. BOOL bRet = this->SubclassWindow(hWnd);
  370. if(bRet)
  371. {
  372. m_bAttachedMenu = true;
  373. T* pT = static_cast<T*>(this);
  374. pT->GetSystemSettings();
  375. }
  376. return bRet;
  377. }
  378. BOOL LoadMenu(ATL::_U_STRINGorID menu)
  379. {
  380. ATLASSERT(::IsWindow(this->m_hWnd));
  381. if(m_bAttachedMenu) // doesn't work in this mode
  382. return FALSE;
  383. if(menu.m_lpstr == NULL)
  384. return FALSE;
  385. HMENU hMenu = ::LoadMenu(ModuleHelper::GetResourceInstance(), menu.m_lpstr);
  386. if(hMenu == NULL)
  387. return FALSE;
  388. return AttachMenu(hMenu);
  389. }
  390. BOOL AttachMenu(HMENU hMenu)
  391. {
  392. ATLASSERT(::IsWindow(this->m_hWnd));
  393. ATLASSERT((hMenu == NULL) || ::IsMenu(hMenu));
  394. if((hMenu != NULL) && !::IsMenu(hMenu))
  395. return FALSE;
  396. #if _WTL_CMDBAR_VISTA_MENUS
  397. // remove Vista bitmaps if used
  398. if(m_bVistaMenus && (m_hMenu != NULL))
  399. {
  400. T* pT = static_cast<T*>(this);
  401. pT->_RemoveVistaBitmapsFromMenu();
  402. }
  403. #endif // _WTL_CMDBAR_VISTA_MENUS
  404. // destroy old menu, if needed, and set new one
  405. if((m_hMenu != NULL) && ((m_dwExtendedStyle & CBR_EX_SHAREMENU) == 0))
  406. ::DestroyMenu(m_hMenu);
  407. m_hMenu = hMenu;
  408. if(m_bAttachedMenu) // Nothing else in this mode
  409. return TRUE;
  410. // Build buttons according to menu
  411. this->SetRedraw(FALSE);
  412. // Clear all buttons
  413. int nCount = this->GetButtonCount();
  414. for(int i = 0; i < nCount; i++)
  415. ATLVERIFY(this->DeleteButton(0) != FALSE);
  416. // Add buttons for each menu item
  417. if(m_hMenu != NULL)
  418. {
  419. int nItems = ::GetMenuItemCount(m_hMenu);
  420. T* pT = static_cast<T*>(this);
  421. (void)pT; // avoid level 4 warning
  422. TCHAR szString[pT->_nMaxMenuItemTextLength] = {};
  423. for(int i = 0; i < nItems; i++)
  424. {
  425. CMenuItemInfo mii;
  426. mii.fMask = MIIM_TYPE | MIIM_STATE | MIIM_SUBMENU;
  427. mii.fType = MFT_STRING;
  428. mii.dwTypeData = szString;
  429. mii.cch = pT->_nMaxMenuItemTextLength;
  430. BOOL bRet = ::GetMenuItemInfo(m_hMenu, i, TRUE, &mii);
  431. ATLASSERT(bRet);
  432. // If we have more than the buffer, we assume we have bitmaps bits
  433. if(lstrlen(szString) > pT->_nMaxMenuItemTextLength - 1)
  434. {
  435. mii.fType = MFT_BITMAP;
  436. ::SetMenuItemInfo(m_hMenu, i, TRUE, &mii);
  437. szString[0] = 0;
  438. }
  439. // NOTE: Command Bar currently supports only drop-down menu items
  440. ATLASSERT(mii.hSubMenu != NULL);
  441. TBBUTTON btn = {};
  442. btn.iBitmap = 0;
  443. btn.idCommand = i;
  444. btn.fsState = (BYTE)(((mii.fState & MFS_DISABLED) == 0) ? TBSTATE_ENABLED : 0);
  445. btn.fsStyle = BTNS_BUTTON | BTNS_AUTOSIZE | BTNS_DROPDOWN;
  446. btn.dwData = 0;
  447. btn.iString = 0;
  448. bRet = this->InsertButton(-1, &btn);
  449. ATLASSERT(bRet);
  450. TBBUTTONINFO bi = {};
  451. bi.cbSize = sizeof(TBBUTTONINFO);
  452. bi.dwMask = TBIF_TEXT;
  453. bi.pszText = szString;
  454. bRet = this->SetButtonInfo(i, &bi);
  455. ATLASSERT(bRet);
  456. }
  457. }
  458. this->SetRedraw(TRUE);
  459. this->Invalidate();
  460. this->UpdateWindow();
  461. return TRUE;
  462. }
  463. BOOL LoadImages(ATL::_U_STRINGorID image)
  464. {
  465. return _LoadImagesHelper(image, false);
  466. }
  467. BOOL LoadMappedImages(UINT nIDImage, UINT nFlags = 0, LPCOLORMAP lpColorMap = NULL, int nMapSize = 0)
  468. {
  469. return _LoadImagesHelper(nIDImage, true, nFlags , lpColorMap, nMapSize);
  470. }
  471. BOOL _LoadImagesHelper(ATL::_U_STRINGorID image, bool bMapped, UINT nFlags = 0, LPCOLORMAP lpColorMap = NULL, int nMapSize = 0)
  472. {
  473. ATLASSERT(::IsWindow(this->m_hWnd));
  474. HINSTANCE hInstance = ModuleHelper::GetResourceInstance();
  475. HRSRC hRsrc = ::FindResource(hInstance, image.m_lpstr, (LPTSTR)RT_TOOLBAR);
  476. if(hRsrc == NULL)
  477. return FALSE;
  478. HGLOBAL hGlobal = ::LoadResource(hInstance, hRsrc);
  479. if(hGlobal == NULL)
  480. return FALSE;
  481. _ToolBarData* pData = (_ToolBarData*)::LockResource(hGlobal);
  482. if(pData == NULL)
  483. return FALSE;
  484. ATLASSERT(pData->wVersion == 1);
  485. WORD* pItems = pData->items();
  486. int nItems = pData->wItemCount;
  487. // Set internal data
  488. SetImageSize(pData->wWidth, pData->wHeight);
  489. // Create image list if needed
  490. if(m_hImageList == NULL)
  491. {
  492. // Check if the bitmap is 32-bit (alpha channel) bitmap (valid for Windows XP only)
  493. T* pT = static_cast<T*>(this);
  494. m_bAlphaImages = AtlIsAlphaBitmapResource(image);
  495. if(!pT->CreateInternalImageList(pData->wItemCount))
  496. return FALSE;
  497. }
  498. #if _WTL_CMDBAR_VISTA_MENUS
  499. int nOldImageCount = ::ImageList_GetImageCount(m_hImageList);
  500. #endif // _WTL_CMDBAR_VISTA_MENUS
  501. // Add bitmap to our image list
  502. CBitmap bmp;
  503. if(bMapped)
  504. {
  505. ATLASSERT(HIWORD(PtrToUlong(image.m_lpstr)) == 0); // if mapped, must be a numeric ID
  506. int nIDImage = (int)(short)LOWORD(PtrToUlong(image.m_lpstr));
  507. bmp.LoadMappedBitmap(nIDImage, (WORD)nFlags, lpColorMap, nMapSize);
  508. }
  509. else
  510. {
  511. if(m_bAlphaImages)
  512. bmp = (HBITMAP)::LoadImage(ModuleHelper::GetResourceInstance(), image.m_lpstr, IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION | LR_DEFAULTSIZE);
  513. else
  514. bmp.LoadBitmap(image.m_lpstr);
  515. }
  516. ATLASSERT(bmp.m_hBitmap != NULL);
  517. if(bmp.m_hBitmap == NULL)
  518. return FALSE;
  519. if(::ImageList_AddMasked(m_hImageList, bmp, m_clrMask) == -1)
  520. return FALSE;
  521. // Fill the array with command IDs
  522. for(int i = 0; i < nItems; i++)
  523. {
  524. if(pItems[i] != 0)
  525. m_arrCommand.Add(pItems[i]);
  526. }
  527. int nImageCount = ::ImageList_GetImageCount(m_hImageList);
  528. ATLASSERT(nImageCount == m_arrCommand.GetSize());
  529. if(nImageCount != m_arrCommand.GetSize())
  530. return FALSE;
  531. #if _WTL_CMDBAR_VISTA_MENUS
  532. if(RunTimeHelper::IsVista())
  533. {
  534. T* pT = static_cast<T*>(this);
  535. pT->_AddVistaBitmapsFromImageList(nOldImageCount, nImageCount - nOldImageCount);
  536. ATLASSERT(nImageCount == m_arrVistaBitmap.GetSize());
  537. }
  538. #endif // _WTL_CMDBAR_VISTA_MENUS
  539. return TRUE;
  540. }
  541. BOOL AddBitmap(ATL::_U_STRINGorID bitmap, int nCommandID)
  542. {
  543. ATLASSERT(::IsWindow(this->m_hWnd));
  544. CBitmap bmp;
  545. bmp.LoadBitmap(bitmap.m_lpstr);
  546. if(bmp.m_hBitmap == NULL)
  547. return FALSE;
  548. return AddBitmap(bmp, nCommandID);
  549. }
  550. BOOL AddBitmap(HBITMAP hBitmap, UINT nCommandID)
  551. {
  552. ATLASSERT(::IsWindow(this->m_hWnd));
  553. T* pT = static_cast<T*>(this);
  554. // Create image list if it doesn't exist
  555. if(m_hImageList == NULL)
  556. {
  557. if(!pT->CreateInternalImageList(1))
  558. return FALSE;
  559. }
  560. // check bitmap size
  561. CBitmapHandle bmp = hBitmap;
  562. SIZE size = {};
  563. bmp.GetSize(size);
  564. if((size.cx != m_szBitmap.cx) || (size.cy != m_szBitmap.cy))
  565. {
  566. ATLASSERT(FALSE); // must match size!
  567. return FALSE;
  568. }
  569. // add bitmap
  570. int nRet = ::ImageList_AddMasked(m_hImageList, hBitmap, m_clrMask);
  571. if(nRet == -1)
  572. return FALSE;
  573. BOOL bRet = m_arrCommand.Add((WORD)nCommandID);
  574. ATLASSERT(::ImageList_GetImageCount(m_hImageList) == m_arrCommand.GetSize());
  575. #if _WTL_CMDBAR_VISTA_MENUS
  576. if(RunTimeHelper::IsVista())
  577. {
  578. pT->_AddVistaBitmapFromImageList(m_arrCommand.GetSize() - 1);
  579. ATLASSERT(m_arrVistaBitmap.GetSize() == m_arrCommand.GetSize());
  580. }
  581. #endif // _WTL_CMDBAR_VISTA_MENUS
  582. return bRet;
  583. }
  584. BOOL AddIcon(ATL::_U_STRINGorID icon, UINT nCommandID)
  585. {
  586. ATLASSERT(::IsWindow(this->m_hWnd));
  587. HICON hIcon = ::LoadIcon(ModuleHelper::GetResourceInstance(), icon.m_lpstr);
  588. if(hIcon == NULL)
  589. return FALSE;
  590. return AddIcon(hIcon, nCommandID);
  591. }
  592. BOOL AddIcon(HICON hIcon, UINT nCommandID)
  593. {
  594. ATLASSERT(::IsWindow(this->m_hWnd));
  595. T* pT = static_cast<T*>(this);
  596. // create image list if it doesn't exist
  597. if(m_hImageList == NULL)
  598. {
  599. if(!pT->CreateInternalImageList(1))
  600. return FALSE;
  601. }
  602. int nRet = ::ImageList_AddIcon(m_hImageList, hIcon);
  603. if(nRet == -1)
  604. return FALSE;
  605. BOOL bRet = m_arrCommand.Add((WORD)nCommandID);
  606. ATLASSERT(::ImageList_GetImageCount(m_hImageList) == m_arrCommand.GetSize());
  607. #if _WTL_CMDBAR_VISTA_MENUS
  608. if(RunTimeHelper::IsVista())
  609. {
  610. pT->_AddVistaBitmapFromImageList(m_arrCommand.GetSize() - 1);
  611. ATLASSERT(m_arrVistaBitmap.GetSize() == m_arrCommand.GetSize());
  612. }
  613. #endif // _WTL_CMDBAR_VISTA_MENUS
  614. return bRet;
  615. }
  616. BOOL ReplaceBitmap(ATL::_U_STRINGorID bitmap, int nCommandID)
  617. {
  618. ATLASSERT(::IsWindow(this->m_hWnd));
  619. CBitmap bmp;
  620. bmp.LoadBitmap(bitmap.m_lpstr);
  621. if(bmp.m_hBitmap == NULL)
  622. return FALSE;
  623. return ReplaceBitmap(bmp, nCommandID);
  624. }
  625. BOOL ReplaceBitmap(HBITMAP hBitmap, UINT nCommandID)
  626. {
  627. ATLASSERT(::IsWindow(this->m_hWnd));
  628. BOOL bRet = FALSE;
  629. for(int i = 0; i < m_arrCommand.GetSize(); i++)
  630. {
  631. if(m_arrCommand[i] == nCommandID)
  632. {
  633. bRet = ::ImageList_Remove(m_hImageList, i);
  634. if(bRet)
  635. {
  636. m_arrCommand.RemoveAt(i);
  637. #if _WTL_CMDBAR_VISTA_MENUS
  638. if(RunTimeHelper::IsVista())
  639. {
  640. if(m_arrVistaBitmap[i] != NULL)
  641. ::DeleteObject(m_arrVistaBitmap[i]);
  642. m_arrVistaBitmap.RemoveAt(i);
  643. }
  644. #endif // _WTL_CMDBAR_VISTA_MENUS
  645. }
  646. break;
  647. }
  648. }
  649. if(bRet)
  650. bRet = AddBitmap(hBitmap, nCommandID);
  651. return bRet;
  652. }
  653. BOOL ReplaceIcon(ATL::_U_STRINGorID icon, UINT nCommandID)
  654. {
  655. ATLASSERT(::IsWindow(this->m_hWnd));
  656. HICON hIcon = ::LoadIcon(ModuleHelper::GetResourceInstance(), icon.m_lpstr);
  657. if(hIcon == NULL)
  658. return FALSE;
  659. return ReplaceIcon(hIcon, nCommandID);
  660. }
  661. BOOL ReplaceIcon(HICON hIcon, UINT nCommandID)
  662. {
  663. ATLASSERT(::IsWindow(this->m_hWnd));
  664. BOOL bRet = FALSE;
  665. for(int i = 0; i < m_arrCommand.GetSize(); i++)
  666. {
  667. if(m_arrCommand[i] == nCommandID)
  668. {
  669. bRet = (::ImageList_ReplaceIcon(m_hImageList, i, hIcon) != -1);
  670. #if _WTL_CMDBAR_VISTA_MENUS
  671. if(RunTimeHelper::IsVista() && (bRet != FALSE))
  672. {
  673. T* pT = static_cast<T*>(this);
  674. pT->_ReplaceVistaBitmapFromImageList(i);
  675. }
  676. #endif // _WTL_CMDBAR_VISTA_MENUS
  677. break;
  678. }
  679. }
  680. return bRet;
  681. }
  682. BOOL RemoveImage(int nCommandID)
  683. {
  684. ATLASSERT(::IsWindow(this->m_hWnd));
  685. BOOL bRet = FALSE;
  686. for(int i = 0; i < m_arrCommand.GetSize(); i++)
  687. {
  688. if(m_arrCommand[i] == nCommandID)
  689. {
  690. bRet = ::ImageList_Remove(m_hImageList, i);
  691. if(bRet)
  692. {
  693. m_arrCommand.RemoveAt(i);
  694. #if _WTL_CMDBAR_VISTA_MENUS
  695. if(RunTimeHelper::IsVista())
  696. {
  697. if(m_arrVistaBitmap[i] != NULL)
  698. ::DeleteObject(m_arrVistaBitmap[i]);
  699. m_arrVistaBitmap.RemoveAt(i);
  700. }
  701. #endif // _WTL_CMDBAR_VISTA_MENUS
  702. }
  703. break;
  704. }
  705. }
  706. return bRet;
  707. }
  708. BOOL RemoveAllImages()
  709. {
  710. ATLASSERT(::IsWindow(this->m_hWnd));
  711. ATLTRACE2(atlTraceUI, 0, _T("CmdBar - Removing all images\n"));
  712. BOOL bRet = ::ImageList_RemoveAll(m_hImageList);
  713. if(bRet)
  714. {
  715. m_arrCommand.RemoveAll();
  716. #if _WTL_CMDBAR_VISTA_MENUS
  717. for(int i = 0; i < m_arrVistaBitmap.GetSize(); i++)
  718. {
  719. if(m_arrVistaBitmap[i] != NULL)
  720. ::DeleteObject(m_arrVistaBitmap[i]);
  721. }
  722. m_arrVistaBitmap.RemoveAll();
  723. #endif // _WTL_CMDBAR_VISTA_MENUS
  724. }
  725. return bRet;
  726. }
  727. BOOL TrackPopupMenu(HMENU hMenu, UINT uFlags, int x, int y, LPTPMPARAMS lpParams = NULL)
  728. {
  729. ATLASSERT(::IsWindow(this->m_hWnd));
  730. ATLASSERT(::IsMenu(hMenu));
  731. if(!::IsMenu(hMenu))
  732. return FALSE;
  733. m_bContextMenu = true;
  734. if(m_bUseKeyboardCues)
  735. m_bShowKeyboardCues = m_bKeyboardInput;
  736. T* pT = static_cast<T*>(this);
  737. return pT->DoTrackPopupMenu(hMenu, uFlags, x, y, lpParams);
  738. }
  739. BOOL SetMDIClient(HWND /*hWndMDIClient*/)
  740. {
  741. // Use CMDICommandBarCtrl for MDI support
  742. ATLASSERT(FALSE);
  743. return FALSE;
  744. }
  745. // Message map and handlers
  746. BEGIN_MSG_MAP(CCommandBarCtrlImpl)
  747. MESSAGE_HANDLER(WM_CREATE, OnCreate)
  748. MESSAGE_HANDLER(WM_DESTROY, OnDestroy)
  749. MESSAGE_HANDLER(WM_ERASEBKGND, OnEraseBackground)
  750. MESSAGE_HANDLER(WM_INITMENU, OnInitMenu)
  751. MESSAGE_HANDLER(WM_INITMENUPOPUP, OnInitMenuPopup)
  752. MESSAGE_HANDLER(WM_MENUSELECT, OnMenuSelect)
  753. MESSAGE_HANDLER(GetAutoPopupMessage(), OnInternalAutoPopup)
  754. MESSAGE_HANDLER(GetGetBarMessage(), OnInternalGetBar)
  755. MESSAGE_HANDLER(WM_SETTINGCHANGE, OnSettingChange)
  756. MESSAGE_HANDLER(WM_MENUCHAR, OnMenuChar)
  757. MESSAGE_HANDLER(WM_KILLFOCUS, OnKillFocus)
  758. MESSAGE_HANDLER(WM_KEYDOWN, OnKeyDown)
  759. MESSAGE_HANDLER(WM_KEYUP, OnKeyUp)
  760. MESSAGE_HANDLER(WM_CHAR, OnChar)
  761. MESSAGE_HANDLER(WM_SYSKEYDOWN, OnSysKeyDown)
  762. MESSAGE_HANDLER(WM_SYSKEYUP, OnSysKeyUp)
  763. MESSAGE_HANDLER(WM_SYSCHAR, OnSysChar)
  764. // public API handlers - these stay to support chevrons in atlframe.h
  765. MESSAGE_HANDLER(CBRM_GETMENU, OnAPIGetMenu)
  766. MESSAGE_HANDLER(CBRM_TRACKPOPUPMENU, OnAPITrackPopupMenu)
  767. MESSAGE_HANDLER(CBRM_GETCMDBAR, OnAPIGetCmdBar)
  768. MESSAGE_HANDLER(WM_DRAWITEM, OnDrawItem)
  769. MESSAGE_HANDLER(WM_MEASUREITEM, OnMeasureItem)
  770. MESSAGE_HANDLER(WM_FORWARDMSG, OnForwardMsg)
  771. ALT_MSG_MAP(1) // Parent window messages
  772. NOTIFY_CODE_HANDLER(TBN_HOTITEMCHANGE, OnParentHotItemChange)
  773. NOTIFY_CODE_HANDLER(TBN_DROPDOWN, OnParentDropDown)
  774. MESSAGE_HANDLER(WM_INITMENUPOPUP, OnParentInitMenuPopup)
  775. MESSAGE_HANDLER(GetGetBarMessage(), OnParentInternalGetBar)
  776. MESSAGE_HANDLER(WM_SYSCOMMAND, OnParentSysCommand)
  777. MESSAGE_HANDLER(CBRM_GETMENU, OnParentAPIGetMenu)
  778. MESSAGE_HANDLER(WM_MENUCHAR, OnParentMenuChar)
  779. MESSAGE_HANDLER(CBRM_TRACKPOPUPMENU, OnParentAPITrackPopupMenu)
  780. MESSAGE_HANDLER(CBRM_GETCMDBAR, OnParentAPIGetCmdBar)
  781. MESSAGE_HANDLER(WM_SETTINGCHANGE, OnParentSettingChange)
  782. MESSAGE_HANDLER(WM_DRAWITEM, OnParentDrawItem)
  783. MESSAGE_HANDLER(WM_MEASUREITEM, OnParentMeasureItem)
  784. MESSAGE_HANDLER(WM_ACTIVATE, OnParentActivate)
  785. NOTIFY_CODE_HANDLER(NM_CUSTOMDRAW, OnParentCustomDraw)
  786. ALT_MSG_MAP(2) // MDI client window messages
  787. // Use CMDICommandBarCtrl for MDI support
  788. ALT_MSG_MAP(3) // Message hook messages
  789. MESSAGE_HANDLER(WM_MOUSEMOVE, OnHookMouseMove)
  790. MESSAGE_HANDLER(WM_SYSKEYDOWN, OnHookSysKeyDown)
  791. MESSAGE_HANDLER(WM_SYSKEYUP, OnHookSysKeyUp)
  792. MESSAGE_HANDLER(WM_SYSCHAR, OnHookSysChar)
  793. MESSAGE_HANDLER(WM_KEYDOWN, OnHookKeyDown)
  794. MESSAGE_HANDLER(WM_NEXTMENU, OnHookNextMenu)
  795. MESSAGE_HANDLER(WM_CHAR, OnHookChar)
  796. END_MSG_MAP()
  797. LRESULT OnForwardMsg(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM lParam, BOOL& /*bHandled*/)
  798. {
  799. LPMSG pMsg = (LPMSG)lParam;
  800. if((pMsg->message >= WM_MOUSEFIRST) && (pMsg->message <= WM_MOUSELAST))
  801. m_bKeyboardInput = false;
  802. else if((pMsg->message >= WM_KEYFIRST) && (pMsg->message <= WM_KEYLAST))
  803. m_bKeyboardInput = true;
  804. LRESULT lRet = 0;
  805. ProcessWindowMessage(pMsg->hwnd, pMsg->message, pMsg->wParam, pMsg->lParam, lRet, 3);
  806. return lRet;
  807. }
  808. LRESULT OnCreate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& /*bHandled*/)
  809. {
  810. // Let the toolbar initialize itself
  811. LRESULT lRet = this->DefWindowProc(uMsg, wParam, lParam);
  812. // get and use system settings
  813. T* pT = static_cast<T*>(this);
  814. pT->GetSystemSettings();
  815. // Parent init
  816. ATL::CWindow wndParent = this->GetParent();
  817. ATL::CWindow wndTopLevelParent = wndParent.GetTopLevelParent();
  818. m_wndParent.SubclassWindow(wndTopLevelParent);
  819. // Toolbar Init
  820. this->SetButtonStructSize();
  821. this->SetImageList(NULL);
  822. // Create message hook if needed
  823. CWindowCreateCriticalSectionLock lock;
  824. if(FAILED(lock.Lock()))
  825. {
  826. ATLTRACE2(atlTraceUI, 0, _T("ERROR : Unable to lock critical section in CCommandBarCtrlImpl::OnCreate.\n"));
  827. ATLASSERT(FALSE);
  828. return -1;
  829. }
  830. if(this->s_pmapMsgHook == NULL)
  831. {
  832. ATLTRY(this->s_pmapMsgHook = new CCommandBarCtrlBase::CMsgHookMap);
  833. ATLASSERT(this->s_pmapMsgHook != NULL);
  834. }
  835. if(this->s_pmapMsgHook != NULL)
  836. {
  837. DWORD dwThreadID = ::GetCurrentThreadId();
  838. CCommandBarCtrlBase::_MsgHookData* pData = this->s_pmapMsgHook->Lookup(dwThreadID);
  839. if(pData == NULL)
  840. {
  841. ATLTRY(pData = new CCommandBarCtrlBase::_MsgHookData);
  842. ATLASSERT(pData != NULL);
  843. HHOOK hMsgHook = ::SetWindowsHookEx(WH_GETMESSAGE, MessageHookProc, ModuleHelper::GetModuleInstance(), dwThreadID);
  844. ATLASSERT(hMsgHook != NULL);
  845. if((pData != NULL) && (hMsgHook != NULL))
  846. {
  847. pData->hMsgHook = hMsgHook;
  848. pData->dwUsage = 1;
  849. BOOL bRet = this->s_pmapMsgHook->Add(dwThreadID, pData);
  850. (void)bRet; // avoid level 4 warning
  851. ATLASSERT(bRet);
  852. }
  853. }
  854. else
  855. {
  856. (pData->dwUsage)++;
  857. }
  858. }
  859. lock.Unlock();
  860. // Get layout
  861. m_bLayoutRTL = ((this->GetExStyle() & WS_EX_LAYOUTRTL) != 0);
  862. return lRet;
  863. }
  864. LRESULT OnDestroy(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& /*bHandled*/)
  865. {
  866. LRESULT lRet = this->DefWindowProc(uMsg, wParam, lParam);
  867. #if _WTL_CMDBAR_VISTA_MENUS
  868. if(m_bVistaMenus && (m_hMenu != NULL))
  869. {
  870. T* pT = static_cast<T*>(this);
  871. pT->_RemoveVistaBitmapsFromMenu();
  872. }
  873. for(int i = 0; i < m_arrVistaBitmap.GetSize(); i++)
  874. {
  875. if(m_arrVistaBitmap[i] != NULL)
  876. ::DeleteObject(m_arrVistaBitmap[i]);
  877. }
  878. #endif // _WTL_CMDBAR_VISTA_MENUS
  879. if(m_bAttachedMenu) // nothing to do in this mode
  880. return lRet;
  881. CWindowCreateCriticalSectionLock lock;
  882. if(FAILED(lock.Lock()))
  883. {
  884. ATLTRACE2(atlTraceUI, 0, _T("ERROR : Unable to lock critical section in CCommandBarCtrlImpl::OnDestroy.\n"));
  885. ATLASSERT(FALSE);
  886. return lRet;
  887. }
  888. if(this->s_pmapMsgHook != NULL)
  889. {
  890. DWORD dwThreadID = ::GetCurrentThreadId();
  891. CCommandBarCtrlBase::_MsgHookData* pData = this->s_pmapMsgHook->Lookup(dwThreadID);
  892. if(pData != NULL)
  893. {
  894. (pData->dwUsage)--;
  895. if(pData->dwUsage == 0)
  896. {
  897. BOOL bRet = ::UnhookWindowsHookEx(pData->hMsgHook);
  898. ATLASSERT(bRet);
  899. bRet = this->s_pmapMsgHook->Remove(dwThreadID);
  900. ATLASSERT(bRet);
  901. if(bRet)
  902. delete pData;
  903. }
  904. if(this->s_pmapMsgHook->GetSize() == 0)
  905. {
  906. delete this->s_pmapMsgHook;
  907. this->s_pmapMsgHook = NULL;
  908. }
  909. }
  910. }
  911. lock.Unlock();
  912. return lRet;
  913. }
  914. LRESULT OnKeyDown(UINT /*uMsg*/, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  915. {
  916. #ifdef _CMDBAR_EXTRA_TRACE
  917. ATLTRACE2(atlTraceUI, 0, _T("CmdBar - OnKeyDown\n"));
  918. #endif
  919. if(m_bAttachedMenu) // nothing to do in this mode
  920. {
  921. bHandled = FALSE;
  922. return 1;
  923. }
  924. bHandled = FALSE;
  925. // Simulate Alt+Space for the parent
  926. if(wParam == VK_SPACE)
  927. {
  928. m_wndParent.PostMessage(WM_SYSKEYDOWN, wParam, lParam | (1 << 29));
  929. bHandled = TRUE;
  930. }
  931. else if((wParam == VK_LEFT) || (wParam == VK_RIGHT))
  932. {
  933. WPARAM wpNext = m_bLayoutRTL ? VK_LEFT : VK_RIGHT;
  934. if(!m_bMenuActive)
  935. {
  936. T* pT = static_cast<T*>(this);
  937. int nBtn = this->GetHotItem();
  938. int nNextBtn = (wParam == wpNext) ? pT->GetNextMenuItem(nBtn) : pT->GetPreviousMenuItem(nBtn);
  939. if(nNextBtn == -2)
  940. {
  941. this->SetHotItem(-1);
  942. if(pT->DisplayChevronMenu())
  943. bHandled = TRUE;
  944. }
  945. }
  946. }
  947. return 0;
  948. }
  949. LRESULT OnKeyUp(UINT /*uMsg*/, WPARAM wParam, LPARAM /*lParam*/, BOOL& bHandled)
  950. {
  951. #ifdef _CMDBAR_EXTRA_TRACE
  952. ATLTRACE2(atlTraceUI, 0, _T("CmdBar - OnKeyUp\n"));
  953. #endif
  954. if(m_bAttachedMenu) // nothing to do in this mode
  955. {
  956. bHandled = FALSE;
  957. return 1;
  958. }
  959. if(wParam != VK_SPACE)
  960. bHandled = FALSE;
  961. return 0;
  962. }
  963. LRESULT OnChar(UINT /*uMsg*/, WPARAM wParam, LPARAM /*lParam*/, BOOL& bHandled)
  964. {
  965. #ifdef _CMDBAR_EXTRA_TRACE
  966. ATLTRACE2(atlTraceUI, 0, _T("CmdBar - OnChar\n"));
  967. #endif
  968. if(m_bAttachedMenu) // nothing to do in this mode
  969. {
  970. bHandled = FALSE;
  971. return 1;
  972. }
  973. if(wParam != VK_SPACE)
  974. bHandled = FALSE;
  975. else
  976. return 0;
  977. // Security
  978. if(!m_wndParent.IsWindowEnabled() || (::GetFocus() != this->m_hWnd))
  979. return 0;
  980. // Handle mnemonic press when we have focus
  981. int nBtn = 0;
  982. if((wParam != VK_RETURN) && !this->MapAccelerator((TCHAR)LOWORD(wParam), nBtn))
  983. {
  984. if((TCHAR)LOWORD(wParam) != _chChevronShortcut)
  985. ::MessageBeep(0);
  986. }
  987. else
  988. {
  989. RECT rcClient = {};
  990. this->GetClientRect(&rcClient);
  991. RECT rcBtn = {};
  992. this->GetItemRect(nBtn, &rcBtn);
  993. TBBUTTON tbb = {};
  994. this->GetButton(nBtn, &tbb);
  995. if(((tbb.fsState & TBSTATE_ENABLED) != 0) && ((tbb.fsState & TBSTATE_HIDDEN) == 0) && (rcBtn.right <= rcClient.right))
  996. {
  997. this->PostMessage(WM_KEYDOWN, VK_DOWN, 0L);
  998. if(wParam != VK_RETURN)
  999. this->SetHotItem(nBtn);
  1000. }
  1001. else
  1002. {
  1003. ::MessageBeep(0);
  1004. bHandled = TRUE;
  1005. }
  1006. }
  1007. return 0;
  1008. }
  1009. LRESULT OnSysKeyDown(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& bHandled)
  1010. {
  1011. #ifdef _CMDBAR_EXTRA_TRACE
  1012. ATLTRACE2(atlTraceUI, 0, _T("CmdBar - OnSysKeyDown\n"));
  1013. #endif
  1014. bHandled = FALSE;
  1015. return 0;
  1016. }
  1017. LRESULT OnSysKeyUp(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& bHandled)
  1018. {
  1019. #ifdef _CMDBAR_EXTRA_TRACE
  1020. ATLTRACE2(atlTraceUI, 0, _T("CmdBar - OnSysKeyUp\n"));
  1021. #endif
  1022. bHandled = FALSE;
  1023. return 0;
  1024. }
  1025. LRESULT OnSysChar(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& bHandled)
  1026. {
  1027. #ifdef _CMDBAR_EXTRA_TRACE
  1028. ATLTRACE2(atlTraceUI, 0, _T("CmdBar - OnSysChar\n"));
  1029. #endif
  1030. bHandled = FALSE;
  1031. return 0;
  1032. }
  1033. LRESULT OnEraseBackground(UINT /*uMsg*/, WPARAM wParam, LPARAM /*lParam*/, BOOL& bHandled)
  1034. {
  1035. if(m_bAttachedMenu || (m_dwExtendedStyle & CBR_EX_TRANSPARENT))
  1036. {
  1037. bHandled = FALSE;
  1038. return 0;
  1039. }
  1040. CDCHandle dc = (HDC)wParam;
  1041. RECT rect = {};
  1042. this->GetClientRect(&rect);
  1043. dc.FillRect(&rect, COLOR_MENU);
  1044. return 1; // don't do the default erase
  1045. }
  1046. LRESULT OnInitMenu(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& bHandled)
  1047. {
  1048. int nIndex = this->GetHotItem();
  1049. this->SendMessage(WM_MENUSELECT, MAKEWPARAM(nIndex, MF_POPUP|MF_HILITE), (LPARAM)m_hMenu);
  1050. bHandled = FALSE;
  1051. return 1;
  1052. }
  1053. LRESULT OnInitMenuPopup(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  1054. {
  1055. if((BOOL)HIWORD(lParam)) // System menu, do nothing
  1056. {
  1057. bHandled = FALSE;
  1058. return 1;
  1059. }
  1060. if(!(m_bAttachedMenu || m_bMenuActive)) // Not attached or ours, do nothing
  1061. {
  1062. bHandled = FALSE;
  1063. return 1;
  1064. }
  1065. #ifdef _CMDBAR_EXTRA_TRACE
  1066. ATLTRACE2(atlTraceUI, 0, _T("CmdBar - OnInitMenuPopup\n"));
  1067. #endif
  1068. // forward to the parent or subclassed window, so it can handle update UI
  1069. LRESULT lRet = 0;
  1070. if(m_bAttachedMenu)
  1071. lRet = this->DefWindowProc(uMsg, wParam, (lParam || m_bContextMenu) ? lParam : this->GetHotItem());
  1072. else
  1073. lRet = m_wndParent.DefWindowProc(uMsg, wParam, (lParam || m_bContextMenu) ? lParam : this->GetHotItem());
  1074. #if _WTL_CMDBAR_VISTA_MENUS
  1075. // If Vista menus are active, just set bitmaps and return
  1076. if(m_bVistaMenus)
  1077. {
  1078. CMenuHandle menu = (HMENU)wParam;
  1079. ATLASSERT(menu.m_hMenu != NULL);
  1080. for(int i = 0; i < menu.GetMenuItemCount(); i++)
  1081. {
  1082. WORD nID = (WORD)menu.GetMenuItemID(i);
  1083. int nIndex = m_arrCommand.Find(nID);
  1084. CMenuItemInfo mii;
  1085. mii.fMask = MIIM_BITMAP;
  1086. mii.hbmpItem = (m_bImagesVisible && (nIndex != -1)) ? m_arrVistaBitmap[nIndex] : NULL;
  1087. menu.SetMenuItemInfo(i, TRUE, &mii);
  1088. }
  1089. return lRet;
  1090. }
  1091. #endif // _WTL_CMDBAR_VISTA_MENUS
  1092. // Convert menu items to ownerdraw, add our data
  1093. if(m_bImagesVisible)
  1094. {
  1095. CMenuHandle menuPopup = (HMENU)wParam;
  1096. ATLASSERT(menuPopup.m_hMenu != NULL);
  1097. T* pT = static_cast<T*>(this);
  1098. (void)pT; // avoid level 4 warning
  1099. TCHAR szString[pT->_nMaxMenuItemTextLength] = {};
  1100. BOOL bRet = FALSE;
  1101. for(int i = 0; i < menuPopup.GetMenuItemCount(); i++)
  1102. {
  1103. CMenuItemInfo mii;
  1104. mii.cch = pT->_nMaxMenuItemTextLength;
  1105. mii.fMask = MIIM_CHECKMARKS | MIIM_DATA | MIIM_ID | MIIM_STATE | MIIM_SUBMENU | MIIM_TYPE;
  1106. mii.dwTypeData = szString;
  1107. bRet = menuPopup.GetMenuItemInfo(i, TRUE, &mii);
  1108. ATLASSERT(bRet);
  1109. if(!(mii.fType & MFT_OWNERDRAW)) // Not already an ownerdraw item
  1110. {
  1111. mii.fMask = MIIM_DATA | MIIM_TYPE | MIIM_STATE;
  1112. _MenuItemData* pMI = NULL;
  1113. ATLTRY(pMI = new _MenuItemData);
  1114. ATLASSERT(pMI != NULL);
  1115. if(pMI != NULL)
  1116. {
  1117. pMI->fType = mii.fType;
  1118. pMI->fState = mii.fState;
  1119. mii.fType |= MFT_OWNERDRAW;
  1120. pMI->iButton = -1;
  1121. for(int j = 0; j < m_arrCommand.GetSize(); j++)
  1122. {
  1123. if(m_arrCommand[j] == mii.wID)
  1124. {
  1125. pMI->iButton = j;
  1126. break;
  1127. }
  1128. }
  1129. int cchLen = lstrlen(szString) + 1;
  1130. pMI->lpstrText = NULL;
  1131. ATLTRY(pMI->lpstrText = new TCHAR[cchLen]);
  1132. ATLASSERT(pMI->lpstrText != NULL);
  1133. if(pMI->lpstrText != NULL)
  1134. ATL::Checked::tcscpy_s(pMI->lpstrText, cchLen, szString);
  1135. mii.dwItemData = (ULONG_PTR)pMI;
  1136. bRet = menuPopup.SetMenuItemInfo(i, TRUE, &mii);
  1137. ATLASSERT(bRet);
  1138. }
  1139. }
  1140. }
  1141. // Add it to the list
  1142. this->m_stackMenuHandle.Push(menuPopup.m_hMenu);
  1143. }
  1144. return lRet;
  1145. }
  1146. LRESULT OnMenuSelect(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  1147. {
  1148. if(!m_bAttachedMenu) // Not attached, do nothing, forward to parent
  1149. {
  1150. m_bPopupItem = (lParam != NULL) && ((HMENU)lParam != m_hMenu) && (HIWORD(wParam) & MF_POPUP);
  1151. if(m_wndParent.IsWindow())
  1152. m_wndParent.SendMessage(uMsg, wParam, lParam);
  1153. bHandled = FALSE;
  1154. return 1;
  1155. }
  1156. // Check if a menu is closing, do a cleanup
  1157. if((HIWORD(wParam) == 0xFFFF) && (lParam == NULL)) // Menu closing
  1158. {
  1159. #ifdef _CMDBAR_EXTRA_TRACE
  1160. ATLTRACE2(atlTraceUI, 0, _T("CmdBar - OnMenuSelect - CLOSING!!!!\n"));
  1161. #endif
  1162. ATLASSERT(this->m_stackMenuWnd.GetSize() == 0);
  1163. // Restore the menu items to the previous state for all menus that were converted
  1164. if(m_bImagesVisible)
  1165. {
  1166. HMENU hMenu = NULL;
  1167. while((hMenu = this->m_stackMenuHandle.Pop()) != NULL)
  1168. {
  1169. CMenuHandle menuPopup = hMenu;
  1170. ATLASSERT(menuPopup.m_hMenu != NULL);
  1171. // Restore state and delete menu item data
  1172. BOOL bRet = FALSE;
  1173. for(int i = 0; i < menuPopup.GetMenuItemCount(); i++)
  1174. {
  1175. CMenuItemInfo mii;
  1176. mii.fMask = MIIM_DATA | MIIM_TYPE;
  1177. bRet = menuPopup.GetMenuItemInfo(i, TRUE, &mii);
  1178. ATLASSERT(bRet);
  1179. _MenuItemData* pMI = (_MenuItemData*)mii.dwItemData;
  1180. if(_IsValidMem(pMI) && pMI->IsCmdBarMenuItem())
  1181. {
  1182. mii.fMask = MIIM_DATA | MIIM_TYPE | MIIM_STATE;
  1183. mii.fType = pMI->fType;
  1184. mii.dwTypeData = pMI->lpstrText;
  1185. mii.cch = lstrlen(pMI->lpstrText);
  1186. mii.dwItemData = NULL;
  1187. bRet = menuPopup.SetMenuItemInfo(i, TRUE, &mii);
  1188. ATLASSERT(bRet);
  1189. delete [] pMI->lpstrText;
  1190. pMI->dwMagic = 0x6666;
  1191. delete pMI;
  1192. }
  1193. }
  1194. }
  1195. }
  1196. }
  1197. bHandled = FALSE;
  1198. return 1;
  1199. }
  1200. LRESULT OnInternalAutoPopup(UINT /*uMsg*/, WPARAM wParam, LPARAM /*lParam*/, BOOL& /*bHandled*/)
  1201. {
  1202. int nIndex = (int)wParam;
  1203. T* pT = static_cast<T*>(this);
  1204. pT->DoPopupMenu(nIndex, false);
  1205. return 0;
  1206. }
  1207. LRESULT OnInternalGetBar(UINT /*uMsg*/, WPARAM wParam, LPARAM /*lParam*/, BOOL& /*bHandled*/)
  1208. {
  1209. // Let's make sure we're not embedded in another process
  1210. if((LPVOID)wParam != NULL)
  1211. *((DWORD*)wParam) = GetCurrentProcessId();
  1212. if(this->IsWindowVisible())
  1213. return (LRESULT)static_cast<CCommandBarCtrlBase*>(this);
  1214. else
  1215. return NULL;
  1216. }
  1217. LRESULT OnSettingChange(UINT /*uMsg*/, WPARAM wParam, LPARAM /*lParam*/, BOOL& /*bHandled*/)
  1218. {
  1219. if((wParam == SPI_SETNONCLIENTMETRICS) || (wParam == SPI_SETKEYBOARDCUES) || (wParam == SPI_SETFLATMENU))
  1220. {
  1221. T* pT = static_cast<T*>(this);
  1222. pT->GetSystemSettings();
  1223. }
  1224. return 0;
  1225. }
  1226. LRESULT OnWindowPosChanging(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& /*bHandled*/)
  1227. {
  1228. LRESULT lRet = this->DefWindowProc(uMsg, wParam, lParam);
  1229. LPWINDOWPOS lpWP = (LPWINDOWPOS)lParam;
  1230. int cyMin = ::GetSystemMetrics(SM_CYMENU);
  1231. if(lpWP->cy < cyMin)
  1232. lpWP->cy = cyMin;
  1233. return lRet;
  1234. }
  1235. LRESULT OnMenuChar(UINT /*uMsg*/, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  1236. {
  1237. #ifdef _CMDBAR_EXTRA_TRACE
  1238. ATLTRACE2(atlTraceUI, 0, _T("CmdBar - OnMenuChar\n"));
  1239. #endif
  1240. bHandled = TRUE;
  1241. T* pT = static_cast<T*>(this);
  1242. LRESULT lRet;
  1243. if(m_bMenuActive && (LOWORD(wParam) != 0x0D))
  1244. lRet = 0;
  1245. else
  1246. lRet = MAKELRESULT(1, 1);
  1247. if(m_bMenuActive && (HIWORD(wParam) == MF_POPUP))
  1248. {
  1249. // Convert character to lower/uppercase and possibly Unicode, using current keyboard layout
  1250. TCHAR ch = (TCHAR)LOWORD(wParam);
  1251. CMenuHandle menu = (HMENU)lParam;
  1252. int nCount = ::GetMenuItemCount(menu);
  1253. int nRetCode = MNC_EXECUTE;
  1254. BOOL bRet = FALSE;
  1255. TCHAR szString[pT->_nMaxMenuItemTextLength] = {};
  1256. WORD wMnem = 0;
  1257. bool bFound = false;
  1258. for(int i = 0; i < nCount; i++)
  1259. {
  1260. CMenuItemInfo mii;
  1261. mii.cch = pT->_nMaxMenuItemTextLength;
  1262. mii.fMask = MIIM_CHECKMARKS | MIIM_DATA | MIIM_ID | MIIM_STATE | MIIM_SUBMENU | MIIM_TYPE;
  1263. mii.dwTypeData = szString;
  1264. bRet = menu.GetMenuItemInfo(i, TRUE, &mii);
  1265. if(!bRet || (mii.fType & MFT_SEPARATOR))
  1266. continue;
  1267. _MenuItemData* pmd = (_MenuItemData*)mii.dwItemData;
  1268. if(_IsValidMem(pmd) && pmd->IsCmdBarMenuItem())
  1269. {
  1270. LPTSTR p = pmd->lpstrText;
  1271. if(p != NULL)
  1272. {
  1273. while(*p && (*p != _T('&')))
  1274. p = ::CharNext(p);
  1275. if((p != NULL) && *p)
  1276. {
  1277. DWORD dwP = MAKELONG(*(++p), 0);
  1278. DWORD dwC = MAKELONG(ch, 0);
  1279. if(::CharLower((LPTSTR)ULongToPtr(dwP)) == ::CharLower((LPTSTR)ULongToPtr(dwC)))
  1280. {
  1281. if(!bFound)
  1282. {
  1283. wMnem = (WORD)i;
  1284. bFound = true;
  1285. }
  1286. else
  1287. {
  1288. nRetCode = MNC_SELECT;
  1289. break;
  1290. }
  1291. }
  1292. }
  1293. }
  1294. }
  1295. }
  1296. if(bFound)
  1297. {
  1298. if(nRetCode == MNC_EXECUTE)
  1299. {
  1300. this->PostMessage(TB_SETHOTITEM, (WPARAM)-1, 0L);
  1301. pT->GiveFocusBack();
  1302. }
  1303. bHandled = TRUE;
  1304. lRet = MAKELRESULT(wMnem, nRetCode);
  1305. }
  1306. }
  1307. else if(!m_bMenuActive)
  1308. {
  1309. int nBtn = 0;
  1310. if(!this->MapAccelerator((TCHAR)LOWORD(wParam), nBtn))
  1311. {
  1312. bHandled = FALSE;
  1313. this->PostMessage(TB_SETHOTITEM, (WPARAM)-1, 0L);
  1314. pT->GiveFocusBack();
  1315. // check if we should display chevron menu
  1316. if((TCHAR)LOWORD(wParam) == pT->_chChevronShortcut)
  1317. {
  1318. if(pT->DisplayChevronMenu())
  1319. bHandled = TRUE;
  1320. }
  1321. }
  1322. else if(m_wndParent.IsWindowEnabled())
  1323. {
  1324. RECT rcClient = {};
  1325. this->GetClientRect(&rcClient);
  1326. RECT rcBtn = {};
  1327. this->GetItemRect(nBtn, &rcBtn);
  1328. TBBUTTON tbb = {};
  1329. this->GetButton(nBtn, &tbb);
  1330. if(((tbb.fsState & TBSTATE_ENABLED) != 0) && ((tbb.fsState & TBSTATE_HIDDEN) == 0) && (rcBtn.right <= rcClient.right))
  1331. {
  1332. if(m_bUseKeyboardCues && !m_bShowKeyboardCues)
  1333. {
  1334. m_bAllowKeyboardCues = true;
  1335. ShowKeyboardCues(true);
  1336. }
  1337. pT->TakeFocus();
  1338. this->PostMessage(WM_KEYDOWN, VK_DOWN, 0L);
  1339. this->SetHotItem(nBtn);
  1340. }
  1341. else
  1342. {
  1343. ::MessageBeep(0);
  1344. }
  1345. }
  1346. }
  1347. return lRet;
  1348. }
  1349. LRESULT OnKillFocus(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& bHandled)
  1350. {
  1351. if(m_bUseKeyboardCues && m_bShowKeyboardCues)
  1352. ShowKeyboardCues(false);
  1353. bHandled = FALSE;
  1354. return 1;
  1355. }
  1356. LRESULT OnDrawItem(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM lParam, BOOL& bHandled)
  1357. {
  1358. LPDRAWITEMSTRUCT lpDrawItemStruct = (LPDRAWITEMSTRUCT)lParam;
  1359. _MenuItemData* pmd = (_MenuItemData*)lpDrawItemStruct->itemData;
  1360. if((lpDrawItemStruct->CtlType == ODT_MENU) && _IsValidMem(pmd) && pmd->IsCmdBarMenuItem())
  1361. {
  1362. T* pT = static_cast<T*>(this);
  1363. pT->DrawItem(lpDrawItemStruct);
  1364. }
  1365. else
  1366. {
  1367. bHandled = FALSE;
  1368. }
  1369. return (LRESULT)TRUE;
  1370. }
  1371. LRESULT OnMeasureItem(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM lParam, BOOL& bHandled)
  1372. {
  1373. LPMEASUREITEMSTRUCT lpMeasureItemStruct = (LPMEASUREITEMSTRUCT)lParam;
  1374. _MenuItemData* pmd = (_MenuItemData*)lpMeasureItemStruct->itemData;
  1375. if((lpMeasureItemStruct->CtlType == ODT_MENU) && _IsValidMem(pmd) && pmd->IsCmdBarMenuItem())
  1376. {
  1377. T* pT = static_cast<T*>(this);
  1378. pT->MeasureItem(lpMeasureItemStruct);
  1379. }
  1380. else
  1381. {
  1382. bHandled = FALSE;
  1383. }
  1384. return (LRESULT)TRUE;
  1385. }
  1386. // API message handlers
  1387. LRESULT OnAPIGetMenu(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
  1388. {
  1389. return (LRESULT)m_hMenu;
  1390. }
  1391. LRESULT OnAPITrackPopupMenu(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM lParam, BOOL& /*bHandled*/)
  1392. {
  1393. if(lParam == NULL)
  1394. return FALSE;
  1395. LPCBRPOPUPMENU lpCBRPopupMenu = (LPCBRPOPUPMENU)lParam;
  1396. if(lpCBRPopupMenu->cbSize != sizeof(CBRPOPUPMENU))
  1397. return FALSE;
  1398. T* pT = static_cast<T*>(this);
  1399. return pT->TrackPopupMenu(lpCBRPopupMenu->hMenu, lpCBRPopupMenu->uFlags, lpCBRPopupMenu->x, lpCBRPopupMenu->y, lpCBRPopupMenu->lptpm);
  1400. }
  1401. LRESULT OnAPIGetCmdBar(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
  1402. {
  1403. return (LRESULT)this->m_hWnd;
  1404. }
  1405. // Parent window message handlers
  1406. LRESULT OnParentHotItemChange(int /*idCtrl*/, LPNMHDR pnmh, BOOL& bHandled)
  1407. {
  1408. LPNMTBHOTITEM lpNMHT = (LPNMTBHOTITEM)pnmh;
  1409. // Check if this comes from us
  1410. if(pnmh->hwndFrom != this->m_hWnd)
  1411. {
  1412. bHandled = FALSE;
  1413. return 0;
  1414. }
  1415. bool bBlockTracking = false;
  1416. if((m_dwExtendedStyle & CBR_EX_TRACKALWAYS) == 0)
  1417. {
  1418. DWORD dwProcessID;
  1419. ::GetWindowThreadProcessId(::GetActiveWindow(), &dwProcessID);
  1420. bBlockTracking = (::GetCurrentProcessId() != dwProcessID);
  1421. }
  1422. if((!m_wndParent.IsWindowEnabled() || bBlockTracking) && (lpNMHT->dwFlags & HICF_MOUSE))
  1423. return 1;
  1424. bHandled = FALSE;
  1425. // Send WM_MENUSELECT to the app if it needs to display a status text
  1426. if(!(lpNMHT->dwFlags & HICF_MOUSE) && !(lpNMHT->dwFlags & HICF_ACCELERATOR) && !(lpNMHT->dwFlags & HICF_LMOUSE))
  1427. {
  1428. if(lpNMHT->dwFlags & HICF_ENTERING)
  1429. m_wndParent.SendMessage(WM_MENUSELECT, 0, (LPARAM)m_hMenu);
  1430. if(lpNMHT->dwFlags & HICF_LEAVING)
  1431. m_wndParent.SendMessage(WM_MENUSELECT, MAKEWPARAM(0, 0xFFFF), NULL);
  1432. }
  1433. return 0;
  1434. }
  1435. LRESULT OnParentDropDown(int /*idCtrl*/, LPNMHDR pnmh, BOOL& bHandled)
  1436. {
  1437. // Check if this comes from us
  1438. if(pnmh->hwndFrom != this->m_hWnd)
  1439. {
  1440. bHandled = FALSE;
  1441. return 1;
  1442. }
  1443. T* pT = static_cast<T*>(this);
  1444. if(::GetFocus() != this->m_hWnd)
  1445. pT->TakeFocus();
  1446. LPNMTOOLBAR pNMToolBar = (LPNMTOOLBAR)pnmh;
  1447. int nIndex = this->CommandToIndex(pNMToolBar->iItem);
  1448. m_bContextMenu = false;
  1449. m_bEscapePressed = false;
  1450. pT->DoPopupMenu(nIndex, true);
  1451. return TBDDRET_DEFAULT;
  1452. }
  1453. LRESULT OnParentInitMenuPopup(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  1454. {
  1455. return OnInitMenuPopup(uMsg, wParam, lParam, bHandled);
  1456. }
  1457. LRESULT OnParentInternalGetBar(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  1458. {
  1459. return OnInternalGetBar(uMsg, wParam, lParam, bHandled);
  1460. }
  1461. LRESULT OnParentSysCommand(UINT /*uMsg*/, WPARAM wParam, LPARAM /*lParam*/, BOOL& bHandled)
  1462. {
  1463. bHandled = FALSE;
  1464. if(((m_uSysKey == VK_MENU)
  1465. || ((m_uSysKey == VK_F10) && !(::GetKeyState(VK_SHIFT) & 0x80))
  1466. || (m_uSysKey == VK_SPACE))
  1467. && (wParam == SC_KEYMENU))
  1468. {
  1469. T* pT = static_cast<T*>(this);
  1470. if(::GetFocus() == this->m_hWnd)
  1471. {
  1472. pT->GiveFocusBack(); // exit menu "loop"
  1473. this->PostMessage(TB_SETHOTITEM, (WPARAM)-1, 0L);
  1474. }
  1475. else if((m_uSysKey != VK_SPACE) && !m_bSkipMsg)
  1476. {
  1477. if(m_bUseKeyboardCues && !m_bShowKeyboardCues && m_bAllowKeyboardCues)
  1478. ShowKeyboardCues(true);
  1479. pT->TakeFocus(); // enter menu "loop"
  1480. bHandled = TRUE;
  1481. }
  1482. else if(m_uSysKey != VK_SPACE)
  1483. {
  1484. bHandled = TRUE;
  1485. }
  1486. }
  1487. m_bSkipMsg = false;
  1488. return 0;
  1489. }
  1490. LRESULT OnParentAPIGetMenu(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  1491. {
  1492. return OnAPIGetMenu(uMsg, wParam, lParam, bHandled);
  1493. }
  1494. LRESULT OnParentMenuChar(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  1495. {
  1496. return OnMenuChar(uMsg, wParam, lParam, bHandled);
  1497. }
  1498. LRESULT OnParentAPITrackPopupMenu(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  1499. {
  1500. return OnAPITrackPopupMenu(uMsg, wParam, lParam, bHandled);
  1501. }
  1502. LRESULT OnParentAPIGetCmdBar(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  1503. {
  1504. return OnAPIGetCmdBar(uMsg, wParam, lParam, bHandled);
  1505. }
  1506. LRESULT OnParentSettingChange(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  1507. {
  1508. OnSettingChange(uMsg, wParam, lParam, bHandled);
  1509. bHandled = FALSE;
  1510. return 1;
  1511. }
  1512. LRESULT OnParentDrawItem(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  1513. {
  1514. return OnDrawItem(uMsg, wParam, lParam, bHandled);
  1515. }
  1516. LRESULT OnParentMeasureItem(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  1517. {
  1518. return OnMeasureItem(uMsg, wParam, lParam, bHandled);
  1519. }
  1520. LRESULT OnParentActivate(UINT /*uMsg*/, WPARAM wParam, LPARAM /*lParam*/, BOOL& bHandled)
  1521. {
  1522. m_bParentActive = (LOWORD(wParam) != WA_INACTIVE);
  1523. if(!m_bParentActive && m_bUseKeyboardCues && m_bShowKeyboardCues)
  1524. {
  1525. ShowKeyboardCues(false); // this will repaint our window
  1526. }
  1527. else
  1528. {
  1529. this->Invalidate();
  1530. this->UpdateWindow();
  1531. }
  1532. bHandled = FALSE;
  1533. return 1;
  1534. }
  1535. LRESULT OnParentCustomDraw(int /*idCtrl*/, LPNMHDR pnmh, BOOL& bHandled)
  1536. {
  1537. LRESULT lRet = CDRF_DODEFAULT;
  1538. bHandled = FALSE;
  1539. if(pnmh->hwndFrom == this->m_hWnd)
  1540. {
  1541. LPNMTBCUSTOMDRAW lpTBCustomDraw = (LPNMTBCUSTOMDRAW)pnmh;
  1542. if(lpTBCustomDraw->nmcd.dwDrawStage == CDDS_PREPAINT)
  1543. {
  1544. lRet = CDRF_NOTIFYITEMDRAW;
  1545. bHandled = TRUE;
  1546. }
  1547. else if(lpTBCustomDraw->nmcd.dwDrawStage == CDDS_ITEMPREPAINT)
  1548. {
  1549. #if _WTL_CMDBAR_VISTA_MENUS && defined(_WTL_CMDBAR_VISTA_STD_MENUBAR)
  1550. if(m_bVistaMenus)
  1551. {
  1552. ::SetRectEmpty(&lpTBCustomDraw->rcText);
  1553. lRet = CDRF_NOTIFYPOSTPAINT;
  1554. bHandled = TRUE;
  1555. }
  1556. else
  1557. #endif // _WTL_CMDBAR_VISTA_MENUS && defined(_WTL_CMDBAR_VISTA_STD_MENUBAR)
  1558. {
  1559. if(m_bFlatMenus)
  1560. {
  1561. bool bDisabled = ((lpTBCustomDraw->nmcd.uItemState & CDIS_DISABLED) == CDIS_DISABLED);
  1562. if(!bDisabled && (((lpTBCustomDraw->nmcd.uItemState & CDIS_HOT) == CDIS_HOT) ||
  1563. (lpTBCustomDraw->nmcd.uItemState & CDIS_SELECTED) == CDIS_SELECTED))
  1564. {
  1565. ::FillRect(lpTBCustomDraw->nmcd.hdc, &lpTBCustomDraw->nmcd.rc, ::GetSysColorBrush(COLOR_MENUHILIGHT));
  1566. ::FrameRect(lpTBCustomDraw->nmcd.hdc, &lpTBCustomDraw->nmcd.rc, ::GetSysColorBrush(COLOR_HIGHLIGHT));
  1567. lpTBCustomDraw->clrText = ::GetSysColor(m_bParentActive ? COLOR_HIGHLIGHTTEXT : COLOR_GRAYTEXT);
  1568. }
  1569. else if(bDisabled || !m_bParentActive)
  1570. {
  1571. lpTBCustomDraw->clrText = ::GetSysColor(COLOR_GRAYTEXT);
  1572. }
  1573. _ParentCustomDrawHelper(lpTBCustomDraw);
  1574. lRet = CDRF_SKIPDEFAULT;
  1575. bHandled = TRUE;
  1576. }
  1577. else if(!m_bParentActive)
  1578. {
  1579. lpTBCustomDraw->clrText = ::GetSysColor(COLOR_GRAYTEXT);
  1580. bHandled = TRUE;
  1581. }
  1582. }
  1583. }
  1584. #if _WTL_CMDBAR_VISTA_MENUS && defined(_WTL_CMDBAR_VISTA_STD_MENUBAR)
  1585. else if (lpTBCustomDraw->nmcd.dwDrawStage == CDDS_ITEMPOSTPAINT)
  1586. {
  1587. bool bDisabled = ((lpTBCustomDraw->nmcd.uItemState & CDIS_DISABLED) == CDIS_DISABLED);
  1588. if(bDisabled || !m_bParentActive)
  1589. lpTBCustomDraw->clrText = ::GetSysColor(COLOR_GRAYTEXT);
  1590. _ParentCustomDrawHelper(lpTBCustomDraw);
  1591. lRet = CDRF_SKIPDEFAULT;
  1592. bHandled = TRUE;
  1593. }
  1594. #endif // _WTL_CMDBAR_VISTA_MENUS && defined(_WTL_CMDBAR_VISTA_STD_MENUBAR)
  1595. }
  1596. return lRet;
  1597. }
  1598. void _ParentCustomDrawHelper(LPNMTBCUSTOMDRAW lpTBCustomDraw)
  1599. {
  1600. CDCHandle dc = lpTBCustomDraw->nmcd.hdc;
  1601. dc.SetTextColor(lpTBCustomDraw->clrText);
  1602. dc.SetBkMode(lpTBCustomDraw->nStringBkMode);
  1603. HFONT hFont = this->GetFont();
  1604. HFONT hFontOld = NULL;
  1605. if(hFont != NULL)
  1606. hFontOld = dc.SelectFont(hFont);
  1607. const int cchText = 200;
  1608. TCHAR szText[cchText] = {};
  1609. TBBUTTONINFO tbbi = {};
  1610. tbbi.cbSize = sizeof(TBBUTTONINFO);
  1611. tbbi.dwMask = TBIF_TEXT;
  1612. tbbi.pszText = szText;
  1613. tbbi.cchText = cchText;
  1614. this->GetButtonInfo((int)lpTBCustomDraw->nmcd.dwItemSpec, &tbbi);
  1615. dc.DrawText(szText, -1, &lpTBCustomDraw->nmcd.rc, DT_SINGLELINE | DT_CENTER | DT_VCENTER | (m_bShowKeyboardCues ? 0 : DT_HIDEPREFIX));
  1616. if(hFont != NULL)
  1617. dc.SelectFont(hFontOld);
  1618. }
  1619. // Message hook handlers
  1620. LRESULT OnHookMouseMove(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& bHandled)
  1621. {
  1622. static POINT s_point = { -1, -1 };
  1623. DWORD dwPoint = ::GetMessagePos();
  1624. POINT point = { GET_X_LPARAM(dwPoint), GET_Y_LPARAM(dwPoint) };
  1625. bHandled = FALSE;
  1626. if(m_bMenuActive)
  1627. {
  1628. if(::WindowFromPoint(point) == this->m_hWnd)
  1629. {
  1630. this->ScreenToClient(&point);
  1631. int nHit = this->HitTest(&point);
  1632. if(((point.x != s_point.x) || (point.y != s_point.y)) && (nHit >= 0) && (nHit < ::GetMenuItemCount(m_hMenu)) && (nHit != m_nPopBtn) && (m_nPopBtn != -1))
  1633. {
  1634. TBBUTTON tbb = {};
  1635. this->GetButton(nHit, &tbb);
  1636. if((tbb.fsState & TBSTATE_ENABLED) != 0)
  1637. {
  1638. m_nNextPopBtn = nHit | 0xFFFF0000;
  1639. HWND hWndMenu = this->m_stackMenuWnd.GetCurrent();
  1640. ATLASSERT(hWndMenu != NULL);
  1641. // this one is needed to close a menu if mouse button was down
  1642. ::PostMessage(hWndMenu, WM_LBUTTONUP, 0, MAKELPARAM(point.x, point.y));
  1643. // this one closes a popup menu
  1644. ::PostMessage(hWndMenu, WM_KEYDOWN, VK_ESCAPE, 0L);
  1645. bHandled = TRUE;
  1646. }
  1647. }
  1648. }
  1649. }
  1650. else
  1651. {
  1652. this->ScreenToClient(&point);
  1653. }
  1654. s_point = point;
  1655. return 0;
  1656. }
  1657. LRESULT OnHookSysKeyDown(UINT /*uMsg*/, WPARAM wParam, LPARAM /*lParam*/, BOOL& bHandled)
  1658. {
  1659. bHandled = FALSE;
  1660. #ifdef _CMDBAR_EXTRA_TRACE
  1661. ATLTRACE2(atlTraceUI, 0, _T("CmdBar - Hook WM_SYSKEYDOWN (0x%2.2X)\n"), wParam);
  1662. #endif
  1663. if((wParam == VK_MENU) && m_bParentActive && m_bUseKeyboardCues && !m_bShowKeyboardCues && m_bAllowKeyboardCues)
  1664. ShowKeyboardCues(true);
  1665. if((wParam != VK_SPACE) && !m_bMenuActive && (::GetFocus() == this->m_hWnd))
  1666. {
  1667. m_bAllowKeyboardCues = false;
  1668. this->PostMessage(TB_SETHOTITEM, (WPARAM)-1, 0L);
  1669. T* pT = static_cast<T*>(this);
  1670. pT->GiveFocusBack();
  1671. m_bSkipMsg = true;
  1672. }
  1673. else
  1674. {
  1675. if((wParam == VK_SPACE) && m_bUseKeyboardCues && m_bShowKeyboardCues)
  1676. {
  1677. m_bAllowKeyboardCues = true;
  1678. ShowKeyboardCues(false);
  1679. }
  1680. m_uSysKey = (UINT)wParam;
  1681. }
  1682. return 0;
  1683. }
  1684. LRESULT OnHookSysKeyUp(UINT /*uMsg*/, WPARAM wParam, LPARAM /*lParam*/, BOOL& bHandled)
  1685. {
  1686. if(!m_bAllowKeyboardCues)
  1687. m_bAllowKeyboardCues = true;
  1688. bHandled = FALSE;
  1689. (void)wParam; // avoid level 4 warning
  1690. #ifdef _CMDBAR_EXTRA_TRACE
  1691. ATLTRACE2(atlTraceUI, 0, _T("CmdBar - Hook WM_SYSKEYUP (0x%2.2X)\n"), wParam);
  1692. #endif
  1693. return 0;
  1694. }
  1695. LRESULT OnHookSysChar(UINT /*uMsg*/, WPARAM wParam, LPARAM /*lParam*/, BOOL& bHandled)
  1696. {
  1697. bHandled = FALSE;
  1698. #ifdef _CMDBAR_EXTRA_TRACE
  1699. ATLTRACE2(atlTraceUI, 0, _T("CmdBar - Hook WM_SYSCHAR (0x%2.2X)\n"), wParam);
  1700. #endif
  1701. if(!m_bMenuActive && (this->m_hWndHook != this->m_hWnd) && (wParam != VK_SPACE))
  1702. bHandled = TRUE;
  1703. return 0;
  1704. }
  1705. LRESULT OnHookKeyDown(UINT /*uMsg*/, WPARAM wParam, LPARAM /*lParam*/, BOOL& bHandled)
  1706. {
  1707. #ifdef _CMDBAR_EXTRA_TRACE
  1708. ATLTRACE2(atlTraceUI, 0, _T("CmdBar - Hook WM_KEYDOWN (0x%2.2X)\n"), wParam);
  1709. #endif
  1710. bHandled = FALSE;
  1711. T* pT = static_cast<T*>(this);
  1712. if((wParam == VK_ESCAPE) && (this->m_stackMenuWnd.GetSize() <= 1))
  1713. {
  1714. if(m_bMenuActive && !m_bContextMenu)
  1715. {
  1716. int nHot = this->GetHotItem();
  1717. if(nHot == -1)
  1718. nHot = m_nPopBtn;
  1719. if(nHot == -1)
  1720. nHot = 0;
  1721. this->SetHotItem(nHot);
  1722. bHandled = TRUE;
  1723. pT->TakeFocus();
  1724. m_bEscapePressed = true; // To keep focus
  1725. m_bSkipPostDown = false;
  1726. }
  1727. else if((::GetFocus() == this->m_hWnd) && m_wndParent.IsWindow())
  1728. {
  1729. this->SetHotItem(-1);
  1730. pT->GiveFocusBack();
  1731. bHandled = TRUE;
  1732. }
  1733. }
  1734. else if((wParam == VK_RETURN) || (wParam == VK_UP) || (wParam == VK_DOWN))
  1735. {
  1736. if(!m_bMenuActive && (::GetFocus() == this->m_hWnd) && m_wndParent.IsWindow())
  1737. {
  1738. int nHot = this->GetHotItem();
  1739. if(nHot != -1)
  1740. {
  1741. if(wParam != VK_RETURN)
  1742. {
  1743. if(!m_bSkipPostDown)
  1744. {
  1745. this->PostMessage(WM_KEYDOWN, VK_DOWN, 0L);
  1746. m_bSkipPostDown = true;
  1747. }
  1748. else
  1749. {
  1750. ATLTRACE2(atlTraceUI, 0, _T("CmdBar - skipping posting another VK_DOWN\n"));
  1751. m_bSkipPostDown = false;
  1752. }
  1753. }
  1754. }
  1755. else
  1756. {
  1757. ATLTRACE2(atlTraceUI, 0, _T("CmdBar - Can't find hot button\n"));
  1758. }
  1759. }
  1760. if((wParam == VK_RETURN) && m_bMenuActive)
  1761. {
  1762. this->PostMessage(TB_SETHOTITEM, (WPARAM)-1, 0L);
  1763. m_nNextPopBtn = -1;
  1764. pT->GiveFocusBack();
  1765. }
  1766. }
  1767. else if((wParam == VK_LEFT) || (wParam == VK_RIGHT))
  1768. {
  1769. WPARAM wpNext = m_bLayoutRTL ? VK_LEFT : VK_RIGHT;
  1770. WPARAM wpPrev = m_bLayoutRTL ? VK_RIGHT : VK_LEFT;
  1771. if(m_bMenuActive && !m_bContextMenu && !((wParam == wpNext) && m_bPopupItem))
  1772. {
  1773. bool bAction = false;
  1774. if((wParam == wpPrev) && (this->s_pCurrentBar->m_stackMenuWnd.GetSize() == 1))
  1775. {
  1776. m_nNextPopBtn = pT->GetPreviousMenuItem(m_nPopBtn);
  1777. if(m_nNextPopBtn != -1)
  1778. bAction = true;
  1779. }
  1780. else if(wParam == wpNext)
  1781. {
  1782. m_nNextPopBtn = pT->GetNextMenuItem(m_nPopBtn);
  1783. if(m_nNextPopBtn != -1)
  1784. bAction = true;
  1785. }
  1786. HWND hWndMenu = this->m_stackMenuWnd.GetCurrent();
  1787. ATLASSERT(hWndMenu != NULL);
  1788. // Close the popup menu
  1789. if(bAction)
  1790. {
  1791. ::PostMessage(hWndMenu, WM_KEYDOWN, VK_ESCAPE, 0L);
  1792. if(wParam == wpNext)
  1793. {
  1794. int cItem = this->m_stackMenuWnd.GetSize() - 1;
  1795. while(cItem >= 0)
  1796. {
  1797. hWndMenu = this->m_stackMenuWnd[cItem];
  1798. if(hWndMenu != NULL)
  1799. ::PostMessage(hWndMenu, WM_KEYDOWN, VK_ESCAPE, 0L);
  1800. cItem--;
  1801. }
  1802. }
  1803. if(m_nNextPopBtn == -2)
  1804. {
  1805. m_nNextPopBtn = -1;
  1806. pT->DisplayChevronMenu();
  1807. }
  1808. bHandled = TRUE;
  1809. }
  1810. }
  1811. }
  1812. return 0;
  1813. }
  1814. LRESULT OnHookNextMenu(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& bHandled)
  1815. {
  1816. #ifdef _CMDBAR_EXTRA_TRACE
  1817. ATLTRACE2(atlTraceUI, 0, _T("CmdBar - Hook WM_NEXTMENU\n"));
  1818. #endif
  1819. bHandled = FALSE;
  1820. return 1;
  1821. }
  1822. LRESULT OnHookChar(UINT /*uMsg*/, WPARAM wParam, LPARAM /*lParam*/, BOOL& bHandled)
  1823. {
  1824. #ifdef _CMDBAR_EXTRA_TRACE
  1825. ATLTRACE2(atlTraceUI, 0, _T("CmdBar - Hook WM_CHAR (0x%2.2X)\n"), wParam);
  1826. #endif
  1827. bHandled = (wParam == VK_ESCAPE);
  1828. return 0;
  1829. }
  1830. // Implementation - ownerdraw overrideables and helpers
  1831. void DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
  1832. {
  1833. T* pT = static_cast<T*>(this);
  1834. if(m_bFlatMenus)
  1835. pT->DrawItemFlat(lpDrawItemStruct);
  1836. else
  1837. pT->DrawItem3D(lpDrawItemStruct);
  1838. }
  1839. void DrawItem3D(LPDRAWITEMSTRUCT lpDrawItemStruct)
  1840. {
  1841. _MenuItemData* pmd = (_MenuItemData*)lpDrawItemStruct->itemData;
  1842. CDCHandle dc = lpDrawItemStruct->hDC;
  1843. const RECT& rcItem = lpDrawItemStruct->rcItem;
  1844. T* pT = static_cast<T*>(this);
  1845. if(pmd->fType & MFT_SEPARATOR)
  1846. {
  1847. // draw separator
  1848. RECT rc = rcItem;
  1849. rc.top += (rc.bottom - rc.top) / 2; // vertical center
  1850. dc.DrawEdge(&rc, EDGE_ETCHED, BF_TOP); // draw separator line
  1851. }
  1852. else // not a separator
  1853. {
  1854. BOOL bDisabled = lpDrawItemStruct->itemState & ODS_GRAYED;
  1855. BOOL bSelected = lpDrawItemStruct->itemState & ODS_SELECTED;
  1856. BOOL bChecked = lpDrawItemStruct->itemState & ODS_CHECKED;
  1857. BOOL bHasImage = FALSE;
  1858. if(LOWORD(lpDrawItemStruct->itemID) == (WORD)-1)
  1859. bSelected = FALSE;
  1860. RECT rcButn = { rcItem.left, rcItem.top, rcItem.left + m_szButton.cx, rcItem.top + m_szButton.cy }; // button rect
  1861. ::OffsetRect(&rcButn, 0, ((rcItem.bottom - rcItem.top) - (rcButn.bottom - rcButn.top)) / 2); // center vertically
  1862. int iButton = pmd->iButton;
  1863. if(iButton >= 0)
  1864. {
  1865. bHasImage = TRUE;
  1866. // calc drawing point
  1867. SIZE sz = { rcButn.right - rcButn.left - m_szBitmap.cx, rcButn.bottom - rcButn.top - m_szBitmap.cy };
  1868. sz.cx /= 2;
  1869. sz.cy /= 2;
  1870. POINT point = { rcButn.left + sz.cx, rcButn.top + sz.cy };
  1871. // fill background depending on state
  1872. if(!bChecked || (bSelected && !bDisabled))
  1873. {
  1874. if(!bDisabled)
  1875. dc.FillRect(&rcButn, (bChecked && !bSelected) ? COLOR_3DLIGHT : COLOR_MENU);
  1876. else
  1877. dc.FillRect(&rcButn, COLOR_MENU);
  1878. }
  1879. else
  1880. {
  1881. COLORREF crTxt = dc.SetTextColor(::GetSysColor(COLOR_BTNFACE));
  1882. COLORREF crBk = dc.SetBkColor(::GetSysColor(COLOR_BTNHILIGHT));
  1883. CBrush hbr(CDCHandle::GetHalftoneBrush());
  1884. dc.SetBrushOrg(rcButn.left, rcButn.top);
  1885. dc.FillRect(&rcButn, hbr);
  1886. dc.SetTextColor(crTxt);
  1887. dc.SetBkColor(crBk);
  1888. }
  1889. // draw disabled or normal
  1890. if(!bDisabled)
  1891. {
  1892. // draw pushed-in or popped-out edge
  1893. if(bSelected || bChecked)
  1894. {
  1895. RECT rc2 = rcButn;
  1896. dc.DrawEdge(&rc2, bChecked ? BDR_SUNKENOUTER : BDR_RAISEDINNER, BF_RECT);
  1897. }
  1898. // draw the image
  1899. ::ImageList_Draw(m_hImageList, iButton, dc, point.x, point.y, ILD_TRANSPARENT);
  1900. }
  1901. else
  1902. {
  1903. HBRUSH hBrushBackground = bChecked ? NULL : ::GetSysColorBrush(COLOR_MENU);
  1904. pT->DrawBitmapDisabled(dc, iButton, point, hBrushBackground);
  1905. }
  1906. }
  1907. else
  1908. {
  1909. // no image - look for custom checked/unchecked bitmaps
  1910. CMenuItemInfo info;
  1911. info.fMask = MIIM_CHECKMARKS | MIIM_TYPE;
  1912. ::GetMenuItemInfo((HMENU)lpDrawItemStruct->hwndItem, lpDrawItemStruct->itemID, MF_BYCOMMAND, &info);
  1913. if(bChecked || (info.hbmpUnchecked != NULL))
  1914. {
  1915. BOOL bRadio = ((info.fType & MFT_RADIOCHECK) != 0);
  1916. bHasImage = pT->DrawCheckmark(dc, rcButn, bSelected, bDisabled, bRadio, bChecked ? info.hbmpChecked : info.hbmpUnchecked);
  1917. }
  1918. }
  1919. // draw item text
  1920. int cxButn = m_szButton.cx;
  1921. COLORREF colorBG = ::GetSysColor(bSelected ? COLOR_HIGHLIGHT : COLOR_MENU);
  1922. if(bSelected || (lpDrawItemStruct->itemAction == ODA_SELECT))
  1923. {
  1924. RECT rcBG = rcItem;
  1925. if(bHasImage)
  1926. rcBG.left += cxButn + s_kcxGap;
  1927. dc.FillRect(&rcBG, bSelected ? COLOR_HIGHLIGHT : COLOR_MENU);
  1928. }
  1929. // calc text rectangle and colors
  1930. RECT rcText = rcItem;
  1931. rcText.left += cxButn + s_kcxGap + s_kcxTextMargin;
  1932. rcText.right -= cxButn;
  1933. dc.SetBkMode(TRANSPARENT);
  1934. COLORREF colorText = ::GetSysColor(bDisabled ? (bSelected ? COLOR_GRAYTEXT : COLOR_3DSHADOW) : (bSelected ? COLOR_HIGHLIGHTTEXT : COLOR_MENUTEXT));
  1935. // font already selected by Windows
  1936. if(bDisabled && (!bSelected || (colorText == colorBG)))
  1937. {
  1938. // disabled - draw shadow text shifted down and right 1 pixel (unles selected)
  1939. RECT rcDisabled = rcText;
  1940. ::OffsetRect(&rcDisabled, 1, 1);
  1941. pT->DrawMenuText(dc, rcDisabled, pmd->lpstrText, ::GetSysColor(COLOR_3DHILIGHT));
  1942. }
  1943. pT->DrawMenuText(dc, rcText, pmd->lpstrText, colorText); // finally!
  1944. }
  1945. }
  1946. void DrawItemFlat(LPDRAWITEMSTRUCT lpDrawItemStruct)
  1947. {
  1948. _MenuItemData* pmd = (_MenuItemData*)lpDrawItemStruct->itemData;
  1949. CDCHandle dc = lpDrawItemStruct->hDC;
  1950. const RECT& rcItem = lpDrawItemStruct->rcItem;
  1951. T* pT = static_cast<T*>(this);
  1952. BOOL bDisabled = lpDrawItemStruct->itemState & ODS_GRAYED;
  1953. BOOL bSelected = lpDrawItemStruct->itemState & ODS_SELECTED;
  1954. BOOL bChecked = lpDrawItemStruct->itemState & ODS_CHECKED;
  1955. // paint background
  1956. if(bSelected || (lpDrawItemStruct->itemAction == ODA_SELECT))
  1957. {
  1958. if(bSelected)
  1959. {
  1960. dc.FillRect(&rcItem, ::GetSysColorBrush(COLOR_MENUHILIGHT));
  1961. dc.FrameRect(&rcItem, ::GetSysColorBrush(COLOR_HIGHLIGHT));
  1962. }
  1963. else
  1964. {
  1965. dc.FillRect(&rcItem, ::GetSysColorBrush(COLOR_MENU));
  1966. }
  1967. }
  1968. if(pmd->fType & MFT_SEPARATOR)
  1969. {
  1970. // draw separator
  1971. RECT rc = rcItem;
  1972. rc.top += (rc.bottom - rc.top) / 2; // vertical center
  1973. dc.DrawEdge(&rc, EDGE_ETCHED, BF_TOP); // draw separator line
  1974. }
  1975. else // not a separator
  1976. {
  1977. if(LOWORD(lpDrawItemStruct->itemID) == (WORD)-1)
  1978. bSelected = FALSE;
  1979. RECT rcButn = { rcItem.left, rcItem.top, rcItem.left + m_szButton.cx, rcItem.top + m_szButton.cy }; // button rect
  1980. ::OffsetRect(&rcButn, 0, ((rcItem.bottom - rcItem.top) - (rcButn.bottom - rcButn.top)) / 2); // center vertically
  1981. // draw background and border for checked items
  1982. if(bChecked)
  1983. {
  1984. RECT rcCheck = rcButn;
  1985. ::InflateRect(&rcCheck, -1, -1);
  1986. if(bSelected)
  1987. dc.FillRect(&rcCheck, ::GetSysColorBrush(COLOR_MENU));
  1988. dc.FrameRect(&rcCheck, ::GetSysColorBrush(COLOR_HIGHLIGHT));
  1989. }
  1990. int iButton = pmd->iButton;
  1991. if(iButton >= 0)
  1992. {
  1993. // calc drawing point
  1994. SIZE sz = { rcButn.right - rcButn.left - m_szBitmap.cx, rcButn.bottom - rcButn.top - m_szBitmap.cy };
  1995. sz.cx /= 2;
  1996. sz.cy /= 2;
  1997. POINT point = { rcButn.left + sz.cx, rcButn.top + sz.cy };
  1998. // draw disabled or normal
  1999. if(!bDisabled)
  2000. {
  2001. ::ImageList_Draw(m_hImageList, iButton, dc, point.x, point.y, ILD_TRANSPARENT);
  2002. }
  2003. else
  2004. {
  2005. HBRUSH hBrushBackground = ::GetSysColorBrush((bSelected && !bChecked) ? COLOR_MENUHILIGHT : COLOR_MENU);
  2006. HBRUSH hBrushDisabledImage = ::GetSysColorBrush(COLOR_3DSHADOW);
  2007. pT->DrawBitmapDisabled(dc, iButton, point, hBrushBackground, hBrushBackground, hBrushDisabledImage);
  2008. }
  2009. }
  2010. else
  2011. {
  2012. // no image - look for custom checked/unchecked bitmaps
  2013. CMenuItemInfo info;
  2014. info.fMask = MIIM_CHECKMARKS | MIIM_TYPE;
  2015. ::GetMenuItemInfo((HMENU)lpDrawItemStruct->hwndItem, lpDrawItemStruct->itemID, MF_BYCOMMAND, &info);
  2016. if(bChecked || (info.hbmpUnchecked != NULL))
  2017. {
  2018. BOOL bRadio = ((info.fType & MFT_RADIOCHECK) != 0);
  2019. pT->DrawCheckmark(dc, rcButn, bSelected, bDisabled, bRadio, bChecked ? info.hbmpChecked : info.hbmpUnchecked);
  2020. }
  2021. }
  2022. // draw item text
  2023. int cxButn = m_szButton.cx;
  2024. // calc text rectangle and colors
  2025. RECT rcText = rcItem;
  2026. rcText.left += cxButn + s_kcxGap + s_kcxTextMargin;
  2027. rcText.right -= cxButn;
  2028. dc.SetBkMode(TRANSPARENT);
  2029. COLORREF colorText = ::GetSysColor(bDisabled ? (bSelected ? COLOR_GRAYTEXT : COLOR_3DSHADOW) : (bSelected ? COLOR_HIGHLIGHTTEXT : COLOR_MENUTEXT));
  2030. pT->DrawMenuText(dc, rcText, pmd->lpstrText, colorText); // finally!
  2031. }
  2032. }
  2033. void DrawMenuText(CDCHandle& dc, RECT& rc, LPCTSTR lpstrText, COLORREF color)
  2034. {
  2035. int nTab = -1;
  2036. const int nLen = lstrlen(lpstrText);
  2037. for(int i = 0; i < nLen; i++)
  2038. {
  2039. if(lpstrText[i] == _T('\t'))
  2040. {
  2041. nTab = i;
  2042. break;
  2043. }
  2044. }
  2045. dc.SetTextColor(color);
  2046. dc.DrawText(lpstrText, nTab, &rc, DT_SINGLELINE | DT_LEFT | DT_VCENTER | (m_bShowKeyboardCues ? 0 : DT_HIDEPREFIX));
  2047. if(nTab != -1)
  2048. dc.DrawText(&lpstrText[nTab + 1], -1, &rc, DT_SINGLELINE | DT_RIGHT | DT_VCENTER | (m_bShowKeyboardCues ? 0 : DT_HIDEPREFIX));
  2049. }
  2050. void DrawBitmapDisabled(CDCHandle& dc, int nImage, POINT point,
  2051. HBRUSH hBrushBackground = ::GetSysColorBrush(COLOR_3DFACE),
  2052. HBRUSH hBrush3DEffect = ::GetSysColorBrush(COLOR_3DHILIGHT),
  2053. HBRUSH hBrushDisabledImage = ::GetSysColorBrush(COLOR_3DSHADOW))
  2054. {
  2055. if(m_bAlphaImages)
  2056. {
  2057. IMAGELISTDRAWPARAMS ildp = {};
  2058. ildp.cbSize = sizeof(IMAGELISTDRAWPARAMS);
  2059. ildp.himl = m_hImageList;
  2060. ildp.i = nImage;
  2061. ildp.hdcDst = dc;
  2062. ildp.x = point.x;
  2063. ildp.y = point.y;
  2064. ildp.cx = 0;
  2065. ildp.cy = 0;
  2066. ildp.xBitmap = 0;
  2067. ildp.yBitmap = 0;
  2068. ildp.fStyle = ILD_TRANSPARENT;
  2069. ildp.fState = ILS_SATURATE;
  2070. ildp.Frame = 0;
  2071. ::ImageList_DrawIndirect(&ildp);
  2072. }
  2073. else
  2074. {
  2075. // create memory DC
  2076. CDC dcMem;
  2077. dcMem.CreateCompatibleDC(dc);
  2078. // create mono or color bitmap
  2079. CBitmap bmp;
  2080. bmp.CreateCompatibleBitmap(dc, m_szBitmap.cx, m_szBitmap.cy);
  2081. ATLASSERT(bmp.m_hBitmap != NULL);
  2082. // draw image into memory DC--fill BG white first
  2083. HBITMAP hBmpOld = dcMem.SelectBitmap(bmp);
  2084. dcMem.PatBlt(0, 0, m_szBitmap.cx, m_szBitmap.cy, WHITENESS);
  2085. // If white is the text color, we can't use the normal painting since
  2086. // it would blend with the WHITENESS, but the mask is OK
  2087. UINT uDrawStyle = (::GetSysColor(COLOR_BTNTEXT) == RGB(255, 255, 255)) ? ILD_MASK : ILD_NORMAL;
  2088. ::ImageList_Draw(m_hImageList, nImage, dcMem, 0, 0, uDrawStyle);
  2089. dc.DitherBlt(point.x, point.y, m_szBitmap.cx, m_szBitmap.cy, dcMem, NULL, 0, 0, hBrushBackground, hBrush3DEffect, hBrushDisabledImage);
  2090. dcMem.SelectBitmap(hBmpOld); // restore
  2091. }
  2092. }
  2093. // old name
  2094. BOOL Draw3DCheckmark(CDCHandle& dc, const RECT& rc, BOOL bSelected, BOOL bDisabled, BOOL bRadio, HBITMAP hBmpCheck)
  2095. {
  2096. return DrawCheckmark(dc, rc, bSelected, bDisabled, bRadio, hBmpCheck);
  2097. }
  2098. BOOL DrawCheckmark(CDCHandle& dc, const RECT& rc, BOOL bSelected, BOOL bDisabled, BOOL bRadio, HBITMAP hBmpCheck)
  2099. {
  2100. // get checkmark bitmap, if none, use Windows standard
  2101. SIZE size = {};
  2102. CBitmapHandle bmp = hBmpCheck;
  2103. if(hBmpCheck != NULL)
  2104. {
  2105. bmp.GetSize(size);
  2106. }
  2107. else
  2108. {
  2109. size.cx = ::GetSystemMetrics(SM_CXMENUCHECK);
  2110. size.cy = ::GetSystemMetrics(SM_CYMENUCHECK);
  2111. bmp.CreateCompatibleBitmap(dc, size.cx, size.cy);
  2112. ATLASSERT(bmp.m_hBitmap != NULL);
  2113. }
  2114. // center bitmap in caller's rectangle
  2115. RECT rcDest = rc;
  2116. if((rc.right - rc.left) > size.cx)
  2117. {
  2118. rcDest.left = rc.left + (rc.right - rc.left - size.cx) / 2;
  2119. rcDest.right = rcDest.left + size.cx;
  2120. }
  2121. if((rc.bottom - rc.top) > size.cy)
  2122. {
  2123. rcDest.top = rc.top + (rc.bottom - rc.top - size.cy) / 2;
  2124. rcDest.bottom = rcDest.top + size.cy;
  2125. }
  2126. // paint background
  2127. if(!m_bFlatMenus)
  2128. {
  2129. if(bSelected && !bDisabled)
  2130. {
  2131. dc.FillRect(&rcDest, COLOR_MENU);
  2132. }
  2133. else
  2134. {
  2135. COLORREF clrTextOld = dc.SetTextColor(::GetSysColor(COLOR_BTNFACE));
  2136. COLORREF clrBkOld = dc.SetBkColor(::GetSysColor(COLOR_BTNHILIGHT));
  2137. CBrush hbr(CDCHandle::GetHalftoneBrush());
  2138. dc.SetBrushOrg(rcDest.left, rcDest.top);
  2139. dc.FillRect(&rcDest, hbr);
  2140. dc.SetTextColor(clrTextOld);
  2141. dc.SetBkColor(clrBkOld);
  2142. }
  2143. }
  2144. // create source image
  2145. CDC dcSource;
  2146. dcSource.CreateCompatibleDC(dc);
  2147. HBITMAP hBmpOld = dcSource.SelectBitmap(bmp);
  2148. // set colors
  2149. const COLORREF clrBlack = RGB(0, 0, 0);
  2150. const COLORREF clrWhite = RGB(255, 255, 255);
  2151. COLORREF clrTextOld = dc.SetTextColor(clrBlack);
  2152. COLORREF clrBkOld = dc.SetBkColor(clrWhite);
  2153. // create mask
  2154. CDC dcMask;
  2155. dcMask.CreateCompatibleDC(dc);
  2156. CBitmap bmpMask;
  2157. bmpMask.CreateBitmap(size.cx, size.cy, 1, 1, NULL);
  2158. HBITMAP hBmpOld1 = dcMask.SelectBitmap(bmpMask);
  2159. // draw the checkmark transparently
  2160. int cx = rcDest.right - rcDest.left;
  2161. int cy = rcDest.bottom - rcDest.top;
  2162. if(hBmpCheck != NULL)
  2163. {
  2164. // build mask based on transparent color
  2165. dcSource.SetBkColor(m_clrMask);
  2166. dcMask.SetBkColor(clrBlack);
  2167. dcMask.SetTextColor(clrWhite);
  2168. dcMask.BitBlt(0, 0, size.cx, size.cy, dcSource, 0, 0, SRCCOPY);
  2169. // draw bitmap using the mask
  2170. dc.BitBlt(rcDest.left, rcDest.top, cx, cy, dcSource, 0, 0, SRCINVERT);
  2171. dc.BitBlt(rcDest.left, rcDest.top, cx, cy, dcMask, 0, 0, SRCAND);
  2172. dc.BitBlt(rcDest.left, rcDest.top, cx, cy, dcSource, 0, 0, SRCINVERT);
  2173. }
  2174. else
  2175. {
  2176. const DWORD ROP_DSno = 0x00BB0226L;
  2177. const DWORD ROP_DSa = 0x008800C6L;
  2178. const DWORD ROP_DSo = 0x00EE0086L;
  2179. const DWORD ROP_DSna = 0x00220326L;
  2180. // draw mask
  2181. RECT rcSource = { 0, 0, __min(size.cx, rc.right - rc.left), __min(size.cy, rc.bottom - rc.top) };
  2182. dcMask.DrawFrameControl(&rcSource, DFC_MENU, bRadio ? DFCS_MENUBULLET : DFCS_MENUCHECK);
  2183. // draw shadow if disabled
  2184. if(!m_bFlatMenus && bDisabled)
  2185. {
  2186. // offset by one pixel
  2187. int x = rcDest.left + 1;
  2188. int y = rcDest.top + 1;
  2189. // paint source bitmap
  2190. const int nColor = COLOR_3DHILIGHT;
  2191. dcSource.FillRect(&rcSource, nColor);
  2192. // draw checkmark - special case black and white colors
  2193. COLORREF clrCheck = ::GetSysColor(nColor);
  2194. if(clrCheck == clrWhite)
  2195. {
  2196. dc.BitBlt(x, y, cx, cy, dcMask, 0, 0, ROP_DSno);
  2197. dc.BitBlt(x, y, cx, cy, dcSource, 0, 0, ROP_DSa);
  2198. }
  2199. else
  2200. {
  2201. if(clrCheck != clrBlack)
  2202. {
  2203. ATLASSERT(dcSource.GetTextColor() == clrBlack);
  2204. ATLASSERT(dcSource.GetBkColor() == clrWhite);
  2205. dcSource.BitBlt(0, 0, size.cx, size.cy, dcMask, 0, 0, ROP_DSna);
  2206. }
  2207. dc.BitBlt(x, y, cx, cy, dcMask, 0, 0, ROP_DSa);
  2208. dc.BitBlt(x, y, cx, cy, dcSource, 0, 0, ROP_DSo);
  2209. }
  2210. }
  2211. // paint source bitmap
  2212. const int nColor = bDisabled ? COLOR_BTNSHADOW : COLOR_MENUTEXT;
  2213. dcSource.FillRect(&rcSource, nColor);
  2214. // draw checkmark - special case black and white colors
  2215. COLORREF clrCheck = ::GetSysColor(nColor);
  2216. if(clrCheck == clrWhite)
  2217. {
  2218. dc.BitBlt(rcDest.left, rcDest.top, cx, cy, dcMask, 0, 0, ROP_DSno);
  2219. dc.BitBlt(rcDest.left, rcDest.top, cx, cy, dcSource, 0, 0, ROP_DSa);
  2220. }
  2221. else
  2222. {
  2223. if(clrCheck != clrBlack)
  2224. {
  2225. ATLASSERT(dcSource.GetTextColor() == clrBlack);
  2226. ATLASSERT(dcSource.GetBkColor() == clrWhite);
  2227. dcSource.BitBlt(0, 0, size.cx, size.cy, dcMask, 0, 0, ROP_DSna);
  2228. }
  2229. dc.BitBlt(rcDest.left, rcDest.top, cx, cy, dcMask, 0, 0, ROP_DSa);
  2230. dc.BitBlt(rcDest.left, rcDest.top, cx, cy, dcSource, 0, 0, ROP_DSo);
  2231. }
  2232. }
  2233. // restore all
  2234. dc.SetTextColor(clrTextOld);
  2235. dc.SetBkColor(clrBkOld);
  2236. dcSource.SelectBitmap(hBmpOld);
  2237. dcMask.SelectBitmap(hBmpOld1);
  2238. if(hBmpCheck == NULL)
  2239. bmp.DeleteObject();
  2240. // draw pushed-in hilight
  2241. if(!m_bFlatMenus && !bDisabled)
  2242. {
  2243. if(rc.right - rc.left > size.cx)
  2244. ::InflateRect(&rcDest, 1,1); // inflate checkmark by one pixel all around
  2245. dc.DrawEdge(&rcDest, BDR_SUNKENOUTER, BF_RECT);
  2246. }
  2247. return TRUE;
  2248. }
  2249. void MeasureItem(LPMEASUREITEMSTRUCT lpMeasureItemStruct)
  2250. {
  2251. _MenuItemData* pmd = (_MenuItemData*)lpMeasureItemStruct->itemData;
  2252. if(pmd->fType & MFT_SEPARATOR) // separator - use half system height and zero width
  2253. {
  2254. lpMeasureItemStruct->itemHeight = ::GetSystemMetrics(SM_CYMENU) / 2;
  2255. lpMeasureItemStruct->itemWidth = 0;
  2256. }
  2257. else
  2258. {
  2259. // compute size of text - use DrawText with DT_CALCRECT
  2260. CWindowDC dc(NULL);
  2261. CFont fontBold;
  2262. HFONT hOldFont = NULL;
  2263. if(pmd->fState & MFS_DEFAULT)
  2264. {
  2265. // need bold version of font
  2266. LOGFONT lf = {};
  2267. m_fontMenu.GetLogFont(lf);
  2268. lf.lfWeight += 200;
  2269. fontBold.CreateFontIndirect(&lf);
  2270. ATLASSERT(fontBold.m_hFont != NULL);
  2271. hOldFont = dc.SelectFont(fontBold);
  2272. }
  2273. else
  2274. {
  2275. hOldFont = dc.SelectFont(m_fontMenu);
  2276. }
  2277. RECT rcText = {};
  2278. dc.DrawText(pmd->lpstrText, -1, &rcText, DT_SINGLELINE | DT_LEFT | DT_VCENTER | DT_CALCRECT);
  2279. int cx = rcText.right - rcText.left;
  2280. dc.SelectFont(hOldFont);
  2281. LOGFONT lf = {};
  2282. m_fontMenu.GetLogFont(lf);
  2283. int cy = lf.lfHeight;
  2284. if(cy < 0)
  2285. cy = -cy;
  2286. const int cyMargin = 8;
  2287. cy += cyMargin;
  2288. // height of item is the bigger of these two
  2289. lpMeasureItemStruct->itemHeight = __max(cy, (int)m_szButton.cy);
  2290. // width is width of text plus a bunch of stuff
  2291. cx += 2 * s_kcxTextMargin; // L/R margin for readability
  2292. cx += s_kcxGap; // space between button and menu text
  2293. cx += 2 * m_szButton.cx; // button width (L=button; R=empty margin)
  2294. cx += m_cxExtraSpacing; // extra between item text and accelerator keys
  2295. // Windows adds 1 to returned value
  2296. cx -= ::GetSystemMetrics(SM_CXMENUCHECK) - 1;
  2297. lpMeasureItemStruct->itemWidth = cx; // done deal
  2298. }
  2299. }
  2300. // Implementation - Hook procs
  2301. static LRESULT CALLBACK CreateHookProc(int nCode, WPARAM wParam, LPARAM lParam)
  2302. {
  2303. const int cchClassName = 7;
  2304. TCHAR szClassName[cchClassName] = {};
  2305. if(nCode == HCBT_CREATEWND)
  2306. {
  2307. HWND hWndMenu = (HWND)wParam;
  2308. #ifdef _CMDBAR_EXTRA_TRACE
  2309. ATLTRACE2(atlTraceUI, 0, _T("CmdBar - HCBT_CREATEWND (HWND = %8.8X)\n"), hWndMenu);
  2310. #endif
  2311. ::GetClassName(hWndMenu, szClassName, cchClassName);
  2312. if(!lstrcmp(_T("#32768"), szClassName))
  2313. CCommandBarCtrlBase::s_pCurrentBar->m_stackMenuWnd.Push(hWndMenu);
  2314. }
  2315. else if(nCode == HCBT_DESTROYWND)
  2316. {
  2317. HWND hWndMenu = (HWND)wParam;
  2318. #ifdef _CMDBAR_EXTRA_TRACE
  2319. ATLTRACE2(atlTraceUI, 0, _T("CmdBar - HCBT_DESTROYWND (HWND = %8.8X)\n"), hWndMenu);
  2320. #endif
  2321. ::GetClassName(hWndMenu, szClassName, cchClassName);
  2322. if(!lstrcmp(_T("#32768"), szClassName))
  2323. {
  2324. ATLASSERT(hWndMenu == CCommandBarCtrlBase::s_pCurrentBar->m_stackMenuWnd.GetCurrent());
  2325. CCommandBarCtrlBase::s_pCurrentBar->m_stackMenuWnd.Pop();
  2326. }
  2327. }
  2328. return ::CallNextHookEx(CCommandBarCtrlBase::s_hCreateHook, nCode, wParam, lParam);
  2329. }
  2330. static LRESULT CALLBACK MessageHookProc(int nCode, WPARAM wParam, LPARAM lParam)
  2331. {
  2332. LPMSG pMsg = (LPMSG)lParam;
  2333. if((nCode == HC_ACTION) && (wParam == PM_REMOVE) && (pMsg->message != GetGetBarMessage()) && (pMsg->message != WM_FORWARDMSG))
  2334. {
  2335. CCommandBarCtrlBase* pCmdBar = NULL;
  2336. HWND hWnd = pMsg->hwnd;
  2337. DWORD dwPID = 0;
  2338. while((pCmdBar == NULL) && (hWnd != NULL))
  2339. {
  2340. pCmdBar = (CCommandBarCtrlBase*)::SendMessage(hWnd, GetGetBarMessage(), (WPARAM)&dwPID, 0L);
  2341. hWnd = ::GetParent(hWnd);
  2342. }
  2343. if((pCmdBar != NULL) && (dwPID == GetCurrentProcessId()))
  2344. {
  2345. pCmdBar->m_hWndHook = pMsg->hwnd;
  2346. ATLASSERT(pCmdBar->IsCommandBarBase());
  2347. if(::IsWindow(pCmdBar->m_hWnd))
  2348. pCmdBar->SendMessage(WM_FORWARDMSG, 0, (LPARAM)pMsg);
  2349. else
  2350. ATLTRACE2(atlTraceUI, 0, _T("CmdBar - Hook skipping message, can't find command bar!\n"));
  2351. }
  2352. }
  2353. LRESULT lRet = 0;
  2354. ATLASSERT(CCommandBarCtrlBase::s_pmapMsgHook != NULL);
  2355. if(CCommandBarCtrlBase::s_pmapMsgHook != NULL)
  2356. {
  2357. DWORD dwThreadID = ::GetCurrentThreadId();
  2358. CCommandBarCtrlBase::_MsgHookData* pData = CCommandBarCtrlBase::s_pmapMsgHook->Lookup(dwThreadID);
  2359. if(pData != NULL)
  2360. {
  2361. lRet = ::CallNextHookEx(pData->hMsgHook, nCode, wParam, lParam);
  2362. }
  2363. }
  2364. return lRet;
  2365. }
  2366. // Implementation
  2367. void DoPopupMenu(int nIndex, bool bAnimate)
  2368. {
  2369. #ifdef _CMDBAR_EXTRA_TRACE
  2370. ATLTRACE2(atlTraceUI, 0, _T("CmdBar - DoPopupMenu, bAnimate = %s\n"), bAnimate ? "true" : "false");
  2371. #endif
  2372. T* pT = static_cast<T*>(this);
  2373. // get popup menu and it's position
  2374. RECT rect = {};
  2375. this->GetItemRect(nIndex, &rect);
  2376. POINT pt = { rect.left, rect.bottom };
  2377. this->MapWindowPoints(NULL, &pt, 1);
  2378. this->MapWindowPoints(NULL, &rect);
  2379. TPMPARAMS TPMParams = {};
  2380. TPMParams.cbSize = sizeof(TPMPARAMS);
  2381. TPMParams.rcExclude = rect;
  2382. HMENU hMenuPopup = ::GetSubMenu(m_hMenu, nIndex);
  2383. ATLASSERT(hMenuPopup != NULL);
  2384. // get button ID
  2385. TBBUTTON tbb = {};
  2386. this->GetButton(nIndex, &tbb);
  2387. int nCmdID = tbb.idCommand;
  2388. m_nPopBtn = nIndex; // remember current button's index
  2389. // press button and display popup menu
  2390. this->PressButton(nCmdID, TRUE);
  2391. this->SetHotItem(nCmdID);
  2392. pT->DoTrackPopupMenu(hMenuPopup, TPM_LEFTBUTTON | TPM_VERTICAL | TPM_LEFTALIGN | TPM_TOPALIGN |
  2393. (bAnimate ? TPM_VERPOSANIMATION : TPM_NOANIMATION), pt.x, pt.y, &TPMParams);
  2394. this->PressButton(nCmdID, FALSE);
  2395. if(::GetFocus() != this->m_hWnd)
  2396. this->SetHotItem(-1);
  2397. m_nPopBtn = -1; // restore
  2398. // eat next message if click is on the same button
  2399. MSG msg = {};
  2400. if(::PeekMessage(&msg, this->m_hWnd, WM_LBUTTONDOWN, WM_LBUTTONDOWN, PM_NOREMOVE) && ::PtInRect(&rect, msg.pt))
  2401. ::PeekMessage(&msg, this->m_hWnd, WM_LBUTTONDOWN, WM_LBUTTONDOWN, PM_REMOVE);
  2402. // check if another popup menu should be displayed
  2403. if(m_nNextPopBtn != -1)
  2404. {
  2405. this->PostMessage(GetAutoPopupMessage(), m_nNextPopBtn & 0xFFFF);
  2406. if(!(m_nNextPopBtn & 0xFFFF0000) && !m_bPopupItem)
  2407. this->PostMessage(WM_KEYDOWN, VK_DOWN, 0);
  2408. m_nNextPopBtn = -1;
  2409. }
  2410. else
  2411. {
  2412. m_bContextMenu = false;
  2413. // If user didn't hit escape, give focus back
  2414. if(!m_bEscapePressed)
  2415. {
  2416. if(m_bUseKeyboardCues && m_bShowKeyboardCues)
  2417. m_bAllowKeyboardCues = false;
  2418. pT->GiveFocusBack();
  2419. }
  2420. else
  2421. {
  2422. this->SetHotItem(nCmdID);
  2423. this->SetAnchorHighlight(TRUE);
  2424. }
  2425. }
  2426. }
  2427. BOOL DoTrackPopupMenu(HMENU hMenu, UINT uFlags, int x, int y, LPTPMPARAMS lpParams = NULL)
  2428. {
  2429. CMenuHandle menuPopup = hMenu;
  2430. CWindowCreateCriticalSectionLock lock;
  2431. if(FAILED(lock.Lock()))
  2432. {
  2433. ATLTRACE2(atlTraceUI, 0, _T("ERROR : Unable to lock critical section in CCommandBarCtrlImpl::DoTrackPopupMenu.\n"));
  2434. ATLASSERT(FALSE);
  2435. return FALSE;
  2436. }
  2437. ATLASSERT(this->s_hCreateHook == NULL);
  2438. this->s_pCurrentBar = static_cast<CCommandBarCtrlBase*>(this);
  2439. this->s_hCreateHook = ::SetWindowsHookEx(WH_CBT, CreateHookProc, ModuleHelper::GetModuleInstance(), GetCurrentThreadId());
  2440. ATLASSERT(this->s_hCreateHook != NULL);
  2441. m_bPopupItem = false;
  2442. m_bMenuActive = true;
  2443. BOOL bTrackRet = menuPopup.TrackPopupMenuEx(uFlags, x, y, this->m_hWnd, lpParams);
  2444. m_bMenuActive = false;
  2445. ::UnhookWindowsHookEx(this->s_hCreateHook);
  2446. this->s_hCreateHook = NULL;
  2447. this->s_pCurrentBar = NULL;
  2448. lock.Unlock();
  2449. // cleanup - convert menus back to original state
  2450. #ifdef _CMDBAR_EXTRA_TRACE
  2451. ATLTRACE2(atlTraceUI, 0, _T("CmdBar - TrackPopupMenu - cleanup\n"));
  2452. #endif
  2453. ATLASSERT(this->m_stackMenuWnd.GetSize() == 0);
  2454. this->UpdateWindow();
  2455. ATL::CWindow wndTL = this->GetTopLevelParent();
  2456. wndTL.UpdateWindow();
  2457. // restore the menu items to the previous state for all menus that were converted
  2458. if(m_bImagesVisible)
  2459. {
  2460. HMENU hMenuSav = NULL;
  2461. while((hMenuSav = this->m_stackMenuHandle.Pop()) != NULL)
  2462. {
  2463. menuPopup = hMenuSav;
  2464. BOOL bRet = FALSE;
  2465. // restore state and delete menu item data
  2466. for(int i = 0; i < menuPopup.GetMenuItemCount(); i++)
  2467. {
  2468. CMenuItemInfo mii;
  2469. mii.fMask = MIIM_DATA | MIIM_TYPE | MIIM_ID;
  2470. bRet = menuPopup.GetMenuItemInfo(i, TRUE, &mii);
  2471. ATLASSERT(bRet);
  2472. _MenuItemData* pMI = (_MenuItemData*)mii.dwItemData;
  2473. if(_IsValidMem(pMI) && pMI->IsCmdBarMenuItem())
  2474. {
  2475. mii.fMask = MIIM_DATA | MIIM_TYPE | MIIM_STATE;
  2476. mii.fType = pMI->fType;
  2477. mii.fState = pMI->fState;
  2478. mii.dwTypeData = pMI->lpstrText;
  2479. mii.cch = lstrlen(pMI->lpstrText);
  2480. mii.dwItemData = NULL;
  2481. bRet = menuPopup.SetMenuItemInfo(i, TRUE, &mii);
  2482. // this one triggers WM_MEASUREITEM
  2483. menuPopup.ModifyMenu(i, MF_BYPOSITION | mii.fType | mii.fState, mii.wID, pMI->lpstrText);
  2484. ATLASSERT(bRet);
  2485. delete [] pMI->lpstrText;
  2486. delete pMI;
  2487. }
  2488. }
  2489. }
  2490. }
  2491. return bTrackRet;
  2492. }
  2493. int GetPreviousMenuItem(int nBtn) const
  2494. {
  2495. if(nBtn == -1)
  2496. return -1;
  2497. RECT rcClient = {};
  2498. this->GetClientRect(&rcClient);
  2499. int nNextBtn;
  2500. for(nNextBtn = nBtn - 1; nNextBtn != nBtn; nNextBtn--)
  2501. {
  2502. if(nNextBtn < 0)
  2503. nNextBtn = ::GetMenuItemCount(m_hMenu) - 1;
  2504. TBBUTTON tbb = {};
  2505. this->GetButton(nNextBtn, &tbb);
  2506. RECT rcBtn = {};
  2507. this->GetItemRect(nNextBtn, &rcBtn);
  2508. if(rcBtn.right > rcClient.right)
  2509. {
  2510. nNextBtn = -2; // chevron
  2511. break;
  2512. }
  2513. if(((tbb.fsState & TBSTATE_ENABLED) != 0) && ((tbb.fsState & TBSTATE_HIDDEN) == 0))
  2514. break;
  2515. }
  2516. return (nNextBtn != nBtn) ? nNextBtn : -1;
  2517. }
  2518. int GetNextMenuItem(int nBtn) const
  2519. {
  2520. if(nBtn == -1)
  2521. return -1;
  2522. RECT rcClient = {};
  2523. this->GetClientRect(&rcClient);
  2524. int nNextBtn = 0;
  2525. int nCount = ::GetMenuItemCount(m_hMenu);
  2526. for(nNextBtn = nBtn + 1; nNextBtn != nBtn; nNextBtn++)
  2527. {
  2528. if(nNextBtn >= nCount)
  2529. nNextBtn = 0;
  2530. TBBUTTON tbb = {};
  2531. this->GetButton(nNextBtn, &tbb);
  2532. RECT rcBtn = {};
  2533. this->GetItemRect(nNextBtn, &rcBtn);
  2534. if(rcBtn.right > rcClient.right)
  2535. {
  2536. nNextBtn = -2; // chevron
  2537. break;
  2538. }
  2539. if(((tbb.fsState & TBSTATE_ENABLED) != 0) && ((tbb.fsState & TBSTATE_HIDDEN) == 0))
  2540. break;
  2541. }
  2542. return (nNextBtn != nBtn) ? nNextBtn : -1;
  2543. }
  2544. bool DisplayChevronMenu()
  2545. {
  2546. // assume we are in a rebar
  2547. HWND hWndReBar = this->GetParent();
  2548. int nCount = (int)::SendMessage(hWndReBar, RB_GETBANDCOUNT, 0, 0L);
  2549. bool bRet = false;
  2550. for(int i = 0; i < nCount; i++)
  2551. {
  2552. REBARBANDINFO rbbi = { RunTimeHelper::SizeOf_REBARBANDINFO(), RBBIM_CHILD | RBBIM_STYLE };
  2553. BOOL bRetBandInfo = (BOOL)::SendMessage(hWndReBar, RB_GETBANDINFO, i, (LPARAM)&rbbi);
  2554. if(bRetBandInfo && (rbbi.hwndChild == this->m_hWnd))
  2555. {
  2556. if((rbbi.fStyle & RBBS_USECHEVRON) != 0)
  2557. {
  2558. ::PostMessage(hWndReBar, RB_PUSHCHEVRON, i, 0L);
  2559. this->PostMessage(WM_KEYDOWN, VK_DOWN, 0L);
  2560. bRet = true;
  2561. }
  2562. break;
  2563. }
  2564. }
  2565. return bRet;
  2566. }
  2567. void GetSystemSettings()
  2568. {
  2569. // refresh our font
  2570. NONCLIENTMETRICS info = { RunTimeHelper::SizeOf_NONCLIENTMETRICS() };
  2571. BOOL bRet = ::SystemParametersInfo(SPI_GETNONCLIENTMETRICS, sizeof(info), &info, 0);
  2572. ATLASSERT(bRet);
  2573. if(bRet)
  2574. {
  2575. LOGFONT logfont = {};
  2576. if(m_fontMenu.m_hFont != NULL)
  2577. m_fontMenu.GetLogFont(logfont);
  2578. if((logfont.lfHeight != info.lfMenuFont.lfHeight) ||
  2579. (logfont.lfWidth != info.lfMenuFont.lfWidth) ||
  2580. (logfont.lfEscapement != info.lfMenuFont.lfEscapement) ||
  2581. (logfont.lfOrientation != info.lfMenuFont.lfOrientation) ||
  2582. (logfont.lfWeight != info.lfMenuFont.lfWeight) ||
  2583. (logfont.lfItalic != info.lfMenuFont.lfItalic) ||
  2584. (logfont.lfUnderline != info.lfMenuFont.lfUnderline) ||
  2585. (logfont.lfStrikeOut != info.lfMenuFont.lfStrikeOut) ||
  2586. (logfont.lfCharSet != info.lfMenuFont.lfCharSet) ||
  2587. (logfont.lfOutPrecision != info.lfMenuFont.lfOutPrecision) ||
  2588. (logfont.lfClipPrecision != info.lfMenuFont.lfClipPrecision) ||
  2589. (logfont.lfQuality != info.lfMenuFont.lfQuality) ||
  2590. (logfont.lfPitchAndFamily != info.lfMenuFont.lfPitchAndFamily) ||
  2591. (lstrcmp(logfont.lfFaceName, info.lfMenuFont.lfFaceName) != 0))
  2592. {
  2593. HFONT hFontMenu = ::CreateFontIndirect(&info.lfMenuFont);
  2594. ATLASSERT(hFontMenu != NULL);
  2595. if(hFontMenu != NULL)
  2596. {
  2597. if(m_fontMenu.m_hFont != NULL)
  2598. m_fontMenu.DeleteObject();
  2599. m_fontMenu.Attach(hFontMenu);
  2600. this->SetFont(m_fontMenu);
  2601. this->AddStrings(_T("NS\0")); // for proper item height
  2602. this->AutoSize();
  2603. }
  2604. }
  2605. }
  2606. // check if we need extra spacing for menu item text
  2607. CWindowDC dc(this->m_hWnd);
  2608. HFONT hFontOld = dc.SelectFont(m_fontMenu);
  2609. RECT rcText = {};
  2610. dc.DrawText(_T("\t"), -1, &rcText, DT_SINGLELINE | DT_LEFT | DT_VCENTER | DT_CALCRECT);
  2611. if((rcText.right - rcText.left) < 4)
  2612. {
  2613. ::SetRectEmpty(&rcText);
  2614. dc.DrawText(_T("x"), -1, &rcText, DT_SINGLELINE | DT_LEFT | DT_VCENTER | DT_CALCRECT);
  2615. m_cxExtraSpacing = rcText.right - rcText.left;
  2616. }
  2617. else
  2618. {
  2619. m_cxExtraSpacing = 0;
  2620. }
  2621. dc.SelectFont(hFontOld);
  2622. // get Windows version
  2623. #ifndef _versionhelpers_H_INCLUDED_
  2624. OSVERSIONINFO ovi = { sizeof(OSVERSIONINFO) };
  2625. ::GetVersionEx(&ovi);
  2626. #endif // !_versionhelpers_H_INCLUDED_
  2627. // query keyboard cues mode (Windows 2000 or later)
  2628. #ifdef _versionhelpers_H_INCLUDED_
  2629. if(::IsWindowsVersionOrGreater(5, 0, 0))
  2630. #else // !_versionhelpers_H_INCLUDED_
  2631. if (ovi.dwMajorVersion >= 5)
  2632. #endif // _versionhelpers_H_INCLUDED_
  2633. {
  2634. BOOL bRetVal = TRUE;
  2635. bRet = ::SystemParametersInfo(SPI_GETKEYBOARDCUES, 0, &bRetVal, 0);
  2636. m_bUseKeyboardCues = (bRet && !bRetVal);
  2637. m_bAllowKeyboardCues = true;
  2638. ShowKeyboardCues(!m_bUseKeyboardCues);
  2639. }
  2640. // query flat menu mode (Windows XP or later)
  2641. #ifdef _versionhelpers_H_INCLUDED_
  2642. if(::IsWindowsXPOrGreater())
  2643. #else // !_versionhelpers_H_INCLUDED_
  2644. if (((ovi.dwMajorVersion == 5) && (ovi.dwMinorVersion >= 1)) || (ovi.dwMajorVersion > 5))
  2645. #endif // _versionhelpers_H_INCLUDED_
  2646. {
  2647. BOOL bRetVal = FALSE;
  2648. bRet = ::SystemParametersInfo(SPI_GETFLATMENU, 0, &bRetVal, 0);
  2649. m_bFlatMenus = (bRet && bRetVal);
  2650. }
  2651. #if _WTL_CMDBAR_VISTA_MENUS
  2652. // check if we should use Vista menus
  2653. bool bVistaMenus = (((m_dwExtendedStyle & CBR_EX_NOVISTAMENUS) == 0) && RunTimeHelper::IsVista() && RunTimeHelper::IsThemeAvailable());
  2654. if(!bVistaMenus && m_bVistaMenus && (m_hMenu != NULL) && (m_arrCommand.GetSize() > 0))
  2655. {
  2656. T* pT = static_cast<T*>(this);
  2657. pT->_RemoveVistaBitmapsFromMenu();
  2658. }
  2659. m_bVistaMenus = bVistaMenus;
  2660. #endif // _WTL_CMDBAR_VISTA_MENUS
  2661. #ifdef _CMDBAR_EXTRA_TRACE
  2662. ATLTRACE2(atlTraceUI, 0, _T("CmdBar - GetSystemSettings:\n m_bFlatMenus = %s\n m_bUseKeyboardCues = %s m_bVistaMenus = %s\n"),
  2663. m_bFlatMenus ? "true" : "false", m_bUseKeyboardCues ? "true" : "false", m_bVistaMenus ? "true" : "false");
  2664. #endif
  2665. }
  2666. // Implementation - alternate focus mode support
  2667. void TakeFocus()
  2668. {
  2669. if((m_dwExtendedStyle & CBR_EX_ALTFOCUSMODE) && (m_hWndFocus == NULL))
  2670. m_hWndFocus = ::GetFocus();
  2671. this->SetFocus();
  2672. }
  2673. void GiveFocusBack()
  2674. {
  2675. if(m_bParentActive)
  2676. {
  2677. if((m_dwExtendedStyle & CBR_EX_ALTFOCUSMODE) && ::IsWindow(m_hWndFocus))
  2678. ::SetFocus(m_hWndFocus);
  2679. else if(!(m_dwExtendedStyle & CBR_EX_ALTFOCUSMODE) && m_wndParent.IsWindow())
  2680. m_wndParent.SetFocus();
  2681. }
  2682. m_hWndFocus = NULL;
  2683. this->SetAnchorHighlight(FALSE);
  2684. if(m_bUseKeyboardCues && m_bShowKeyboardCues)
  2685. this->ShowKeyboardCues(false);
  2686. m_bSkipPostDown = false;
  2687. }
  2688. void ShowKeyboardCues(bool bShow)
  2689. {
  2690. m_bShowKeyboardCues = bShow;
  2691. this->SetDrawTextFlags(DT_HIDEPREFIX, m_bShowKeyboardCues ? 0 : DT_HIDEPREFIX);
  2692. this->Invalidate();
  2693. this->UpdateWindow();
  2694. }
  2695. // Implementation - internal message helpers
  2696. static UINT GetAutoPopupMessage()
  2697. {
  2698. static UINT uAutoPopupMessage = 0;
  2699. if(uAutoPopupMessage == 0)
  2700. {
  2701. CStaticDataInitCriticalSectionLock lock;
  2702. if(FAILED(lock.Lock()))
  2703. {
  2704. ATLTRACE2(atlTraceUI, 0, _T("ERROR : Unable to lock critical section in CCommandBarCtrlImpl::GetAutoPopupMessage.\n"));
  2705. ATLASSERT(FALSE);
  2706. return 0;
  2707. }
  2708. if(uAutoPopupMessage == 0)
  2709. uAutoPopupMessage = ::RegisterWindowMessage(_T("WTL_CmdBar_InternalAutoPopupMsg"));
  2710. lock.Unlock();
  2711. }
  2712. ATLASSERT(uAutoPopupMessage != 0);
  2713. return uAutoPopupMessage;
  2714. }
  2715. static UINT GetGetBarMessage()
  2716. {
  2717. static UINT uGetBarMessage = 0;
  2718. if(uGetBarMessage == 0)
  2719. {
  2720. CStaticDataInitCriticalSectionLock lock;
  2721. if(FAILED(lock.Lock()))
  2722. {
  2723. ATLTRACE2(atlTraceUI, 0, _T("ERROR : Unable to lock critical section in CCommandBarCtrlImpl::GetGetBarMessage.\n"));
  2724. ATLASSERT(FALSE);
  2725. return 0;
  2726. }
  2727. if(uGetBarMessage == 0)
  2728. uGetBarMessage = ::RegisterWindowMessage(_T("WTL_CmdBar_InternalGetBarMsg"));
  2729. lock.Unlock();
  2730. }
  2731. ATLASSERT(uGetBarMessage != 0);
  2732. return uGetBarMessage;
  2733. }
  2734. // Implementation
  2735. bool CreateInternalImageList(int cImages)
  2736. {
  2737. UINT uFlags = (m_bAlphaImages ? ILC_COLOR32 : ILC_COLOR24) | ILC_MASK;
  2738. m_hImageList = ::ImageList_Create(m_szBitmap.cx, m_szBitmap.cy, uFlags, cImages, 1);
  2739. ATLASSERT(m_hImageList != NULL);
  2740. return (m_hImageList != NULL);
  2741. }
  2742. // Implementation - support for Vista menus
  2743. #if _WTL_CMDBAR_VISTA_MENUS
  2744. void _AddVistaBitmapsFromImageList(int nStartIndex, int nCount)
  2745. {
  2746. // Create display compatible memory DC
  2747. CClientDC dc(NULL);
  2748. CDC dcMem;
  2749. dcMem.CreateCompatibleDC(dc);
  2750. HBITMAP hBitmapSave = dcMem.GetCurrentBitmap();
  2751. T* pT = static_cast<T*>(this);
  2752. // Create bitmaps for all menu items
  2753. for(int i = 0; i < nCount; i++)
  2754. {
  2755. HBITMAP hBitmap = pT->_CreateVistaBitmapHelper(nStartIndex + i, dc, dcMem);
  2756. dcMem.SelectBitmap(hBitmapSave);
  2757. m_arrVistaBitmap.Add(hBitmap);
  2758. }
  2759. }
  2760. void _AddVistaBitmapFromImageList(int nIndex)
  2761. {
  2762. // Create display compatible memory DC
  2763. CClientDC dc(NULL);
  2764. CDC dcMem;
  2765. dcMem.CreateCompatibleDC(dc);
  2766. HBITMAP hBitmapSave = dcMem.GetCurrentBitmap();
  2767. // Create bitmap for menu item
  2768. T* pT = static_cast<T*>(this);
  2769. HBITMAP hBitmap = pT->_CreateVistaBitmapHelper(nIndex, dc, dcMem);
  2770. // Select saved bitmap back and add bitmap to the array
  2771. dcMem.SelectBitmap(hBitmapSave);
  2772. m_arrVistaBitmap.Add(hBitmap);
  2773. }
  2774. void _ReplaceVistaBitmapFromImageList(int nIndex)
  2775. {
  2776. // Delete existing bitmap
  2777. if(m_arrVistaBitmap[nIndex] != NULL)
  2778. ::DeleteObject(m_arrVistaBitmap[nIndex]);
  2779. // Create display compatible memory DC
  2780. CClientDC dc(NULL);
  2781. CDC dcMem;
  2782. dcMem.CreateCompatibleDC(dc);
  2783. HBITMAP hBitmapSave = dcMem.GetCurrentBitmap();
  2784. // Create bitmap for menu item
  2785. T* pT = static_cast<T*>(this);
  2786. HBITMAP hBitmap = pT->_CreateVistaBitmapHelper(nIndex, dc, dcMem);
  2787. // Select saved bitmap back and replace bitmap in the array
  2788. dcMem.SelectBitmap(hBitmapSave);
  2789. m_arrVistaBitmap.SetAtIndex(nIndex, hBitmap);
  2790. }
  2791. HBITMAP _CreateVistaBitmapHelper(int nIndex, HDC hDCSource, HDC hDCTarget)
  2792. {
  2793. // Create 32-bit bitmap
  2794. BITMAPINFO bi = {};
  2795. bi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
  2796. bi.bmiHeader.biWidth = m_szBitmap.cx;
  2797. bi.bmiHeader.biHeight = m_szBitmap.cy;
  2798. bi.bmiHeader.biPlanes = 1;
  2799. bi.bmiHeader.biBitCount = 32;
  2800. bi.bmiHeader.biCompression = BI_RGB;
  2801. bi.bmiHeader.biSizeImage = 0;
  2802. bi.bmiHeader.biXPelsPerMeter = 0;
  2803. bi.bmiHeader.biYPelsPerMeter = 0;
  2804. bi.bmiHeader.biClrUsed = 0;
  2805. bi.bmiHeader.biClrImportant = 0;
  2806. HBITMAP hBitmap = ::CreateDIBSection(hDCSource, &bi, DIB_RGB_COLORS, NULL, NULL, 0);
  2807. ATLASSERT(hBitmap != NULL);
  2808. // Select bitmap into target DC and draw from image list to it
  2809. if(hBitmap != NULL)
  2810. {
  2811. ::SelectObject(hDCTarget, hBitmap);
  2812. IMAGELISTDRAWPARAMS ildp = {};
  2813. ildp.cbSize = sizeof(IMAGELISTDRAWPARAMS);
  2814. ildp.himl = m_hImageList;
  2815. ildp.i = nIndex;
  2816. ildp.hdcDst = hDCTarget;
  2817. ildp.x = 0;
  2818. ildp.y = 0;
  2819. ildp.cx = 0;
  2820. ildp.cy = 0;
  2821. ildp.xBitmap = 0;
  2822. ildp.yBitmap = 0;
  2823. ildp.fStyle = ILD_TRANSPARENT;
  2824. ildp.fState = ILS_ALPHA;
  2825. ildp.Frame = 255;
  2826. ::ImageList_DrawIndirect(&ildp);
  2827. }
  2828. return hBitmap;
  2829. }
  2830. void _RemoveVistaBitmapsFromMenu()
  2831. {
  2832. CMenuHandle menu = m_hMenu;
  2833. for(int i = 0; i < m_arrCommand.GetSize(); i++)
  2834. {
  2835. CMenuItemInfo mii;
  2836. mii.fMask = MIIM_BITMAP;
  2837. mii.hbmpItem = NULL;
  2838. menu.SetMenuItemInfo(m_arrCommand[i], FALSE, &mii);
  2839. }
  2840. }
  2841. #endif // _WTL_CMDBAR_VISTA_MENUS
  2842. // Implementation helper
  2843. static bool _IsValidMem(void* pMem)
  2844. {
  2845. bool bRet = false;
  2846. if(pMem != NULL)
  2847. {
  2848. MEMORY_BASIC_INFORMATION mbi = {};
  2849. ::VirtualQuery(pMem, &mbi, sizeof(MEMORY_BASIC_INFORMATION));
  2850. bRet = (mbi.BaseAddress != NULL) && ((mbi.Protect & (PAGE_READONLY | PAGE_READWRITE)) != 0);
  2851. }
  2852. return bRet;
  2853. }
  2854. };
  2855. class CCommandBarCtrl : public CCommandBarCtrlImpl<CCommandBarCtrl>
  2856. {
  2857. public:
  2858. DECLARE_WND_SUPERCLASS(_T("WTL_CommandBar"), GetWndClassName())
  2859. };
  2860. ///////////////////////////////////////////////////////////////////////////////
  2861. // CMDICommandBarCtrl - ATL implementation of Command Bars for MDI apps
  2862. template <class T, class TBase = CCommandBarCtrlBase, class TWinTraits = ATL::CControlWinTraits>
  2863. class ATL_NO_VTABLE CMDICommandBarCtrlImpl : public CCommandBarCtrlImpl< T, TBase, TWinTraits>
  2864. {
  2865. public:
  2866. // Data members
  2867. ATL::CContainedWindow m_wndMDIClient;
  2868. bool m_bChildMaximized;
  2869. HWND m_hWndChildMaximized;
  2870. HICON m_hIconChildMaximized;
  2871. int m_nBtnPressed;
  2872. int m_nBtnWasPressed;
  2873. int m_cxyOffset; // offset between nonclient elements
  2874. int m_cxIconWidth; // small icon width
  2875. int m_cyIconHeight; // small icon height
  2876. int m_cxBtnWidth; // nonclient button width
  2877. int m_cyBtnHeight; // nonclient button height
  2878. int m_cxLeft; // left nonclient area width
  2879. int m_cxRight; // right nonclient area width
  2880. HTHEME m_hTheme;
  2881. // Constructor/destructor
  2882. CMDICommandBarCtrlImpl() :
  2883. m_wndMDIClient(this, 2), m_bChildMaximized(false),
  2884. m_hWndChildMaximized(NULL), m_hIconChildMaximized(NULL),
  2885. m_nBtnPressed(-1), m_nBtnWasPressed(-1),
  2886. m_cxyOffset(2),
  2887. m_cxIconWidth(16), m_cyIconHeight(16),
  2888. m_cxBtnWidth(16), m_cyBtnHeight(14),
  2889. m_cxLeft(20), m_cxRight(55),
  2890. m_hTheme(NULL)
  2891. { }
  2892. ~CMDICommandBarCtrlImpl()
  2893. {
  2894. if(m_wndMDIClient.IsWindow())
  2895. /*scary!*/ m_wndMDIClient.UnsubclassWindow();
  2896. }
  2897. // Operations
  2898. BOOL SetMDIClient(HWND hWndMDIClient)
  2899. {
  2900. ATLASSERT(::IsWindow(this->m_hWnd));
  2901. ATLASSERT(::IsWindow(hWndMDIClient));
  2902. if(!::IsWindow(hWndMDIClient))
  2903. return FALSE;
  2904. #ifdef _DEBUG
  2905. // BLOCK: Test if the passed window is MDICLIENT
  2906. {
  2907. LPCTSTR lpszMDIClientClass = _T("MDICLIENT");
  2908. const int nNameLen = 9 + 1; // "MDICLIENT" + NULL
  2909. TCHAR szClassName[nNameLen] = {};
  2910. ::GetClassName(hWndMDIClient, szClassName, nNameLen);
  2911. ATLASSERT(lstrcmpi(szClassName, lpszMDIClientClass) == 0);
  2912. }
  2913. #endif // _DEBUG
  2914. if(m_wndMDIClient.IsWindow())
  2915. /*scary!*/ m_wndMDIClient.UnsubclassWindow();
  2916. return m_wndMDIClient.SubclassWindow(hWndMDIClient);
  2917. }
  2918. // Message maps
  2919. typedef CCommandBarCtrlImpl< T, TBase, TWinTraits > _baseClass;
  2920. BEGIN_MSG_MAP(CMDICommandBarCtrlImpl)
  2921. MESSAGE_HANDLER(WM_CREATE, OnCreate)
  2922. MESSAGE_HANDLER(WM_DESTROY, OnDestroy)
  2923. MESSAGE_HANDLER(WM_THEMECHANGED, OnThemeChanged)
  2924. MESSAGE_HANDLER(WM_SIZE, OnSize)
  2925. MESSAGE_HANDLER(WM_NCCALCSIZE, OnNcCalcSize)
  2926. MESSAGE_HANDLER(WM_NCPAINT, OnNcPaint)
  2927. MESSAGE_HANDLER(WM_NCHITTEST, OnNcHitTest)
  2928. MESSAGE_HANDLER(WM_NCLBUTTONDOWN, OnNcLButtonDown)
  2929. MESSAGE_HANDLER(WM_MOUSEMOVE, OnMouseMove)
  2930. MESSAGE_HANDLER(WM_LBUTTONUP, OnLButtonUp)
  2931. MESSAGE_HANDLER(WM_NCLBUTTONDBLCLK, OnNcLButtonDblClk)
  2932. MESSAGE_HANDLER(WM_CAPTURECHANGED, OnCaptureChanged)
  2933. CHAIN_MSG_MAP(_baseClass)
  2934. ALT_MSG_MAP(1) // Parent window messages
  2935. MESSAGE_HANDLER(WM_ACTIVATE, OnParentActivate)
  2936. CHAIN_MSG_MAP_ALT(_baseClass, 1)
  2937. ALT_MSG_MAP(2) // MDI client window messages
  2938. MESSAGE_HANDLER(WM_MDISETMENU, OnMDISetMenu)
  2939. // no chaining needed since this was moved from the base class here
  2940. ALT_MSG_MAP(3) // Message hook messages
  2941. MESSAGE_RANGE_HANDLER(0, 0xFFFF, OnAllHookMessages)
  2942. CHAIN_MSG_MAP_ALT(_baseClass, 3)
  2943. END_MSG_MAP()
  2944. // Additional MDI message handlers
  2945. LRESULT OnCreate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  2946. {
  2947. LRESULT lRet = _baseClass::OnCreate(uMsg, wParam, lParam, bHandled);
  2948. if(lRet == (LRESULT)-1)
  2949. return lRet;
  2950. T* pT = static_cast<T*>(this);
  2951. pT->_OpenThemeData();
  2952. return lRet;
  2953. }
  2954. LRESULT OnDestroy(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  2955. {
  2956. LRESULT lRet = _baseClass::OnDestroy(uMsg, wParam, lParam, bHandled);
  2957. T* pT = static_cast<T*>(this);
  2958. pT->_CloseThemeData();
  2959. return lRet;
  2960. }
  2961. LRESULT OnThemeChanged(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
  2962. {
  2963. T* pT = static_cast<T*>(this);
  2964. pT->_CloseThemeData();
  2965. pT->_OpenThemeData();
  2966. return 0;
  2967. }
  2968. LRESULT OnSize(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& /*bHandled*/)
  2969. {
  2970. LRESULT lRet = this->DefWindowProc(uMsg, wParam, lParam);
  2971. T* pT = static_cast<T*>(this);
  2972. pT->_AdjustBtnSize(GET_Y_LPARAM(lParam));
  2973. return lRet;
  2974. }
  2975. LRESULT OnNcCalcSize(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& /*bHandled*/)
  2976. {
  2977. LRESULT lRet = this->DefWindowProc(uMsg, wParam, lParam);
  2978. if(m_bChildMaximized && (BOOL)wParam)
  2979. {
  2980. LPNCCALCSIZE_PARAMS lpParams = (LPNCCALCSIZE_PARAMS)lParam;
  2981. if(this->m_bLayoutRTL)
  2982. {
  2983. lpParams->rgrc[0].left += m_cxRight;
  2984. lpParams->rgrc[0].right -= m_cxLeft;
  2985. }
  2986. else
  2987. {
  2988. lpParams->rgrc[0].left += m_cxLeft;
  2989. lpParams->rgrc[0].right -= m_cxRight;
  2990. }
  2991. }
  2992. return lRet;
  2993. }
  2994. LRESULT OnNcPaint(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& /*bHandled*/)
  2995. {
  2996. LRESULT lRet = this->DefWindowProc(uMsg, wParam, lParam);
  2997. if(!m_bChildMaximized)
  2998. return lRet;
  2999. ATLASSERT((m_hWndChildMaximized != NULL) && (m_hIconChildMaximized != NULL));
  3000. // get DC and window rectangle
  3001. CWindowDC dc(this->m_hWnd);
  3002. RECT rect = {};
  3003. this->GetWindowRect(&rect);
  3004. int cxWidth = rect.right - rect.left;
  3005. int cyHeight = rect.bottom - rect.top;
  3006. // paint left side nonclient background and draw icon
  3007. ::SetRect(&rect, 0, 0, m_cxLeft, cyHeight);
  3008. if(m_hTheme != NULL)
  3009. {
  3010. ::DrawThemeParentBackground(this->m_hWnd, dc, &rect);
  3011. }
  3012. else
  3013. {
  3014. if((this->m_dwExtendedStyle & CBR_EX_TRANSPARENT) != 0)
  3015. dc.FillRect(&rect, COLOR_3DFACE);
  3016. else
  3017. dc.FillRect(&rect, COLOR_MENU);
  3018. }
  3019. RECT rcIcon = {};
  3020. T* pT = static_cast<T*>(this);
  3021. pT->_CalcIconRect(cxWidth, cyHeight, rcIcon);
  3022. dc.DrawIconEx(rcIcon.left, rcIcon.top, m_hIconChildMaximized, m_cxIconWidth, m_cyIconHeight);
  3023. // paint right side nonclient background
  3024. ::SetRect(&rect, cxWidth - m_cxRight, 0, cxWidth, cyHeight);
  3025. if(m_hTheme != NULL)
  3026. {
  3027. // this is to account for the left non-client area
  3028. POINT ptOrg = {};
  3029. dc.GetViewportOrg(&ptOrg);
  3030. dc.SetViewportOrg(ptOrg.x + m_cxLeft, ptOrg.y);
  3031. ::OffsetRect(&rect, -m_cxLeft, 0);
  3032. ::DrawThemeParentBackground(this->m_hWnd, dc, &rect);
  3033. // restore
  3034. dc.SetViewportOrg(ptOrg);
  3035. ::OffsetRect(&rect, m_cxLeft, 0);
  3036. }
  3037. else
  3038. {
  3039. if((this->m_dwExtendedStyle & CBR_EX_TRANSPARENT) != 0)
  3040. dc.FillRect(&rect, COLOR_3DFACE);
  3041. else
  3042. dc.FillRect(&rect, COLOR_MENU);
  3043. }
  3044. // draw buttons
  3045. RECT arrRect[3] = {};
  3046. pT->_CalcBtnRects(cxWidth, cyHeight, arrRect);
  3047. pT->_DrawMDIButton(dc, arrRect, -1); // draw all buttons
  3048. return lRet;
  3049. }
  3050. LRESULT OnNcHitTest(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& /*bHandled*/)
  3051. {
  3052. LRESULT lRet = this->DefWindowProc(uMsg, wParam, lParam);
  3053. if(m_bChildMaximized)
  3054. {
  3055. RECT rect = {};
  3056. this->GetWindowRect(&rect);
  3057. POINT pt = { GET_X_LPARAM(lParam) - rect.left, GET_Y_LPARAM(lParam) - rect.top };
  3058. if(this->m_bLayoutRTL)
  3059. {
  3060. if((pt.x < m_cxRight) || (pt.x > ((rect.right - rect.left) - m_cxLeft)))
  3061. lRet = HTBORDER;
  3062. }
  3063. else
  3064. {
  3065. if((pt.x < m_cxLeft) || (pt.x > ((rect.right - rect.left) - m_cxRight)))
  3066. lRet = HTBORDER;
  3067. }
  3068. }
  3069. return lRet;
  3070. }
  3071. LRESULT OnNcLButtonDown(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM lParam, BOOL& bHandled)
  3072. {
  3073. if(!m_bChildMaximized)
  3074. {
  3075. bHandled = FALSE;
  3076. return 1;
  3077. }
  3078. ATLASSERT(_DebugCheckChild());
  3079. POINT pt = { GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam) };
  3080. RECT rect = {};
  3081. this->GetWindowRect(&rect);
  3082. pt.x -= rect.left;
  3083. pt.y -= rect.top;
  3084. RECT rcIcon = {};
  3085. T* pT = static_cast<T*>(this);
  3086. pT->_CalcIconRect(rect.right - rect.left, rect.bottom - rect.top, rcIcon, this->m_bLayoutRTL);
  3087. RECT arrRect[3] = {};
  3088. pT->_CalcBtnRects(rect.right - rect.left, rect.bottom - rect.top, arrRect, this->m_bLayoutRTL);
  3089. if(::PtInRect(&rcIcon, pt))
  3090. {
  3091. #ifdef _CMDBAR_EXTRA_TRACE
  3092. ATLTRACE2(atlTraceUI, 0, _T("MDI CmdBar - LButtonDown: icon\n"));
  3093. #endif
  3094. CMenuHandle menu = ::GetSystemMenu(m_hWndChildMaximized, FALSE);
  3095. UINT uRet = (UINT)menu.TrackPopupMenu(TPM_LEFTBUTTON | TPM_VERTICAL | TPM_LEFTALIGN | TPM_TOPALIGN | TPM_RETURNCMD |
  3096. TPM_VERPOSANIMATION, this->m_bLayoutRTL ? rect.right : rect.left, rect.bottom, m_hWndChildMaximized);
  3097. // eat next message if click is on the same button
  3098. ::OffsetRect(&rcIcon, rect.left, rect.top);
  3099. MSG msg = {};
  3100. if(::PeekMessage(&msg, this->m_hWnd, WM_NCLBUTTONDOWN, WM_NCLBUTTONDOWN, PM_NOREMOVE) && ::PtInRect(&rcIcon, msg.pt))
  3101. ::PeekMessage(&msg, this->m_hWnd, WM_NCLBUTTONDOWN, WM_NCLBUTTONDOWN, PM_REMOVE);
  3102. if(uRet != 0)
  3103. ::SendMessage(m_hWndChildMaximized, WM_SYSCOMMAND, uRet, 0L);
  3104. }
  3105. else if(::PtInRect(&arrRect[0], pt))
  3106. {
  3107. #ifdef _CMDBAR_EXTRA_TRACE
  3108. ATLTRACE2(atlTraceUI, 0, _T("MDI CmdBar - LButtonDown: close button\n"));
  3109. #endif
  3110. m_nBtnWasPressed = m_nBtnPressed = 0;
  3111. }
  3112. else if(::PtInRect(&arrRect[1], pt))
  3113. {
  3114. #ifdef _CMDBAR_EXTRA_TRACE
  3115. ATLTRACE2(atlTraceUI, 0, _T("MDI CmdBar - LButtonDown: restore button\n"));
  3116. #endif
  3117. m_nBtnWasPressed = m_nBtnPressed = 1;
  3118. }
  3119. else if(::PtInRect(&arrRect[2], pt))
  3120. {
  3121. #ifdef _CMDBAR_EXTRA_TRACE
  3122. ATLTRACE2(atlTraceUI, 0, _T("MDI CmdBar - LButtonDown: minimize button\n"));
  3123. #endif
  3124. m_nBtnWasPressed = m_nBtnPressed = 2;
  3125. }
  3126. else
  3127. {
  3128. bHandled = FALSE;
  3129. }
  3130. // draw the button state if it was pressed
  3131. if(m_nBtnPressed != -1)
  3132. {
  3133. this->SetCapture();
  3134. CWindowDC dc(this->m_hWnd);
  3135. pT->_CalcBtnRects(rect.right - rect.left, rect.bottom - rect.top, arrRect);
  3136. pT->_DrawMDIButton(dc, arrRect, m_nBtnPressed);
  3137. }
  3138. return 0;
  3139. }
  3140. LRESULT OnMouseMove(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM lParam, BOOL& bHandled)
  3141. {
  3142. if(!m_bChildMaximized || (::GetCapture() != this->m_hWnd) || (m_nBtnWasPressed == -1))
  3143. {
  3144. bHandled = FALSE;
  3145. return 1;
  3146. }
  3147. POINT pt = { GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam) };
  3148. this->ClientToScreen(&pt);
  3149. RECT rect = {};
  3150. this->GetWindowRect(&rect);
  3151. pt.x -= rect.left;
  3152. pt.y -= rect.top;
  3153. RECT arrRect[3] = {};
  3154. T* pT = static_cast<T*>(this);
  3155. pT->_CalcBtnRects(rect.right - rect.left, rect.bottom - rect.top, arrRect, this->m_bLayoutRTL);
  3156. int nOldBtnPressed = m_nBtnPressed;
  3157. m_nBtnPressed = ::PtInRect(&arrRect[m_nBtnWasPressed], pt) ? m_nBtnWasPressed : -1;
  3158. if(nOldBtnPressed != m_nBtnPressed)
  3159. {
  3160. CWindowDC dc(this->m_hWnd);
  3161. pT->_CalcBtnRects(rect.right - rect.left, rect.bottom - rect.top, arrRect);
  3162. pT->_DrawMDIButton(dc, arrRect, (m_nBtnPressed != -1) ? m_nBtnPressed : nOldBtnPressed);
  3163. }
  3164. return 0;
  3165. }
  3166. LRESULT OnLButtonUp(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM lParam, BOOL& bHandled)
  3167. {
  3168. if(!m_bChildMaximized || (::GetCapture() != this->m_hWnd) || (m_nBtnWasPressed == -1))
  3169. {
  3170. bHandled = FALSE;
  3171. return 1;
  3172. }
  3173. ATLASSERT(_DebugCheckChild());
  3174. POINT pt = { GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam) };
  3175. this->ClientToScreen(&pt);
  3176. RECT rect = {};
  3177. this->GetWindowRect(&rect);
  3178. pt.x -= rect.left;
  3179. pt.y -= rect.top;
  3180. int nBtn = m_nBtnWasPressed;
  3181. ReleaseCapture();
  3182. RECT arrRect[3] = {};
  3183. T* pT = static_cast<T*>(this);
  3184. pT->_CalcBtnRects(rect.right - rect.left, rect.bottom - rect.top, arrRect, this->m_bLayoutRTL);
  3185. if(::PtInRect(&arrRect[nBtn], pt))
  3186. {
  3187. switch(nBtn)
  3188. {
  3189. case 0: // close
  3190. #ifdef _CMDBAR_EXTRA_TRACE
  3191. ATLTRACE2(atlTraceUI, 0, _T("MDI CmdBar - LButtonUp: close button\n"));
  3192. #endif
  3193. ::SendMessage(m_hWndChildMaximized, WM_SYSCOMMAND, SC_CLOSE, 0L);
  3194. break;
  3195. case 1: // restore
  3196. #ifdef _CMDBAR_EXTRA_TRACE
  3197. ATLTRACE2(atlTraceUI, 0, _T("MDI CmdBar - LButtonUp: restore button\n"));
  3198. #endif
  3199. ::SendMessage(m_hWndChildMaximized, WM_SYSCOMMAND, SC_RESTORE, 0L);
  3200. break;
  3201. case 2: // minimize
  3202. #ifdef _CMDBAR_EXTRA_TRACE
  3203. ATLTRACE2(atlTraceUI, 0, _T("MDI CmdBar - LButtonUp: minimize button\n"));
  3204. #endif
  3205. ::SendMessage(m_hWndChildMaximized, WM_SYSCOMMAND, SC_MINIMIZE, 0L);
  3206. break;
  3207. default:
  3208. break;
  3209. }
  3210. }
  3211. return 0;
  3212. }
  3213. LRESULT OnNcLButtonDblClk(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM lParam, BOOL& bHandled)
  3214. {
  3215. if(!m_bChildMaximized || (m_nBtnWasPressed != -1))
  3216. {
  3217. bHandled = FALSE;
  3218. return 1;
  3219. }
  3220. ATLASSERT(_DebugCheckChild());
  3221. POINT pt = { GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam) };
  3222. RECT rect = {};
  3223. this->GetWindowRect(&rect);
  3224. pt.x -= rect.left;
  3225. pt.y -= rect.top;
  3226. RECT rcIcon = {};
  3227. T* pT = static_cast<T*>(this);
  3228. pT->_CalcIconRect(rect.right - rect.left, rect.bottom - rect.top, rcIcon, this->m_bLayoutRTL);
  3229. RECT arrRect[3] = {};
  3230. pT->_CalcBtnRects(rect.right - rect.left, rect.bottom - rect.top, arrRect, this->m_bLayoutRTL);
  3231. if(::PtInRect(&rcIcon, pt))
  3232. {
  3233. CMenuHandle menu = ::GetSystemMenu(m_hWndChildMaximized, FALSE);
  3234. UINT uDefID = menu.GetMenuDefaultItem();
  3235. if(uDefID == (UINT)-1)
  3236. uDefID = SC_CLOSE;
  3237. ::SendMessage(m_hWndChildMaximized, WM_SYSCOMMAND, uDefID, 0L);
  3238. }
  3239. return 0;
  3240. }
  3241. LRESULT OnCaptureChanged(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& bHandled)
  3242. {
  3243. if(m_bChildMaximized)
  3244. {
  3245. if(m_nBtnPressed != -1)
  3246. {
  3247. ATLASSERT(m_nBtnPressed == m_nBtnWasPressed); // must be
  3248. m_nBtnPressed = -1;
  3249. RECT rect = {};
  3250. this->GetWindowRect(&rect);
  3251. RECT arrRect[3] = {};
  3252. T* pT = static_cast<T*>(this);
  3253. pT->_CalcBtnRects(rect.right - rect.left, rect.bottom - rect.top, arrRect);
  3254. CWindowDC dc(this->m_hWnd);
  3255. pT->_DrawMDIButton(dc, arrRect, m_nBtnWasPressed);
  3256. }
  3257. m_nBtnWasPressed = -1;
  3258. }
  3259. else
  3260. {
  3261. bHandled = FALSE;
  3262. }
  3263. return 0;
  3264. }
  3265. // Parent window message handlers
  3266. LRESULT OnParentActivate(UINT /*uMsg*/, WPARAM wParam, LPARAM /*lParam*/, BOOL& bHandled)
  3267. {
  3268. this->m_bParentActive = (LOWORD(wParam) != WA_INACTIVE);
  3269. this->RedrawWindow(NULL, NULL, RDW_INVALIDATE | RDW_FRAME | RDW_UPDATENOW);
  3270. bHandled = FALSE;
  3271. return 1;
  3272. }
  3273. // MDI client window message handlers
  3274. LRESULT OnMDISetMenu(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& /*bHandled*/)
  3275. {
  3276. m_wndMDIClient.DefWindowProc(uMsg, NULL, lParam);
  3277. HMENU hOldMenu = this->GetMenu();
  3278. BOOL bRet = this->AttachMenu((HMENU)wParam);
  3279. (void)bRet; // avoid level 4 warning
  3280. ATLASSERT(bRet);
  3281. T* pT = static_cast<T*>(this);
  3282. pT->UpdateRebarBandIdealSize();
  3283. return (LRESULT)hOldMenu;
  3284. }
  3285. // All messages from the message hook
  3286. LRESULT OnAllHookMessages(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  3287. {
  3288. T* pT = static_cast<T*>(this);
  3289. pT->_ProcessAllHookMessages(uMsg, wParam, lParam);
  3290. bHandled = FALSE;
  3291. return 1;
  3292. }
  3293. // Overrideables
  3294. // override this to provide different ideal size
  3295. void UpdateRebarBandIdealSize()
  3296. {
  3297. // assuming we are in a rebar, change ideal size to our size
  3298. // we hope that if we are not in a rebar, nCount will be 0
  3299. ATL::CWindow wndParent = this->GetParent();
  3300. int nCount = (int)wndParent.SendMessage(RB_GETBANDCOUNT, 0, 0L);
  3301. for(int i = 0; i < nCount; i++)
  3302. {
  3303. REBARBANDINFO rbi = { RunTimeHelper::SizeOf_REBARBANDINFO(), RBBIM_CHILD | RBBIM_CHILDSIZE | RBBIM_IDEALSIZE };
  3304. wndParent.SendMessage(RB_GETBANDINFO, i, (LPARAM)&rbi);
  3305. if(rbi.hwndChild == this->m_hWnd)
  3306. {
  3307. rbi.fMask = RBBIM_IDEALSIZE;
  3308. rbi.cxIdeal = m_bChildMaximized ? m_cxLeft + m_cxRight : 0;
  3309. int nBtnCount = this->GetButtonCount();
  3310. if(nBtnCount > 0)
  3311. {
  3312. RECT rect = {};
  3313. this->GetItemRect(nBtnCount - 1, &rect);
  3314. rbi.cxIdeal += rect.right;
  3315. }
  3316. wndParent.SendMessage(RB_SETBANDINFO, i, (LPARAM)&rbi);
  3317. break;
  3318. }
  3319. }
  3320. }
  3321. // all hook messages - check for the maximized MDI child window change
  3322. void _ProcessAllHookMessages(UINT uMsg, WPARAM /*wParam*/, LPARAM /*lParam*/)
  3323. {
  3324. if((uMsg == WM_MDIGETACTIVE) || (uMsg == WM_MDISETMENU))
  3325. return;
  3326. BOOL bMaximized = FALSE;
  3327. HWND hWndChild = (HWND)::SendMessage(m_wndMDIClient, WM_MDIGETACTIVE, 0, (LPARAM)&bMaximized);
  3328. bool bMaxOld = m_bChildMaximized;
  3329. m_bChildMaximized = ((hWndChild != NULL) && bMaximized);
  3330. HICON hIconOld = m_hIconChildMaximized;
  3331. if(m_bChildMaximized)
  3332. {
  3333. if(m_hWndChildMaximized != hWndChild)
  3334. {
  3335. ATL::CWindow wnd = m_hWndChildMaximized = hWndChild;
  3336. m_hIconChildMaximized = wnd.GetIcon(FALSE);
  3337. if(m_hIconChildMaximized == NULL)
  3338. {
  3339. m_hIconChildMaximized = wnd.GetIcon(TRUE);
  3340. if(m_hIconChildMaximized == NULL) // no icon set with WM_SETICON, get the class one
  3341. m_hIconChildMaximized = (HICON)::GetClassLongPtr(wnd, GCLP_HICONSM);
  3342. }
  3343. }
  3344. }
  3345. else
  3346. {
  3347. m_hWndChildMaximized = NULL;
  3348. m_hIconChildMaximized = NULL;
  3349. }
  3350. if(bMaxOld != m_bChildMaximized)
  3351. {
  3352. #ifdef _CMDBAR_EXTRA_TRACE
  3353. ATLTRACE2(atlTraceUI, 0, _T("MDI CmdBar - All messages hook change: m_bChildMaximized = %s\n"), m_bChildMaximized ? "true" : "false");
  3354. #endif
  3355. // assuming we are in a rebar, change our size to accomodate new state
  3356. // we hope that if we are not in a rebar, nCount will be 0
  3357. ATL::CWindow wndParent = this->GetParent();
  3358. int nCount = (int)wndParent.SendMessage(RB_GETBANDCOUNT, 0, 0L);
  3359. int cxDiff = (m_bChildMaximized ? 1 : -1) * (m_cxLeft + m_cxRight);
  3360. for(int i = 0; i < nCount; i++)
  3361. {
  3362. REBARBANDINFO rbi = { RunTimeHelper::SizeOf_REBARBANDINFO(), RBBIM_CHILD | RBBIM_CHILDSIZE | RBBIM_IDEALSIZE | RBBIM_STYLE };
  3363. wndParent.SendMessage(RB_GETBANDINFO, i, (LPARAM)&rbi);
  3364. if(rbi.hwndChild == this->m_hWnd)
  3365. {
  3366. if((rbi.fStyle & RBBS_USECHEVRON) != 0)
  3367. {
  3368. rbi.fMask = RBBIM_CHILDSIZE | RBBIM_IDEALSIZE;
  3369. rbi.cxMinChild += cxDiff;
  3370. rbi.cxIdeal += cxDiff;
  3371. wndParent.SendMessage(RB_SETBANDINFO, i, (LPARAM)&rbi);
  3372. }
  3373. break;
  3374. }
  3375. }
  3376. }
  3377. if((bMaxOld != m_bChildMaximized) || (hIconOld != m_hIconChildMaximized))
  3378. {
  3379. // force size change and redraw everything
  3380. RECT rect = {};
  3381. this->GetWindowRect(&rect);
  3382. ::MapWindowPoints(NULL, this->GetParent(), (LPPOINT)&rect, 2);
  3383. this->SetRedraw(FALSE);
  3384. this->SetWindowPos(NULL, 0, 0, 1, 1, SWP_NOZORDER | SWP_NOMOVE);
  3385. this->SetWindowPos(NULL, &rect, SWP_NOZORDER | SWP_NOMOVE);
  3386. this->SetRedraw(TRUE);
  3387. this->RedrawWindow(NULL, NULL, RDW_FRAME | RDW_INVALIDATE | RDW_UPDATENOW);
  3388. }
  3389. }
  3390. // Implementation
  3391. void GetSystemSettings()
  3392. {
  3393. #ifdef _CMDBAR_EXTRA_TRACE
  3394. ATLTRACE2(atlTraceUI, 0, _T("MDI CmdBar - GetSystemSettings\n"));
  3395. #endif
  3396. _baseClass::GetSystemSettings();
  3397. NONCLIENTMETRICS info = { RunTimeHelper::SizeOf_NONCLIENTMETRICS() };
  3398. BOOL bRet = ::SystemParametersInfo(SPI_GETNONCLIENTMETRICS, sizeof(info), &info, 0);
  3399. ATLASSERT(bRet);
  3400. if(bRet)
  3401. {
  3402. m_cxIconWidth = ::GetSystemMetrics(SM_CXSMICON);
  3403. m_cyIconHeight = ::GetSystemMetrics(SM_CYSMICON);
  3404. m_cxLeft = m_cxIconWidth;
  3405. if(m_hTheme != NULL)
  3406. {
  3407. m_cxBtnWidth = info.iCaptionWidth - 2 * m_cxyOffset;
  3408. m_cyBtnHeight = info.iCaptionHeight - 2 * m_cxyOffset;
  3409. m_cxRight = 3 * m_cxBtnWidth;
  3410. }
  3411. else
  3412. {
  3413. m_cxBtnWidth = info.iCaptionWidth - m_cxyOffset;
  3414. m_cyBtnHeight = info.iCaptionHeight - 2 * m_cxyOffset;
  3415. m_cxRight = 3 * m_cxBtnWidth + m_cxyOffset;
  3416. }
  3417. }
  3418. RECT rect = {};
  3419. this->GetClientRect(&rect);
  3420. T* pT = static_cast<T*>(this);
  3421. pT->_AdjustBtnSize(rect.bottom);
  3422. }
  3423. void _AdjustBtnSize(int cyHeight)
  3424. {
  3425. if((cyHeight > 1) && (m_cyBtnHeight > cyHeight))
  3426. {
  3427. if(m_hTheme != NULL)
  3428. {
  3429. m_cyBtnHeight = cyHeight;
  3430. m_cxBtnWidth = cyHeight;
  3431. m_cxRight = 3 * m_cxBtnWidth;
  3432. }
  3433. else
  3434. {
  3435. m_cyBtnHeight = cyHeight;
  3436. m_cxBtnWidth = cyHeight + m_cxyOffset;
  3437. m_cxRight = 3 * m_cxBtnWidth + m_cxyOffset;
  3438. }
  3439. }
  3440. }
  3441. void _CalcIconRect(int cxWidth, int cyHeight, RECT& rect, bool bInvertX = false) const
  3442. {
  3443. int xStart = (m_cxLeft - m_cxIconWidth) / 2;
  3444. if(xStart < 0)
  3445. xStart = 0;
  3446. int yStart = (cyHeight - m_cyIconHeight) / 2;
  3447. if(yStart < 0)
  3448. yStart = 0;
  3449. if(bInvertX)
  3450. ::SetRect(&rect, cxWidth - (xStart + m_cxBtnWidth), yStart, cxWidth - xStart, yStart + m_cyBtnHeight);
  3451. else
  3452. ::SetRect(&rect, xStart, yStart, xStart + m_cxBtnWidth, yStart + m_cyBtnHeight);
  3453. }
  3454. void _CalcBtnRects(int cxWidth, int cyHeight, RECT arrRect[3], bool bInvertX = false) const
  3455. {
  3456. int yStart = (cyHeight - m_cyBtnHeight) / 2;
  3457. if(yStart < 0)
  3458. yStart = 0;
  3459. RECT rcBtn = { cxWidth - m_cxBtnWidth, yStart, cxWidth, yStart + m_cyBtnHeight };
  3460. int nDirection = -1;
  3461. if(bInvertX)
  3462. {
  3463. ::SetRect(&rcBtn, 0, yStart, m_cxBtnWidth, yStart + m_cyBtnHeight);
  3464. nDirection = 1;
  3465. }
  3466. arrRect[0] = rcBtn;
  3467. if(m_hTheme != NULL)
  3468. ::OffsetRect(&rcBtn, nDirection * m_cxBtnWidth, 0);
  3469. else
  3470. ::OffsetRect(&rcBtn, nDirection * (m_cxBtnWidth + m_cxyOffset), 0);
  3471. arrRect[1] = rcBtn;
  3472. ::OffsetRect(&rcBtn, nDirection * m_cxBtnWidth, 0);
  3473. arrRect[2] = rcBtn;
  3474. }
  3475. void _DrawMDIButton(CWindowDC& dc, LPRECT pRects, int nBtn)
  3476. {
  3477. if(m_hTheme != NULL)
  3478. {
  3479. #ifndef __VSSYM32_H__
  3480. const int WP_MDICLOSEBUTTON = 20;
  3481. const int CBS_NORMAL = 1;
  3482. const int CBS_PUSHED = 3;
  3483. const int CBS_DISABLED = 4;
  3484. const int WP_MDIRESTOREBUTTON = 22;
  3485. const int RBS_NORMAL = 1;
  3486. const int RBS_PUSHED = 3;
  3487. const int RBS_DISABLED = 4;
  3488. const int WP_MDIMINBUTTON = 16;
  3489. const int MINBS_NORMAL = 1;
  3490. const int MINBS_PUSHED = 3;
  3491. const int MINBS_DISABLED = 4;
  3492. #endif // __VSSYM32_H__
  3493. if((nBtn == -1) || (nBtn == 0))
  3494. ::DrawThemeBackground(m_hTheme, dc, WP_MDICLOSEBUTTON, this->m_bParentActive ? ((m_nBtnPressed == 0) ? CBS_PUSHED : CBS_NORMAL) : CBS_DISABLED, &pRects[0], NULL);
  3495. if((nBtn == -1) || (nBtn == 1))
  3496. ::DrawThemeBackground(m_hTheme, dc, WP_MDIRESTOREBUTTON, this->m_bParentActive ? ((m_nBtnPressed == 1) ? RBS_PUSHED : RBS_NORMAL) : RBS_DISABLED, &pRects[1], NULL);
  3497. if((nBtn == -1) || (nBtn == 2))
  3498. ::DrawThemeBackground(m_hTheme, dc, WP_MDIMINBUTTON, this->m_bParentActive ? ((m_nBtnPressed == 2) ? MINBS_PUSHED : MINBS_NORMAL) : MINBS_DISABLED, &pRects[2], NULL);
  3499. }
  3500. else
  3501. {
  3502. if((nBtn == -1) || (nBtn == 0))
  3503. dc.DrawFrameControl(&pRects[0], DFC_CAPTION, DFCS_CAPTIONCLOSE | ((m_nBtnPressed == 0) ? DFCS_PUSHED : 0));
  3504. if((nBtn == -1) || (nBtn == 1))
  3505. dc.DrawFrameControl(&pRects[1], DFC_CAPTION, DFCS_CAPTIONRESTORE | ((m_nBtnPressed == 1) ? DFCS_PUSHED : 0));
  3506. if((nBtn == -1) || (nBtn == 2))
  3507. dc.DrawFrameControl(&pRects[2], DFC_CAPTION, DFCS_CAPTIONMIN | ((m_nBtnPressed == 2) ? DFCS_PUSHED : 0));
  3508. }
  3509. }
  3510. void _OpenThemeData()
  3511. {
  3512. if(RunTimeHelper::IsThemeAvailable())
  3513. m_hTheme = ::OpenThemeData(this->m_hWnd, L"Window");
  3514. }
  3515. void _CloseThemeData()
  3516. {
  3517. if(m_hTheme != NULL)
  3518. {
  3519. ::CloseThemeData(m_hTheme);
  3520. m_hTheme = NULL;
  3521. }
  3522. }
  3523. bool _DebugCheckChild()
  3524. {
  3525. #ifdef _DEBUG
  3526. BOOL bMaximized = FALSE;
  3527. HWND hWndChild = (HWND)::SendMessage(m_wndMDIClient, WM_MDIGETACTIVE, 0, (LPARAM)&bMaximized);
  3528. return (bMaximized && (hWndChild == m_hWndChildMaximized));
  3529. #else // !_DEBUG
  3530. return true;
  3531. #endif // !_DEBUG
  3532. }
  3533. };
  3534. class CMDICommandBarCtrl : public CMDICommandBarCtrlImpl<CMDICommandBarCtrl>
  3535. {
  3536. public:
  3537. DECLARE_WND_SUPERCLASS(_T("WTL_MDICommandBar"), GetWndClassName())
  3538. };
  3539. } // namespace WTL
  3540. #endif // __ATLCTRLW_H__