我是初学者。请帮助我使用c# win表格中的代码。
我不知道HWND。请解释这些代码,并帮助我在C# win表单中使用这个函数。
BOOL SetWindowDisplayAffinity(HWND hWnd,DWORD dwAffinity);您能用C# win表单为该函数编写示例代码吗?非常感谢
发布于 2019-06-22 06:09:33
您可以通过win32 (google )调用本机PInvoke API,如下所示:
[DllImport("user32.dll")]
public static extern uint SetWindowDisplayAffinity(IntPtr hwnd, uint dwAffinity);表单有一个名为“句柄”的属性,即本机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);
}
}
}现在,当我运行这个程序并尝试用打印屏幕键拍摄一个屏幕截图时,这就是被发布到剪贴板上的实际情况:

https://stackoverflow.com/questions/56712964
复制相似问题