2010-03-25 64 views
4

我正在開發一個應用程序在VS2008 VC++ .net移動應用程序到第二個監視器在MFC中

我想將應用程序移動到輔助監視器。不是通過點擊和拖動使用鼠標。

是否有像MoveToMonitor這樣的按鈕或任何快捷鍵的功能。 然後它應該移動到輔助監視器。

+0

我回答的基礎是假設你正在問你可以在編程中使用的函數。如果您詢問Windows提供的快捷鍵,那麼這可能屬於SuperUser。 – 2010-03-25 06:24:51

回答

2

您應該可以致電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. 

如果你是微軟Windows 7則顯示器之間的移動窗口是Windows-Arrow

+0

你能否提供我任何樣品編碼。 – Anu 2010-03-25 06:27:17

+0

在第二個鏈接上有一些示例代碼 – 2010-03-25 06:53:56

+0

通過使用MSDN示例代碼,屏幕適合居中,不移動到第二個監視器。 – Anu 2010-03-25 07:31:04

2

您使用MoveWindow(或SetWindowPos,雖然你並不需要多餘的東西能在這種情況下做的)移動窗口顯示在顯示器上的桌面部分。你可以在EnumDisplayMonitors之中找到這個,它會告訴你與每個顯示器相關的矩形。

相關問題