⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mdiclientwindow.cs

📁 机械制造业信息管理系统(含源码) 是为一个粮仪厂开发的
💻 CS
字号:
using System;
using System.Runtime.InteropServices;
using System.Text;
using System.Windows.Forms;

using vbAccelerator.Components.Win32;

namespace vbAccelerator.Components.Win32 {

	public interface IMDIClientNotify {
		void WndProc(ref Message m, ref bool doDefault);
	}

	/// <summary>
	/// Summary description for MDIClientWindow.
	/// </summary>
	public class MDIClientWindow : NativeWindow {

		#region Delegates
		private delegate int EnumWindowsProc(IntPtr hwnd, int lParam);
		private IMDIClientNotify notify = null;
		#endregion

		#region UnManagedMethods
		private class UnManagedMethods {
			[DllImport("user32")]
			public extern static int EnumWindows (
				EnumWindowsProc lpEnumFunc, 
				int lParam);
			[DllImport("user32")]
			public extern static int EnumChildWindows (
				IntPtr hWndParent,
				EnumWindowsProc lpEnumFunc, 
				int lParam);
			[DllImport("user32", CharSet = CharSet.Auto)]
			public extern static int GetClassName (
				IntPtr hWnd, 
				StringBuilder lpClassName, 
				int nMaxCount);
		}
		#endregion

		#region Member variables
		private IntPtr hWndMdiClient = IntPtr.Zero;
		#endregion

		#region EnumWindows Code
		/// <summary>
		/// Gets all child windows of the specified window
		/// </summary>
		/// <param name="hWndParent">Window Handle to get children for</param>
		private void GetWindows(
			IntPtr hWndParent) {
			UnManagedMethods.EnumChildWindows(
				hWndParent,
				new EnumWindowsProc(this.WindowEnum),
				0);
		}

		/// <summary>
		/// The enum Windows callback.
		/// </summary>
		/// <param name="hWnd">Window Handle</param>
		/// <param name="lParam">Application defined value</param>
		/// <returns>1 to continue enumeration, 0 to stop</returns>
		private int WindowEnum(
			IntPtr hWnd,
			int lParam) {
			StringBuilder className = new StringBuilder(260, 260);
			UnManagedMethods.GetClassName(hWnd, className, className.Capacity);
			if (className.ToString().ToUpper().IndexOf("MDICLIENT") > 0) {
				// stop
				hWndMdiClient = hWnd;
				return 0;
			}
			else {
				// continue
				return 1;
			}
		}
		#endregion

		protected override void WndProc(ref Message m) {
			bool doDefault = true;
			if (notify != null) {
				notify.WndProc(ref m, ref doDefault);
			}
			if (doDefault) {
				base.WndProc(ref m);				
			}
		}

		public MDIClientWindow(IMDIClientNotify i, IntPtr handle) {
			// Find the MDI Client window handle:
			GetWindows(handle);
			if (hWndMdiClient != IntPtr.Zero) {
				this.AssignHandle(hWndMdiClient);
			}
			this.notify = i;
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -