C

科技玩点原始事 2024-02-24 14:45:57

目录

1、查找窗口句柄

2、查找窗口内子对象

3、指定窗口样式

4、指定窗口扩展样式

5、调整窗口大小Z轴(层叠)

6、获得窗口样式

7、向窗口发送命令

8、指定父窗口

9、获取窗口进程

10、移动及缩放窗口

11、隐藏任务栏

12、隐藏任务栏按钮

13、WinAPI调用的类含常数定义

1、查找窗口句柄

[DllImport("user32.dll", EntryPoint = "FindWindow")]private extern static IntPtr FindWindow(string lpClassName, string lpWindowName);

lpClassName类名,用Spy++工具可以获得

lpWindowName窗口标题,任务栏、任务管理器都可以看到

以上两个参数,可以只写一个,另一个写null

2、查找窗口内子对象

[DllImport("user32.dll", EntryPoint = "FindWindow")]private static extern IntPtr FindWindowEx( IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow )

如:

ShowWindow((int)FindWindowEx(FindWindow("Shell_TrayWnd", null), IntPtr.Zero, "Start", null), SW_RESTORE); //隐藏开始按钮

3、指定窗口样式

[DllImport("user32.dll")]SetWindowLong(PPThwnd, GWL_STYLE, s | WS_CHILD);

4、指定窗口扩展样式

SetWindowLong(IntPtr hWnd, GWL_EXSTYLE, WS_EX_TOOLWINDOW);

5、调整窗口大小Z轴(层叠)

[DllImport("User32.dll", CharSet = CharSet.Auto)]private static extern bool SetWindowPos(IntPtr hWnd, int hWndlnsertAfter, int X, int Y, int cx, int cy, uint Flags);

6、获得窗口样式

[DllImport("user32.dll", EntryPoint = "GetWindowLong")]public static extern int GetWindowLong(IntPtr hwnd, int nIndex);

7、向窗口发送命令

[DllImport("user32.dll", EntryPoint = "SendMessageA")]public static extern int SendMessage(IntPtr hwnd, int wMsg, int wParam, int lParam);

8、指定父窗口

[DllImport("user32.dll")]private static extern IntPtr SetParent(IntPtr childIntPtr, IntPtr parentIntPtr);

9、获取窗口进程

[DllImport("User32.dll", CharSet = CharSet.Auto)]public static extern int GetWindowThreadProcessId(IntPtr hwnd, out int ID);//获取进程ID

10、移动及缩放窗口

[DllImport("user32.dll", SetLastError = true)]public static extern bool MoveWindow(IntPtr hwnd, int x, int y, int cx, int cy, bool repaint);

*窗体被嵌入其它程序后,如果需哟调整位置及大小,就用这个!

11、隐藏任务栏

IntPtr trayHwnd = FindWindow("Shell_TrayWnd", null);ShowWindow(trayHwnd, 0);

“0”改为“1”,为显示任务栏

12、隐藏任务栏按钮

SetWindowLong((IntPtr)pvm , GWL_EXSTYLE, WS_EX_TOOLWINDOW); //设置窗口扩展样式为WS_EX_TOOLWINDOW,可以让窗体不在任务栏中显示。

13、WinAPI调用的类含常数定义

using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Drawing;using System.Runtime.InteropServices; namespace APIHelper{ /// <summary> /// Windows API 函数声明 /// </summary> public Win32API { #region .ctor() // No need to construct this object private Win32API() { } #endregion #region Constans values public const string TOOLBARCLASSNAME = "ToolbarWindow32"; public const string REBARCLASSNAME = "ReBarWindow32"; public const string PROGRESSBARCLASSNAME = "msctls_progress32"; public const string SCROLLBAR = "SCROLLBAR"; #endregion ……(详见源码)}

源码私信

0 阅读:0

科技玩点原始事

简介:感谢大家的关注