BCMenu.cpp 84 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103
  1. //*************************************************************************
  2. // BCMenu.cpp : implementation file
  3. // Version : 3.02
  4. // Date : March 2002
  5. // Author : Brent Corkum
  6. // Email : corkum@rocscience.com
  7. // Latest Version : http://www.rocscience.com/~corkum/BCMenu.html
  8. //
  9. // Bug Fixes and portions of code supplied by:
  10. //
  11. // Ben Ashley,Girish Bharadwaj,Jean-Edouard Lachand-Robert,
  12. // Robert Edward Caldecott,Kenny Goers,Leonardo Zide,
  13. // Stefan Kuhr,Reiner Jung,Martin Vladic,Kim Yoo Chul,
  14. // Oz Solomonovich,Tongzhe Cui,Stephane Clog,Warren Stevens,
  15. // Damir Valiulin,David Kinder,Marc Loiry
  16. //
  17. // You are free to use/modify this code but leave this header intact.
  18. // This class is public domain so you are free to use it any of
  19. // your applications (Freeware,Shareware,Commercial). All I ask is
  20. // that you let me know so that if you have a real winner I can
  21. // brag to my buddies that some of my code is in your app. I also
  22. // wouldn't mind if you sent me a copy of your application since I
  23. // like to play with new stuff.
  24. //*************************************************************************
  25. #include "stdafx.h" // Standard windows header file
  26. #include "BCMenu.h" // BCMenu class declaration
  27. #include <afxpriv.h> //SK: makes A2W and other spiffy AFX macros work
  28. #ifdef _DEBUG
  29. #define new DEBUG_NEW
  30. #undef THIS_FILE
  31. static char THIS_FILE[] = __FILE__;
  32. #endif
  33. #define BCMENU_GAP 1
  34. #ifndef OBM_CHECK
  35. #define OBM_CHECK 32760 // from winuser.h
  36. #endif
  37. #if _MFC_VER <0x400
  38. #error This code does not work on Versions of MFC prior to 4.0
  39. #endif
  40. static CPINFO CPInfo;
  41. // how the menu's are drawn in win9x/NT/2000
  42. UINT BCMenu::original_drawmode=BCMENU_DRAWMODE_ORIGINAL;
  43. BOOL BCMenu::original_select_disabled=TRUE;
  44. // how the menu's are drawn in winXP
  45. UINT BCMenu::xp_drawmode=BCMENU_DRAWMODE_XP;
  46. BOOL BCMenu::xp_select_disabled=FALSE;
  47. BOOL BCMenu::xp_draw_3D_bitmaps=TRUE;
  48. CImageList BCMenu::m_AllImages;
  49. CArray<int,int&> BCMenu::m_AllImagesID;
  50. enum Win32Type{
  51. Win32s,
  52. WinNT3,
  53. Win95,
  54. Win98,
  55. WinME,
  56. WinNT4,
  57. Win2000,
  58. WinXP
  59. };
  60. Win32Type IsShellType()
  61. {
  62. Win32Type ShellType;
  63. DWORD winVer;
  64. OSVERSIONINFO *osvi;
  65. winVer=GetVersion();
  66. if(winVer<0x80000000){/*NT */
  67. ShellType=WinNT3;
  68. osvi= (OSVERSIONINFO *)malloc(sizeof(OSVERSIONINFO));
  69. if (osvi!=NULL){
  70. memset(osvi,0,sizeof(OSVERSIONINFO));
  71. osvi->dwOSVersionInfoSize=sizeof(OSVERSIONINFO);
  72. GetVersionEx(osvi);
  73. if(osvi->dwMajorVersion==4L)ShellType=WinNT4;
  74. else if(osvi->dwMajorVersion==5L&&osvi->dwMinorVersion==0L)ShellType=Win2000;
  75. else if(osvi->dwMajorVersion==5L&&osvi->dwMinorVersion==1L)ShellType=WinXP;
  76. free(osvi);
  77. }
  78. }
  79. else if (LOBYTE(LOWORD(winVer))<4)
  80. ShellType=Win32s;
  81. else{
  82. ShellType=Win95;
  83. osvi= (OSVERSIONINFO *)malloc(sizeof(OSVERSIONINFO));
  84. if (osvi!=NULL){
  85. memset(osvi,0,sizeof(OSVERSIONINFO));
  86. osvi->dwOSVersionInfoSize=sizeof(OSVERSIONINFO);
  87. GetVersionEx(osvi);
  88. if(osvi->dwMajorVersion==4L&&osvi->dwMinorVersion==10L)ShellType=Win98;
  89. else if(osvi->dwMajorVersion==4L&&osvi->dwMinorVersion==90L)ShellType=WinME;
  90. free(osvi);
  91. }
  92. }
  93. return ShellType;
  94. }
  95. static Win32Type g_Shell=IsShellType();
  96. void BCMenuData::SetAnsiString(LPCSTR szAnsiString)
  97. {
  98. USES_CONVERSION;
  99. SetWideString(A2W(szAnsiString)); //SK: see MFC Tech Note 059
  100. }
  101. CString BCMenuData::GetString(void)//returns the menu text in ANSI or UNICODE
  102. //depending on the MFC-Version we are using
  103. {
  104. CString strText;
  105. if (m_szMenuText)
  106. {
  107. #ifdef UNICODE
  108. strText = m_szMenuText;
  109. #else
  110. USES_CONVERSION;
  111. strText=W2A(m_szMenuText); //SK: see MFC Tech Note 059
  112. #endif
  113. }
  114. return strText;
  115. }
  116. CTypedPtrArray<CPtrArray, HMENU> BCMenu::m_AllSubMenus; // Stores list of all sub-menus
  117. IMPLEMENT_DYNAMIC( BCMenu, CMenu )
  118. /*
  119. ===============================================================================
  120. BCMenu::BCMenu()
  121. BCMenu::~BCMenu()
  122. -----------------
  123. Constructor and Destructor.
  124. ===============================================================================
  125. */
  126. BCMenu::BCMenu()
  127. {
  128. m_bDynIcons = FALSE; // O.S. - no dynamic icons by default
  129. disable_old_style=FALSE;
  130. m_iconX = 16; // Icon sizes default to 16 x 16
  131. m_iconY = 15; // ...
  132. m_selectcheck = -1;
  133. m_unselectcheck = -1;
  134. checkmaps=NULL;
  135. checkmapsshare=FALSE;
  136. // set the color used for the transparent background in all bitmaps
  137. m_bitmapBackground=RGB(192,192,192); //gray
  138. m_bitmapBackgroundFlag=FALSE;
  139. GetCPInfo(CP_ACP,&CPInfo);
  140. m_loadmenu=FALSE;
  141. }
  142. BCMenu::~BCMenu()
  143. {
  144. DestroyMenu();
  145. }
  146. BOOL BCMenu::IsNewShell ()
  147. {
  148. return (g_Shell>=Win95);
  149. }
  150. BOOL BCMenu::IsWinXPLuna()
  151. {
  152. if(g_Shell==WinXP){
  153. if(IsWindowsClassicTheme())return(FALSE);
  154. else return(TRUE);
  155. }
  156. return(FALSE);
  157. }
  158. BOOL BCMenu::IsLunaMenuStyle()
  159. {
  160. if(IsWinXPLuna()){
  161. if(xp_drawmode==BCMENU_DRAWMODE_XP)return(TRUE);
  162. }
  163. else{
  164. if(original_drawmode==BCMENU_DRAWMODE_XP)return(TRUE);
  165. }
  166. return(FALSE);
  167. }
  168. BCMenuData::~BCMenuData()
  169. {
  170. if(bitmap)
  171. delete(bitmap);
  172. delete[] m_szMenuText; //Need not check for NULL because ANSI X3J16 allows "delete NULL"
  173. }
  174. void BCMenuData::SetWideString(const wchar_t *szWideString)
  175. {
  176. delete[] m_szMenuText;//Need not check for NULL because ANSI X3J16 allows "delete NULL"
  177. if (szWideString)
  178. {
  179. m_szMenuText = new wchar_t[sizeof(wchar_t)*(wcslen(szWideString)+1)];
  180. if (m_szMenuText)
  181. wcscpy(m_szMenuText,szWideString);
  182. }
  183. else
  184. m_szMenuText=NULL;//set to NULL so we need not bother about dangling non-NULL Ptrs
  185. }
  186. BOOL BCMenu::IsMenu(CMenu *submenu)
  187. {
  188. int m;
  189. int numSubMenus = m_AllSubMenus.GetUpperBound();
  190. for(m=0;m<=numSubMenus;++m){
  191. if(submenu->m_hMenu==m_AllSubMenus[m])return(TRUE);
  192. }
  193. return(FALSE);
  194. }
  195. BOOL BCMenu::IsMenu(HMENU submenu)
  196. {
  197. int m;
  198. int numSubMenus = m_AllSubMenus.GetUpperBound();
  199. for(m=0;m<=numSubMenus;++m){
  200. if(submenu==m_AllSubMenus[m])return(TRUE);
  201. }
  202. return(FALSE);
  203. }
  204. BOOL BCMenu::DestroyMenu()
  205. {
  206. // Destroy Sub menus:
  207. int m,n;
  208. int numAllSubMenus = m_AllSubMenus.GetUpperBound();
  209. for(n = numAllSubMenus; n>= 0; n--){
  210. if(m_AllSubMenus[n]==this->m_hMenu)m_AllSubMenus.RemoveAt(n);
  211. }
  212. int numSubMenus = m_SubMenus.GetUpperBound();
  213. for(m = numSubMenus; m >= 0; m--){
  214. numAllSubMenus = m_AllSubMenus.GetUpperBound();
  215. for(n = numAllSubMenus; n>= 0; n--){
  216. if(m_AllSubMenus[n]==m_SubMenus[m])m_AllSubMenus.RemoveAt(n);
  217. }
  218. CMenu *ptr=FromHandle(m_SubMenus[m]);
  219. BOOL flag=ptr->IsKindOf(RUNTIME_CLASS( BCMenu ));
  220. if(flag)delete((BCMenu *)ptr);
  221. }
  222. m_SubMenus.RemoveAll();
  223. // Destroy menu data
  224. int numItems = m_MenuList.GetUpperBound();
  225. for(m = 0; m <= numItems; m++)delete(m_MenuList[m]);
  226. m_MenuList.RemoveAll();
  227. if(checkmaps&&!checkmapsshare){
  228. delete checkmaps;
  229. checkmaps=NULL;
  230. }
  231. // Call base-class implementation last:
  232. return(CMenu::DestroyMenu());
  233. };
  234. int BCMenu::GetMenuDrawMode(void)
  235. {
  236. if(IsWinXPLuna())return(xp_drawmode);
  237. return(original_drawmode);
  238. }
  239. BOOL BCMenu::GetSelectDisableMode(void)
  240. {
  241. if(IsLunaMenuStyle())return(xp_select_disabled);
  242. return(original_select_disabled);
  243. }
  244. /*
  245. ==========================================================================
  246. void BCMenu::DrawItem(LPDRAWITEMSTRUCT)
  247. ---------------------------------------
  248. Called by the framework when a particular item needs to be drawn. We
  249. overide this to draw the menu item in a custom-fashion, including icons
  250. and the 3D rectangle bar.
  251. ==========================================================================
  252. */
  253. void BCMenu::DrawItem (LPDRAWITEMSTRUCT lpDIS)
  254. {
  255. ASSERT(lpDIS != NULL);
  256. CDC* pDC = CDC::FromHandle(lpDIS->hDC);
  257. if(pDC->GetDeviceCaps(RASTERCAPS) & RC_PALETTE)DrawItem_Win9xNT2000(lpDIS);
  258. else{
  259. if(IsWinXPLuna()){
  260. if(xp_drawmode==BCMENU_DRAWMODE_XP) DrawItem_WinXP(lpDIS);
  261. else DrawItem_Win9xNT2000(lpDIS);
  262. }
  263. else{
  264. if(original_drawmode==BCMENU_DRAWMODE_XP) DrawItem_WinXP(lpDIS);
  265. else DrawItem_Win9xNT2000(lpDIS);
  266. }
  267. }
  268. }
  269. void BCMenu::DrawItem_Win9xNT2000 (LPDRAWITEMSTRUCT lpDIS)
  270. {
  271. ASSERT(lpDIS != NULL);
  272. CDC* pDC = CDC::FromHandle(lpDIS->hDC);
  273. CRect rect;
  274. UINT state = (((BCMenuData*)(lpDIS->itemData))->nFlags);
  275. CBrush m_brBackground;
  276. COLORREF m_clrBack;
  277. if(IsWinXPLuna())m_clrBack=GetSysColor(COLOR_3DFACE);
  278. else m_clrBack=GetSysColor(COLOR_MENU);
  279. m_brBackground.CreateSolidBrush(m_clrBack);
  280. // remove the selected bit if it's grayed out
  281. if(lpDIS->itemState & ODS_GRAYED&&!original_select_disabled){
  282. if(lpDIS->itemState & ODS_SELECTED)lpDIS->itemState=lpDIS->itemState & ~ODS_SELECTED;
  283. }
  284. if(state & MF_SEPARATOR){
  285. rect.CopyRect(&lpDIS->rcItem);
  286. pDC->FillRect (rect,&m_brBackground);
  287. rect.top += (rect.Height()>>1);
  288. pDC->DrawEdge(&rect,EDGE_ETCHED,BF_TOP);
  289. }
  290. else{
  291. CRect rect2;
  292. BOOL standardflag=FALSE,selectedflag=FALSE,disableflag=FALSE;
  293. BOOL checkflag=FALSE;
  294. COLORREF crText = GetSysColor(COLOR_MENUTEXT);
  295. CBrush m_brSelect;
  296. CPen m_penBack;
  297. int x0,y0,dy;
  298. int nIconNormal=-1,xoffset=-1,global_offset=-1;
  299. CImageList *bitmap=NULL;
  300. // set some colors
  301. m_penBack.CreatePen (PS_SOLID,0,m_clrBack);
  302. m_brSelect.CreateSolidBrush(GetSysColor(COLOR_HIGHLIGHT));
  303. // draw the colored rectangle portion
  304. rect.CopyRect(&lpDIS->rcItem);
  305. rect2=rect;
  306. // draw the up/down/focused/disabled state
  307. UINT state = lpDIS->itemState;
  308. CString strText;
  309. if(lpDIS->itemData != NULL){
  310. nIconNormal = (((BCMenuData*)(lpDIS->itemData))->menuIconNormal);
  311. xoffset = (((BCMenuData*)(lpDIS->itemData))->xoffset);
  312. global_offset = (((BCMenuData*)(lpDIS->itemData))->global_offset);
  313. bitmap = (((BCMenuData*)(lpDIS->itemData))->bitmap);
  314. strText = ((BCMenuData*) (lpDIS->itemData))->GetString();
  315. if(nIconNormal<0&&global_offset>=0){
  316. xoffset=global_offset;
  317. nIconNormal=0;
  318. bitmap = &m_AllImages;
  319. }
  320. if(state&ODS_CHECKED && nIconNormal<0){
  321. if(state&ODS_SELECTED && m_selectcheck>0)checkflag=TRUE;
  322. else if(m_unselectcheck>0) checkflag=TRUE;
  323. }
  324. else if(nIconNormal != -1){
  325. standardflag=TRUE;
  326. if(state&ODS_SELECTED && !(state&ODS_GRAYED))selectedflag=TRUE;
  327. else if(state&ODS_GRAYED) disableflag=TRUE;
  328. }
  329. }
  330. else{
  331. strText.Empty();
  332. }
  333. if(state&ODS_SELECTED){ // draw the down edges
  334. CPen *pOldPen = pDC->SelectObject (&m_penBack);
  335. // You need only Text highlight and thats what you get
  336. if(checkflag||standardflag||selectedflag||disableflag||state&ODS_CHECKED)
  337. rect2.SetRect(rect.left+m_iconX+4+BCMENU_GAP,rect.top,rect.right,rect.bottom);
  338. pDC->FillRect (rect2,&m_brSelect);
  339. pDC->SelectObject (pOldPen);
  340. crText = GetSysColor(COLOR_HIGHLIGHTTEXT);
  341. }
  342. else {
  343. CPen *pOldPen = pDC->SelectObject (&m_penBack);
  344. pDC->FillRect (rect,&m_brBackground);
  345. pDC->SelectObject (pOldPen);
  346. // draw the up edges
  347. pDC->Draw3dRect (rect,m_clrBack,m_clrBack);
  348. }
  349. // draw the text if there is any
  350. //We have to paint the text only if the image is nonexistant
  351. dy = (rect.Height()-4-m_iconY)/2;
  352. dy = dy<0 ? 0 : dy;
  353. if(checkflag||standardflag||selectedflag||disableflag){
  354. rect2.SetRect(rect.left+1,rect.top+1+dy,rect.left+m_iconX+3,
  355. rect.top+m_iconY+3+dy);
  356. pDC->Draw3dRect (rect2,m_clrBack,m_clrBack);
  357. if(checkflag && checkmaps){
  358. pDC->FillRect (rect2,&m_brBackground);
  359. rect2.SetRect(rect.left,rect.top+dy,rect.left+m_iconX+4,
  360. rect.top+m_iconY+4+dy);
  361. pDC->Draw3dRect (rect2,m_clrBack,m_clrBack);
  362. CPoint ptImage(rect.left+2,rect.top+2+dy);
  363. if(state&ODS_SELECTED)checkmaps->Draw(pDC,1,ptImage,ILD_TRANSPARENT);
  364. else checkmaps->Draw(pDC,0,ptImage,ILD_TRANSPARENT);
  365. }
  366. else if(disableflag){
  367. if(!selectedflag){
  368. CBitmap bitmapstandard;
  369. GetBitmapFromImageList(pDC,bitmap,xoffset,bitmapstandard);
  370. rect2.SetRect(rect.left,rect.top+dy,rect.left+m_iconX+4,
  371. rect.top+m_iconY+4+dy);
  372. pDC->Draw3dRect (rect2,m_clrBack,m_clrBack);
  373. if(disable_old_style)
  374. DitherBlt(lpDIS->hDC,rect.left+2,rect.top+2+dy,m_iconX,m_iconY,
  375. (HBITMAP)(bitmapstandard),0,0,m_clrBack);
  376. else
  377. DitherBlt2(pDC,rect.left+2,rect.top+2+dy,m_iconX,m_iconY,
  378. bitmapstandard,0,0,m_clrBack);
  379. bitmapstandard.DeleteObject();
  380. }
  381. }
  382. else if(selectedflag){
  383. pDC->FillRect (rect2,&m_brBackground);
  384. rect2.SetRect(rect.left,rect.top+dy,rect.left+m_iconX+4,
  385. rect.top+m_iconY+4+dy);
  386. if (IsNewShell()){
  387. if(state&ODS_CHECKED)
  388. pDC->Draw3dRect(rect2,GetSysColor(COLOR_3DSHADOW),
  389. GetSysColor(COLOR_3DHILIGHT));
  390. else
  391. pDC->Draw3dRect(rect2,GetSysColor(COLOR_3DHILIGHT),
  392. GetSysColor(COLOR_3DSHADOW));
  393. }
  394. CPoint ptImage(rect.left+2,rect.top+2+dy);
  395. if(bitmap)bitmap->Draw(pDC,xoffset,ptImage,ILD_TRANSPARENT);
  396. }
  397. else{
  398. if(state&ODS_CHECKED){
  399. CBrush brush;
  400. COLORREF col = m_clrBack;
  401. col = LightenColor(col,0.6);
  402. brush.CreateSolidBrush(col);
  403. pDC->FillRect(rect2,&brush);
  404. brush.DeleteObject();
  405. rect2.SetRect(rect.left,rect.top+dy,rect.left+m_iconX+4,
  406. rect.top+m_iconY+4+dy);
  407. if (IsNewShell())
  408. pDC->Draw3dRect(rect2,GetSysColor(COLOR_3DSHADOW),
  409. GetSysColor(COLOR_3DHILIGHT));
  410. }
  411. else{
  412. pDC->FillRect (rect2,&m_brBackground);
  413. rect2.SetRect(rect.left,rect.top+dy,rect.left+m_iconX+4,
  414. rect.top+m_iconY+4+dy);
  415. pDC->Draw3dRect (rect2,m_clrBack,m_clrBack);
  416. }
  417. CPoint ptImage(rect.left+2,rect.top+2+dy);
  418. if(bitmap)bitmap->Draw(pDC,xoffset,ptImage,ILD_TRANSPARENT);
  419. }
  420. }
  421. if(nIconNormal<0 && state&ODS_CHECKED && !checkflag){
  422. rect2.SetRect(rect.left+1,rect.top+2+dy,rect.left+m_iconX+1,
  423. rect.top+m_iconY+2+dy);
  424. CMenuItemInfo info;
  425. info.fMask = MIIM_CHECKMARKS;
  426. ::GetMenuItemInfo((HMENU)lpDIS->hwndItem,lpDIS->itemID,
  427. MF_BYCOMMAND, &info);
  428. if(state&ODS_CHECKED || info.hbmpUnchecked) {
  429. Draw3DCheckmark(pDC, rect2, state&ODS_SELECTED,
  430. state&ODS_CHECKED ? info.hbmpChecked :
  431. info.hbmpUnchecked);
  432. }
  433. }
  434. //This is needed always so that we can have the space for check marks
  435. x0=rect.left;y0=rect.top;
  436. rect.left = rect.left + m_iconX + 8 + BCMENU_GAP;
  437. if(!strText.IsEmpty()){
  438. CRect rectt(rect.left,rect.top-1,rect.right,rect.bottom-1);
  439. // Find tabs
  440. CString leftStr,rightStr;
  441. leftStr.Empty();rightStr.Empty();
  442. int tablocr=strText.ReverseFind(_T('\t'));
  443. if(tablocr!=-1){
  444. rightStr=strText.Mid(tablocr+1);
  445. leftStr=strText.Left(strText.Find(_T('\t')));
  446. rectt.right-=m_iconX;
  447. }
  448. else leftStr=strText;
  449. int iOldMode = pDC->GetBkMode();
  450. pDC->SetBkMode( TRANSPARENT);
  451. // Draw the text in the correct colour:
  452. UINT nFormat = DT_LEFT|DT_SINGLELINE|DT_VCENTER;
  453. UINT nFormatr = DT_RIGHT|DT_SINGLELINE|DT_VCENTER;
  454. if(!(lpDIS->itemState & ODS_GRAYED)){
  455. pDC->SetTextColor(crText);
  456. pDC->DrawText (leftStr,rectt,nFormat);
  457. if(tablocr!=-1) pDC->DrawText (rightStr,rectt,nFormatr);
  458. }
  459. else{
  460. // Draw the disabled text
  461. if(!(state & ODS_SELECTED)){
  462. RECT offset = *rectt;
  463. offset.left+=1;
  464. offset.right+=1;
  465. offset.top+=1;
  466. offset.bottom+=1;
  467. pDC->SetTextColor(GetSysColor(COLOR_BTNHILIGHT));
  468. pDC->DrawText(leftStr,&offset, nFormat);
  469. if(tablocr!=-1) pDC->DrawText (rightStr,&offset,nFormatr);
  470. pDC->SetTextColor(GetSysColor(COLOR_GRAYTEXT));
  471. pDC->DrawText(leftStr,rectt, nFormat);
  472. if(tablocr!=-1) pDC->DrawText (rightStr,rectt,nFormatr);
  473. }
  474. else{
  475. // And the standard Grey text:
  476. pDC->SetTextColor(m_clrBack);
  477. pDC->DrawText(leftStr,rectt, nFormat);
  478. if(tablocr!=-1) pDC->DrawText (rightStr,rectt,nFormatr);
  479. }
  480. }
  481. pDC->SetBkMode( iOldMode );
  482. }
  483. m_penBack.DeleteObject();
  484. m_brSelect.DeleteObject();
  485. }
  486. m_brBackground.DeleteObject();
  487. }
  488. COLORREF BCMenu::LightenColor(COLORREF col,double factor)
  489. {
  490. if(factor>0.0&&factor<=1.0){
  491. BYTE red,green,blue,lightred,lightgreen,lightblue;
  492. red = GetRValue(col);
  493. green = GetGValue(col);
  494. blue = GetBValue(col);
  495. lightred = (BYTE)((factor*(255-red)) + red);
  496. lightgreen = (BYTE)((factor*(255-green)) + green);
  497. lightblue = (BYTE)((factor*(255-blue)) + blue);
  498. col = RGB(lightred,lightgreen,lightblue);
  499. }
  500. return(col);
  501. }
  502. COLORREF BCMenu::DarkenColor(COLORREF col,double factor)
  503. {
  504. if(factor>0.0&&factor<=1.0){
  505. BYTE red,green,blue,lightred,lightgreen,lightblue;
  506. red = GetRValue(col);
  507. green = GetGValue(col);
  508. blue = GetBValue(col);
  509. lightred = (BYTE)(red-(factor*red));
  510. lightgreen = (BYTE)(green-(factor*green));
  511. lightblue = (BYTE)(blue-(factor*blue));
  512. col = RGB(lightred,lightgreen,lightblue);
  513. }
  514. return(col);
  515. }
  516. void BCMenu::DrawItem_WinXP (LPDRAWITEMSTRUCT lpDIS)
  517. {
  518. ASSERT(lpDIS != NULL);
  519. CDC* pDC = CDC::FromHandle(lpDIS->hDC);
  520. #ifdef BCMENU_USE_MEMDC
  521. BCMenuMemDC *pMemDC=NULL;
  522. #endif
  523. CRect rect,rect2;
  524. UINT state = (((BCMenuData*)(lpDIS->itemData))->nFlags);
  525. COLORREF m_newclrBack=GetSysColor(COLOR_3DFACE);
  526. COLORREF m_clrBack=GetSysColor(COLOR_WINDOW);
  527. CFont m_fontMenu,*pFont=NULL;
  528. LOGFONT m_lf;
  529. if(!IsWinXPLuna())m_newclrBack=LightenColor(m_newclrBack,0.25);
  530. CBrush m_newbrBackground,m_brBackground;
  531. m_brBackground.CreateSolidBrush(m_clrBack);
  532. m_newbrBackground.CreateSolidBrush(m_newclrBack);
  533. int BCMENU_PAD=4;
  534. if(xp_draw_3D_bitmaps)BCMENU_PAD=7;
  535. int barwidth=m_iconX+BCMENU_PAD;
  536. // remove the selected bit if it's grayed out
  537. if(lpDIS->itemState & ODS_GRAYED&&!xp_select_disabled){
  538. if(lpDIS->itemState & ODS_SELECTED)lpDIS->itemState=lpDIS->itemState & ~ODS_SELECTED;
  539. #ifdef BCMENU_USE_MEMDC
  540. pMemDC=new BCMenuMemDC(pDC,&lpDIS->rcItem);
  541. pDC = pMemDC;
  542. ZeroMemory ((PVOID) &m_lf,sizeof (LOGFONT));
  543. NONCLIENTMETRICS nm;
  544. nm.cbSize = sizeof (NONCLIENTMETRICS);
  545. VERIFY (SystemParametersInfo(SPI_GETNONCLIENTMETRICS,nm.cbSize,&nm,0));
  546. m_lf = nm.lfMenuFont;
  547. m_fontMenu.CreateFontIndirect (&m_lf);
  548. pFont = pDC->SelectObject (&m_fontMenu);
  549. #endif
  550. }
  551. if(state & MF_SEPARATOR){
  552. rect.CopyRect(&lpDIS->rcItem);
  553. pDC->FillRect (rect,&m_brBackground);
  554. rect2.SetRect(rect.left,rect.top,rect.left+barwidth,rect.bottom);
  555. rect.top+=rect.Height()>>1;
  556. rect.left = rect2.right+BCMENU_PAD;
  557. pDC->DrawEdge(&rect,EDGE_ETCHED,BF_TOP);
  558. pDC->FillRect (rect2,&m_newbrBackground);
  559. pDC->Draw3dRect (rect2,m_newclrBack,m_newclrBack);
  560. }
  561. else{
  562. BOOL standardflag=FALSE,selectedflag=FALSE,disableflag=FALSE;
  563. BOOL checkflag=FALSE;
  564. COLORREF crText = GetSysColor(COLOR_MENUTEXT);
  565. COLORREF crSelect = GetSysColor(COLOR_HIGHLIGHT);
  566. COLORREF crSelectFill;
  567. if(!IsWinXPLuna())crSelectFill=LightenColor(crSelect,0.85);
  568. else crSelectFill=LightenColor(crSelect,0.7);
  569. CBrush m_brSelect;
  570. CPen m_penBack;
  571. int x0,y0,dx,dy;
  572. int nIconNormal=-1,xoffset=-1,global_offset=-1;
  573. int faded_offset=1,shadow_offset=2;
  574. CImageList *bitmap=NULL;
  575. BOOL CanDraw3D=FALSE;
  576. // set some colors
  577. m_penBack.CreatePen (PS_SOLID,0,m_clrBack);
  578. m_brSelect.CreateSolidBrush(crSelectFill);
  579. // draw the colored rectangle portion
  580. rect.CopyRect(&lpDIS->rcItem);
  581. rect2=rect;
  582. // draw the up/down/focused/disabled state
  583. UINT state = lpDIS->itemState;
  584. CString strText;
  585. if(lpDIS->itemData != NULL){
  586. nIconNormal = (((BCMenuData*)(lpDIS->itemData))->menuIconNormal);
  587. xoffset = (((BCMenuData*)(lpDIS->itemData))->xoffset);
  588. bitmap = (((BCMenuData*)(lpDIS->itemData))->bitmap);
  589. strText = ((BCMenuData*) (lpDIS->itemData))->GetString();
  590. global_offset = (((BCMenuData*)(lpDIS->itemData))->global_offset);
  591. if(xoffset==0&&xp_draw_3D_bitmaps&&bitmap&&bitmap->GetImageCount()>2)CanDraw3D=TRUE;
  592. if(nIconNormal<0&&xoffset<0&&global_offset>=0){
  593. xoffset=global_offset;
  594. nIconNormal=0;
  595. bitmap = &m_AllImages;
  596. if(xp_draw_3D_bitmaps&&CanDraw3DImageList(global_offset)){
  597. CanDraw3D=TRUE;
  598. faded_offset=global_offset+1;
  599. shadow_offset=global_offset+2;
  600. }
  601. }
  602. if(state&ODS_CHECKED && nIconNormal<0){
  603. if(state&ODS_SELECTED && m_selectcheck>0)checkflag=TRUE;
  604. else if(m_unselectcheck>0) checkflag=TRUE;
  605. }
  606. else if(nIconNormal != -1){
  607. standardflag=TRUE;
  608. if(state&ODS_SELECTED && !(state&ODS_GRAYED))selectedflag=TRUE;
  609. else if(state&ODS_GRAYED) disableflag=TRUE;
  610. }
  611. }
  612. else{
  613. strText.Empty();
  614. }
  615. if(state&ODS_SELECTED){ // draw the down edges
  616. CPen *pOldPen = pDC->SelectObject (&m_penBack);
  617. pDC->FillRect (rect,&m_brSelect);
  618. pDC->Draw3dRect (rect,crSelect,crSelect);
  619. pDC->SelectObject (pOldPen);
  620. }
  621. else {
  622. rect2.SetRect(rect.left,rect.top,rect.left+barwidth,rect.bottom);
  623. CPen *pOldPen = pDC->SelectObject (&m_penBack);
  624. pDC->FillRect (rect,&m_brBackground);
  625. pDC->FillRect (rect2,&m_newbrBackground);
  626. pDC->SelectObject (pOldPen);
  627. // draw the up edges
  628. pDC->Draw3dRect (rect,m_clrBack,m_clrBack);
  629. pDC->Draw3dRect (rect2,m_newclrBack,m_newclrBack);
  630. }
  631. // draw the text if there is any
  632. //We have to paint the text only if the image is nonexistant
  633. dy = (int)(0.5+(rect.Height()-m_iconY)/2.0);
  634. dy = dy<0 ? 0 : dy;
  635. dx = (int)(0.5+(barwidth-m_iconX)/2.0);
  636. dx = dx<0 ? 0 : dx;
  637. if(checkflag||standardflag||selectedflag||disableflag){
  638. rect2.SetRect(rect.left+1,rect.top+1,rect.left+barwidth-1,
  639. rect.bottom-1);
  640. if(checkflag && checkmaps){
  641. pDC->FillRect (rect2,&m_newbrBackground);
  642. CPoint ptImage(rect.left+dx,rect.top+dy);
  643. if(state&ODS_SELECTED)checkmaps->Draw(pDC,1,ptImage,ILD_TRANSPARENT);
  644. else checkmaps->Draw(pDC,0,ptImage,ILD_TRANSPARENT);
  645. }
  646. else if(disableflag){
  647. if(!selectedflag){
  648. CBitmap bitmapstandard;
  649. GetBitmapFromImageList(pDC,bitmap,xoffset,bitmapstandard);
  650. COLORREF transparentcol=m_newclrBack;
  651. if(state&ODS_SELECTED)transparentcol=crSelectFill;
  652. if(disable_old_style)
  653. DitherBlt(lpDIS->hDC,rect.left+dx,rect.top+dy,m_iconX,m_iconY,
  654. (HBITMAP)(bitmapstandard),0,0,transparentcol);
  655. else
  656. DitherBlt2(pDC,rect.left+dx,rect.top+dy,m_iconX,m_iconY,
  657. bitmapstandard,0,0,transparentcol);
  658. if(state&ODS_SELECTED)pDC->Draw3dRect (rect,crSelect,crSelect);
  659. bitmapstandard.DeleteObject();
  660. }
  661. }
  662. else if(selectedflag){
  663. pDC->FillRect (rect2,&m_brSelect);
  664. CPoint ptImage(rect.left+dx,rect.top+dy);
  665. if(state&ODS_CHECKED){
  666. pDC->Draw3dRect(rect2,crSelect,crSelect);
  667. ptImage.x-=1;ptImage.y-=1;
  668. }
  669. if(bitmap){
  670. if(CanDraw3D&&!(state&ODS_CHECKED)){
  671. CPoint ptImage1(ptImage.x+1,ptImage.y+1);
  672. CPoint ptImage2(ptImage.x-1,ptImage.y-1);
  673. bitmap->Draw(pDC,shadow_offset,ptImage1,ILD_TRANSPARENT);
  674. bitmap->Draw(pDC,xoffset,ptImage2,ILD_TRANSPARENT);
  675. }
  676. else bitmap->Draw(pDC,xoffset,ptImage,ILD_TRANSPARENT);
  677. }
  678. }
  679. else{
  680. if(state&ODS_CHECKED){
  681. CBrush brushin;
  682. brushin.CreateSolidBrush(LightenColor(crSelect,0.85));
  683. pDC->FillRect(rect2,&brushin);
  684. brushin.DeleteObject();
  685. pDC->Draw3dRect(rect2,crSelect,crSelect);
  686. CPoint ptImage(rect.left+dx-1,rect.top+dy-1);
  687. if(bitmap)bitmap->Draw(pDC,xoffset,ptImage,ILD_TRANSPARENT);
  688. }
  689. else{
  690. pDC->FillRect (rect2,&m_newbrBackground);
  691. pDC->Draw3dRect (rect2,m_newclrBack,m_newclrBack);
  692. CPoint ptImage(rect.left+dx,rect.top+dy);
  693. if(bitmap){
  694. if(CanDraw3D)
  695. bitmap->Draw(pDC,faded_offset,ptImage,ILD_TRANSPARENT);
  696. else
  697. bitmap->Draw(pDC,xoffset,ptImage,ILD_TRANSPARENT);
  698. }
  699. }
  700. }
  701. }
  702. if(nIconNormal<0 && state&ODS_CHECKED && !checkflag){
  703. dy = (int)(0.5+(rect.Height()-16)/2.0);
  704. dy = dy<0 ? 0 : dy;
  705. dx = (int)(0.5+(barwidth-16)/2.0);
  706. dx = dx<0 ? 0 : dx;
  707. CMenuItemInfo info;
  708. info.fMask = MIIM_CHECKMARKS;
  709. ::GetMenuItemInfo((HMENU)lpDIS->hwndItem,lpDIS->itemID,
  710. MF_BYCOMMAND, &info);
  711. if(state&ODS_CHECKED || info.hbmpUnchecked) {
  712. rect2.SetRect(rect.left+dx,rect.top+dy,rect.left+dx+16,rect.top+dy+16);
  713. DrawXPCheckmark(pDC, rect2,state&ODS_CHECKED ? info.hbmpChecked :
  714. info.hbmpUnchecked,crSelect);
  715. }
  716. }
  717. //This is needed always so that we can have the space for check marks
  718. x0=rect.left;y0=rect.top;
  719. rect.left = rect.left + barwidth + 8;
  720. if(!strText.IsEmpty()){
  721. CRect rectt(rect.left,rect.top-1,rect.right,rect.bottom-1);
  722. // Find tabs
  723. CString leftStr,rightStr;
  724. leftStr.Empty();rightStr.Empty();
  725. int tablocr=strText.ReverseFind(_T('\t'));
  726. if(tablocr!=-1){
  727. rightStr=strText.Mid(tablocr+1);
  728. leftStr=strText.Left(strText.Find(_T('\t')));
  729. rectt.right-=m_iconX;
  730. }
  731. else leftStr=strText;
  732. int iOldMode = pDC->GetBkMode();
  733. pDC->SetBkMode( TRANSPARENT);
  734. // Draw the text in the correct colour:
  735. UINT nFormat = DT_LEFT|DT_SINGLELINE|DT_VCENTER;
  736. UINT nFormatr = DT_RIGHT|DT_SINGLELINE|DT_VCENTER;
  737. if(!(lpDIS->itemState & ODS_GRAYED)){
  738. pDC->SetTextColor(crText);
  739. pDC->DrawText (leftStr,rectt,nFormat);
  740. if(tablocr!=-1) pDC->DrawText (rightStr,rectt,nFormatr);
  741. }
  742. else{
  743. RECT offset = *rectt;
  744. offset.left+=1;
  745. offset.right+=1;
  746. offset.top+=1;
  747. offset.bottom+=1;
  748. if(!IsWinXPLuna()){
  749. COLORREF graycol=GetSysColor(COLOR_GRAYTEXT);
  750. if(!(state&ODS_SELECTED))graycol = LightenColor(graycol,0.4);
  751. pDC->SetTextColor(graycol);
  752. }
  753. else pDC->SetTextColor(GetSysColor(COLOR_GRAYTEXT));
  754. pDC->DrawText(leftStr,rectt, nFormat);
  755. if(tablocr!=-1) pDC->DrawText (rightStr,rectt,nFormatr);
  756. }
  757. pDC->SetBkMode( iOldMode );
  758. }
  759. m_penBack.DeleteObject();
  760. m_brSelect.DeleteObject();
  761. }
  762. m_brBackground.DeleteObject();
  763. m_newbrBackground.DeleteObject();
  764. #ifdef BCMENU_USE_MEMDC
  765. if(pFont)pDC->SelectObject (pFont); //set it to the old font
  766. m_fontMenu.DeleteObject();
  767. if(pMemDC)delete pMemDC;
  768. #endif
  769. }
  770. BOOL BCMenu::GetBitmapFromImageList(CDC* pDC,CImageList *imglist,int nIndex,CBitmap &bmp)
  771. {
  772. HICON hIcon = imglist->ExtractIcon(nIndex);
  773. CDC dc;
  774. dc.CreateCompatibleDC(pDC);
  775. bmp.CreateCompatibleBitmap(pDC,m_iconX,m_iconY);
  776. CBitmap* pOldBmp = dc.SelectObject(&bmp);
  777. CBrush brush ;
  778. COLORREF m_newclrBack;
  779. m_newclrBack=GetSysColor(COLOR_3DFACE);
  780. brush.CreateSolidBrush(m_newclrBack);
  781. ::DrawIconEx(
  782. dc.GetSafeHdc(),
  783. 0,
  784. 0,
  785. hIcon,
  786. m_iconX,
  787. m_iconY,
  788. 0,
  789. (HBRUSH)brush,
  790. DI_NORMAL
  791. );
  792. dc.SelectObject( pOldBmp );
  793. dc.DeleteDC();
  794. // the icon is not longer needed
  795. ::DestroyIcon(hIcon);
  796. return(TRUE);
  797. }
  798. /*
  799. ==========================================================================
  800. void BCMenu::MeasureItem(LPMEASUREITEMSTRUCT)
  801. ---------------------------------------------
  802. Called by the framework when it wants to know what the width and height
  803. of our item will be. To accomplish this we provide the width of the
  804. icon plus the width of the menu text, and then the height of the icon.
  805. ==========================================================================
  806. */
  807. void BCMenu::MeasureItem( LPMEASUREITEMSTRUCT lpMIS )
  808. {
  809. UINT state = (((BCMenuData*)(lpMIS->itemData))->nFlags);
  810. int BCMENU_PAD=4;
  811. if(IsLunaMenuStyle()&&xp_draw_3D_bitmaps)BCMENU_PAD=7;
  812. if(state & MF_SEPARATOR){
  813. lpMIS->itemWidth = 0;
  814. int temp = GetSystemMetrics(SM_CYMENU)>>1;
  815. lpMIS->itemHeight = temp>(m_iconY+BCMENU_PAD)/2 ? temp : (m_iconY+BCMENU_PAD)/2;
  816. }
  817. else{
  818. CFont m_fontMenu;
  819. LOGFONT m_lf;
  820. ZeroMemory ((PVOID) &m_lf,sizeof (LOGFONT));
  821. NONCLIENTMETRICS nm;
  822. nm.cbSize = sizeof (NONCLIENTMETRICS);
  823. VERIFY(SystemParametersInfo(SPI_GETNONCLIENTMETRICS,
  824. nm.cbSize,&nm,0));
  825. m_lf = nm.lfMenuFont;
  826. m_fontMenu.CreateFontIndirect (&m_lf);
  827. // Obtain the width of the text:
  828. CWnd *pWnd = AfxGetMainWnd(); // Get main window
  829. if (pWnd == NULL) pWnd = CWnd::GetDesktopWindow();
  830. CDC *pDC = pWnd->GetDC(); // Get device context
  831. CFont* pFont=NULL; // Select menu font in...
  832. if (IsNewShell())
  833. pFont = pDC->SelectObject (&m_fontMenu);// Select menu font in...
  834. //Get pointer to text SK
  835. const wchar_t *lpstrText = ((BCMenuData*)(lpMIS->itemData))->GetWideString();//SK: we use const to prevent misuse
  836. SIZE size;
  837. size.cx=size.cy=0;
  838. if (Win32s!=g_Shell)
  839. VERIFY(::GetTextExtentPoint32W(pDC->m_hDC,lpstrText,
  840. wcslen(lpstrText),&size)); //SK should also work on 95
  841. #ifndef UNICODE //can't be UNICODE for Win32s
  842. else{//it's Win32suckx
  843. RECT rect;
  844. rect.left=rect.top=0;
  845. size.cy=DrawText(pDC->m_hDC,(LPCTSTR)lpstrText,
  846. wcslen(lpstrText),&rect,
  847. DT_SINGLELINE|DT_LEFT|DT_VCENTER|DT_CALCRECT);
  848. //+3 makes at least three pixels space to the menu border
  849. size.cx=rect.right-rect.left+3;
  850. size.cx += 3*(size.cx/wcslen(lpstrText));
  851. }
  852. #endif
  853. CSize t = CSize(size);
  854. if(IsNewShell())
  855. pDC->SelectObject (pFont); // Select old font in
  856. pWnd->ReleaseDC(pDC); // Release the DC
  857. // Set width and height:
  858. if(IsLunaMenuStyle())lpMIS->itemWidth = m_iconX+BCMENU_PAD+8+t.cx;
  859. else lpMIS->itemWidth = m_iconX + t.cx + m_iconX + BCMENU_GAP;
  860. int temp = GetSystemMetrics(SM_CYMENU);
  861. lpMIS->itemHeight = temp>m_iconY+BCMENU_PAD ? temp : m_iconY+BCMENU_PAD;
  862. m_fontMenu.DeleteObject();
  863. }
  864. }
  865. void BCMenu::SetIconSize (int width, int height)
  866. {
  867. m_iconX = width;
  868. m_iconY = height;
  869. }
  870. BOOL BCMenu::AppendODMenuA(LPCSTR lpstrText,UINT nFlags,UINT nID,
  871. int nIconNormal)
  872. {
  873. USES_CONVERSION;
  874. return AppendODMenuW(A2W(lpstrText),nFlags,nID,nIconNormal);//SK: See MFC Tech Note 059
  875. }
  876. BOOL BCMenu::AppendODMenuW(wchar_t *lpstrText,UINT nFlags,UINT nID,
  877. int nIconNormal)
  878. {
  879. // Add the MF_OWNERDRAW flag if not specified:
  880. if(!nID){
  881. if(nFlags&MF_BYPOSITION)nFlags=MF_SEPARATOR|MF_OWNERDRAW|MF_BYPOSITION;
  882. else nFlags=MF_SEPARATOR|MF_OWNERDRAW;
  883. }
  884. else if(!(nFlags & MF_OWNERDRAW))nFlags |= MF_OWNERDRAW;
  885. if(nFlags & MF_POPUP){
  886. m_AllSubMenus.Add((HMENU)nID);
  887. m_SubMenus.Add((HMENU)nID);
  888. }
  889. BCMenuData *mdata = new BCMenuData;
  890. m_MenuList.Add(mdata);
  891. mdata->SetWideString(lpstrText); //SK: modified for dynamic allocation
  892. mdata->menuIconNormal = -1;
  893. mdata->xoffset = -1;
  894. if(nIconNormal>=0){
  895. CImageList bitmap;
  896. int xoffset=0;
  897. LoadFromToolBar(nID,nIconNormal,xoffset);
  898. if(mdata->bitmap){
  899. mdata->bitmap->DeleteImageList();
  900. mdata->bitmap=NULL;
  901. }
  902. bitmap.Create(m_iconX,m_iconY,ILC_COLORDDB|ILC_MASK,1,1);
  903. if(AddBitmapToImageList(&bitmap,nIconNormal)){
  904. mdata->global_offset = AddToGlobalImageList(&bitmap,xoffset,nID);
  905. }
  906. }
  907. else mdata->global_offset = GlobalImageListOffset(nID);
  908. mdata->nFlags = nFlags;
  909. mdata->nID = nID;
  910. BOOL returnflag=CMenu::AppendMenu(nFlags, nID, (LPCTSTR)mdata);
  911. if(m_loadmenu)RemoveTopLevelOwnerDraw();
  912. return(returnflag);
  913. }
  914. BOOL BCMenu::AppendODMenuA(LPCSTR lpstrText,UINT nFlags,UINT nID,
  915. CImageList *il,int xoffset)
  916. {
  917. USES_CONVERSION;
  918. return AppendODMenuW(A2W(lpstrText),nFlags,nID,il,xoffset);
  919. }
  920. BOOL BCMenu::AppendODMenuW(wchar_t *lpstrText,UINT nFlags,UINT nID,
  921. CImageList *il,int xoffset)
  922. {
  923. // Add the MF_OWNERDRAW flag if not specified:
  924. if(!nID){
  925. if(nFlags&MF_BYPOSITION)nFlags=MF_SEPARATOR|MF_OWNERDRAW|MF_BYPOSITION;
  926. else nFlags=MF_SEPARATOR|MF_OWNERDRAW;
  927. }
  928. else if(!(nFlags & MF_OWNERDRAW))nFlags |= MF_OWNERDRAW;
  929. if(nFlags & MF_POPUP){
  930. m_AllSubMenus.Add((HMENU)nID);
  931. m_SubMenus.Add((HMENU)nID);
  932. }
  933. BCMenuData *mdata = new BCMenuData;
  934. m_MenuList.Add(mdata);
  935. mdata->SetWideString(lpstrText); //SK: modified for dynamic allocation
  936. if(il){
  937. mdata->menuIconNormal = 0;
  938. mdata->xoffset=0;
  939. if(mdata->bitmap)mdata->bitmap->DeleteImageList();
  940. else mdata->bitmap=new(CImageList);
  941. ImageListDuplicate(il,xoffset,mdata->bitmap);
  942. }
  943. else{
  944. mdata->menuIconNormal = -1;
  945. mdata->xoffset = -1;
  946. }
  947. mdata->nFlags = nFlags;
  948. mdata->nID = nID;
  949. return(CMenu::AppendMenu(nFlags, nID, (LPCTSTR)mdata));
  950. }
  951. BOOL BCMenu::InsertODMenuA(UINT nPosition,LPCSTR lpstrText,UINT nFlags,UINT nID,
  952. int nIconNormal)
  953. {
  954. USES_CONVERSION;
  955. return InsertODMenuW(nPosition,A2W(lpstrText),nFlags,nID,nIconNormal);
  956. }
  957. BOOL BCMenu::InsertODMenuW(UINT nPosition,wchar_t *lpstrText,UINT nFlags,UINT nID,
  958. int nIconNormal)
  959. {
  960. if(!(nFlags & MF_BYPOSITION)){
  961. int iPosition =0;
  962. BCMenu* pMenu = FindMenuOption(nPosition,iPosition);
  963. if(pMenu){
  964. return(pMenu->InsertODMenuW(iPosition,lpstrText,nFlags|MF_BYPOSITION,nID,nIconNormal));
  965. }
  966. else return(FALSE);
  967. }
  968. if(!nID)nFlags=MF_SEPARATOR|MF_OWNERDRAW|MF_BYPOSITION;
  969. else if(!(nFlags & MF_OWNERDRAW))nFlags |= MF_OWNERDRAW;
  970. int menustart=0;
  971. if(nFlags & MF_POPUP){
  972. if(m_loadmenu){
  973. menustart=GetMenuStart();
  974. if(nPosition<(UINT)menustart)menustart=0;
  975. }
  976. m_AllSubMenus.Add((HMENU)nID);
  977. m_SubMenus.InsertAt(nPosition,(HMENU)nID);
  978. }
  979. //Stephane Clog suggested adding this, believe it or not it's in the help
  980. if(nPosition==(UINT)-1)nPosition=GetMenuItemCount();
  981. BCMenuData *mdata = new BCMenuData;
  982. m_MenuList.InsertAt(nPosition-menustart,mdata);
  983. mdata->SetWideString(lpstrText); //SK: modified for dynamic allocation
  984. mdata->menuIconNormal = nIconNormal;
  985. mdata->xoffset=-1;
  986. if(nIconNormal>=0){
  987. CImageList bitmap;
  988. int xoffset=0;
  989. LoadFromToolBar(nID,nIconNormal,xoffset);
  990. if(mdata->bitmap){
  991. mdata->bitmap->DeleteImageList();
  992. mdata->bitmap=NULL;
  993. }
  994. bitmap.Create(m_iconX,m_iconY,ILC_COLORDDB|ILC_MASK,1,1);
  995. if(AddBitmapToImageList(&bitmap,nIconNormal)){
  996. mdata->global_offset = AddToGlobalImageList(&bitmap,xoffset,nID);
  997. }
  998. }
  999. else mdata->global_offset = GlobalImageListOffset(nID);
  1000. mdata->nFlags = nFlags;
  1001. mdata->nID = nID;
  1002. BOOL returnflag=CMenu::InsertMenu(nPosition,nFlags,nID,(LPCTSTR)mdata);
  1003. if(m_loadmenu)RemoveTopLevelOwnerDraw();
  1004. return(returnflag);
  1005. }
  1006. BOOL BCMenu::InsertODMenuA(UINT nPosition,LPCSTR lpstrText,UINT nFlags,UINT nID,
  1007. CImageList *il,int xoffset)
  1008. {
  1009. USES_CONVERSION;
  1010. return InsertODMenuW(nPosition,A2W(lpstrText),nFlags,nID,il,xoffset);
  1011. }
  1012. BOOL BCMenu::InsertODMenuW(UINT nPosition,wchar_t *lpstrText,UINT nFlags,UINT nID,
  1013. CImageList *il,int xoffset)
  1014. {
  1015. if(!(nFlags & MF_BYPOSITION)){
  1016. int iPosition =0;
  1017. BCMenu* pMenu = FindMenuOption(nPosition,iPosition);
  1018. if(pMenu){
  1019. return(pMenu->InsertODMenuW(iPosition,lpstrText,nFlags|MF_BYPOSITION,nID,il,xoffset));
  1020. }
  1021. else return(FALSE);
  1022. }
  1023. if(!nID)nFlags=MF_SEPARATOR|MF_OWNERDRAW|MF_BYPOSITION;
  1024. else if(!(nFlags & MF_OWNERDRAW))nFlags |= MF_OWNERDRAW;
  1025. if(nFlags & MF_POPUP){
  1026. m_AllSubMenus.Add((HMENU)nID);
  1027. m_SubMenus.InsertAt(nPosition,(HMENU)nID);
  1028. }
  1029. //Stephane Clog suggested adding this, believe it or not it's in the help
  1030. if(nPosition==(UINT)-1)nPosition=GetMenuItemCount();
  1031. BCMenuData *mdata = new BCMenuData;
  1032. m_MenuList.InsertAt(nPosition,mdata);
  1033. mdata->SetWideString(lpstrText); //SK: modified for dynamic allocation
  1034. mdata->menuIconNormal = -1;
  1035. mdata->xoffset = -1;
  1036. if(il){
  1037. if(mdata->bitmap){
  1038. mdata->bitmap->DeleteImageList();
  1039. mdata->bitmap=NULL;
  1040. }
  1041. mdata->global_offset = AddToGlobalImageList(il,xoffset,nID);
  1042. }
  1043. mdata->nFlags = nFlags;
  1044. mdata->nID = nID;
  1045. return(CMenu::InsertMenu(nPosition,nFlags,nID,(LPCTSTR)mdata));
  1046. }
  1047. BOOL BCMenu::ModifyODMenuA(const char * lpstrText,UINT nID,int nIconNormal)
  1048. {
  1049. USES_CONVERSION;
  1050. return ModifyODMenuW(A2W(lpstrText),nID,nIconNormal);//SK: see MFC Tech Note 059
  1051. }
  1052. BOOL BCMenu::ModifyODMenuW(wchar_t *lpstrText,UINT nID,int nIconNormal)
  1053. {
  1054. int nLoc;
  1055. BCMenuData *mdata;
  1056. CArray<BCMenu*,BCMenu*>bcsubs;
  1057. CArray<int,int&>bclocs;
  1058. // Find the old BCMenuData structure:
  1059. BCMenu *psubmenu = FindMenuOption(nID,nLoc);
  1060. do{
  1061. if(psubmenu && nLoc>=0)mdata = psubmenu->m_MenuList[nLoc];
  1062. else{
  1063. // Create a new BCMenuData structure:
  1064. mdata = new BCMenuData;
  1065. m_MenuList.Add(mdata);
  1066. }
  1067. ASSERT(mdata);
  1068. if(lpstrText)
  1069. mdata->SetWideString(lpstrText); //SK: modified for dynamic allocation
  1070. mdata->menuIconNormal = -1;
  1071. mdata->xoffset = -1;
  1072. if(nIconNormal>=0){
  1073. CImageList bitmap;
  1074. int xoffset=0;
  1075. LoadFromToolBar(nID,nIconNormal,xoffset);
  1076. if(mdata->bitmap){
  1077. mdata->bitmap->DeleteImageList();
  1078. mdata->bitmap=NULL;
  1079. }
  1080. bitmap.Create(m_iconX,m_iconY,ILC_COLORDDB|ILC_MASK,1,1);
  1081. if(AddBitmapToImageList(&bitmap,nIconNormal)){
  1082. mdata->global_offset = AddToGlobalImageList(&bitmap,xoffset,nID);
  1083. }
  1084. }
  1085. else mdata->global_offset = GlobalImageListOffset(nID);
  1086. mdata->nFlags &= ~(MF_BYPOSITION);
  1087. mdata->nFlags |= MF_OWNERDRAW;
  1088. mdata->nID = nID;
  1089. bcsubs.Add(psubmenu);
  1090. bclocs.Add(nLoc);
  1091. if(psubmenu && nLoc>=0)psubmenu = FindAnotherMenuOption(nID,nLoc,bcsubs,bclocs);
  1092. else psubmenu=NULL;
  1093. }while(psubmenu);
  1094. return (CMenu::ModifyMenu(nID,mdata->nFlags,nID,(LPCTSTR)mdata));
  1095. }
  1096. BOOL BCMenu::ModifyODMenuA(const char * lpstrText,UINT nID,CImageList *il,int xoffset)
  1097. {
  1098. USES_CONVERSION;
  1099. return ModifyODMenuW(A2W(lpstrText),nID,il,xoffset);
  1100. }
  1101. BOOL BCMenu::ModifyODMenuW(wchar_t *lpstrText,UINT nID,CImageList *il,int xoffset)
  1102. {
  1103. int nLoc;
  1104. BCMenuData *mdata;
  1105. CArray<BCMenu*,BCMenu*>bcsubs;
  1106. CArray<int,int&>bclocs;
  1107. // Find the old BCMenuData structure:
  1108. BCMenu *psubmenu = FindMenuOption(nID,nLoc);
  1109. do{
  1110. if(psubmenu && nLoc>=0)mdata = psubmenu->m_MenuList[nLoc];
  1111. else{
  1112. // Create a new BCMenuData structure:
  1113. mdata = new BCMenuData;
  1114. m_MenuList.Add(mdata);
  1115. }
  1116. ASSERT(mdata);
  1117. if(lpstrText)
  1118. mdata->SetWideString(lpstrText); //SK: modified for dynamic allocation
  1119. mdata->menuIconNormal = -1;
  1120. mdata->xoffset = -1;
  1121. if(il){
  1122. if(mdata->bitmap){
  1123. mdata->bitmap->DeleteImageList();
  1124. mdata->bitmap=NULL;
  1125. }
  1126. mdata->global_offset = AddToGlobalImageList(il,xoffset,nID);
  1127. }
  1128. mdata->nFlags &= ~(MF_BYPOSITION);
  1129. mdata->nFlags |= MF_OWNERDRAW;
  1130. mdata->nID = nID;
  1131. bcsubs.Add(psubmenu);
  1132. bclocs.Add(nLoc);
  1133. if(psubmenu && nLoc>=0)psubmenu = FindAnotherMenuOption(nID,nLoc,bcsubs,bclocs);
  1134. else psubmenu=NULL;
  1135. }while(psubmenu);
  1136. return (CMenu::ModifyMenu(nID,mdata->nFlags,nID,(LPCTSTR)mdata));
  1137. }
  1138. BOOL BCMenu::ModifyODMenuA(const char * lpstrText,UINT nID,CBitmap *bmp)
  1139. {
  1140. USES_CONVERSION;
  1141. return ModifyODMenuW(A2W(lpstrText),nID,bmp);
  1142. }
  1143. BOOL BCMenu::ModifyODMenuW(wchar_t *lpstrText,UINT nID,CBitmap *bmp)
  1144. {
  1145. if(bmp){
  1146. CImageList temp;
  1147. temp.Create(m_iconX,m_iconY,ILC_COLORDDB|ILC_MASK,1,1);
  1148. if(m_bitmapBackgroundFlag)temp.Add(bmp,m_bitmapBackground);
  1149. else temp.Add(bmp,GetSysColor(COLOR_3DFACE));
  1150. return ModifyODMenuW(lpstrText,nID,&temp,0);
  1151. }
  1152. return ModifyODMenuW(lpstrText,nID,NULL,0);
  1153. }
  1154. // courtesy of Warren Stevens
  1155. BOOL BCMenu::ModifyODMenuA(const char * lpstrText,UINT nID,COLORREF fill,COLORREF border,int hatchstyle,CSize *pSize)
  1156. {
  1157. USES_CONVERSION;
  1158. return ModifyODMenuW(A2W(lpstrText),nID,fill,border,hatchstyle,pSize);
  1159. }
  1160. BOOL BCMenu::ModifyODMenuW(wchar_t *lpstrText,UINT nID,COLORREF fill,COLORREF border,int hatchstyle,CSize *pSize)
  1161. {
  1162. CWnd *pWnd = AfxGetMainWnd(); // Get main window
  1163. CDC *pDC = pWnd->GetDC(); // Get device context
  1164. SIZE sz;
  1165. if(!pSize){
  1166. sz.cx = m_iconX;
  1167. sz.cy = m_iconY;
  1168. }
  1169. else{
  1170. sz.cx = pSize->cx;
  1171. sz.cy = pSize->cy;
  1172. }
  1173. CSize bitmap_size(sz);
  1174. CSize icon_size(m_iconX,m_iconY);
  1175. CBitmap bmp;
  1176. ColorBitmap(pDC,bmp,bitmap_size,icon_size,fill,border,hatchstyle);
  1177. pWnd->ReleaseDC(pDC);
  1178. return ModifyODMenuW(lpstrText,nID,&bmp);
  1179. }
  1180. BOOL BCMenu::ModifyODMenuA(const char *lpstrText,const char *OptionText,
  1181. int nIconNormal)
  1182. {
  1183. USES_CONVERSION;
  1184. return ModifyODMenuW(A2W(lpstrText),A2W(OptionText),nIconNormal);//SK: see MFC Tech Note 059
  1185. }
  1186. BOOL BCMenu::ModifyODMenuW(wchar_t *lpstrText,wchar_t *OptionText,
  1187. int nIconNormal)
  1188. {
  1189. BCMenuData *mdata;
  1190. // Find the old BCMenuData structure:
  1191. #ifdef _UNICODE
  1192. CString junk;
  1193. #else
  1194. CStringW junk;
  1195. #endif
  1196. junk=OptionText;
  1197. mdata=FindMenuOption(OptionText);
  1198. if(mdata){
  1199. if(lpstrText)
  1200. mdata->SetWideString(lpstrText);//SK: modified for dynamic allocation
  1201. mdata->menuIconNormal = nIconNormal;
  1202. mdata->xoffset=-1;
  1203. if(nIconNormal>=0){
  1204. mdata->xoffset=0;
  1205. if(mdata->bitmap)mdata->bitmap->DeleteImageList();
  1206. else mdata->bitmap=new(CImageList);
  1207. mdata->bitmap->Create(m_iconX,m_iconY,ILC_COLORDDB|ILC_MASK,1,1);
  1208. if(!AddBitmapToImageList(mdata->bitmap,nIconNormal)){
  1209. mdata->bitmap->DeleteImageList();
  1210. delete mdata->bitmap;
  1211. mdata->bitmap=NULL;
  1212. mdata->menuIconNormal = nIconNormal = -1;
  1213. mdata->xoffset = -1;
  1214. }
  1215. }
  1216. return(TRUE);
  1217. }
  1218. return(FALSE);
  1219. }
  1220. BCMenuData *BCMenu::NewODMenu(UINT pos,UINT nFlags,UINT nID,CString string)
  1221. {
  1222. BCMenuData *mdata;
  1223. mdata = new BCMenuData;
  1224. mdata->menuIconNormal = -1;
  1225. mdata->xoffset=-1;
  1226. #ifdef UNICODE
  1227. mdata->SetWideString((LPCTSTR)string);//SK: modified for dynamic allocation
  1228. #else
  1229. mdata->SetAnsiString(string);
  1230. #endif
  1231. mdata->nFlags = nFlags;
  1232. mdata->nID = nID;
  1233. // if(nFlags & MF_POPUP)m_AllSubMenus.Add((HMENU)nID);
  1234. if (nFlags&MF_OWNERDRAW){
  1235. ASSERT(!(nFlags&MF_STRING));
  1236. ModifyMenu(pos,nFlags,nID,(LPCTSTR)mdata);
  1237. }
  1238. else if (nFlags&MF_STRING){
  1239. ASSERT(!(nFlags&MF_OWNERDRAW));
  1240. ModifyMenu(pos,nFlags,nID,mdata->GetString());
  1241. }
  1242. else{
  1243. ASSERT(nFlags&MF_SEPARATOR);
  1244. ModifyMenu(pos,nFlags,nID);
  1245. }
  1246. return(mdata);
  1247. };
  1248. BOOL BCMenu::LoadToolbars(const UINT *arID,int n)
  1249. {
  1250. ASSERT(arID);
  1251. BOOL returnflag=TRUE;
  1252. for(int i=0;i<n;++i){
  1253. if(!LoadToolbar(arID[i]))returnflag=FALSE;
  1254. }
  1255. return(returnflag);
  1256. }
  1257. BOOL BCMenu::LoadToolbar(UINT nToolBar)
  1258. {
  1259. UINT nID,nStyle;
  1260. BOOL returnflag=FALSE;
  1261. BCMenuToolBar bar;
  1262. int xoffset=-1,xset;
  1263. int iconx,icony;
  1264. CWnd* pWnd = AfxGetMainWnd();
  1265. if (pWnd == NULL)pWnd = CWnd::GetDesktopWindow();
  1266. bar.Create(pWnd);
  1267. if(bar.LoadToolBar(nToolBar)){
  1268. bar.GetIconSize(iconx,icony);
  1269. if(iconx>m_iconX)m_iconX=iconx;
  1270. if(icony>m_iconY)m_iconY=icony;
  1271. CImageList imglist;
  1272. imglist.Create(m_iconX,m_iconY,ILC_COLORDDB|ILC_MASK,1,1);
  1273. if(AddBitmapToImageList(&imglist,nToolBar)){
  1274. returnflag=TRUE;
  1275. for(int i=0;i<bar.GetCount();++i){
  1276. nID = bar.GetItemID(i);
  1277. if(nID && GetMenuState(nID, MF_BYCOMMAND)
  1278. !=0xFFFFFFFF){
  1279. xoffset=bar.CommandToIndex(nID);
  1280. if(xoffset>=0){
  1281. bar.GetButtonInfo(xoffset,nID,nStyle,xset);
  1282. if(xset>0)xoffset=xset;
  1283. }
  1284. ModifyODMenu(NULL,nID,&imglist,xoffset);
  1285. }
  1286. }
  1287. }
  1288. }
  1289. return(returnflag);
  1290. }
  1291. BOOL BCMenu::LoadFromToolBar(UINT nID,UINT nToolBar,int& xoffset)
  1292. {
  1293. int xset,offset;
  1294. UINT nStyle;
  1295. BOOL returnflag=FALSE;
  1296. CToolBar bar;
  1297. CWnd* pWnd = AfxGetMainWnd();
  1298. if (pWnd == NULL)pWnd = CWnd::GetDesktopWindow();
  1299. bar.Create(pWnd);
  1300. if(bar.LoadToolBar(nToolBar)){
  1301. offset=bar.CommandToIndex(nID);
  1302. if(offset>=0){
  1303. bar.GetButtonInfo(offset,nID,nStyle,xset);
  1304. if(xset>0)xoffset=xset;
  1305. returnflag=TRUE;
  1306. }
  1307. }
  1308. return(returnflag);
  1309. }
  1310. // O.S.
  1311. BCMenuData *BCMenu::FindMenuItem(UINT nID)
  1312. {
  1313. BCMenuData *pData = NULL;
  1314. int i;
  1315. for(i = 0; i <= m_MenuList.GetUpperBound(); i++){
  1316. if (m_MenuList[i]->nID == nID){
  1317. pData = m_MenuList[i];
  1318. break;
  1319. }
  1320. }
  1321. if (!pData){
  1322. int loc;
  1323. BCMenu *pMenu = FindMenuOption(nID, loc);
  1324. ASSERT(pMenu != this);
  1325. if (loc >= 0){
  1326. return pMenu->FindMenuItem(nID);
  1327. }
  1328. }
  1329. return pData;
  1330. }
  1331. BCMenu *BCMenu::FindAnotherMenuOption(int nId,int& nLoc,CArray<BCMenu*,BCMenu*>&bcsubs,
  1332. CArray<int,int&>&bclocs)
  1333. {
  1334. int i,numsubs,j;
  1335. BCMenu *psubmenu,*pgoodmenu;
  1336. BOOL foundflag;
  1337. for(i=0;i<(int)(GetMenuItemCount());++i){
  1338. #ifdef _CPPRTTI
  1339. psubmenu=dynamic_cast<BCMenu *>(GetSubMenu(i));
  1340. #else
  1341. psubmenu=(BCMenu *)GetSubMenu(i);
  1342. #endif
  1343. if(psubmenu){
  1344. pgoodmenu=psubmenu->FindAnotherMenuOption(nId,nLoc,bcsubs,bclocs);
  1345. if(pgoodmenu)return(pgoodmenu);
  1346. }
  1347. else if(nId==(int)GetMenuItemID(i)){
  1348. numsubs=bcsubs.GetSize();
  1349. foundflag=TRUE;
  1350. for(j=0;j<numsubs;++j){
  1351. if(bcsubs[j]==this&&bclocs[j]==i){
  1352. foundflag=FALSE;
  1353. break;
  1354. }
  1355. }
  1356. if(foundflag){
  1357. nLoc=i;
  1358. return(this);
  1359. }
  1360. }
  1361. }
  1362. nLoc = -1;
  1363. return(NULL);
  1364. }
  1365. BCMenu *BCMenu::FindMenuOption(int nId,int& nLoc)
  1366. {
  1367. int i;
  1368. BCMenu *psubmenu,*pgoodmenu;
  1369. for(i=0;i<(int)(GetMenuItemCount());++i){
  1370. #ifdef _CPPRTTI
  1371. psubmenu=dynamic_cast<BCMenu *>(GetSubMenu(i));
  1372. #else
  1373. psubmenu=(BCMenu *)GetSubMenu(i);
  1374. #endif
  1375. if(psubmenu){
  1376. pgoodmenu=psubmenu->FindMenuOption(nId,nLoc);
  1377. if(pgoodmenu)return(pgoodmenu);
  1378. }
  1379. else if(nId==(int)GetMenuItemID(i)){
  1380. nLoc=i;
  1381. return(this);
  1382. }
  1383. }
  1384. nLoc = -1;
  1385. return(NULL);
  1386. }
  1387. BCMenuData *BCMenu::FindMenuOption(wchar_t *lpstrText)
  1388. {
  1389. int i,j;
  1390. BCMenu *psubmenu;
  1391. BCMenuData *pmenulist;
  1392. for(i=0;i<(int)(GetMenuItemCount());++i){
  1393. #ifdef _CPPRTTI
  1394. psubmenu=dynamic_cast<BCMenu *>(GetSubMenu(i));
  1395. #else
  1396. psubmenu=(BCMenu *)GetSubMenu(i);
  1397. #endif
  1398. if(psubmenu){
  1399. pmenulist=psubmenu->FindMenuOption(lpstrText);
  1400. if(pmenulist)return(pmenulist);
  1401. }
  1402. else{
  1403. const wchar_t *szWide;//SK: we use const to prevent misuse of this Ptr
  1404. for(j=0;j<=m_MenuList.GetUpperBound();++j){
  1405. szWide = m_MenuList[j]->GetWideString ();
  1406. if(szWide && !wcscmp(lpstrText,szWide))//SK: modified for dynamic allocation
  1407. return(m_MenuList[j]);
  1408. }
  1409. }
  1410. }
  1411. return(NULL);
  1412. }
  1413. BOOL BCMenu::LoadMenu(int nResource)
  1414. {
  1415. return(BCMenu::LoadMenu(MAKEINTRESOURCE(nResource)));
  1416. };
  1417. BOOL BCMenu::LoadMenu(LPCTSTR lpszResourceName)
  1418. {
  1419. ASSERT_VALID(this);
  1420. ASSERT(lpszResourceName != NULL);
  1421. // Find the Menu Resource:
  1422. HINSTANCE hInst = AfxFindResourceHandle(lpszResourceName,RT_MENU);
  1423. HRSRC hRsrc = ::FindResource(hInst,lpszResourceName,RT_MENU);
  1424. if (hRsrc == NULL){
  1425. hInst = NULL;
  1426. hRsrc = ::FindResource(hInst,lpszResourceName,RT_MENU);
  1427. }
  1428. if(hRsrc == NULL)return FALSE;
  1429. // Load the Menu Resource:
  1430. HGLOBAL hGlobal = LoadResource(hInst, hRsrc);
  1431. if(hGlobal == NULL)return FALSE;
  1432. // first destroy the menu if we're trying to loadmenu again
  1433. DestroyMenu();
  1434. // Attempt to create us as a menu...
  1435. if(!CMenu::CreateMenu())return FALSE;
  1436. // Get Item template Header, and calculate offset of MENUITEMTEMPLATES
  1437. MENUITEMTEMPLATEHEADER *pTpHdr=
  1438. (MENUITEMTEMPLATEHEADER*)LockResource(hGlobal);
  1439. BYTE* pTp=(BYTE*)pTpHdr +
  1440. (sizeof(MENUITEMTEMPLATEHEADER) + pTpHdr->offset);
  1441. // Variables needed during processing of Menu Item Templates:
  1442. int j=0;
  1443. WORD dwFlags = 0; // Flags of the Menu Item
  1444. WORD dwID = 0; // ID of the Menu Item
  1445. UINT uFlags; // Actual Flags.
  1446. wchar_t *szCaption=NULL;
  1447. int nLen = 0; // Length of caption
  1448. CTypedPtrArray<CPtrArray, BCMenu*> m_Stack; // Popup menu stack
  1449. CArray<BOOL,BOOL> m_StackEnd; // Popup menu stack
  1450. m_Stack.Add(this); // Add it to this...
  1451. m_StackEnd.Add(FALSE);
  1452. do{
  1453. // Obtain Flags and (if necessary), the ID...
  1454. memcpy(&dwFlags, pTp, sizeof(WORD));pTp+=sizeof(WORD);// Obtain Flags
  1455. if(!(dwFlags & MF_POPUP)){
  1456. memcpy(&dwID, pTp, sizeof(WORD)); // Obtain ID
  1457. pTp+=sizeof(WORD);
  1458. }
  1459. else dwID = 0;
  1460. uFlags = (UINT)dwFlags; // Remove MF_END from the flags that will
  1461. if(uFlags & MF_END) // be passed to the Append(OD)Menu functions.
  1462. uFlags -= MF_END;
  1463. // Obtain Caption (and length)
  1464. nLen = 0;
  1465. szCaption=new wchar_t[wcslen((wchar_t *)pTp)+1];
  1466. wcscpy(szCaption,(wchar_t *)pTp);
  1467. pTp=&pTp[(wcslen((wchar_t *)pTp)+1)*sizeof(wchar_t)];//modified SK
  1468. // Handle popup menus first....
  1469. //WideCharToMultiByte
  1470. if(dwFlags & MF_POPUP){
  1471. if(dwFlags & MF_END)m_StackEnd.SetAt(m_Stack.GetUpperBound(),TRUE);
  1472. BCMenu* pSubMenu = new BCMenu;
  1473. pSubMenu->m_unselectcheck=m_unselectcheck;
  1474. pSubMenu->m_selectcheck=m_selectcheck;
  1475. pSubMenu->checkmaps=checkmaps;
  1476. pSubMenu->checkmapsshare=TRUE;
  1477. pSubMenu->CreatePopupMenu();
  1478. // Append it to the top of the stack:
  1479. m_Stack[m_Stack.GetUpperBound()]->AppendODMenuW(szCaption,uFlags,
  1480. (UINT)pSubMenu->m_hMenu, -1);
  1481. m_Stack.Add(pSubMenu);
  1482. m_StackEnd.Add(FALSE);
  1483. }
  1484. else {
  1485. m_Stack[m_Stack.GetUpperBound()]->AppendODMenuW(szCaption, uFlags,
  1486. dwID, -1);
  1487. if(dwFlags & MF_END)m_StackEnd.SetAt(m_Stack.GetUpperBound(),TRUE);
  1488. j = m_Stack.GetUpperBound();
  1489. while(j>=0 && m_StackEnd.GetAt(j)){
  1490. m_Stack[m_Stack.GetUpperBound()]->InsertSpaces();
  1491. m_Stack.RemoveAt(j);
  1492. m_StackEnd.RemoveAt(j);
  1493. --j;
  1494. }
  1495. }
  1496. delete[] szCaption;
  1497. }while(m_Stack.GetUpperBound() != -1);
  1498. for(int i=0;i<(int)GetMenuItemCount();++i){
  1499. CString str=m_MenuList[i]->GetString();
  1500. if(GetSubMenu(i)){
  1501. m_MenuList[i]->nFlags=MF_POPUP|MF_BYPOSITION;
  1502. ModifyMenu(i,MF_POPUP|MF_BYPOSITION,
  1503. (UINT)GetSubMenu(i)->m_hMenu,str);
  1504. }
  1505. else{
  1506. m_MenuList[i]->nFlags=MF_STRING|MF_BYPOSITION;
  1507. ModifyMenu(i,MF_STRING|MF_BYPOSITION,m_MenuList[i]->nID,str);
  1508. }
  1509. }
  1510. m_loadmenu=TRUE;
  1511. return(TRUE);
  1512. }
  1513. int BCMenu::GetMenuStart(void)
  1514. {
  1515. if(!m_loadmenu)return(0);
  1516. CString name,str;
  1517. int menuloc=-1,listloc=-1,menustart=0,i=0,j=0;
  1518. int nummenulist=m_MenuList.GetSize();
  1519. int nummenu=(int)GetMenuItemCount();
  1520. while(i<nummenu&&menuloc==-1){
  1521. GetMenuString (i, name, MF_BYPOSITION);
  1522. if(name.GetLength()>0){
  1523. for(j=0;j<nummenulist;++j){
  1524. str=m_MenuList[j]->GetString();
  1525. if(name==str){
  1526. menuloc=i;
  1527. listloc=j;
  1528. break;
  1529. }
  1530. }
  1531. }
  1532. ++i;
  1533. }
  1534. if(menuloc>=0&&listloc>=0&&menuloc>=listloc)menustart=menuloc-listloc;
  1535. return(menustart);
  1536. }
  1537. void BCMenu::RemoveTopLevelOwnerDraw(void)
  1538. {
  1539. CString str;
  1540. int i=0,j=0;
  1541. int nummenulist=m_MenuList.GetSize(),menustart;
  1542. menustart=GetMenuStart();
  1543. for(i=menustart,j=0;i<(int)GetMenuItemCount();++i,++j){
  1544. if(j<nummenulist){
  1545. str=m_MenuList[j]->GetString();
  1546. if(GetSubMenu(i)){
  1547. m_MenuList[j]->nFlags=MF_POPUP|MF_BYPOSITION;
  1548. ModifyMenu(i,MF_POPUP|MF_BYPOSITION,
  1549. (UINT)GetSubMenu(i)->m_hMenu,str);
  1550. }
  1551. }
  1552. }
  1553. }
  1554. void BCMenu::InsertSpaces(void)
  1555. {
  1556. int i,j,numitems,maxlength;
  1557. CString string,newstring;
  1558. CSize t;
  1559. CFont m_fontMenu;
  1560. LOGFONT m_lf;
  1561. ZeroMemory ((PVOID) &m_lf,sizeof (LOGFONT));
  1562. NONCLIENTMETRICS nm;
  1563. nm.cbSize = sizeof (NONCLIENTMETRICS);
  1564. VERIFY (SystemParametersInfo (SPI_GETNONCLIENTMETRICS,nm.cbSize,&nm,0));
  1565. m_lf = nm.lfMenuFont;
  1566. m_fontMenu.CreateFontIndirect (&m_lf);
  1567. CWnd *pWnd = AfxGetMainWnd();
  1568. if (pWnd == NULL)pWnd = CWnd::GetDesktopWindow();
  1569. CDC *pDC = pWnd->GetDC();
  1570. CFont* pFont = pDC->SelectObject (&m_fontMenu);
  1571. numitems=GetMenuItemCount();
  1572. maxlength = -1;
  1573. for(i=0;i<numitems;++i){
  1574. string=m_MenuList[i]->GetString();
  1575. j=string.Find((char)9);
  1576. newstring.Empty();
  1577. if(j!=-1)newstring=string.Left(j);
  1578. else newstring=string;
  1579. newstring+=_T(" ");//SK: modified for Unicode correctness.
  1580. LPCTSTR lpstrText = (LPCTSTR)newstring;
  1581. t=pDC->GetTextExtent(lpstrText,_tcslen(lpstrText));
  1582. if(t.cx>maxlength)maxlength = t.cx;
  1583. }
  1584. for(i=0;i<numitems;++i){
  1585. string=m_MenuList[i]->GetString();
  1586. j=string.Find((char)9);
  1587. if(j!=-1){
  1588. newstring.Empty();
  1589. newstring=string.Left(j);
  1590. LPCTSTR lpstrText = (LPCTSTR)(newstring);
  1591. t=pDC->GetTextExtent(lpstrText,_tcslen(lpstrText));
  1592. while(t.cx<maxlength){
  1593. newstring+=_T(' ');//SK: modified for Unicode correctness
  1594. LPCTSTR lpstrText = (LPCTSTR)(newstring);
  1595. t=pDC->GetTextExtent(lpstrText,_tcslen(lpstrText));
  1596. }
  1597. newstring+=string.Mid(j);
  1598. #ifdef UNICODE
  1599. m_MenuList[i]->SetWideString(newstring);//SK: modified for dynamic allocation
  1600. #else
  1601. m_MenuList[i]->SetAnsiString(newstring);
  1602. #endif
  1603. }
  1604. }
  1605. pDC->SelectObject (pFont); // Select old font in
  1606. pWnd->ReleaseDC(pDC); // Release the DC
  1607. m_fontMenu.DeleteObject();
  1608. }
  1609. void BCMenu::LoadCheckmarkBitmap(int unselect, int select)
  1610. {
  1611. if(unselect>0 && select>0){
  1612. m_selectcheck=select;
  1613. m_unselectcheck=unselect;
  1614. if(checkmaps)checkmaps->DeleteImageList();
  1615. else checkmaps=new(CImageList);
  1616. checkmaps->Create(m_iconX,m_iconY,ILC_MASK,2,1);
  1617. BOOL flag1=AddBitmapToImageList(checkmaps,unselect);
  1618. BOOL flag2=AddBitmapToImageList(checkmaps,select);
  1619. if(!flag1||!flag2){
  1620. checkmaps->DeleteImageList();
  1621. delete checkmaps;
  1622. checkmaps=NULL;
  1623. }
  1624. }
  1625. }
  1626. //--------------------------------------------------------------------------
  1627. //[18.06.99 rj]
  1628. BOOL BCMenu::GetMenuText(UINT id, CString& string, UINT nFlags/*= MF_BYPOSITION*/)
  1629. {
  1630. BOOL returnflag=FALSE;
  1631. if(MF_BYPOSITION&nFlags){
  1632. UINT numMenuItems = m_MenuList.GetUpperBound();
  1633. if(id<=numMenuItems){
  1634. string=m_MenuList[id]->GetString();
  1635. returnflag=TRUE;
  1636. }
  1637. }
  1638. else{
  1639. int uiLoc;
  1640. BCMenu* pMenu = FindMenuOption(id,uiLoc);
  1641. if(NULL!=pMenu) returnflag = pMenu->GetMenuText(uiLoc,string);
  1642. }
  1643. return(returnflag);
  1644. }
  1645. void BCMenu::DrawRadioDot(CDC *pDC,int x,int y,COLORREF color)
  1646. {
  1647. CRect rcDot(x,y,x+6,y+6);
  1648. CBrush brush;
  1649. CPen pen;
  1650. brush.CreateSolidBrush(color);
  1651. pen.CreatePen(PS_SOLID,0,color);
  1652. CBrush *pOldBrush=pDC->SelectObject(&brush);
  1653. CPen *pOldPen=pDC->SelectObject(&pen);
  1654. pDC->Ellipse(&rcDot);
  1655. pDC->SelectObject(pOldBrush);
  1656. pDC->SelectObject(pOldPen);
  1657. pen.DeleteObject();
  1658. brush.DeleteObject();
  1659. }
  1660. void BCMenu::DrawCheckMark(CDC* pDC,int x,int y,COLORREF color)
  1661. {
  1662. CPen m_penBack;
  1663. m_penBack.CreatePen (PS_SOLID,0,color);
  1664. CPen *pOldPen = pDC->SelectObject (&m_penBack);
  1665. pDC->MoveTo(x,y+2);
  1666. pDC->LineTo(x,y+5);
  1667. pDC->MoveTo(x+1,y+3);
  1668. pDC->LineTo(x+1,y+6);
  1669. pDC->MoveTo(x+2,y+4);
  1670. pDC->LineTo(x+2,y+7);
  1671. pDC->MoveTo(x+3,y+3);
  1672. pDC->LineTo(x+3,y+6);
  1673. pDC->MoveTo(x+4,y+2);
  1674. pDC->LineTo(x+4,y+5);
  1675. pDC->MoveTo(x+5,y+1);
  1676. pDC->LineTo(x+5,y+4);
  1677. pDC->MoveTo(x+6,y);
  1678. pDC->LineTo(x+6,y+3);
  1679. pDC->SelectObject (pOldPen);
  1680. m_penBack.DeleteObject();
  1681. }
  1682. BCMenuData *BCMenu::FindMenuList(UINT nID)
  1683. {
  1684. for(int i=0;i<=m_MenuList.GetUpperBound();++i){
  1685. if(m_MenuList[i]->nID==nID && !m_MenuList[i]->syncflag){
  1686. m_MenuList[i]->syncflag=1;
  1687. return(m_MenuList[i]);
  1688. }
  1689. }
  1690. return(NULL);
  1691. }
  1692. void BCMenu::InitializeMenuList(int value)
  1693. {
  1694. for(int i=0;i<=m_MenuList.GetUpperBound();++i)
  1695. m_MenuList[i]->syncflag=value;
  1696. }
  1697. void BCMenu::DeleteMenuList(void)
  1698. {
  1699. for(int i=0;i<=m_MenuList.GetUpperBound();++i){
  1700. if(!m_MenuList[i]->syncflag){
  1701. delete m_MenuList[i];
  1702. }
  1703. }
  1704. }
  1705. void BCMenu::SynchronizeMenu(void)
  1706. {
  1707. CTypedPtrArray<CPtrArray, BCMenuData*> temp;
  1708. BCMenuData *mdata;
  1709. CString string;
  1710. UINT submenu,nID=0,state,j;
  1711. InitializeMenuList(0);
  1712. for(j=0;j<GetMenuItemCount();++j){
  1713. mdata=NULL;
  1714. state=GetMenuState(j,MF_BYPOSITION);
  1715. if(state&MF_POPUP){
  1716. submenu=(UINT)GetSubMenu(j)->m_hMenu;
  1717. mdata=FindMenuList(submenu);
  1718. GetMenuString(j,string,MF_BYPOSITION);
  1719. if(!mdata)mdata=NewODMenu(j,
  1720. (state&0xFF)|MF_BYPOSITION|MF_POPUP|MF_OWNERDRAW,submenu,string);
  1721. else if(string.GetLength()>0)
  1722. #ifdef UNICODE
  1723. mdata->SetWideString(string); //SK: modified for dynamic allocation
  1724. #else
  1725. mdata->SetAnsiString(string);
  1726. #endif
  1727. }
  1728. else if(state&MF_SEPARATOR){
  1729. mdata=FindMenuList(0);
  1730. if(!mdata)mdata=NewODMenu(j,
  1731. state|MF_BYPOSITION|MF_SEPARATOR|MF_OWNERDRAW,0,_T(""));//SK: modified for Unicode correctness
  1732. else ModifyMenu(j,mdata->nFlags,nID,(LPCTSTR)mdata);
  1733. }
  1734. else{
  1735. nID=GetMenuItemID(j);
  1736. mdata=FindMenuList(nID);
  1737. GetMenuString(j,string,MF_BYPOSITION);
  1738. if(!mdata)mdata=NewODMenu(j,state|MF_BYPOSITION|MF_OWNERDRAW,
  1739. nID,string);
  1740. else{
  1741. mdata->nFlags=state|MF_BYPOSITION|MF_OWNERDRAW;
  1742. if(string.GetLength()>0)
  1743. #ifdef UNICODE
  1744. mdata->SetWideString(string);//SK: modified for dynamic allocation
  1745. #else
  1746. mdata->SetAnsiString(string);
  1747. #endif
  1748. ModifyMenu(j,mdata->nFlags,nID,(LPCTSTR)mdata);
  1749. }
  1750. }
  1751. if(mdata)temp.Add(mdata);
  1752. }
  1753. DeleteMenuList();
  1754. m_MenuList.RemoveAll();
  1755. m_MenuList.Append(temp);
  1756. temp.RemoveAll();
  1757. }
  1758. void BCMenu::UpdateMenu(CMenu *pmenu)
  1759. {
  1760. #ifdef _CPPRTTI
  1761. BCMenu *psubmenu = dynamic_cast<BCMenu *>(pmenu);
  1762. #else
  1763. BCMenu *psubmenu = (BCMenu *)pmenu;
  1764. #endif
  1765. if(psubmenu)psubmenu->SynchronizeMenu();
  1766. }
  1767. LRESULT BCMenu::FindKeyboardShortcut(UINT nChar, UINT nFlags,
  1768. CMenu *pMenu)
  1769. {
  1770. #ifdef _CPPRTTI
  1771. BCMenu *pBCMenu = dynamic_cast<BCMenu *>(pMenu);
  1772. #else
  1773. BCMenu *pBCMenu = (BCMenu *)pMenu;
  1774. #endif
  1775. if(pBCMenu && nFlags&MF_POPUP){
  1776. CString key(_T('&'),2);//SK: modified for Unicode correctness
  1777. key.SetAt(1,(TCHAR)nChar);
  1778. key.MakeLower();
  1779. CString menutext;
  1780. int menusize = (int)pBCMenu->GetMenuItemCount();
  1781. if(menusize!=(pBCMenu->m_MenuList.GetUpperBound()+1))
  1782. pBCMenu->SynchronizeMenu();
  1783. for(int i=0;i<menusize;++i){
  1784. if(pBCMenu->GetMenuText(i,menutext)){
  1785. menutext.MakeLower();
  1786. if(menutext.Find(key)>=0)return(MAKELRESULT(i,2));
  1787. }
  1788. }
  1789. }
  1790. return(0);
  1791. }
  1792. void BCMenu::DitherBlt (HDC hdcDest, int nXDest, int nYDest, int nWidth,
  1793. int nHeight, HBITMAP hbm, int nXSrc, int nYSrc,
  1794. COLORREF bgcolor)
  1795. {
  1796. ASSERT(hdcDest && hbm);
  1797. ASSERT(nWidth > 0 && nHeight > 0);
  1798. // Create a generic DC for all BitBlts
  1799. HDC hDC = CreateCompatibleDC(hdcDest);
  1800. ASSERT(hDC);
  1801. if (hDC)
  1802. {
  1803. // Create a DC for the monochrome DIB section
  1804. HDC bwDC = CreateCompatibleDC(hDC);
  1805. ASSERT(bwDC);
  1806. if (bwDC)
  1807. {
  1808. // Create the monochrome DIB section with a black and white palette
  1809. struct {
  1810. BITMAPINFOHEADER bmiHeader;
  1811. RGBQUAD bmiColors[2];
  1812. } RGBBWBITMAPINFO = {
  1813. { // a BITMAPINFOHEADER
  1814. sizeof(BITMAPINFOHEADER), // biSize
  1815. nWidth, // biWidth;
  1816. nHeight, // biHeight;
  1817. 1, // biPlanes;
  1818. 1, // biBitCount
  1819. BI_RGB, // biCompression;
  1820. 0, // biSizeImage;
  1821. 0, // biXPelsPerMeter;
  1822. 0, // biYPelsPerMeter;
  1823. 0, // biClrUsed;
  1824. 0 // biClrImportant;
  1825. },
  1826. {
  1827. { 0x00, 0x00, 0x00, 0x00 }, { 0xFF, 0xFF, 0xFF, 0x00 }
  1828. }
  1829. };
  1830. VOID *pbitsBW;
  1831. HBITMAP hbmBW = CreateDIBSection(bwDC,
  1832. (LPBITMAPINFO)&RGBBWBITMAPINFO, DIB_RGB_COLORS, &pbitsBW, NULL, 0);
  1833. ASSERT(hbmBW);
  1834. if (hbmBW)
  1835. {
  1836. // Attach the monochrome DIB section and the bitmap to the DCs
  1837. HBITMAP olddib = (HBITMAP)SelectObject(bwDC, hbmBW);
  1838. HBITMAP hdcolddib = (HBITMAP)SelectObject(hDC, hbm);
  1839. // BitBlt the bitmap into the monochrome DIB section
  1840. BitBlt(bwDC, 0, 0, nWidth, nHeight, hDC, nXSrc, nYSrc, SRCCOPY);
  1841. // Paint the destination rectangle in gray
  1842. FillRect(hdcDest, CRect(nXDest, nYDest, nXDest + nWidth, nYDest +
  1843. nHeight), GetSysColorBrush(bgcolor));
  1844. //SK: looks better on the old shell
  1845. // BitBlt the black bits in the monochrome bitmap into COLOR_3DHILIGHT
  1846. // bits in the destination DC
  1847. // The magic ROP comes from the Charles Petzold's book
  1848. HBRUSH hb = CreateSolidBrush(GetSysColor(COLOR_3DHILIGHT));
  1849. HBRUSH oldBrush = (HBRUSH)SelectObject(hdcDest, hb);
  1850. BitBlt(hdcDest,nXDest+1,nYDest+1,nWidth,nHeight,bwDC,0,0,0xB8074A);
  1851. // BitBlt the black bits in the monochrome bitmap into COLOR_3DSHADOW
  1852. // bits in the destination DC
  1853. hb = CreateSolidBrush(GetSysColor(COLOR_3DSHADOW));
  1854. DeleteObject(SelectObject(hdcDest, hb));
  1855. BitBlt(hdcDest, nXDest, nYDest, nWidth, nHeight,bwDC,0,0,0xB8074A);
  1856. DeleteObject(SelectObject(hdcDest, oldBrush));
  1857. VERIFY(DeleteObject(SelectObject(bwDC, olddib)));
  1858. SelectObject(hDC, hdcolddib);
  1859. }
  1860. VERIFY(DeleteDC(bwDC));
  1861. }
  1862. VERIFY(DeleteDC(hDC));
  1863. }
  1864. }
  1865. void BCMenu::GetFadedBitmap(CBitmap &bmp)
  1866. {
  1867. CDC ddc;
  1868. COLORREF bgcol,col;
  1869. BITMAP BitMap;
  1870. bmp.GetBitmap(&BitMap);
  1871. ddc.CreateCompatibleDC(NULL);
  1872. CBitmap * pddcOldBmp = ddc.SelectObject(&bmp);
  1873. // use this to get the background color, takes into account color shifting
  1874. CDC ddc2;
  1875. CBrush brush;
  1876. CBitmap bmp2;
  1877. ddc2.CreateCompatibleDC(NULL);
  1878. bmp2.CreateCompatibleBitmap(&ddc,BitMap.bmWidth,BitMap.bmHeight);
  1879. col=GetSysColor(COLOR_3DFACE);
  1880. brush.CreateSolidBrush(col);
  1881. CBitmap * pddcOldBmp2 = ddc2.SelectObject(&bmp2);
  1882. CRect rect(0,0,BitMap.bmWidth,BitMap.bmHeight);
  1883. ddc2.FillRect(rect,&brush);
  1884. bgcol=ddc2.GetPixel(1,1);
  1885. brush.DeleteObject();
  1886. ddc2.SelectObject(pddcOldBmp2);
  1887. for(int i=0;i<BitMap.bmWidth;++i){
  1888. for(int j=0;j<BitMap.bmHeight;++j){
  1889. col=ddc.GetPixel(i,j);
  1890. if(col!=bgcol)ddc.SetPixel(i,j,LightenColor(col,0.3));
  1891. }
  1892. }
  1893. ddc.SelectObject(pddcOldBmp);
  1894. }
  1895. void BCMenu::GetShadowBitmap(CBitmap &bmp)
  1896. {
  1897. CDC ddc;
  1898. COLORREF bgcol,col,shadowcol=GetSysColor(COLOR_BTNSHADOW);
  1899. BITMAP BitMap;
  1900. if(!IsWinXPLuna())shadowcol=LightenColor(shadowcol,0.49);
  1901. bmp.GetBitmap(&BitMap);
  1902. ddc.CreateCompatibleDC(NULL);
  1903. CBitmap * pddcOldBmp = ddc.SelectObject(&bmp);
  1904. // use this to get the background color, takes into account color shifting
  1905. CDC ddc2;
  1906. CBrush brush;
  1907. CBitmap bmp2;
  1908. ddc2.CreateCompatibleDC(NULL);
  1909. bmp2.CreateCompatibleBitmap(&ddc,BitMap.bmWidth,BitMap.bmHeight);
  1910. col=GetSysColor(COLOR_3DFACE);
  1911. brush.CreateSolidBrush(col);
  1912. CBitmap * pddcOldBmp2 = ddc2.SelectObject(&bmp2);
  1913. CRect rect(0,0,BitMap.bmWidth,BitMap.bmHeight);
  1914. ddc2.FillRect(rect,&brush);
  1915. bgcol=ddc2.GetPixel(1,1);
  1916. brush.DeleteObject();
  1917. ddc2.SelectObject(pddcOldBmp2);
  1918. for(int i=0;i<BitMap.bmWidth;++i){
  1919. for(int j=0;j<BitMap.bmHeight;++j){
  1920. col=ddc.GetPixel(i,j);
  1921. if(col!=bgcol)ddc.SetPixel(i,j,shadowcol);
  1922. }
  1923. }
  1924. ddc.SelectObject(pddcOldBmp);
  1925. }
  1926. BOOL BCMenu::AddBitmapToImageList(CImageList *bmplist,UINT nResourceID)
  1927. {
  1928. BOOL bReturn=FALSE;
  1929. // O.S.
  1930. if (m_bDynIcons){
  1931. bmplist->Add((HICON)nResourceID);
  1932. bReturn=TRUE;
  1933. }
  1934. else{
  1935. HBITMAP hbmp=LoadSysColorBitmap(nResourceID);
  1936. if(hbmp){
  1937. CBitmap bmp;
  1938. bmp.Attach(hbmp);
  1939. if(m_bitmapBackgroundFlag){
  1940. if(bmplist->Add(&bmp,m_bitmapBackground)>=0)bReturn=TRUE;
  1941. }
  1942. else{
  1943. if(bmplist->Add(&bmp,GetSysColor(COLOR_3DFACE))>=0)bReturn=TRUE;
  1944. }
  1945. bmp.Detach();
  1946. DeleteObject(hbmp);
  1947. }
  1948. else{
  1949. CBitmap mybmp;
  1950. if(mybmp.LoadBitmap(nResourceID)){
  1951. if(m_bitmapBackgroundFlag){
  1952. if(bmplist->Add(&mybmp,m_bitmapBackground)>=0)bReturn=TRUE;
  1953. }
  1954. else{
  1955. if(bmplist->Add(&mybmp,GetSysColor(COLOR_3DFACE))>=0)bReturn=TRUE;
  1956. }
  1957. }
  1958. }
  1959. }
  1960. if(bReturn&&IsLunaMenuStyle()&&xp_draw_3D_bitmaps){
  1961. CWnd *pWnd = AfxGetMainWnd(); // Get main window
  1962. if (pWnd == NULL) pWnd = CWnd::GetDesktopWindow();
  1963. CDC *pDC = pWnd->GetDC(); // Get device context
  1964. CBitmap bmp,bmp2;
  1965. GetBitmapFromImageList(pDC,bmplist,0,bmp);
  1966. GetFadedBitmap(bmp);
  1967. bmplist->Add(&bmp,GetSysColor(COLOR_3DFACE));
  1968. GetBitmapFromImageList(pDC,bmplist,0,bmp2);
  1969. GetShadowBitmap(bmp2);
  1970. bmplist->Add(&bmp2,GetSysColor(COLOR_3DFACE));
  1971. pWnd->ReleaseDC(pDC); // Release the DC
  1972. }
  1973. return(bReturn);
  1974. }
  1975. void BCMenu::SetBitmapBackground(COLORREF color)
  1976. {
  1977. m_bitmapBackground=color;
  1978. m_bitmapBackgroundFlag=TRUE;
  1979. }
  1980. void BCMenu::UnSetBitmapBackground(void)
  1981. {
  1982. m_bitmapBackgroundFlag=FALSE;
  1983. }
  1984. // Given a toolbar, append all the options from it to this menu
  1985. // Passed a ptr to the toolbar object and the toolbar ID
  1986. // Author : Robert Edward Caldecott
  1987. void BCMenu::AddFromToolBar(CToolBar* pToolBar, int nResourceID)
  1988. {
  1989. for (int i = 0; i < pToolBar->GetCount(); i++) {
  1990. UINT nID = pToolBar->GetItemID(i);
  1991. // See if this toolbar option
  1992. // appears as a command on this
  1993. // menu or is a separator
  1994. if (nID == 0 || GetMenuState(nID, MF_BYCOMMAND) == 0xFFFFFFFF)
  1995. continue; // Item doesn't exist
  1996. UINT nStyle;
  1997. int nImage;
  1998. // Get the toolbar button info
  1999. pToolBar->GetButtonInfo(i, nID, nStyle, nImage);
  2000. // OK, we have the command ID of the toolbar
  2001. // option, and the tollbar bitmap offset
  2002. int nLoc;
  2003. BCMenuData* pData;
  2004. BCMenu *pSubMenu = FindMenuOption(nID, nLoc);
  2005. if (pSubMenu && nLoc >= 0)pData = pSubMenu->m_MenuList[nLoc];
  2006. else {
  2007. // Create a new BCMenuData structure
  2008. pData = new BCMenuData;
  2009. m_MenuList.Add(pData);
  2010. }
  2011. // Set some default structure members
  2012. pData->menuIconNormal = nResourceID;
  2013. pData->nID = nID;
  2014. pData->nFlags = MF_BYCOMMAND | MF_OWNERDRAW;
  2015. pData->xoffset = nImage;
  2016. if (pData->bitmap)pData->bitmap->DeleteImageList();
  2017. else pData->bitmap = new CImageList;
  2018. pData->bitmap->Create(m_iconX, m_iconY,ILC_COLORDDB|ILC_MASK, 1, 1);
  2019. if(!AddBitmapToImageList(pData->bitmap, nResourceID)){
  2020. pData->bitmap->DeleteImageList();
  2021. delete pData->bitmap;
  2022. pData->bitmap=NULL;
  2023. pData->menuIconNormal = -1;
  2024. pData->xoffset = -1;
  2025. }
  2026. // Modify our menu
  2027. ModifyMenu(nID,pData->nFlags,nID,(LPCTSTR)pData);
  2028. }
  2029. }
  2030. BOOL BCMenu::Draw3DCheckmark(CDC *dc, const CRect& rc,
  2031. BOOL bSelected, HBITMAP hbmCheck)
  2032. {
  2033. CRect rcDest = rc;
  2034. CBrush brush;
  2035. COLORREF col;
  2036. if(IsWinXPLuna())col=GetSysColor(COLOR_3DFACE);
  2037. else col=GetSysColor(COLOR_MENU);
  2038. if(!bSelected)col = LightenColor(col,0.6);
  2039. brush.CreateSolidBrush(col);
  2040. dc->FillRect(rcDest,&brush);
  2041. brush.DeleteObject();
  2042. if (IsNewShell()) //SK: looks better on the old shell
  2043. dc->DrawEdge(&rcDest, BDR_SUNKENOUTER, BF_RECT);
  2044. if (!hbmCheck)DrawCheckMark(dc,rc.left+4,rc.top+4,GetSysColor(COLOR_MENUTEXT));
  2045. else DrawRadioDot(dc,rc.left+5,rc.top+4,GetSysColor(COLOR_MENUTEXT));
  2046. return TRUE;
  2047. }
  2048. BOOL BCMenu::DrawXPCheckmark(CDC *dc, const CRect& rc, HBITMAP hbmCheck,COLORREF &colorout)
  2049. {
  2050. CBrush brushin;
  2051. brushin.CreateSolidBrush(LightenColor(colorout,0.85));
  2052. dc->FillRect(rc,&brushin);
  2053. brushin.DeleteObject();
  2054. dc->Draw3dRect (rc,colorout,colorout);
  2055. if (!hbmCheck)DrawCheckMark(dc,rc.left+5,rc.top+4,GetSysColor(COLOR_MENUTEXT));
  2056. else DrawRadioDot(dc,rc.left+5,rc.top+4,GetSysColor(COLOR_MENUTEXT));
  2057. return TRUE;
  2058. }
  2059. void BCMenu::DitherBlt2(CDC *drawdc, int nXDest, int nYDest, int nWidth,
  2060. int nHeight, CBitmap &bmp, int nXSrc, int nYSrc,
  2061. COLORREF bgcolor)
  2062. {
  2063. // create a monochrome memory DC
  2064. CDC ddc;
  2065. ddc.CreateCompatibleDC(0);
  2066. CBitmap bwbmp;
  2067. bwbmp.CreateCompatibleBitmap(&ddc, nWidth, nHeight);
  2068. CBitmap * pddcOldBmp = ddc.SelectObject(&bwbmp);
  2069. CDC dc;
  2070. dc.CreateCompatibleDC(0);
  2071. CBitmap * pdcOldBmp = dc.SelectObject(&bmp);
  2072. // build a mask
  2073. ddc.PatBlt(0, 0, nWidth, nHeight, WHITENESS);
  2074. dc.SetBkColor(GetSysColor(COLOR_BTNFACE));
  2075. ddc.BitBlt(0, 0, nWidth, nHeight, &dc, nXSrc,nYSrc, SRCCOPY);
  2076. dc.SetBkColor(GetSysColor(COLOR_BTNHILIGHT));
  2077. ddc.BitBlt(0, 0, nWidth, nHeight, &dc, nXSrc,nYSrc, SRCPAINT);
  2078. // Copy the image from the toolbar into the memory DC
  2079. // and draw it (grayed) back into the toolbar.
  2080. dc.FillSolidRect(0,0, nWidth, nHeight, bgcolor);
  2081. //SK: Looks better on the old shell
  2082. dc.SetBkColor(RGB(0, 0, 0));
  2083. dc.SetTextColor(RGB(255, 255, 255));
  2084. CBrush brShadow, brHilight;
  2085. brHilight.CreateSolidBrush(GetSysColor(COLOR_BTNHILIGHT));
  2086. brShadow.CreateSolidBrush(GetSysColor(COLOR_BTNSHADOW));
  2087. CBrush * pOldBrush = dc.SelectObject(&brHilight);
  2088. dc.BitBlt(0,0, nWidth, nHeight, &ddc, 0, 0, 0x00E20746L);
  2089. drawdc->BitBlt(nXDest+1,nYDest+1,nWidth, nHeight, &dc,0,0,SRCCOPY);
  2090. dc.BitBlt(1,1, nWidth, nHeight, &ddc, 0, 0, 0x00E20746L);
  2091. dc.SelectObject(&brShadow);
  2092. dc.BitBlt(0,0, nWidth, nHeight, &ddc, 0, 0, 0x00E20746L);
  2093. drawdc->BitBlt(nXDest,nYDest,nWidth, nHeight, &dc,0,0,SRCCOPY);
  2094. // reset DCs
  2095. ddc.SelectObject(pddcOldBmp);
  2096. ddc.DeleteDC();
  2097. dc.SelectObject(pOldBrush);
  2098. dc.SelectObject(pdcOldBmp);
  2099. dc.DeleteDC();
  2100. brShadow.DeleteObject();
  2101. brHilight.DeleteObject();
  2102. bwbmp.DeleteObject();
  2103. }
  2104. void BCMenu::SetDisableOldStyle(void)
  2105. {
  2106. disable_old_style=TRUE;
  2107. }
  2108. void BCMenu::UnSetDisableOldStyle(void)
  2109. {
  2110. disable_old_style=FALSE;
  2111. }
  2112. BOOL BCMenu::GetDisableOldStyle(void)
  2113. {
  2114. return(disable_old_style);
  2115. }
  2116. WORD BCMenu::NumBitmapColors(LPBITMAPINFOHEADER lpBitmap)
  2117. {
  2118. if ( lpBitmap->biClrUsed != 0)
  2119. return (WORD)lpBitmap->biClrUsed;
  2120. switch (lpBitmap->biBitCount){
  2121. case 1:
  2122. return 2;
  2123. case 4:
  2124. return 16;
  2125. case 8:
  2126. return 256;
  2127. default:
  2128. return 0;
  2129. }
  2130. return 0;
  2131. }
  2132. HBITMAP BCMenu::LoadSysColorBitmap(int nResourceId)
  2133. {
  2134. HINSTANCE hInst =
  2135. AfxFindResourceHandle(MAKEINTRESOURCE(nResourceId),RT_BITMAP);
  2136. HRSRC hRsrc =
  2137. ::FindResource(hInst,MAKEINTRESOURCE(nResourceId),RT_BITMAP);
  2138. if (hRsrc == NULL){
  2139. hInst = NULL;
  2140. hRsrc = ::FindResource(hInst,MAKEINTRESOURCE(nResourceId),RT_BITMAP);
  2141. }
  2142. if (hRsrc == NULL)return NULL;
  2143. // determine how many colors in the bitmap
  2144. HGLOBAL hglb;
  2145. if ((hglb = LoadResource(hInst, hRsrc)) == NULL)
  2146. return NULL;
  2147. LPBITMAPINFOHEADER lpBitmap = (LPBITMAPINFOHEADER)LockResource(hglb);
  2148. if (lpBitmap == NULL)return NULL;
  2149. WORD numcol = NumBitmapColors(lpBitmap);
  2150. ::FreeResource(hglb);
  2151. if(numcol!=16)return(NULL);
  2152. return AfxLoadSysColorBitmap(hInst, hRsrc, FALSE);
  2153. }
  2154. BOOL BCMenu::RemoveMenu(UINT uiId,UINT nFlags)
  2155. {
  2156. if(MF_BYPOSITION&nFlags){
  2157. UINT uint = GetMenuState(uiId,MF_BYPOSITION);
  2158. if(uint&MF_SEPARATOR && !(uint&MF_POPUP)){
  2159. delete m_MenuList.GetAt(uiId);
  2160. m_MenuList.RemoveAt(uiId);
  2161. }
  2162. else{
  2163. BCMenu* pSubMenu = (BCMenu*) GetSubMenu(uiId);
  2164. if(NULL==pSubMenu){
  2165. UINT uiCommandId = GetMenuItemID(uiId);
  2166. for(int i=0;i<m_MenuList.GetSize(); i++){
  2167. if(m_MenuList[i]->nID==uiCommandId){
  2168. delete m_MenuList.GetAt(i);
  2169. m_MenuList.RemoveAt(i);
  2170. break;
  2171. }
  2172. }
  2173. }
  2174. else{
  2175. int numSubMenus = m_SubMenus.GetUpperBound();
  2176. for(int m = numSubMenus; m >= 0; m--){
  2177. if(m_SubMenus[m]==pSubMenu->m_hMenu){
  2178. int numAllSubMenus = m_AllSubMenus.GetUpperBound();
  2179. for(int n = numAllSubMenus; n>= 0; n--){
  2180. if(m_AllSubMenus[n]==m_SubMenus[m])m_AllSubMenus.RemoveAt(n);
  2181. }
  2182. m_SubMenus.RemoveAt(m);
  2183. }
  2184. }
  2185. int num = pSubMenu->GetMenuItemCount();
  2186. for(int i=num-1;i>=0;--i)
  2187. pSubMenu->RemoveMenu(i,MF_BYPOSITION);
  2188. for(int i=m_MenuList.GetUpperBound();i>=0;i--){
  2189. if(m_MenuList[i]->nID==(UINT)pSubMenu->m_hMenu){
  2190. delete m_MenuList.GetAt(i);
  2191. m_MenuList.RemoveAt(i);
  2192. break;
  2193. }
  2194. }
  2195. delete pSubMenu;
  2196. }
  2197. }
  2198. }
  2199. else{
  2200. int iPosition =0;
  2201. BCMenu* pMenu = FindMenuOption(uiId,iPosition);
  2202. // bug fix RIA 14th September 2000
  2203. // failed to return correct value on call to remove menu as the item was
  2204. // removed twice. The second time its not found
  2205. // so a value of 0 was being returned
  2206. if(pMenu) return pMenu->RemoveMenu(iPosition,MF_BYPOSITION); // added return
  2207. }
  2208. return CMenu::RemoveMenu(uiId,nFlags);
  2209. }
  2210. BOOL BCMenu::DeleteMenu(UINT uiId,UINT nFlags)
  2211. {
  2212. if(MF_BYPOSITION&nFlags){
  2213. UINT uint = GetMenuState(uiId,MF_BYPOSITION);
  2214. if(uint&MF_SEPARATOR && !(uint&MF_POPUP)){
  2215. // make sure it's a separator
  2216. int menulistsize=m_MenuList.GetSize();
  2217. if(uiId<(UINT)menulistsize){
  2218. CString str=m_MenuList[uiId]->GetString();
  2219. if(str==""){
  2220. delete m_MenuList.GetAt(uiId);
  2221. m_MenuList.RemoveAt(uiId);
  2222. }
  2223. }
  2224. }
  2225. else{
  2226. BCMenu* pSubMenu = (BCMenu*) GetSubMenu(uiId);
  2227. if(NULL==pSubMenu){
  2228. UINT uiCommandId = GetMenuItemID(uiId);
  2229. for(int i=0;i<m_MenuList.GetSize(); i++){
  2230. if(m_MenuList[i]->nID==uiCommandId){
  2231. delete m_MenuList.GetAt(i);
  2232. m_MenuList.RemoveAt(i);
  2233. break;
  2234. }
  2235. }
  2236. }
  2237. else{
  2238. int numSubMenus = m_SubMenus.GetUpperBound();
  2239. for(int m = numSubMenus; m >= 0; m--){
  2240. if(m_SubMenus[m]==pSubMenu->m_hMenu){
  2241. int numAllSubMenus = m_AllSubMenus.GetUpperBound();
  2242. for(int n = numAllSubMenus; n>= 0; n--){
  2243. if(m_AllSubMenus[n]==m_SubMenus[m])m_AllSubMenus.RemoveAt(n);
  2244. }
  2245. m_SubMenus.RemoveAt(m);
  2246. }
  2247. }
  2248. int num = pSubMenu->GetMenuItemCount();
  2249. for(int i=num-1;i>=0;--i)
  2250. pSubMenu->DeleteMenu(i,MF_BYPOSITION);
  2251. for(int i=m_MenuList.GetUpperBound();i>=0;i--){
  2252. if(m_MenuList[i]->nID==(UINT)pSubMenu->m_hMenu){
  2253. delete m_MenuList.GetAt(i);
  2254. m_MenuList.RemoveAt(i);
  2255. break;
  2256. }
  2257. }
  2258. delete pSubMenu;
  2259. }
  2260. }
  2261. }
  2262. else{
  2263. int iPosition =0;
  2264. BCMenu* pMenu = FindMenuOption(uiId,iPosition);
  2265. if(pMenu)return pMenu->DeleteMenu(iPosition,MF_BYPOSITION);
  2266. }
  2267. return(CMenu::DeleteMenu(uiId,nFlags));
  2268. }
  2269. BOOL BCMenu::AppendMenuA(UINT nFlags,UINT nIDNewItem,const char *lpszNewItem,int nIconNormal)
  2270. {
  2271. USES_CONVERSION;
  2272. return AppendMenuW(nFlags,nIDNewItem,A2W(lpszNewItem),nIconNormal);
  2273. }
  2274. BOOL BCMenu::AppendMenuW(UINT nFlags,UINT nIDNewItem,wchar_t *lpszNewItem,int nIconNormal)
  2275. {
  2276. return AppendODMenuW(lpszNewItem,nFlags,nIDNewItem,nIconNormal);
  2277. }
  2278. BOOL BCMenu::AppendMenuA(UINT nFlags,UINT nIDNewItem,const char *lpszNewItem,CImageList *il,int xoffset)
  2279. {
  2280. USES_CONVERSION;
  2281. return AppendMenuW(nFlags,nIDNewItem,A2W(lpszNewItem),il,xoffset);
  2282. }
  2283. BOOL BCMenu::AppendMenuW(UINT nFlags,UINT nIDNewItem,wchar_t *lpszNewItem,CImageList *il,int xoffset)
  2284. {
  2285. return AppendODMenuW(lpszNewItem,nFlags,nIDNewItem,il,xoffset);
  2286. }
  2287. BOOL BCMenu::AppendMenuA(UINT nFlags,UINT nIDNewItem,const char *lpszNewItem,CBitmap *bmp)
  2288. {
  2289. USES_CONVERSION;
  2290. return AppendMenuW(nFlags,nIDNewItem,A2W(lpszNewItem),bmp);
  2291. }
  2292. BOOL BCMenu::AppendMenuW(UINT nFlags,UINT nIDNewItem,wchar_t *lpszNewItem,CBitmap *bmp)
  2293. {
  2294. if(bmp){
  2295. CImageList temp;
  2296. temp.Create(m_iconX,m_iconY,ILC_COLORDDB|ILC_MASK,1,1);
  2297. if(m_bitmapBackgroundFlag)temp.Add(bmp,m_bitmapBackground);
  2298. else temp.Add(bmp,GetSysColor(COLOR_3DFACE));
  2299. return AppendODMenuW(lpszNewItem,nFlags,nIDNewItem,&temp,0);
  2300. }
  2301. return AppendODMenuW(lpszNewItem,nFlags,nIDNewItem,NULL,0);
  2302. }
  2303. BOOL BCMenu::InsertMenuA(UINT nPosition,UINT nFlags,UINT nIDNewItem,const char *lpszNewItem,int nIconNormal)
  2304. {
  2305. USES_CONVERSION;
  2306. return InsertMenuW(nPosition,nFlags,nIDNewItem,A2W(lpszNewItem),nIconNormal);
  2307. }
  2308. BOOL BCMenu::InsertMenuW(UINT nPosition,UINT nFlags,UINT nIDNewItem,wchar_t *lpszNewItem,int nIconNormal)
  2309. {
  2310. return InsertODMenuW(nPosition,lpszNewItem,nFlags,nIDNewItem,nIconNormal);
  2311. }
  2312. BOOL BCMenu::InsertMenuA(UINT nPosition,UINT nFlags,UINT nIDNewItem,const char *lpszNewItem,CImageList *il,int xoffset)
  2313. {
  2314. USES_CONVERSION;
  2315. return InsertMenuW(nPosition,nFlags,nIDNewItem,A2W(lpszNewItem),il,xoffset);
  2316. }
  2317. BOOL BCMenu::InsertMenuW(UINT nPosition,UINT nFlags,UINT nIDNewItem,wchar_t *lpszNewItem,CImageList *il,int xoffset)
  2318. {
  2319. return InsertODMenuW(nPosition,lpszNewItem,nFlags,nIDNewItem,il,xoffset);
  2320. }
  2321. BOOL BCMenu::InsertMenuA(UINT nPosition,UINT nFlags,UINT nIDNewItem,const char *lpszNewItem,CBitmap *bmp)
  2322. {
  2323. USES_CONVERSION;
  2324. return InsertMenuW(nPosition,nFlags,nIDNewItem,A2W(lpszNewItem),bmp);
  2325. }
  2326. BOOL BCMenu::InsertMenuW(UINT nPosition,UINT nFlags,UINT nIDNewItem,wchar_t *lpszNewItem,CBitmap *bmp)
  2327. {
  2328. if(bmp){
  2329. CImageList temp;
  2330. temp.Create(m_iconX,m_iconY,ILC_COLORDDB|ILC_MASK,1,1);
  2331. if(m_bitmapBackgroundFlag)temp.Add(bmp,m_bitmapBackground);
  2332. else temp.Add(bmp,GetSysColor(COLOR_3DFACE));
  2333. return InsertODMenuW(nPosition,lpszNewItem,nFlags,nIDNewItem,&temp,0);
  2334. }
  2335. return InsertODMenuW(nPosition,lpszNewItem,nFlags,nIDNewItem,NULL,0);
  2336. }
  2337. //--------------------------------------------------------------------------
  2338. //[21.06.99 rj]
  2339. BCMenu* BCMenu::AppendODPopupMenuW(wchar_t *lpstrText)
  2340. {
  2341. BCMenu* pSubMenu = new BCMenu;
  2342. pSubMenu->m_unselectcheck=m_unselectcheck;
  2343. pSubMenu->m_selectcheck=m_selectcheck;
  2344. pSubMenu->checkmaps=checkmaps;
  2345. pSubMenu->checkmapsshare=TRUE;
  2346. pSubMenu->CreatePopupMenu();
  2347. AppendODMenuW(lpstrText,MF_POPUP,(UINT)pSubMenu->m_hMenu, -1);
  2348. return pSubMenu;
  2349. }
  2350. //--------------------------------------------------------------------------
  2351. //[21.06.99 rj]
  2352. BCMenu* BCMenu::AppendODPopupMenuA(LPCSTR lpstrText)
  2353. {
  2354. USES_CONVERSION;
  2355. return AppendODPopupMenuW(A2W(lpstrText));
  2356. }
  2357. BOOL BCMenu::ImageListDuplicate(CImageList *il,int xoffset,CImageList *newlist)
  2358. {
  2359. if (il == NULL||newlist==NULL||xoffset<0) return FALSE;
  2360. HICON hIcon = il->ExtractIcon(xoffset);
  2361. int cx, cy;
  2362. ImageList_GetIconSize(il->m_hImageList, &cx, &cy);
  2363. newlist->Create(cx,cy,ILC_COLORDDB|ILC_MASK,1,1);
  2364. newlist->Add(hIcon);
  2365. ::DestroyIcon(hIcon);
  2366. if(IsLunaMenuStyle()&&xp_draw_3D_bitmaps){
  2367. CWnd *pWnd = AfxGetMainWnd(); // Get main window
  2368. if (pWnd == NULL) pWnd = CWnd::GetDesktopWindow();
  2369. CDC *pDC = pWnd->GetDC(); // Get device context
  2370. CBitmap bmp,bmp2;
  2371. GetBitmapFromImageList(pDC,newlist,0,bmp);
  2372. GetFadedBitmap(bmp);
  2373. newlist->Add(&bmp,GetSysColor(COLOR_3DFACE));
  2374. GetBitmapFromImageList(pDC,newlist,0,bmp2);
  2375. GetShadowBitmap(bmp2);
  2376. newlist->Add(&bmp2,GetSysColor(COLOR_3DFACE));
  2377. pWnd->ReleaseDC(pDC); // Release the DC
  2378. }
  2379. return TRUE;
  2380. }
  2381. // 2001-07-12, Damir Valiulin:
  2382. // Added GetSubMenu (LPCTSTR lpszSubMenuName) function
  2383. //
  2384. CMenu* BCMenu::GetSubMenu(int nPos)
  2385. {
  2386. return CMenu::GetSubMenu (nPos);
  2387. }
  2388. CMenu* BCMenu::GetSubMenu(LPCTSTR lpszSubMenuName)
  2389. {
  2390. int num = GetMenuItemCount ();
  2391. CString name;
  2392. for (int i=0; i<num; i++)
  2393. {
  2394. GetMenuString (i, name, MF_BYPOSITION);
  2395. if (name.Compare (lpszSubMenuName) == 0)
  2396. {
  2397. return CMenu::GetSubMenu (i);
  2398. }
  2399. }
  2400. return NULL;
  2401. }
  2402. BCMenu* BCMenu::GetSubBCMenu(char* pText)
  2403. {
  2404. USES_CONVERSION;
  2405. return GetSubBCMenu(A2W(pText));
  2406. }
  2407. BCMenu* BCMenu::GetSubBCMenu(wchar_t* lpszSubMenuName)
  2408. {
  2409. BCMenuData *mdata;
  2410. mdata=FindMenuOption(lpszSubMenuName);
  2411. if(mdata){
  2412. HMENU bchmenu=(HMENU)mdata->nID;
  2413. CMenu *ptr=FromHandle(bchmenu);
  2414. BOOL flag=ptr->IsKindOf(RUNTIME_CLASS( BCMenu ));
  2415. if(flag)return((BCMenu *)ptr);
  2416. }
  2417. return NULL;
  2418. }
  2419. // Tongzhe Cui, Functions to remove a popup menu based on its name. Seperators
  2420. // before and after the popup menu can also be removed if they exist.
  2421. int BCMenu::GetMenuPosition(char* pText)
  2422. {
  2423. USES_CONVERSION;
  2424. return GetMenuPosition(A2W(pText));
  2425. }
  2426. int BCMenu::GetMenuPosition(wchar_t* pText)
  2427. {
  2428. int i,j;
  2429. BCMenu* psubmenu;
  2430. for(i=0;i<(int)(GetMenuItemCount());++i)
  2431. {
  2432. psubmenu=(BCMenu *)GetSubMenu(i);
  2433. if(!psubmenu)
  2434. {
  2435. const wchar_t *szWide;//SK: we use const to prevent misuse of this Ptr
  2436. for(j=0;j<=m_MenuList.GetUpperBound();++j)
  2437. {
  2438. szWide = m_MenuList[j]->GetWideString ();
  2439. if(szWide && !wcscmp(pText,szWide))//SK: modified for dynamic allocation
  2440. return j;
  2441. }
  2442. }
  2443. }
  2444. // means no found;
  2445. return -1;
  2446. }
  2447. int BCMenu::RemoveMenu(char* pText, BC_Seperator sPos)
  2448. {
  2449. USES_CONVERSION;
  2450. return RemoveMenu(A2W(pText), sPos);
  2451. }
  2452. int BCMenu::RemoveMenu(wchar_t* pText, BC_Seperator sPos)
  2453. {
  2454. int nPos = GetMenuPosition(pText);
  2455. if(nPos != -1)
  2456. {
  2457. RemoveMenu(nPos, MF_BYPOSITION);
  2458. }
  2459. if(sPos == BCMENU_HEAD)
  2460. {
  2461. ASSERT(nPos - 1 >= 0);
  2462. RemoveMenu(nPos-1, MF_BYPOSITION);
  2463. }
  2464. else if(sPos == BCMENU_TAIL)
  2465. {
  2466. RemoveMenu(nPos-1, MF_BYPOSITION);
  2467. }
  2468. else if(sPos == BCMENU_BOTH)
  2469. {
  2470. // remove the end first;
  2471. RemoveMenu(nPos-1, MF_BYPOSITION);
  2472. // remove the head;
  2473. ASSERT(nPos - 1 >= 0);
  2474. RemoveMenu(nPos-1, MF_BYPOSITION);
  2475. }
  2476. return nPos;
  2477. }
  2478. int BCMenu::DeleteMenu(char* pText, BC_Seperator sPos)
  2479. {
  2480. USES_CONVERSION;
  2481. return DeleteMenu(A2W(pText), sPos);
  2482. }
  2483. int BCMenu::DeleteMenu(wchar_t* pText, BC_Seperator sPos)
  2484. {
  2485. int nPos = GetMenuPosition(pText);
  2486. if(nPos != -1)
  2487. {
  2488. DeleteMenu(nPos, MF_BYPOSITION);
  2489. }
  2490. if(sPos == BCMENU_HEAD)
  2491. {
  2492. ASSERT(nPos - 1 >= 0);
  2493. DeleteMenu(nPos-1, MF_BYPOSITION);
  2494. }
  2495. else if(sPos == BCMENU_TAIL)
  2496. {
  2497. DeleteMenu(nPos-1, MF_BYPOSITION);
  2498. }
  2499. else if(sPos == BCMENU_BOTH)
  2500. {
  2501. // remove the end first;
  2502. DeleteMenu(nPos-1, MF_BYPOSITION);
  2503. // remove the head;
  2504. ASSERT(nPos - 1 >= 0);
  2505. DeleteMenu(nPos-1, MF_BYPOSITION);
  2506. }
  2507. return nPos;
  2508. }
  2509. // Larry Antram
  2510. BOOL BCMenu::SetMenuText(UINT id, CString string, UINT nFlags/*= MF_BYPOSITION*/ )
  2511. {
  2512. BOOL returnflag=FALSE;
  2513. if(MF_BYPOSITION&nFlags)
  2514. {
  2515. UINT numMenuItems = m_MenuList.GetUpperBound();
  2516. if(id<=numMenuItems){
  2517. #ifdef UNICODE
  2518. m_MenuList[id]->SetWideString((LPCTSTR)string);
  2519. #else
  2520. m_MenuList[id]->SetAnsiString(string);
  2521. #endif
  2522. returnflag=TRUE;
  2523. }
  2524. }
  2525. else{
  2526. int uiLoc;
  2527. BCMenu* pMenu = FindMenuOption(id,uiLoc);
  2528. if(NULL!=pMenu) returnflag = pMenu->SetMenuText(uiLoc,string);
  2529. }
  2530. return(returnflag);
  2531. }
  2532. // courtesy of Warren Stevens
  2533. void BCMenu::ColorBitmap(CDC* pDC,CBitmap& bmp,CSize bitmap_size,CSize icon_size,COLORREF fill,COLORREF border,int hatchstyle)
  2534. {
  2535. CDC bmpdc;
  2536. COLORREF m_newclrBack;
  2537. int x1=0,y1=0,x2=bitmap_size.cx,y2=bitmap_size.cy;
  2538. if(IsWinXPLuna())m_newclrBack=GetSysColor(COLOR_3DFACE);
  2539. else m_newclrBack=GetSysColor(COLOR_MENU);
  2540. bmpdc.CreateCompatibleDC(pDC);
  2541. bmp.CreateCompatibleBitmap(pDC, icon_size.cx, icon_size.cy);
  2542. CBitmap* pOldBitmap = bmpdc.SelectObject(&bmp);
  2543. if(bitmap_size!=icon_size){
  2544. CBrush background_brush;
  2545. background_brush.CreateSolidBrush(m_newclrBack);
  2546. CRect rect(0,0, icon_size.cx, icon_size.cy);
  2547. bmpdc.FillRect(rect,&background_brush);
  2548. x1 = (icon_size.cx-bitmap_size.cx)/2;
  2549. y1 = (icon_size.cy-bitmap_size.cy)/2;
  2550. x2 = x1+bitmap_size.cx;
  2551. y2 = y1+bitmap_size.cy;
  2552. background_brush.DeleteObject();
  2553. }
  2554. CPen border_pen(PS_SOLID, 1, border);
  2555. CBrush fill_brush;
  2556. if(hatchstyle!=-1) { fill_brush.CreateHatchBrush(hatchstyle, fill); }
  2557. else { fill_brush.CreateSolidBrush(fill); }
  2558. CPen* pOldPen = bmpdc.SelectObject(&border_pen);
  2559. CBrush* pOldBrush = bmpdc.SelectObject(&fill_brush);
  2560. bmpdc.Rectangle(x1,y1,x2,y2);
  2561. if(NULL!=pOldBrush) { bmpdc.SelectObject(pOldBrush); }
  2562. if(NULL!=pOldPen) { bmpdc.SelectObject(pOldPen); }
  2563. if(NULL!=pOldBitmap) { bmpdc.SelectObject(pOldBitmap); }
  2564. }
  2565. BOOL BCMenu::IsWindowsClassicTheme(void)
  2566. {
  2567. TCHAR Buf[_MAX_PATH+10];
  2568. HKEY hKey;
  2569. DWORD size,type;
  2570. long lRetCode;
  2571. static BOOL XPTheme_returnflag=FALSE;
  2572. static BOOL XPTheme_checkflag=FALSE;
  2573. if(XPTheme_checkflag)return(XPTheme_returnflag);
  2574. XPTheme_checkflag=TRUE;
  2575. lRetCode = RegOpenKeyEx ( HKEY_CURRENT_USER,
  2576. _T("Software\\Microsoft\\Plus!\\Themes\\Current"),
  2577. 0,KEY_READ,&hKey);
  2578. if (lRetCode == ERROR_SUCCESS){
  2579. size = _MAX_PATH;type=REG_SZ;
  2580. lRetCode=::RegQueryValueEx(hKey,NULL,NULL,&type,
  2581. (unsigned char *)Buf,&size);
  2582. if(lRetCode == ERROR_SUCCESS){
  2583. TCHAR szClassicTheme[]=_T("Windows Classic.theme");
  2584. int len=lstrlen(Buf);
  2585. if(len>=lstrlen(szClassicTheme)){
  2586. if(!lstrcmpi(&Buf[len-lstrlen(szClassicTheme)],szClassicTheme)){
  2587. XPTheme_returnflag=TRUE;
  2588. }
  2589. }
  2590. }
  2591. RegCloseKey(hKey);
  2592. }
  2593. return(XPTheme_returnflag);
  2594. }
  2595. int BCMenu::GlobalImageListOffset(int nID)
  2596. {
  2597. int numcurrent=m_AllImagesID.GetSize();
  2598. int existsloc = -1;
  2599. for(int i=0;i<numcurrent;++i){
  2600. if(m_AllImagesID[i]==nID){
  2601. existsloc=i;
  2602. break;
  2603. }
  2604. }
  2605. return existsloc;
  2606. }
  2607. BOOL BCMenu::CanDraw3DImageList(int offset)
  2608. {
  2609. BOOL retflag=FALSE;
  2610. int numcurrent=m_AllImagesID.GetSize();
  2611. if(offset+1<numcurrent&&offset+2<numcurrent){
  2612. int nID=m_AllImagesID[offset];
  2613. if(m_AllImagesID[offset+1]==nID&&m_AllImagesID[offset+2]==nID)retflag=TRUE;
  2614. }
  2615. return(retflag);
  2616. }
  2617. int BCMenu::AddToGlobalImageList(CImageList *il,int xoffset,int nID)
  2618. {
  2619. int loc = -1;
  2620. HIMAGELIST hImageList = m_AllImages.m_hImageList;
  2621. if(!hImageList){
  2622. m_AllImages.Create(m_iconX,m_iconY,ILC_COLORDDB|ILC_MASK,1,1);
  2623. }
  2624. HICON hIcon = il->ExtractIcon(xoffset);
  2625. if(hIcon){
  2626. CBitmap bmp,bmp2;
  2627. if(IsLunaMenuStyle()&&xp_draw_3D_bitmaps){
  2628. CWnd *pWnd = AfxGetMainWnd(); // Get main window
  2629. if (pWnd == NULL) pWnd = CWnd::GetDesktopWindow();
  2630. CDC *pDC = pWnd->GetDC(); // Get device context
  2631. GetBitmapFromImageList(pDC,il,xoffset,bmp);
  2632. GetFadedBitmap(bmp);
  2633. GetBitmapFromImageList(pDC,il,xoffset,bmp2);
  2634. GetShadowBitmap(bmp2);
  2635. pWnd->ReleaseDC(pDC); // Release the DC
  2636. }
  2637. int numcurrent=m_AllImagesID.GetSize();
  2638. int existsloc = -1;
  2639. for(int i=0;i<numcurrent;++i){
  2640. if(m_AllImagesID[i]==nID){
  2641. existsloc=i;
  2642. break;
  2643. }
  2644. }
  2645. if(existsloc>=0){
  2646. m_AllImages.Replace(existsloc,hIcon);
  2647. loc = existsloc;
  2648. if(IsLunaMenuStyle()&&xp_draw_3D_bitmaps){
  2649. if(existsloc+1<numcurrent&&m_AllImagesID[existsloc+1]==nID){
  2650. if(existsloc+2<numcurrent&&m_AllImagesID[existsloc+2]==nID){
  2651. CImageList il2;
  2652. il2.Create(m_iconX,m_iconY,ILC_COLORDDB|ILC_MASK,1,1);
  2653. il2.Add(&bmp,GetSysColor(COLOR_3DFACE));
  2654. HICON hIcon2 = il2.ExtractIcon(0);
  2655. m_AllImages.Replace(existsloc+1,hIcon2);
  2656. il2.Add(&bmp2,GetSysColor(COLOR_3DFACE));
  2657. HICON hIcon3 = il2.ExtractIcon(1);
  2658. m_AllImages.Replace(existsloc+2,hIcon3);
  2659. ::DestroyIcon(hIcon2);
  2660. ::DestroyIcon(hIcon3);
  2661. }
  2662. }
  2663. }
  2664. }
  2665. else{
  2666. m_AllImages.Add(hIcon);
  2667. m_AllImagesID.Add(nID);
  2668. loc=numcurrent;
  2669. if(IsLunaMenuStyle()&&xp_draw_3D_bitmaps){
  2670. m_AllImages.Add(&bmp,GetSysColor(COLOR_3DFACE));
  2671. m_AllImages.Add(&bmp2,GetSysColor(COLOR_3DFACE));
  2672. m_AllImagesID.Add(nID);
  2673. m_AllImagesID.Add(nID);
  2674. }
  2675. }
  2676. ::DestroyIcon(hIcon);
  2677. }
  2678. return(loc);
  2679. }
  2680. //*************************************************************************
  2681. /////////////////////////////////////////////////////////////////////////////
  2682. // Toolbar for loading images
  2683. /////////////////////////////////////////////////////////////////////////////
  2684. struct CToolBarData
  2685. {
  2686. WORD wVersion;
  2687. WORD wWidth;
  2688. WORD wHeight;
  2689. WORD wItemCount;
  2690. WORD* items(){
  2691. return (WORD*)(this+1);
  2692. }
  2693. };
  2694. BOOL BCMenuToolBar::LoadToolBar(LPCTSTR lpszResourceName)
  2695. {
  2696. ASSERT_VALID(this);
  2697. ASSERT(lpszResourceName != NULL);
  2698. HINSTANCE hInst = AfxFindResourceHandle(lpszResourceName,RT_TOOLBAR);
  2699. HRSRC hRsrc = ::FindResource(hInst,lpszResourceName,RT_TOOLBAR);
  2700. if (hRsrc == NULL){
  2701. hInst = NULL;
  2702. hRsrc = ::FindResource(hInst,lpszResourceName,RT_TOOLBAR);
  2703. }
  2704. if (hRsrc == NULL)
  2705. return FALSE;
  2706. HGLOBAL hGlobal = ::LoadResource(hInst,hRsrc);
  2707. if (hGlobal == NULL)
  2708. return FALSE;
  2709. CToolBarData* pData = (CToolBarData*)::LockResource(hGlobal);
  2710. if (pData == NULL)
  2711. return FALSE;
  2712. ASSERT(pData->wVersion == 1);
  2713. UINT* pItems = new UINT[pData->wItemCount];
  2714. for (int i = 0; i < pData->wItemCount; i++)
  2715. pItems[i] = pData->items()[i];
  2716. BOOL bResult = SetButtons(pItems,pData->wItemCount);
  2717. delete[] pItems;
  2718. if (bResult){
  2719. CSize sizeImage(pData->wWidth,pData->wHeight);
  2720. CSize sizeButton(pData->wWidth+7,pData->wHeight+7);
  2721. SetSizes(sizeButton,sizeImage);
  2722. m_iconX=pData->wWidth;
  2723. m_iconY=pData->wHeight;
  2724. bResult = LoadBitmap(lpszResourceName);
  2725. }
  2726. ::UnlockResource(hGlobal);
  2727. ::FreeResource(hGlobal);
  2728. return bResult;
  2729. }
  2730. BOOL BCMenuToolBar::LoadBitmap(LPCTSTR lpszResourceName)
  2731. {
  2732. ASSERT_VALID(this);
  2733. ASSERT(lpszResourceName != NULL);
  2734. HINSTANCE hInstImageWell = AfxFindResourceHandle(lpszResourceName,RT_BITMAP);
  2735. HRSRC hRsrcImageWell = ::FindResource(hInstImageWell,lpszResourceName,RT_BITMAP);
  2736. if (hRsrcImageWell == NULL){
  2737. hInstImageWell = NULL;
  2738. hRsrcImageWell = ::FindResource(hInstImageWell,lpszResourceName,RT_BITMAP);
  2739. }
  2740. if (hRsrcImageWell == NULL)
  2741. return FALSE;
  2742. HBITMAP hbmImageWell;
  2743. hbmImageWell = AfxLoadSysColorBitmap(hInstImageWell,hRsrcImageWell);
  2744. if (!AddReplaceBitmap(hbmImageWell))
  2745. return FALSE;
  2746. m_hInstImageWell = hInstImageWell;
  2747. m_hRsrcImageWell = hRsrcImageWell;
  2748. return TRUE;
  2749. }