mfc - 在 MFC 中将应用程序移动到第二个显示器

标签 mfc multiple-monitors

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

我想将应用程序移至辅助显示器。不是通过使用鼠标单击和拖动来实现的。

有没有像MoveToMonitor这样通过按按钮或快捷键的功能。 然后它应该移动到辅助监视器。

最佳答案

您应该可以调用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

关于mfc - 在 MFC 中将应用程序移动到第二个显示器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2513441/

相关文章:

c++ - 有没有办法在 OnHotKey 函数中获取热键 ID?

javascript - Electron -如何处理多台显示器的屏幕窗口?

browser - 在第二台显示器上打开新的浏览器页面

C++ MFC如何在if语句中比较LPCTSTR?

c++ - 从 MFC 中的 DoDataExchange 确定调用者 ID

c++ - 有没有办法不用/UNICODE编译就可以使用MFC的CEdit的函数 "ShowBalloonTip"?

google-chrome - 如何在不同的显示器中打开 Chrome kiosk 模式的两个实例 (Windows)

command-line - ffplay双显示器设置

c++ - 支持不同的显示器分辨率

visual-studio - MFC 是否可以为 32 位和 64 位使用不同的应用程序名称?