我是初学者。请帮助我以c#win形式使用此代码。
我不知道HWND hWnd。请解释此代码,并帮助我以C#win形式使用此功能
domain1.website/page
您能以C#win形式为此函数编写示例代码吗?非常感谢
答案 0 :(得分:2)
您可以通过PInvoke(用Google调用)来调用本地win32 API,如下所示:
[DllImport("user32.dll")]
public static extern uint SetWindowDisplayAffinity(IntPtr hwnd, uint dwAffinity);
该表单具有一个称为“ Handle”的属性,它是本机HWND。
using System;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace WindowsFormsApp2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
[DllImport("user32.dll")]
public static extern uint SetWindowDisplayAffinity(IntPtr hwnd, uint dwAffinity);
private void Form1_Load(object sender, EventArgs e)
{
const uint WDA_NONE = 0;
const uint WDA_MONITOR = 1;
SetWindowDisplayAffinity(this.Handle, WDA_MONITOR);
}
}
}
现在,当我运行该程序并尝试使用打印屏幕键拍摄屏幕截图时,这是实际粘贴到剪贴板上的东西: