WINUI3_BOOKMS/MainWindow.xaml.cs

(开头部分) 10KB

这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。

using Microsoft.UI;
using Microsoft.UI.Windowing;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using MySql.Data.MySqlClient;
using System;
using System.Collections.ObjectModel;
using System.Runtime.InteropServices;
using Windows.Graphics;
using WinRT.Interop;

// To learn more about WinUI, the WinUI project structure,
// and more about our project templates, see: http://aka.ms/winui-project-info.

namespace WINUI3_BOOKMS
{
	public partial class MainWindow : Window
	{
		// 声明 GetWindowRect 函数,该函数从 user32.dll 中导入,用于获取窗口的尺寸和位置
		[DllImport("user32.dll", SetLastError = true)]
		private static extern bool GetWindowRect(IntPtr hwnd, out RECT lpRect);

		// RECT 结构表示窗口的矩形边界。StructLayout 属性确保其成员按顺序排列,以便与非托管代码兼容。
		[StructLayout(LayoutKind.Sequential)]
		private struct RECT
		{
			public int Left;
			public int Top;
			public int Right;
			public int Bottom;
		}

		// 保存所有图书
		public ObservableCollection<Book> Books { get; set; }

		public MainWindow()
		{
			this.InitializeComponent();

			// 获取窗口句柄
			IntPtr hwnd = WindowNative.GetWindowHandle(this);
			WindowId windowId = Win32Interop.GetWindowIdFromWindow(hwnd);
			AppWindow appWindow = AppWindow.GetFromWindowId(windowId);

			// 设置窗口标题
			appWindow.Title = "图书管理系统";

			// 设置窗口大小
			appWindow.Resize(new Windows.Graphics.SizeInt32(1200, 900));

			CenterWindowOnScreen(appWindow);

			Books = new ObservableCollection<Book>
			{
				new Book { id = 1, name = "红楼梦", author = "曹雪芹", press = "人民文学出版社" },
				new Book { id = 2, name = "西游记", author = "昊承恩", press = "中华书局" },
				new Book { id = 3, name = "水浒传", author = "施耐庵", press = "人民文学出版社" },
				new Book { id = 4, name = "三国演义", author = "罗贯中", press = "中华书局" },
				new Book { id = 5, name = "百年孤独", author = "加西亚·马尔克斯", press = "南海出版社" },
				new Book { id = 6, name = "追风筝的人", author = "卡勒德·胡赛尼", press = "上海人民出版社" },
后面还有 272 行代码,解锁后查看完整代码

24 小时内免费解锁 3 个项目,之后 1 积分/个。 规则说明

AI 解读

登录后可用,每次 10 积分,解读结果公开显示在下面。

还没有人解读过这个文件。