| 1075 | } |
| 1076 | |
| 1077 | BOOL BCMenu::LoadMenu(LPCTSTR lpszResourceName) |
| 1078 | { |
| 1079 | ASSERT_VALID(this); |
| 1080 | ASSERT(lpszResourceName != nullptr); |
| 1081 | |
| 1082 | // Find the Menu Resource: |
| 1083 | HINSTANCE hInst = AfxFindResourceHandle(lpszResourceName,RT_MENU); |
| 1084 | HRSRC hRsrc = ::FindResource(hInst,lpszResourceName,RT_MENU); |
| 1085 | if (hRsrc == nullptr){ |
| 1086 | hInst = nullptr; |
| 1087 | hRsrc = ::FindResource(hInst,lpszResourceName,RT_MENU); |
| 1088 | } |
| 1089 | if(hRsrc == nullptr) |
| 1090 | return FALSE; |
| 1091 | |
| 1092 | // Load the Menu Resource: |
| 1093 | |
| 1094 | HGLOBAL hGlobal = LoadResource(hInst, hRsrc); |
| 1095 | if(hGlobal == nullptr) |
| 1096 | return FALSE; |
| 1097 | |
| 1098 | // first destroy the menu if we're trying to loadmenu again |
| 1099 | DestroyMenu(); |
| 1100 | |
| 1101 | // Attempt to create us as a menu... |
| 1102 | if(!CMenu::CreateMenu()) |
| 1103 | return FALSE; |
| 1104 | |
| 1105 | // Get Item template Header, and calculate offset of MENUITEMTEMPLATES |
| 1106 | |
| 1107 | MENUITEMTEMPLATEHEADER *pTpHdr= |
| 1108 | (MENUITEMTEMPLATEHEADER*)LockResource(hGlobal); |
| 1109 | BYTE* pTp=(BYTE*)pTpHdr + |
| 1110 | (sizeof(MENUITEMTEMPLATEHEADER) + pTpHdr->offset); |
| 1111 | |
| 1112 | |
| 1113 | // Variables needed during processing of Menu Item Templates: |
| 1114 | |
| 1115 | WORD dwFlags = 0; // Flags of the Menu Item |
| 1116 | WORD dwID = 0; // ID of the Menu Item |
| 1117 | CTypedPtrArray<CPtrArray, BCMenu*> stack; // Popup menu stack |
| 1118 | CArray<bool,bool> stackEnd; // Popup menu stack |
| 1119 | stack.Add(this); // Add it to this... |
| 1120 | stackEnd.Add(false); |
| 1121 | |
| 1122 | do{ |
| 1123 | // Obtain Flags and (if necessary), the ID... |
| 1124 | memcpy(&dwFlags, pTp, sizeof(WORD));pTp+=sizeof(WORD);// Obtain Flags |
| 1125 | if((dwFlags & MF_POPUP)==0){ |
| 1126 | memcpy(&dwID, pTp, sizeof(WORD)); // Obtain ID |
| 1127 | pTp+=sizeof(WORD); |
| 1128 | } |
| 1129 | else dwID = 0; |
| 1130 | |
| 1131 | UINT uFlags = (UINT)dwFlags; // Remove MF_END from the flags that will |
| 1132 | if((uFlags & MF_END) != 0) // be passed to the Append(OD)Menu functions. |
| 1133 | uFlags -= MF_END; |
| 1134 |
no test coverage detected