本文整理汇总了C#中System.Windows.Interop.WindowInteropHelper类的典型用法代码示例。如果您正苦于以下问题:C# WindowInteropHelper类的具体用法?C# WindowInteropHelper怎么用?C# WindowInteropHelper使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
WindowInteropHelper类属于System.Windows.Interop命名空间,在下文中一共展示了WindowInteropHelper类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GoFullScreen
public static void GoFullScreen(this Window window)
{
if (IsFullScreen(window))
{
return;
}
windowState = window.WindowState;
windowStyle = window.WindowStyle;
windowTopmost = window.Topmost;
windowResizeMode = window.ResizeMode;
windowRect.X = window.Left;
windowRect.Y = window.Top;
windowRect.Width = window.Width;
windowRect.Height = window.Height;
window.WindowState = WindowState.Maximized;
window.WindowStyle = WindowStyle.None;
windowTopmost = false;
windowResizeMode = ResizeMode.NoResize;
IntPtr handle = new WindowInteropHelper(window).Handle;
Screen screen = Screen.FromHandle(handle);
window.Width = screen.Bounds.Width;
window.Height = screen.Bounds.Height;
fullWindow = window;
}
示例2: ShowDialog
public static CustomMessageBoxResult ShowDialog(Form owner, string caption, string message)
{
VersionPickDialog messageBox = new VersionPickDialog();
var helper = new WindowInteropHelper(messageBox);
helper.Owner = owner.Handle;
return messageBox.ShowDialogInternal(caption, message);
}
示例3: PostInitializeWindow
private void PostInitializeWindow()
{
Activate();
Focus();
// Set the name of the inspected app to the title
var process = Process.GetCurrentProcess();
string processName = process.MainWindowTitle ?? process.ProcessName;
Title += " - " + processName;
try
{
var interopHelper = new WindowInteropHelper(this);
_handle = interopHelper.Handle;
NativeMethods.SetForegroundWindow(_handle);
}
catch (Exception)
{
}
if( _viewModel.ShowUsageHint)
{
var usageHintWindow = new UsageHintWindow();
usageHintWindow.Owner = this;
usageHintWindow.ShowDialog();
}
// Initialize this service
ServiceLocator.Resolve<MouseElementService>();
}
示例4: LoginDialog_Loaded
void LoginDialog_Loaded(object sender, RoutedEventArgs e)
{
Handle = new WindowInteropHelper(this).Handle;
Presenter.Initialise(this);
wb.Navigating += wb_Navigating;
wb.Navigated += wb_Navigated;
}
示例5: AfterEngineInit
public void AfterEngineInit()
{
// Basics.
{
var deviceDesc = new Device.Descriptor {DebugDevice = true};
renderDevice = new ClearSight.RendererDX12.Device(ref deviceDesc,
ClearSight.RendererDX12.Device.FeatureLevel.Level_11_0);
var descCQ = new CommandQueue.Descriptor() {Type = CommandListType.Graphics};
commandQueue = renderDevice.Create(ref descCQ);
var wih = new WindowInteropHelper(window);
var swapChainDesc = new SwapChain.Descriptor()
{
AssociatedGraphicsQueue = commandQueue,
MaxFramesInFlight = 3,
BufferCount = 3,
Width = (uint) window.Width,
Height = (uint) window.Height,
Format = Format.R8G8B8A8_UNorm,
SampleCount = 1,
SampleQuality = 0,
WindowHandle = wih.Handle,
Fullscreen = false
};
swapChain = renderDevice.Create(ref swapChainDesc);
var commandListDesc = new CommandList.Descriptor()
{
Type = CommandListType.Graphics,
AllocationPolicy = new CommandListInFlightFrameAllocationPolicy(CommandListType.Graphics, swapChain)
};
commandList = renderDevice.Create(ref commandListDesc);
}
// Render targets.
{
var descHeapDesc = new DescriptorHeap.Descriptor()
{
Type = DescriptorHeap.Descriptor.ResourceDescriptorType.RenderTarget,
NumResourceDescriptors = swapChain.Desc.BufferCount
};
descHeapRenderTargets = renderDevice.Create(ref descHeapDesc);
var rtvViewDesc = new RenderTargetViewDescription()
{
Format = swapChain.Desc.Format,
Dimension = Dimension.Texture2D,
Texture = new TextureSubresourceDesc(mipSlice: 0)
};
for (uint i = 0; i < swapChain.Desc.BufferCount; ++i)
{
renderDevice.CreateRenderTargetView(descHeapRenderTargets, i, swapChain.BackbufferResources[i], ref rtvViewDesc);
}
}
}
示例6: SetWindowStyle
private void SetWindowStyle()
{
var helper = new WindowInteropHelper(this);
const int gwlExstyle = -20;
const int wsExNoactivate = 0x08000000;
NativeWin32.SetWindowLong(helper.Handle, gwlExstyle, (IntPtr)(wsExNoactivate | wsExNoactivate));
}
示例7: OnLoaded
void OnLoaded(object sender, RoutedEventArgs e)
{
// Hide Maximize & Size on the system context menu
var hwnd = new WindowInteropHelper(this).Handle;
NativeMethods.SetWindowLong(hwnd, NativeMethods.GWL_STYLE,
NativeMethods.GetWindowLong(hwnd, NativeMethods.GWL_STYLE) & ~NativeMethods.WS_SYSMENU);
}
示例8: wnd_Loaded
static void wnd_Loaded(object sender, RoutedEventArgs e)
{
Window wnd = (Window)sender;
Brush originalBackground = wnd.Background;
wnd.Background = Brushes.Transparent;
try
{
IntPtr mainWindowPtr = new WindowInteropHelper(wnd).Handle;
HwndSource mainWindowSrc = HwndSource.FromHwnd(mainWindowPtr);
mainWindowSrc.CompositionTarget.BackgroundColor = Color.FromArgb(0, 0, 0, 0);
//System.Drawing.Graphics desktop = System.Drawing.Graphics.FromHwnd(mainWindowPtr);
//float DesktopDpiX = desktop.DpiX;
//float DesktopDpiY = desktop.DpiY;
MARGINS margins = new MARGINS();
margins.cxLeftWidth = -1;
margins.cxRightWidth = -1;
margins.cyTopHeight = -1;
margins.cyBottomHeight = -1;
//DwmExtendFrameIntoClientArea(mainWindowSrc.Handle, ref margins);
}
catch (DllNotFoundException)
{
wnd.Background = originalBackground;
}
}
示例9: ExtendGlassFrame
public static bool ExtendGlassFrame(Window window, Thickness margin)
{
try
{
// desktop window manader must be enabled if it isn't don't bother trying to add glass
if (!DwmIsCompositionEnabled())
{
return false;
}
IntPtr hwnd = new WindowInteropHelper(window).Handle;
if (hwnd == IntPtr.Zero)
{
throw new InvalidOperationException("The Window must be shown before extending glass.");
}
// Set the background to transparent from both the WPF and Win32 perspectives
//window.Background = Brushes.Transparent;
HwndSource.FromHwnd(hwnd).CompositionTarget.BackgroundColor = Colors.Transparent;
MARGINS margins = new MARGINS(margin);
DwmExtendFrameIntoClientArea(hwnd, ref margins);
return true;
}
catch
{
return false;
}
}
示例10: ToFullscreen
public static void ToFullscreen(this Window window)
{
if (window.IsFullscreen())
{
return;
}
_windowState = window.WindowState;
_windowStyle = window.WindowStyle;
_windowTopMost = window.Topmost;
_windowResizeMode = window.ResizeMode;
_windowRect.X = window.Left;
_windowRect.Y = window.Top;
_windowRect.Width = window.Width;
_windowRect.Height = window.Height;
window.WindowState = WindowState.Normal;
window.WindowStyle = WindowStyle.None;
window.ResizeMode = ResizeMode.NoResize;
window.Topmost = true;
var handle = new WindowInteropHelper(window).Handle;
Screen screen = Screen.FromHandle(handle);
window.MaxWidth = screen.Bounds.Width;
window.MaxHeight = screen.Bounds.Height;
window.WindowState = WindowState.Maximized;
window.Activated += new EventHandler(window_Activated);
window.Deactivated += new EventHandler(window_Deactivated);
_fullWindow = window;
}
示例11: AddInstanceButton_Click
private void AddInstanceButton_Click(object sender, RoutedEventArgs e)
{
NewEnemyInstanceWindow instWindow = new NewEnemyInstanceWindow(this.NewEnemyElement);
var helper = new WindowInteropHelper(instWindow);
helper.Owner = new WindowInteropHelper(this).Handle;
bool? res = instWindow.ShowDialog();
if (res != null && (bool)res)
{
}
else
{
// MessageBox.Show("Did not add new enemy instance");
}
/*
* NewEnemyWindow eneWindow = new NewEnemyWindow();
var helper = new WindowInteropHelper(eneWindow);
helper.Owner = new WindowInteropHelper(this).Handle;
bool? res = eneWindow.ShowDialog();
if (res != null && (bool)res)
{
}
else
{
MessageBox.Show("Did not add new enemy");
}
*/
}
示例12: OnSourceInitialized
protected override void OnSourceInitialized(EventArgs e)
{
base.OnSourceInitialized(e);
var helper = new WindowInteropHelper(this);
SetWindowLong(helper.Handle, GWL_EXSTYLE, GetWindowLong(helper.Handle, GWL_EXSTYLE) | WS_EX_NOACTIVATE);
}
示例13: OnShowDialog
private void OnShowDialog(object sender, EventArgs e)
{
var application = (DTE)GetService(typeof(SDTE));
if (application.Solution == null || !application.Solution.IsOpen)
MessageBox.Show("Please open a solution first. ", "No solution");
else
{
if (application.Solution.IsDirty) // solution must be saved otherwise adding/removing projects will raise errors
{
MessageBox.Show("Please save your solution first. \n" +
"Select the solution in the Solution Explorer and press Ctrl-S. ",
"Solution not saved");
}
else if (application.Solution.Projects.OfType<Project>().Any(p => p.IsDirty))
{
MessageBox.Show("Please save your projects first. \n" +
"Select the project in the Solution Explorer and press Ctrl-S. ",
"Project not saved");
}
else
{
var window = new MainDialog(application, GetType().Assembly);
var helper = new WindowInteropHelper(window);
helper.Owner = (IntPtr)application.MainWindow.HWnd;
window.ShowDialog();
}
}
}
示例14: ExtendGlassFrame
public static bool ExtendGlassFrame(Window window, Thickness margin)
{
// Get the Operating System From Environment Class
OperatingSystem os = Environment.OSVersion;
// Get the version information
Version vs = os.Version;
if (vs.Major < 6)
return false;
if (!DwmIsCompositionEnabled())
return false;
IntPtr hwnd = new WindowInteropHelper(window).Handle;
if (hwnd == IntPtr.Zero)
throw new InvalidOperationException("Glass cannot be extended before the window is shown.");
// Set the background to transparent from both the WPF and Win32 perspectives
window.Background = Brushes.Transparent;
HwndSource.FromHwnd(hwnd).CompositionTarget.BackgroundColor = Colors.Transparent;
MARGINS margins = new MARGINS(margin);
DwmExtendFrameIntoClientArea(hwnd, ref margins);
return true;
}
示例15: ExtendGlassFrame
public static bool ExtendGlassFrame(Window window, Thickness margin)
{
if (!Native.DwmIsCompositionEnabled())
return false;
try
{
IntPtr hwnd = new WindowInteropHelper(window).Handle;
if (hwnd == IntPtr.Zero)
throw new InvalidOperationException("The Window must be shown before extending glass.");
// Set the background to transparent from both the WPF and Win32 perspectives
window.Background = Brushes.Transparent;
HwndSource.FromHwnd(hwnd).CompositionTarget.BackgroundColor = Colors.Transparent;
Native.MARGINS margins = new Native.MARGINS(margin);
Native.DwmExtendFrameIntoClientArea(hwnd, ref margins);
return true;
}
catch (Exception ex)
{
LogWriter.Log(ex, "Error • Glass");
}
return false;
}