void CMainFrame::DoPopupMenu() { // Creates the popup menu for the "View Menu" toolbar button // Position the popup menu CToolBar& TB = GetToolBar(); CRect rc = TB.GetItemRect(TB.CommandToIndex(IDM_VIEWMENU)); TB.MapWindowPoints(NULL, (LPPOINT)&rc, 2); TPMPARAMS tpm; tpm.cbSize = sizeof(TPMPARAMS); tpm.rcExclude = rc; // Load the popup menu CMenu TopMenu(IDM_VIEWMENU); CMenu PopupMenu = TopMenu.GetSubMenu(0); // Put a radio check in the currently checked item MENUITEMINFO mii; ZeroMemory(&mii, sizeof(MENUITEMINFO)); for (int i = 3 ; i < 7 ; i++) { ZeroMemory(&mii, GetSizeofMenuItemInfo()); mii.cbSize = GetSizeofMenuItemInfo(); mii.fMask = MIIM_STATE | MIIM_ID; CMenu SubMenu = GetFrameMenu().GetSubMenu(1); SubMenu.GetMenuItemInfo(i, mii, TRUE); if (mii.fState & MFS_CHECKED) TopMenu.CheckMenuRadioItem(IDM_VIEW_SMALLICON, IDM_VIEW_REPORT, mii.wID, 0); } // Start the popup menu PopupMenu.TrackPopupMenuEx(TPM_LEFTALIGN | TPM_LEFTBUTTON | TPM_VERTICAL, rc.left, rc.bottom, *this, &tpm); }
void Application::main() { while (1){ char command; TopMenu("MAIN MENU"); iface->drawString("a. Add book\n"); iface->drawString("b. Remove book\n"); iface->drawString("c. Show books\n"); iface->drawString("d. Play\n"); iface->drawString("q. Quit(!)\n\n"); iface->drawString(" > "); iface->readChar(command); if (command == 'a'){ addBook(); } else if (command == 'b'){ removeBook(); } else if (command == 'c'){ showBooks(); } else if (command == 'd') { play(); } else if (command == 'q'){ saveBooks(); exit(0); } } }
void Application::start(){ char command; TopMenu("WELCOME"); loadBooks(); Sleep(2000); main(); }
LRESULT CView::OnTrayIcon(WPARAM wParam, LPARAM lParam) { // For a NOTIFYICONDATA with uVersion= 0, wParam and lParam have the following values: // The wParam parameter contains the identifier of the taskbar icon in which the event occurred. // The lParam parameter holds the mouse or keyboard message associated with the event. if (wParam != IDW_MAIN) return 0L; if (lParam == WM_LBUTTONUP) { Restore(); } else if (lParam == WM_RBUTTONUP) { CMenu TopMenu(IDM_MINIMIZED); CMenu* pSubMenu = TopMenu.GetSubMenu(0); SetForegroundWindow(); CPoint pt = GetCursorPos(); UINT uSelected = pSubMenu->TrackPopupMenu(TPM_RETURNCMD | TPM_NONOTIFY, pt.x, pt.y, this, NULL); switch (uSelected) { case IDM_MIN_RESTORE: Restore(); break; case IDM_MIN_ABOUT: OnAbout(); break; case IDM_MIN_EXIT: Destroy(); break; } } return 0; }
void Application::showBooks(){ TopMenu("SHOW BOOKS"); iface->drawHeader("Title","Author","Year"); iface->drawString("-----------------------------------------------------------------------------\n"); for (unsigned int i = 0; i < books.size(); i++){ iface->drawTable(books[i]); } iface->getInput(); }
void Application::removeBook(){ unsigned int command; while (1){ TopMenu("REMOVE BOOK"); for (unsigned int i = 0; i < books.size(); i++){ iface->drawString(to_string(i + 1) + ". " + books[i].getName()); iface->newLine(); } iface->drawString("\n0. Return"); iface->drawString("\n\n > "); iface->read(command); if (command == 0) return; else if (command > 0 && command <= books.size()){ TopMenu("REMOVE BOOK"); iface->drawString("\n\n\n" + books[command - 1].getName() + " was sucefully removed!!!\n"); books.erase(books.begin() + (command - 1)); iface->getInput(); } } }
void Application::play(){ int score = 0; int round = 1; while (round <= 5){ TopMenu("PLAY"); string line, word; char cmd; iface->drawString("Entering words base (singular, male, infinitive) separated by spaces.\nA clue may include, at most, a word missing in the book's title.\nYou have 5 rounds\n\n"); iface->drawString("Round: " + to_string(round)); iface->drawString("\nScore: " + to_string(score)); iface->drawString("\n\nClue: "); iface->readLine(line); vector<string> guesses; stringstream s1(line); while (!s1.eof()) { s1 >> word; guesses.push_back(word); } vector<pair<int, Book>> res = calculateGuess(calCombinations(guesses)); unsigned int i = 0; for (i; i < res.size(); i++){ iface->drawString("\n\n"); iface->drawHeader("Title", "Author", "Year"); iface->drawString("-----------------------------------------------------------------------------\n"); iface->drawTable(res[i].second); while (1){ iface->drawString("\n\nThis is the book that you want?\na. Yes\nb. No\n"); iface->drawString(" > "); iface->readChar(cmd); if (cmd == 'a'){ score += 5; break; } else if (cmd == 'b'){ score -= 1; break; } } if (cmd == 'a') break; } if (i < res.size()) iface->drawString("\n\nBook found"); else iface->drawString("\n\n\nGive up"); round++; } iface->drawString("\n\nYour score: " + to_string(score)); iface->getInput(); return; }
void MenuItem::handleFlashUpdate(UpdateEventDetails* const e) { _FlashElps += e->getElapsedTime(); if(_FlashElps > LookAndFeelManager::the()->getLookAndFeel()->getKeyAcceleratorMenuFlashTime()) { MenuRefPtr TopMenu(getTopLevelMenu()); if(TopMenu != NULL) { TopMenu->setDrawAsThoughSelected(false); } _FlashUpdateConnection.disconnect(); } }
void MenuItem::handleAcceleratorTyped(KeyEventDetails* const e) { //Set TopLevelMenu MenuRefPtr TopMenu(getTopLevelMenu()); if(TopMenu != NULL) { TopMenu->setDrawAsThoughSelected(true); _FlashElps = 0.0; _FlashUpdateConnection = getParentWindow()->getParentDrawingSurface()->getEventProducer()->connectUpdate(boost::bind(&MenuItem::handleFlashUpdate, this, _1)); } produceActionPerformed(); }
void Application::addBook(){ string title, author; int year; TopMenu("ADD BOOK"); iface->drawString("Title: "); iface->readLine(title); iface->drawString("Author: "); iface->readLine(author); do { iface->drawString("Publication year: "); iface->read(year); } while (year <= 0 || year > 2015); books.push_back(Book(title, author, year)); std::sort(books.begin(), books.end()); }