Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

实现双屏复制 #29

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion Loaf/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,9 @@ public void Loaf()
}
Frame.Navigate(typeof(Windows11UpdateView));


_appWindow.SetPresenter(AppWindowPresenterKind.FullScreen);

ScreenHelper.SetScreenMode(1);
while (ShowCursor(true) < 0)
{
ShowCursor(true); //显示光标
Expand All @@ -99,6 +100,7 @@ public void Unloaf()
{
_isLoafing = false;
_appWindow.SetPresenter(AppWindowPresenterKind.Default);
ScreenHelper.SetScreenMode(2);
var parent = VisualTreeHelper.GetParent(Root);
while (parent != null)
{
Expand Down
64 changes: 64 additions & 0 deletions Loaf/ScreenHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;

namespace Loaf
{
public static class ScreenHelper
{
private const uint SDC_APPLY = 0x00000080;

private const uint SDC_TOPOLOGY_INTERNAL = 0x00000001;

private const uint SDC_TOPOLOGY_CLONE = 0x00000002;

/// <summary>
/// 扩展模式
/// </summary>
private const uint SDC_TOPOLOGY_EXTEND = 0x00000004;

[DllImport("user32.dll", CharSet = CharSet.Unicode)]
private static extern long SetDisplayConfig(uint numPathArrayElements, IntPtr pathArray, uint numModeArrayElements,
IntPtr modeArray, uint flags);
/// <summary>
/// 设置屏幕的显示模式
/// </summary>
/// <param name="displayModel"></param>
/// <returns></returns>
private static bool SetScreen(uint displayModel)
{
return SetDisplayConfig(0, IntPtr.Zero, 0, IntPtr.Zero, SDC_APPLY | displayModel) == 0;
}

/// <summary>
/// 设置屏幕的显示模式
/// </summary>
/// <param name="type">模式(0 - 主屏 1 - 双屏复制 2 - 双屏扩展</param>
/// <returns></returns>
public static bool SetScreenMode(int type)
{
uint smode;

switch (type)
{
case 0:
smode = SDC_APPLY | SDC_TOPOLOGY_INTERNAL;
break;
case 1:
smode = SDC_APPLY | SDC_TOPOLOGY_CLONE;
break;
case 2:
smode = SDC_APPLY | SDC_TOPOLOGY_EXTEND;
break;
default:
smode = SDC_APPLY | SDC_TOPOLOGY_INTERNAL;
break;
}

return SetDisplayConfig(0, IntPtr.Zero, 0, IntPtr.Zero, smode) == 0;
}
}
}