本文整理汇总了C#中MONITORINFO类的典型用法代码示例。如果您正苦于以下问题:C# MONITORINFO类的具体用法?C# MONITORINFO怎么用?C# MONITORINFO使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MONITORINFO类属于命名空间,在下文中一共展示了MONITORINFO类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: WmGetMinMaxInfo
private static void WmGetMinMaxInfo(IntPtr hwnd, IntPtr lParam)
{
POINT lMousePosition;
GetCursorPos(out lMousePosition);
IntPtr lPrimaryScreen = MonitorFromPoint(new POINT(0, 0), MonitorOptions.MONITOR_DEFAULTTOPRIMARY);
MONITORINFO lPrimaryScreenInfo = new MONITORINFO();
if (GetMonitorInfo(lPrimaryScreen, lPrimaryScreenInfo) == false)
{
return;
}
IntPtr lCurrentScreen = MonitorFromPoint(lMousePosition, MonitorOptions.MONITOR_DEFAULTTONEAREST);
MINMAXINFO lMmi = (MINMAXINFO)Marshal.PtrToStructure(lParam, typeof(MINMAXINFO));
if (lPrimaryScreen.Equals(lCurrentScreen))
{
lMmi.ptMaxPosition.X = lPrimaryScreenInfo.rcWork.Left;
lMmi.ptMaxPosition.Y = lPrimaryScreenInfo.rcWork.Top;
lMmi.ptMaxSize.X = lPrimaryScreenInfo.rcWork.Right - lPrimaryScreenInfo.rcWork.Left;
lMmi.ptMaxSize.Y = lPrimaryScreenInfo.rcWork.Bottom - lPrimaryScreenInfo.rcWork.Top;
}
else
{
lMmi.ptMaxPosition.X = lPrimaryScreenInfo.rcMonitor.Left;
lMmi.ptMaxPosition.Y = lPrimaryScreenInfo.rcMonitor.Top;
lMmi.ptMaxSize.X = lPrimaryScreenInfo.rcMonitor.Right - lPrimaryScreenInfo.rcMonitor.Left;
lMmi.ptMaxSize.Y = lPrimaryScreenInfo.rcMonitor.Bottom - lPrimaryScreenInfo.rcMonitor.Top;
}
Marshal.StructureToPtr(lMmi, lParam, true);
}
示例2: WmGetMinMaxInfo
internal static void WmGetMinMaxInfo(IntPtr hwnd, IntPtr lParam)
{
MINMAXINFO mmi = (MINMAXINFO)Marshal.PtrToStructure(lParam, typeof(MINMAXINFO));
// Adjust the maximized size and position to fit the work area
// of the correct monitor.
Int32 MONITOR_DEFAULTTONEAREST = 0x00000002;
IntPtr monitor = MonitorFromWindow(hwnd, MONITOR_DEFAULTTONEAREST);
if (monitor != IntPtr.Zero)
{
MONITORINFO monitorInfo = new MONITORINFO();
GetMonitorInfo(monitor, monitorInfo);
RECT rcWorkArea = monitorInfo.m_rcWork;
RECT rcMonitorArea = monitorInfo.m_rcMonitor;
mmi.m_ptMaxPosition.m_x = Math.Abs(rcWorkArea.m_left - rcMonitorArea.m_left);
mmi.m_ptMaxPosition.m_y = Math.Abs(rcWorkArea.m_top - rcMonitorArea.m_top);
mmi.m_ptMaxSize.m_x = Math.Abs(rcWorkArea.m_right - rcWorkArea.m_left);
mmi.m_ptMaxSize.m_y = Math.Abs(rcWorkArea.m_bottom - rcWorkArea.m_top);
}
Marshal.StructureToPtr(mmi, lParam, true);
}
示例3: WmGetMinMaxInfo
private void WmGetMinMaxInfo(IntPtr hwnd, IntPtr lParam)
{
MINMAXINFO mmi = (MINMAXINFO)Marshal.PtrToStructure(lParam, typeof(MINMAXINFO));
// Adjust the maximized size and position to fit the work area of the correct monitor
int MONITOR_DEFAULTTONEAREST =0x00000002;
IntPtr monitor = MonitorFromWindow(hwnd, MONITOR_DEFAULTTONEAREST);
if (monitor != IntPtr.Zero)
{
MONITORINFO monitorInfo = new MONITORINFO();
GetMonitorInfo(monitor, monitorInfo);
RECT rcWorkArea = monitorInfo.rcWork;
RECT rcMonitorArea = monitorInfo.rcMonitor;
mmi.ptMaxPosition.x = Math.Abs(rcWorkArea.left - rcMonitorArea.left);
mmi.ptMaxPosition.y = Math.Abs(rcWorkArea.top - rcMonitorArea.top);
mmi.ptMaxSize.x = Math.Abs(rcWorkArea.right - rcWorkArea.left);
mmi.ptMaxSize.y = Math.Abs(rcWorkArea.bottom - rcWorkArea.top);
// Convert pixel sizes based on current DPI settings.
// Window.MinHeight/MinWidth are 1/96th of an inch.
PresentationSource presentationSource = PresentationSource.FromVisual(this);
if (presentationSource != null)
{
if (presentationSource.CompositionTarget != null)
{
Point minSize = presentationSource.CompositionTarget.TransformToDevice.Transform(new Point(MinWidth, MinHeight));
mmi.ptMinTrackSize.x = (int)minSize.X;
mmi.ptMinTrackSize.y = (int)minSize.Y;
}
}
}
Marshal.StructureToPtr(mmi, lParam, true);
}
示例4: WmGetMinMaxInfo
private static void WmGetMinMaxInfo(IntPtr hwnd, IntPtr lParam)
{
MINMAXINFO mmi = (MINMAXINFO)Marshal.PtrToStructure(lParam, typeof(MINMAXINFO));
int MONITOR_DEFAULTTONEAREST = 0x00000002;
IntPtr monitor = MonitorFromWindow(hwnd, MONITOR_DEFAULTTONEAREST);
if (monitor != IntPtr.Zero)
{
MONITORINFO monitorInfo = new MONITORINFO();
GetMonitorInfo(monitor, monitorInfo);
RECT rcWorkArea = monitorInfo.rcWork;
RECT rcMonitorArea = monitorInfo.rcMonitor;
mmi.ptMaxPosition.x = Math.Abs(rcWorkArea.left - rcMonitorArea.left);
mmi.ptMaxPosition.y = Math.Abs(rcWorkArea.top - rcMonitorArea.top);
mmi.ptMaxSize.x = Math.Abs(rcWorkArea.right - rcWorkArea.left);
mmi.ptMaxSize.y = Math.Abs(rcWorkArea.bottom - rcWorkArea.top);
}
Marshal.StructureToPtr(mmi, lParam, true);
}
示例5: WmGetMinMaxInfo
private static void WmGetMinMaxInfo(IntPtr hwnd, IntPtr lParam)
{
var structure = (MINMAXINFO)Marshal.PtrToStructure(lParam, typeof(MINMAXINFO));
var hMonitor = MonitorFromWindow(hwnd, 2);
if (hMonitor != IntPtr.Zero)
{
var lpmi = new MONITORINFO();
GetMonitorInfo(hMonitor, lpmi);
RECT rcWork = lpmi.rcWork;
RECT rcMonitor = lpmi.rcMonitor;
structure.ptMaxPosition.x = Math.Abs((int)(rcWork.left - rcMonitor.left));
structure.ptMaxPosition.y = Math.Abs((int)(rcWork.top - rcMonitor.top));
structure.ptMaxSize.x = Math.Abs((int)(rcWork.right - rcWork.left));
structure.ptMaxSize.y = Math.Abs((int)(rcWork.bottom - rcWork.top));
structure.ptMinTrackSize.x = (int)Application.Current.MainWindow.MinWidth;
structure.ptMinTrackSize.y = (int)Application.Current.MainWindow.MinHeight;
}
Marshal.StructureToPtr(structure, lParam, true);
}
示例6: WmGetMinMaxInfo
private static void WmGetMinMaxInfo(IntPtr hwnd, IntPtr lParam)
{
var mmi = (MINMAXINFO) Marshal.PtrToStructure(lParam, typeof (MINMAXINFO));
// Adjust the maximized size and position to fit the work area of the correct monitor
var MONITOR_DEFAULTTONEAREST = 0x00000002;
var monitor = MonitorFromWindow(hwnd, MONITOR_DEFAULTTONEAREST);
if (monitor != IntPtr.Zero) {
var monitorInfo = new MONITORINFO();
GetMonitorInfo(monitor, monitorInfo);
var rcWorkArea = monitorInfo.rcWork;
var rcMonitorArea = monitorInfo.rcMonitor;
mmi.ptMaxPosition.x = Math.Abs(rcWorkArea.left - rcMonitorArea.left);
mmi.ptMaxPosition.y = Math.Abs(rcWorkArea.top - rcMonitorArea.top);
mmi.ptMaxSize.x = Math.Abs(rcWorkArea.right - rcWorkArea.left);
mmi.ptMaxSize.y = Math.Abs(rcWorkArea.bottom - rcWorkArea.top);
}
Marshal.StructureToPtr(mmi, lParam, true);
}
示例7: getNativeMonitorResolution
private void getNativeMonitorResolution(out int width, out int height)
{
var monitor = MonitorFromWindow(GetActiveWindow(), MONITOR_DEFAULTTONEAREST);
MONITORINFO monitorInfo = new MONITORINFO();
monitorInfo.cbSize = Marshal.SizeOf(monitorInfo);
if (!GetMonitorInfo(monitor, ref monitorInfo))
{
width = Screen.width;
height = Screen.height;
}
else
{
width = monitorInfo.rcMonitor.Width;
height = monitorInfo.rcMonitor.Height;
}
}
示例8: GetMonitorInfo
public static extern int GetMonitorInfo(IntPtr hMonitor, ref MONITORINFO lpmi);
示例9: GetMonitor
public static Monitor GetMonitor(IntPtr hMonitor)
{
MONITORINFO _info = new MONITORINFO();
_info.cbSize = Marshal.SizeOf(_info);
NativeMethods.GetMonitorInfo(hMonitor, ref _info);
uint _dpiX = Monitor.DPICONST;
uint _dpiY = Monitor.DPICONST;
if (OS.SupportDPI)
{
NativeMethods.GetDpiForMonitor(hMonitor, MONITOR_DPI_TYPE.MDT_EFFECTIVE_DPI, out _dpiX, out _dpiY);
}
return new Monitor()
{
Size = _info.Size,
WorkArea = _info.WorkArea,
DPIx = _dpiX,
DPIy = _dpiY,
IsPrimary = _info.IsPrimary
};
}
示例10: IsFullScreen
/*---------------------------------------------------------------------------------*/
public bool IsFullScreen(string[] classNamesExcluded)
{
if (m_hWnd == IntPtr.Zero)
return false;
// 컨트롤의 최상위 핸들을 얻어옵니다.
IntPtr hWnd = GetAncestor(m_hWnd, GetAncestorFlags.GetRoot);
if (hWnd == IntPtr.Zero)
return false;
// 클래스이름을 얻어옵니다.
StringBuilder className = new StringBuilder(256);
if (GetClassName(hWnd, className, className.Capacity) == 0)
return false;
// 제외목록에서 하나라도 해당되는지 확인.
if (classNamesExcluded.Any((string s) => s == className.ToString()))
return false;
// 현재 컨트롤이 속하는 모니터의 사각영역을 얻어옵니다.
RECT desktop;
IntPtr monitor = MonitorFromWindow(hWnd, MONITOR_DEFAULTTONEAREST);
if (monitor == IntPtr.Zero)
{
// 모니터를 찾을 수 없으면 현재 윈도우 화면의 핸들로 설정한다.
IntPtr desktopWnd = GetDesktopWindow();
if (desktopWnd == IntPtr.Zero)
return false;
if (GetWindowRect(desktopWnd, out desktop) == false)
return false;
}
else
{
MONITORINFO info = new MONITORINFO();
info.cbSize = Marshal.SizeOf(info);
if (GetMonitorInfo(monitor, ref info) == false)
return false;
desktop = info.rcMonitor;
}
// 컨트롤의 작업영역을 알아낸다.
RECT client;
if (GetClientRect(hWnd, out client) == false)
return false;
// 컨트롤의 크기가 모니터 크기보다 작으면 전체화면이 아니다.
if (client.Width < desktop.Width
||
client.Height < desktop.Height)
return false;
// 여기까지 도달했으면 전체화면이다.
return true;
}
示例11: GetActualScreenData
private static void GetActualScreenData(ABEdge edge, Window appbarWindow, ref int leftOffset, ref int topOffset, ref int actualScreenWidth, ref int actualScreenHeight)
{
IntPtr handle = new WindowInteropHelper(appbarWindow).Handle;
IntPtr monitorHandle = MonitorFromWindow(handle, MONITOR_DEFAULTTONEAREST);
MONITORINFO mi = new MONITORINFO();
mi.cbSize = Marshal.SizeOf(mi);
if (GetMonitorInfo(monitorHandle, ref mi))
{
if (mi.dwFlags == MONITORINFOF_PRIMARY)
{
return;
}
leftOffset = mi.rcWork.left;
topOffset = mi.rcWork.top;
actualScreenWidth = mi.rcWork.right - leftOffset;
actualScreenHeight = mi.rcWork.bottom - mi.rcWork.top;
}
}
示例12: WmGetMinMaxInfo
private static void WmGetMinMaxInfo(System.IntPtr hwnd, System.IntPtr lParam)
{
MINMAXINFO mmi = (MINMAXINFO)Marshal.PtrToStructure(lParam, typeof(MINMAXINFO));
// Adjust the maximized size and position to fit the work area of the correct monitor
int MONITOR_DEFAULTTONEAREST = 0x00000002;
System.IntPtr monitor = MonitorFromWindow(hwnd, MONITOR_DEFAULTTONEAREST);
if (monitor != System.IntPtr.Zero)
{
MONITORINFO monitorInfo = new MONITORINFO();
GetMonitorInfo(monitor, monitorInfo);
RECT rcWorkArea = monitorInfo.rcWork;
RECT rcMonitorArea = monitorInfo.rcMonitor;
mmi.ptMaxPosition.x = Math.Abs(rcWorkArea.left - rcMonitorArea.left);
mmi.ptMaxPosition.y = Math.Abs(rcWorkArea.top - rcMonitorArea.top);
// 这行如果不注释掉在多显示器情况下显示会有问题!
// mmi.ptMaxSize.x = Math.Abs(rcWorkArea.right - rcWorkArea.left);
mmi.ptMaxSize.y = Math.Abs(rcWorkArea.bottom - rcWorkArea.top);
workAreaMaxHeight = mmi.ptMaxSize.y;
//当窗口的任务栏自动隐藏时,最大化的时候最下边要留几个像素的空白,否则此窗口将屏幕铺满,则鼠标移到最下边时,任务栏无法自动弹出
if (rcWorkArea.Height == rcMonitorArea.Height)
{
mmi.ptMaxSize.y -= 2;
}
}
Marshal.StructureToPtr(mmi, lParam, true);
}
示例13: GetMonitorInfo
public static extern bool GetMonitorInfo(IntPtr hMonitor, ref MONITORINFO info);
示例14: GetMonitorInfo
private static extern bool GetMonitorInfo(IntPtr monitor, ref MONITORINFO info);
示例15: GetMonitorInfo
internal static extern bool GetMonitorInfo(IntPtr hMonitor, MONITORINFO lpmi);