atlctrlw.h 111 KB

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