////////////////// // Load a different menu. The HMENU must not belong to any CMenu, // and you must free it when you're done. Returns old menu. // HMENU CMenuBar::LoadMenu(HMENU hmenu) { UINT iPrevID=(UINT)-1; ASSERT(::IsMenu(hmenu)); ASSERT_VALID(this); HMENU hOldMenu = m_hmenu; m_hmenu = hmenu; // delete existing buttons int nCount = GetToolBarCtrl().GetButtonCount(); while (nCount--) { VERIFY(GetToolBarCtrl().DeleteButton(0)); } GetToolBarCtrl().SetImageList(NULL); DWORD dwStyle = GetStyle(); BOOL bModifyStyle = ModifyStyle(0, TBSTYLE_FLAT|TBSTYLE_TRANSPARENT); // add text buttons UINT nMenuItems = hmenu ? ::GetMenuItemCount(hmenu) : 0; for (UINT i=0; i < nMenuItems; i++) { TCHAR name[64]; memset(name, 0, sizeof(name)); // guarantees double-0 at end if (theApp.m_bUseLngFile) { char num[10]; sprintf(num,"X%d",i); if (_GetPrivateProfileString("MenuMain", num, NULL, name, countof(name)-1, theApp.m_strLngFile)==FALSE) ::GetMenuString(hmenu, i, name, countof(name)-1, MF_BYPOSITION); } else ::GetMenuString(hmenu, i, name, countof(name)-1, MF_BYPOSITION); // TBBUTTON tbb; memset(&tbb, 0, sizeof(tbb)); tbb.idCommand = ::GetMenuItemID(hmenu, i); // Because the toolbar is too brain-damaged to know if it already has // a string, and is also too brain-dead to even let you delete strings, // I have to determine if each string has been added already. Otherwise // in a MDI app, as the menus are repeatedly switched between doc and // no-doc menus, I will keep adding strings until somebody runs out of // memory. Sheesh! // int iString = -1; for (int j=0; j<m_arStrings.GetSize(); j++) { if (m_arStrings[j] == name) { iString = j; // found it break; } } if (iString <0) { // string not found: add it iString = GetToolBarCtrl().AddStrings(name); m_arStrings.SetAtGrow(iString, name); } tbb.iString = iString; tbb.fsState = TBSTATE_ENABLED; tbb.fsStyle = TBSTYLE_AUTOSIZE; tbb.iBitmap = -1; tbb.idCommand = i; VERIFY(GetToolBarCtrl().AddButtons(1, &tbb)); } if (bModifyStyle) SetWindowLong(m_hWnd, GWL_STYLE, dwStyle); if (hmenu) { GetToolBarCtrl().AutoSize();// size buttons m_nMenuItems = GetToolBarCtrl().GetButtonCount(); } return hOldMenu; }
BOOL CALLBACK RomNotesProc (HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) { switch (uMsg) { case WM_INITDIALOG: SetDlgItemText(hDlg,IDC_STATUS_TEXT,GS(NOTE_STATUS)); SetDlgItemText(hDlg,IDC_CORE,GS(NOTE_CORE)); SetDlgItemText(hDlg,IDC_PLUGIN,GS(NOTE_PLUGIN)); { char Identifier[100], *IniFile; sprintf(Identifier,"%08X-%08X-C:%X",*(DWORD *)(&RomHeader[0x10]),*(DWORD *)(&RomHeader[0x14]),RomHeader[0x3D]); IniFile = GetIniFileName(); { char String[0x3000], RomStatus[100], Status[200], *p; int len, index; _GetPrivateProfileString(Identifier,"Status",Default_RomStatus,RomStatus,sizeof(RomStatus),IniFile); GetPrivateProfileSection("Rom Status",String,sizeof(String), IniFile); for (p = String; strlen(p) > 0; p += strlen(p) + 1) { strncpy(Status,p,sizeof(Status)); if (strrchr(Status,'=') == NULL) { continue; } *(strrchr(Status,'=')) = 0; len = strlen(Status); if (len > 4 && _strnicmp(&Status[len-4],".Sel",4) == 0) { continue; } if (len > 8 && _strnicmp(&Status[len-8],".Seltext",8) == 0) { continue; } if (len > 15 && _strnicmp(&Status[len-15],".AutoFullScreen",15) == 0) { continue; } index = SendMessage(GetDlgItem(hDlg,IDC_STATUS),CB_ADDSTRING,0,(LPARAM)Status); if (strcmp(Status,RomStatus) == 0) { SendMessage(GetDlgItem(hDlg,IDC_STATUS),CB_SETCURSEL,index,0); } if (SendMessage(GetDlgItem(hDlg,IDC_STATUS),CB_GETCOUNT,0,0) == 0) { SendMessage(GetDlgItem(hDlg,IDC_STATUS),CB_SETCURSEL,0,0); } } } { char CoreNotes[800]; _GetPrivateProfileString(Identifier,"Core Note","",CoreNotes,sizeof(CoreNotes),IniFile); SetDlgItemText(hDlg,IDC_CORE_NOTES,CoreNotes); } { char PluginNotes[800]; _GetPrivateProfileString(Identifier,"Plugin Note","",PluginNotes,sizeof(PluginNotes),IniFile); SetDlgItemText(hDlg,IDC_PLUGIN_NOTE,PluginNotes); } } if (strlen(RomName) == 0) { EnableWindow(GetDlgItem(hDlg,IDC_STATUS_TEXT),FALSE); EnableWindow(GetDlgItem(hDlg,IDC_STATUS),FALSE); EnableWindow(GetDlgItem(hDlg,IDC_CORE),FALSE); EnableWindow(GetDlgItem(hDlg,IDC_CORE_NOTES),FALSE); EnableWindow(GetDlgItem(hDlg,IDC_PLUGIN),FALSE); EnableWindow(GetDlgItem(hDlg,IDC_PLUGIN_NOTE),FALSE); } break; case WM_NOTIFY: if (((NMHDR FAR *) lParam)->code == PSN_APPLY) { char Identifier[100], string[200], *IniFile; sprintf(Identifier,"%08X-%08X-C:%X",*(DWORD *)(&RomHeader[0x10]),*(DWORD *)(&RomHeader[0x14]),RomHeader[0x3D]); IniFile = GetIniFileName(); GetWindowText(GetDlgItem(hDlg, IDC_STATUS), string, sizeof(string)); if (strlen(string) == 0) { strcpy(string, Default_RomStatus); } _WritePrivateProfileString(Identifier,"Status",string,IniFile); GetWindowText(GetDlgItem(hDlg, IDC_CORE_NOTES), string, sizeof(string)); _WritePrivateProfileString(Identifier,"Core Note",string,IniFile); GetWindowText(GetDlgItem(hDlg, IDC_PLUGIN_NOTE), string, sizeof(string)); _WritePrivateProfileString(Identifier,"Plugin Note",string,IniFile); } break; default: return FALSE; } return TRUE; }