MScreenInfoCtl.cpp
资源名称:mulmon.zip [点击查看]
上传用户:zqemid3000
上传日期:2007-01-04
资源大小:158k
文件大小:10k
源码类别:
多显示器编程
开发平台:
Visual C++
- // MScreenInfoCtl.cpp : Implementation of the CMScreenInfoCtrl ActiveX Control class.
- #include "stdafx.h"
- #include "MScreenInfo.h"
- #include "MScreenInfoCtl.h"
- #include "MScreenInfoPpg.h"
- #define COMPILE_MULTIMON_STUBS
- #include "multimon.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- IMPLEMENT_DYNCREATE(CMScreenInfoCtrl, COleControl)
- /////////////////////////////////////////////////////////////////////////////
- // Message map
- BEGIN_MESSAGE_MAP(CMScreenInfoCtrl, COleControl)
- //{{AFX_MSG_MAP(CMScreenInfoCtrl)
- // NOTE - ClassWizard will add and remove message map entries
- // DO NOT EDIT what you see in these blocks of generated code !
- //}}AFX_MSG_MAP
- ON_OLEVERB(AFX_IDS_VERB_EDIT, OnEdit)
- ON_OLEVERB(AFX_IDS_VERB_PROPERTIES, OnProperties)
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // Dispatch map
- BEGIN_DISPATCH_MAP(CMScreenInfoCtrl, COleControl)
- //{{AFX_DISPATCH_MAP(CMScreenInfoCtrl)
- DISP_PROPERTY_NOTIFY(CMScreenInfoCtrl, "MonitorNum", m_monitorNum, OnMonitorNumChanged, VT_I2)
- DISP_PROPERTY_EX(CMScreenInfoCtrl, "PrimaryScreen", GetPrimaryScreen, SetPrimaryScreen, VT_I2)
- DISP_PROPERTY_PARAM(CMScreenInfoCtrl, "ScreenWidth", GetScreenWidth, SetScreenWidth, VT_I2, VTS_I2)
- DISP_PROPERTY_PARAM(CMScreenInfoCtrl, "ScreenHeight", GetScreenHeight, SetScreenHeight, VT_I2, VTS_I2)
- DISP_PROPERTY_PARAM(CMScreenInfoCtrl, "ScreenTop", GetScreenTop, SetScreenTop, VT_I2, VTS_I2)
- DISP_PROPERTY_PARAM(CMScreenInfoCtrl, "ScreenLeft", GetScreenLeft, SetScreenLeft, VT_I2, VTS_I2)
- //}}AFX_DISPATCH_MAP
- END_DISPATCH_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // Event map
- BEGIN_EVENT_MAP(CMScreenInfoCtrl, COleControl)
- //{{AFX_EVENT_MAP(CMScreenInfoCtrl)
- // NOTE - ClassWizard will add and remove event map entries
- // DO NOT EDIT what you see in these blocks of generated code !
- //}}AFX_EVENT_MAP
- END_EVENT_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // Property pages
- // TODO: Add more property pages as needed. Remember to increase the count!
- BEGIN_PROPPAGEIDS(CMScreenInfoCtrl, 1)
- PROPPAGEID(CMScreenInfoPropPage::guid)
- END_PROPPAGEIDS(CMScreenInfoCtrl)
- /////////////////////////////////////////////////////////////////////////////
- // Initialize class factory and guid
- IMPLEMENT_OLECREATE_EX(CMScreenInfoCtrl, "MSCREENINFO.MScreenInfoCtrl.1",
- 0x223de668, 0xe7d7, 0x11d2, 0x85, 0x72, 0, 0, 0x1a, 0x1, 0x69, 0xac)
- /////////////////////////////////////////////////////////////////////////////
- // Type library ID and version
- IMPLEMENT_OLETYPELIB(CMScreenInfoCtrl, _tlid, _wVerMajor, _wVerMinor)
- /////////////////////////////////////////////////////////////////////////////
- // Interface IDs
- const IID BASED_CODE IID_DMScreenInfo =
- { 0x223de666, 0xe7d7, 0x11d2, { 0x85, 0x72, 0, 0, 0x1a, 0x1, 0x69, 0xac } };
- const IID BASED_CODE IID_DMScreenInfoEvents =
- { 0x223de667, 0xe7d7, 0x11d2, { 0x85, 0x72, 0, 0, 0x1a, 0x1, 0x69, 0xac } };
- /////////////////////////////////////////////////////////////////////////////
- // Control type information
- static const DWORD BASED_CODE _dwMScreenInfoOleMisc =
- OLEMISC_INVISIBLEATRUNTIME |
- OLEMISC_ACTIVATEWHENVISIBLE |
- OLEMISC_SETCLIENTSITEFIRST |
- OLEMISC_INSIDEOUT |
- OLEMISC_CANTLINKINSIDE |
- OLEMISC_RECOMPOSEONRESIZE;
- IMPLEMENT_OLECTLTYPE(CMScreenInfoCtrl, IDS_MSCREENINFO, _dwMScreenInfoOleMisc)
- /////////////////////////////////////////////////////////////////////////////
- // CMScreenInfoCtrl::CMScreenInfoCtrlFactory::UpdateRegistry -
- // Adds or removes system registry entries for CMScreenInfoCtrl
- BOOL CMScreenInfoCtrl::CMScreenInfoCtrlFactory::UpdateRegistry(BOOL bRegister)
- {
- // TODO: Verify that your control follows apartment-model threading rules.
- // Refer to MFC TechNote 64 for more information.
- // If your control does not conform to the apartment-model rules, then
- // you must modify the code below, changing the 6th parameter from
- // afxRegInsertable | afxRegApartmentThreading to afxRegInsertable.
- if (bRegister)
- return AfxOleRegisterControlClass(
- AfxGetInstanceHandle(),
- m_clsid,
- m_lpszProgID,
- IDS_MSCREENINFO,
- IDB_MSCREENINFO,
- afxRegInsertable | afxRegApartmentThreading,
- _dwMScreenInfoOleMisc,
- _tlid,
- _wVerMajor,
- _wVerMinor);
- else
- return AfxOleUnregisterClass(m_clsid, m_lpszProgID);
- }
- /////////////////////////////////////////////////////////////////////////////
- // CMScreenInfoCtrl::CMScreenInfoCtrl - Constructor
- CMScreenInfoCtrl::CMScreenInfoCtrl()
- {
- InitializeIIDs(&IID_DMScreenInfo, &IID_DMScreenInfoEvents);
- // TODO: Initialize your control's instance data here.
- // Find out the Moniter number
- int i;
- BOOL flag;
- DISPLAY_DEVICE dd;
- i = 0;
- flag = true;
- ZeroMemory(&dd, sizeof(dd));
- dd.cb = sizeof(dd);
- do
- {
- flag = EnumDisplayDevices(NULL, i, &dd, 0);
- if (flag) i += 1;
- } while (flag);
- m_monitorNum = i;
- }
- /////////////////////////////////////////////////////////////////////////////
- // CMScreenInfoCtrl::~CMScreenInfoCtrl - Destructor
- CMScreenInfoCtrl::~CMScreenInfoCtrl()
- {
- // TODO: Cleanup your control's instance data here.
- }
- /////////////////////////////////////////////////////////////////////////////
- // CMScreenInfoCtrl::OnDraw - Drawing function
- void CMScreenInfoCtrl::OnDraw(
- CDC* pdc, const CRect& rcBounds, const CRect& rcInvalid)
- {
- // TODO: Replace the following code with your own drawing code.
- pdc->FillRect(rcBounds, CBrush::FromHandle((HBRUSH)GetStockObject(WHITE_BRUSH)));
- pdc->Ellipse(rcBounds);
- }
- /////////////////////////////////////////////////////////////////////////////
- // CMScreenInfoCtrl::DoPropExchange - Persistence support
- void CMScreenInfoCtrl::DoPropExchange(CPropExchange* pPX)
- {
- ExchangeVersion(pPX, MAKELONG(_wVerMinor, _wVerMajor));
- COleControl::DoPropExchange(pPX);
- // TODO: Call PX_ functions for each persistent custom property.
- }
- /////////////////////////////////////////////////////////////////////////////
- // CMScreenInfoCtrl::OnResetState - Reset control to default state
- void CMScreenInfoCtrl::OnResetState()
- {
- COleControl::OnResetState(); // Resets defaults found in DoPropExchange
- // TODO: Reset any other control state here.
- }
- /////////////////////////////////////////////////////////////////////////////
- // CMScreenInfoCtrl message handlers
- void CMScreenInfoCtrl::OnMonitorNumChanged()
- {
- // TODO: Add notification handler code
- SetModifiedFlag();
- }
- short CMScreenInfoCtrl::GetScreenWidth(short ScreenNo)
- {
- // TODO: Add your property handler here
- // Make sure the ScreenNo is validable
- if (ScreenNo < 0 || ScreenNo >= m_monitorNum) return 0;
- // Get the Display device name
- BOOL flag;
- DISPLAY_DEVICE dd;
- ZeroMemory(&dd, sizeof(dd));
- dd.cb = sizeof(dd);
- flag = EnumDisplayDevices(NULL, ScreenNo, &dd, 0);
- // Make sure it's successful
- if (!flag) return 0;
- // Get the Display setting
- DEVMODE dm;
- ZeroMemory(&dm, sizeof(dm));
- dm.dmSize = sizeof(dm);
- flag = EnumDisplaySettings((char*)dd.DeviceName,ENUM_CURRENT_SETTINGS, &dm);
- // Make sure it's successful
- if (!flag) return 0;
- return (short) dm.dmPelsWidth;
- }
- void CMScreenInfoCtrl::SetScreenWidth(short ScreenNo, short nNewValue)
- {
- // TODO: Add your property handler here
- SetModifiedFlag();
- }
- short CMScreenInfoCtrl::GetScreenHeight(short ScreenNo)
- {
- // TODO: Add your property handler here
- // Make sure the ScreenNo is validable
- if (ScreenNo < 0 || ScreenNo >= m_monitorNum) return 0;
- // Get the Display device name
- BOOL flag;
- DISPLAY_DEVICE dd;
- ZeroMemory(&dd, sizeof(dd));
- dd.cb = sizeof(dd);
- flag = EnumDisplayDevices(NULL, ScreenNo, &dd, 0);
- // Make sure it's successful
- if (!flag) return 0;
- // Get the Display setting
- DEVMODE dm;
- ZeroMemory(&dm, sizeof(dm));
- dm.dmSize = sizeof(dm);
- flag = EnumDisplaySettings((char*)dd.DeviceName,ENUM_CURRENT_SETTINGS, &dm);
- // Make sure it's successful
- if (!flag) return 0;
- return (short) dm.dmPelsHeight;
- }
- void CMScreenInfoCtrl::SetScreenHeight(short ScreenNo, short nNewValue)
- {
- // TODO: Add your property handler here
- SetModifiedFlag();
- }
- short CMScreenInfoCtrl::GetScreenTop(short ScreenNo)
- {
- // TODO: Add your property handler here
- if (ScreenNo < 0 || ScreenNo >= m_monitorNum) return -1;
- // Get the Display device name
- BOOL flag;
- DISPLAY_DEVICE dd;
- ZeroMemory(&dd, sizeof(dd));
- dd.cb = sizeof(dd);
- flag = EnumDisplayDevices(NULL, ScreenNo, &dd, 0);
- // Make sure it's successful
- if (!flag) return -1;
- // Get the Display setting
- DEVMODE dm;
- ZeroMemory(&dm, sizeof(dm));
- dm.dmSize = sizeof(dm);
- flag = EnumDisplaySettings((char*)dd.DeviceName,ENUM_CURRENT_SETTINGS, &dm);
- // Make sure it's successful
- if (!flag) return -1;
- return (short) dm.dmPosition.y ;
- }
- void CMScreenInfoCtrl::SetScreenTop(short ScreenNo, short nNewValue)
- {
- // TODO: Add your property handler here
- SetModifiedFlag();
- }
- short CMScreenInfoCtrl::GetScreenLeft(short ScreenNo)
- {
- // TODO: Add your property handler here
- if (ScreenNo < 0 || ScreenNo >= m_monitorNum) return -1;
- // Get the Display device name
- BOOL flag;
- DISPLAY_DEVICE dd;
- ZeroMemory(&dd, sizeof(dd));
- dd.cb = sizeof(dd);
- flag = EnumDisplayDevices(NULL, ScreenNo, &dd, 0);
- // Make sure it's successful
- if (!flag) return -1;
- // Get the Display setting
- DEVMODE dm;
- ZeroMemory(&dm, sizeof(dm));
- dm.dmSize = sizeof(dm);
- flag = EnumDisplaySettings((char*)dd.DeviceName,ENUM_CURRENT_SETTINGS, &dm);
- // Make sure it's successful
- if (!flag) return -1;
- return (short) dm.dmPosition.x ;
- }
- void CMScreenInfoCtrl::SetScreenLeft(short ScreenNo, short nNewValue)
- {
- // TODO: Add your property handler here
- SetModifiedFlag();
- }
- short CMScreenInfoCtrl::GetPrimaryScreen()
- {
- // TODO: Add your property handler here
- if (m_monitorNum <= 1) return 0;
- // if the Screen Top = 0 and Left = 0, then, it's the Primary Screen
- short i;
- for (i=0; i<m_monitorNum; i++)
- {
- if (GetScreenTop(i)==0 && GetScreenLeft(i)==0) return i;
- }
- return 0;
- }
- void CMScreenInfoCtrl::SetPrimaryScreen(short nNewValue)
- {
- // TODO: Add your property handler here
- SetModifiedFlag();
- }