A simple menu

本文介绍了一个简单的Windows应用程序,该程序使用Windows API创建了一个包含新建、打开和退出选项的菜单。通过Beep函数对选中菜单项进行了声音反馈,并实现了退出菜单项关闭窗口的功能。
#include <windows.h>

LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
void AddMenus(HWND);

#define IDM_FILE_NEW 1
#define IDM_FILE_OPEN 2
#define IDM_FILE_QUIT 3

int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
                    PWSTR lpCmdLine, int nCmdShow)
{
  MSG  msg;    
  WNDCLASSW wc = {0};
  wc.lpszClassName = L"Menu";
  wc.hInstance     = hInstance;
  wc.hbrBackground = GetSysColorBrush(COLOR_3DFACE);
  wc.lpfnWndProc   = WndProc;
  wc.hCursor       = LoadCursor(0, IDC_ARROW);

  RegisterClassW(&wc);
  CreateWindowW(wc.lpszClassName, L"Menu",
                WS_OVERLAPPEDWINDOW | WS_VISIBLE,
                100, 100, 200, 150, 0, 0, hInstance, 0);

  while( GetMessage(&msg, NULL, 0, 0)) {
    TranslateMessage(&msg);
    DispatchMessage(&msg);
  }

  return (int) msg.wParam;
}

LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, 
    WPARAM wParam, LPARAM lParam)
{   
  switch(msg)  
  {
      case WM_CREATE:
          AddMenus(hwnd);
          break;

      case WM_COMMAND:
          switch(LOWORD(wParam)) {
              case IDM_FILE_NEW:
              case IDM_FILE_OPEN:
                  Beep(50, 100);
                  break;
              case IDM_FILE_QUIT:
                  SendMessage(hwnd, WM_CLOSE, 0, 0);
                  break;
           }
           break;

      case WM_DESTROY:
          PostQuitMessage(0);
          break;
  }

  return DefWindowProcW(hwnd, msg, wParam, lParam);
}

void AddMenus(HWND hwnd) 
{
  HMENU hMenubar;
  HMENU hMenu;

  hMenubar = CreateMenu();
  hMenu    = CreateMenu();

  AppendMenuW(hMenu, MF_STRING, IDM_FILE_NEW, L"&New");
  AppendMenuW(hMenu, MF_STRING, IDM_FILE_OPEN, L"&Open");
  AppendMenuW(hMenu, MF_SEPARATOR, 0, NULL);
  AppendMenuW(hMenu, MF_STRING, IDM_FILE_QUIT, L"&Quit");

  AppendMenuW(hMenubar, MF_POPUP, (UINT_PTR)hMenu, L"&File");
  SetMenu(hwnd, hMenubar);
}

You are asked to design and implement a Python-based system for managing a small library. The system should support the following core tasks, including manage users of different types (students, staff, and other members), manage the collection of books in the library and track and update loan records for borrowed books. Description The library has provided you with three CSV files containing its current data in the data folder: users.csv for user information, books.csv for book information and loans.csv containing loan history. In Task 1-3, you can assume all CSV files contain valid data. You are allowed to modify the import statements in the scaffold or move the import statements to different modules if required; but you are not allowed to import any modules which weren't originally imported in the scaffold. Users (users.csv) This file contains details of all registered users: Fields: user ID, password, name, role, and department (for students and staff only). User types: Student (s prefix in the user ID) Staff (e prefix in the user ID) Others (o prefix in the user ID) Each user type follows specific borrowing policies: Users Physical book Online Quota Student 10 days Unlimited 4 Staff 14 days Unlimited 6 Other 7 days Unlimited 2 Users Student Staff Other ​ Physical book 10 days 14 days 7 days ​ Online Unlimited Unlimited Unlimited ​ Quota 4 6 2 ​ ​ All users can borrow, return, and renew books, as well as view their active loans and loan policies. Only staff can add, update, or view detailed information about users and books. (More detail in Task 2-3). Books (books.csv) This file contains information about books in the collection: Fields: book ID, type (e.g., physical or online), total copies, title, authors, year, and keywords (colon-separated). Each book has a unique ID beginning with a character that denotes its category, followed by 4 digits. Physical books are identified by the prefix P in the Book ID. Online books (e-book) are identified by the prefix E in the Book ID. For online books, the total copies field is always 0. Loans (loans.csv) This file contains borrowing records: Fields: user ID, book ID, borrow date, due date, returned date. All dates are in the following format dd/mm/yyyy. The due date is automatically calculated based on loan policy. Active loans are those without a returned date. Your Task Write a program that reads users, books and loans from files users.csv, books.csv and loans.csv and a simple menu that allow interaction with the data. You are provided with 3 modules: user.py, book.py and task1.py. Your task is to Complete the implementation User and Book class in the users.py and books.py modules. You are allowed to add additional classes and functions if necessary. Implement the interaction menu in task1.py Login Menu When the program starts, the user is prompted to log in with their ID and password. If the user id does not exist or user id and password does not match, the program will print "Invalid credentials. x attempt(s) remaining." and prompt user to login again. Successful login displays a welcome message with the user's name and role. Users have three login attempts before the program prints a message "Sorry you're out of attempts. Please contact your librarian for assistance." and back to welcome and login menu. In the login menu, user can type "quit" to terminate the program. Welcome to Library Login as: s31267 Password: chr1267 Logged in as Chris Manner (Student) Main menu Once logged in, users see a personalized main menu based on their role. For student, other users, and staff members outside the Library department: Logged in as Chris Manner (Student) ================================== My Library Account 0. Quit 1. Log out 2. View account policies 3. View my loans ================================== Enter your choice: For staff from the Library department: Logged in as Mary Alan (Staff) ================================== My Library Account 0. Quit 1. Log out 2. View account policies 3. View my loans 4. Library Report ================================== Enter your choice: A user's input may provide incorrect choice, e.g. 5 or four. In this case your program should prompt for input again. 0. Quit The program will print the message: "Goodbye!", and terminates. 1. Log out The user is logged out and returned to the welcome screen and login menu. 2. View account policies Upon entering 2, the program will display user current membership policies, and their total loans. Logged in as Chris Manner (Student) ================================== My Library Account 0. Quit 1. Log out 2. View account policies 3. View my loans ================================== Enter your choice: 2 Student Chris Manner. Policies: maximum of 10 days, 4 items. Current loans: 2 (1 physical / 1 online). 3. View my loans Upon entering 3, the program will display all active loans (sorted by due date). Active loans are those without a returned date. Logged in as Chris Manner (Student) ================================== My Library Account 0. Quit 1. Log out 2. View account policies 3. View my loans ================================== Enter your choice: 3 You are currently have 2 loan(s). 1. P0006 'Hands-On ML' by Aurelien Geron (2019). Due date: 13/09/2025. 2. E0001 'Python Crash Course' by Eric Matthes (2015). Due date: 15/09/2025. 4. Library Report (Library Staff only) Upon entering 4, library staff can access a summary report of the library. This report provides key statistics, including the total number of users (with a breakdown by role), as well as details about the book collection and available books which currently have one or more copies available. Logged in as Mary Alan (Staff) ================================== My Library Account 0. Quit 1. Log out 2. View account policies 3. View my loans 4. Library Report ================================== Enter your choice: 4 Library Report - 9 users, including 4 student(s), 3 staff and 2 others. - 14 books, including 10 physical book(s) (7 currently available) and 4 online book(s). Examples User inputs are in bold font below. Example 1 Welcome to Library Login as: s312 Password: chr1267 Invalid credentials. 2 attempt(s) remaining. Login as: s31267 Password: chr12 Invalid credentials. 1 attempt(s) remaining. Login as: s31267 Password: chr126 Sorry you're out of attempts. Please contact your librarian for assistance. Welcome to Library Login as: quit Goodbye! Example 2 Welcome to Library Login as: s31267 Password: chr1267 Logged in as Chris Manner (Student) ================================== My Library Account 0. Quit 1. Log out 2. View account policies 3. View my loans ================================== Enter your choice: 2 Student Chris Manner. Policies: maximum of 10 days, 4 items. Current loans: 2 (1 physical / 1 online). ================================== My Library Account 0. Quit 1. Log out 2. View account policies 3. View my loans ================================== Enter your choice: 3 You are currently have 2 loan(s). 1. P0006 'Hands-On ML' by Aurelien Geron (2019). Due date: 13/09/2025. 2. E0001 'Python Crash Course' by Eric Matthes (2015). Due date: 15/09/2025. ================================== My Library Account 0. Quit 1. Log out 2. View account policies 3. View my loans ================================== Enter your choice: 0 Goodbye! Example 3 Welcome to Library Login as: e118102 Password: pa55word Logged in as Mary Alan (Staff) ================================== My Library Account 0. Quit 1. Log out 2. View account policies 3. View my loans 4. Library Report ================================== Enter your choice: 4 Library report - 9 users, including 4 student(s), 3 staff, and 2 others. - 14 books, including 10 physical book(s) (7 currently available) and 4 online book(s). ================================== My Library Account 0. Quit 1. Log out 2. View account policies 3. View my loans 4. Library Report ================================== Enter your choice: 5 Enter your choice: 3 You are currently have 1 loan(s). 1. P0004 'The Hitchhiker's Guide to the Galaxy' by Douglas Adams (1985). Due date: 17/09/2025. ================================== My Library Account 0. Quit 1. Log out 2. View account policies 3. View my loans 4. Library Report ================================== Enter your choice: 0 Goodbye! Example 4 Welcome to Library Login as: o56789 Password: hackme Logged in as Chloe (Others) ================================== My Library Account 0. Quit 1. Log out 2. View account policies 3. View my loans ================================== Enter your choice: 2 Others Chloe. Policies: maximum of 7 days, 2 items. Current loans: 0 (0 physical / 0 online). ================================== My Library Account 0. Quit 1. Log out 2. View account policies 3. View my loans ================================== Enter your choice: 3 You are currently have 0 loan(s). ================================== My Library Account 0. Quit 1. Log out 2. View account policies 3. View my loans ================================== Enter your choice: 0 Goodbye! Example 5 Login as: e45261 Password: readmore Logged in as Lan Nguyen (Staff) ================================== My Library Account 0. Quit 1. Log out 2. View account policies 3. View my loans ================================== Enter your choice: 2 Staff Lan Nguyen. Policies: maximum of 14 days, 6 items. Current loans: 1 (1 physical / 0 online). ================================== My Library Account 0. Quit 1. Log out 2. View account policies 3. View my loans ================================== Enter your choice: 3 You are currently have 1 loan(s). 1. P0019 'Principles of Marketing' by Philip Kotler (2016). Due date: 21/09/2025. ================================== My Library Account 0. Quit 1. Log out 2. View account policies 3. View my loans ================================== Enter your choice: 0 Goodbye!from abc import ABC, abstractmethod import csv import datetime import re class User(ABC): # Your code goes here passimport csv import datetime import re class Book: # your code goes hereimport user import book import csv import datetime import typing def main(user_file: str, book_file:str, loan_file:str) -> None: """ This is the entry of your program. Please DO NOT modify this function signature, i.e. function name, parameters Parameteres: - user_file (str): path the `users.csv` which stores user information - book_file (str): path the `books.csv` which stores book information - loan_file (str): path the `loans.csv` which stores loan information """ # Your implemetation goes here pass if __name__ == "__main__": main('data/users.csv', 'data/books.csv', 'data/loans.csv')
最新发布
10-11
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值