【问题标题】:Move application to second monitor in MFC将应用程序移动到 MFC 中的第二个监视器
【发布时间】:2017-10-19 09:55:18
【问题描述】:

我正在用VS2008 VC++.net开发一个应用程序

我想将应用程序移至辅助监视器。不是通过鼠标点击和拖动。

是否有类似MoveToMonitor的功能,可以通过按键或任意快捷键实现。 然后它应该移动到辅助监视器。

【问题讨论】:

  • 我的回答是基于您在询问您可以在编程中使用的功能的假设。如果您询问的是 Windows 提供的快捷键,那么这可能属于 SuperUser。

标签: mfc multiple-monitors


【解决方案1】:

您应该可以致电GetMonitorInfo 并将您的窗口移至其中。

看这里' MFC Example Multiple monitor support with GetSystemMetrics EnumDisplayMonitors and GetMonitorInfo' 了解更多信息。

Using the code

CMointor is a basic MFC class that allows you to safely use the multiple-monitor API on any Win32 platform. 

There are three classes in this library:

CMonitors represents the collection of monitors currently attached to the system and wraps the EnumDisplayMonitors API function.

  Collapse Copy Code
//CMonitors' interface
CMonitor GetMonitor( const int index ) const;
int GetCount() const; 

//returns the monitor closest to the specified item
static CMonitor GetNearestMonitor( const LPRECT lprc );
static CMonitor GetNearestMonitor( const POINT pt );
static CMonitor GetNearestMonitor( const CWnd* pWnd );

//is the specificed item visible on any monitor
static BOOL IsOnScreen( const POINT pt );
static BOOL IsOnScreen( const CWnd* pWnd );
static BOOL IsOnScreen( const LPRECT lprc );

//returns the rectangle encompassing all monitors
static void GetVirtualDesktopRect( LPRECT lprc );

//determines whether the given handle is a valid monitor handle
static BOOL IsMonitor( const HMONITOR hMonitor );
static CMonitor GetPrimaryMonitor();
static BOOL AllMonitorsShareDisplayFormat();

static int GetMonitorCount();
CMonitor is a wrapper around an HMONITOR handle (returned from EnumDisplayMonitors) and the GetMonitorInfo function. With CMonitor you can get at the characteristics of a given monitor.

  Collapse Copy Code
//The interface of CMonitor            
void Attach( const HMONITOR hMonitor );
HMONITOR Detach();

void ClipRectToMonitor( LPRECT lprc, 
                        const BOOL UseWorkAreaRect = FALSE ) const;
void CenterRectToMonitor( LPRECT lprc, 
                          const BOOL UseWorkAreaRect = FALSE ) const;
void CenterWindowToMonitor( CWnd* const pWnd,
                            const BOOL UseWorkAreaRect = FALSE ) const;

//creates a device context for the monitor - the client is responsible for 
// DeleteDC
HDC CreateDC() const;

void GetMonitorRect( LPRECT lprc ) const;
//the work area is the monitor rect minus the start bar
void GetWorkAreaRect( LPRECT lprc ) const;

void GetName( CString& string ) const;

int GetBitsPerPixel() const;

//determines if the specified item on the monitor
BOOL IsOnMonitor( const POINT pt ) const;
BOOL IsOnMonitor( const CWnd* pWnd ) const;
BOOL IsOnMonitor( const LPRECT lprc ) const;

BOOL IsPrimaryMonitor() const;
BOOL IsMonitor() const;

CMonitorDC is a CDC derived class that represents a monitor specific device context. I haven't really gone to far with this class but it seemed like a logical part of the library.  

Known Limitations

CMonitor and CMonitors rely on the assumption that a monitor handle does not change. This has proved to be a safe assumption empirically but isn't nessecarily a guarantee.

如果您在 Window 7 上,那么监视器之间的移动窗口是 Windows-Arrow

【讨论】:

  • 你能给我提供任何代码示例吗?
  • 通过使用 MSDN 示例代码,屏幕适合居中,它不会移动到第二台显示器。
  • 第二个链接坏了。
  • 修复链接并复制相关信息。
【解决方案2】:

您使用MoveWindow(或SetWindowPos,尽管在这种情况下您不需要它可以做的额外事情)将窗口移动到相关显示器上显示的桌面部分。您可以使用(以及其他可能性)EnumDisplayMonitors 找到它,它会告诉您与每个监视器关联的矩形。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-10-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-07-22
    相关资源
    最近更新 更多