MM.cpp
上传用户:jyxwjx
上传日期:2020-03-13
资源大小:221k
文件大小:7k
源码类别:

多显示器编程

开发平台:

Visual C++

  1. // MM.cpp : 览侩 橇肺弊伐俊 措茄 努贰胶 悼累阑 沥狼钦聪促.
  2. //
  3. #include "stdafx.h"
  4. #include "MM.h"
  5. #include "MainFrm.h"
  6. #include "ChildFrm.h"
  7. #include "MMDoc.h"
  8. #include "MMView.h"
  9. #ifdef _DEBUG
  10. #define new DEBUG_NEW
  11. #endif
  12. // CMMApp
  13. BEGIN_MESSAGE_MAP(CMMApp, CWinApp)
  14. ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
  15. // 钎霖 颇老阑 扁檬肺 窍绰 巩辑 疙飞涝聪促.
  16. ON_COMMAND(ID_FILE_NEW, CWinApp::OnFileNew)
  17. ON_COMMAND(ID_FILE_OPEN, CWinApp::OnFileOpen)
  18. // 钎霖 牢尖 汲沥 疙飞涝聪促.
  19. ON_COMMAND(ID_FILE_PRINT_SETUP, CWinApp::OnFilePrintSetup)
  20. END_MESSAGE_MAP()
  21. // CMMApp 积己
  22. CMMApp::CMMApp()
  23. {
  24. // TODO: 咯扁俊 积己 内靛甫 眠啊钦聪促.
  25. // InitInstance俊 葛电 吝夸茄 檬扁拳 累诀阑 硅摹钦聪促.
  26. m_infoMonitor.nMonitor = 1;
  27. m_infoMonitor.nWidthVirtual = 1024;
  28. m_infoMonitor.nHeightVirtual = 768;
  29. m_infoMonitor.nWidth = 1024;
  30. m_infoMonitor.nHeight = 768;
  31. m_infoMonitor.nBitPerPixel= 16;
  32. m_infoMonitor.nRefresh = 60;
  33. }
  34. // 蜡老茄 CMMApp 俺眉涝聪促.
  35. CMMApp theApp;
  36. // CMMApp 檬扁拳
  37. BOOL CMMApp::InitInstance()
  38. {
  39. // 览侩 橇肺弊伐 概聪其胶飘啊 ComCtl32.dll 滚傈 6 捞惑阑 荤侩窍咯 厚林倔 胶鸥老阑
  40. // 荤侩窍档废 瘤沥窍绰 版快, Windows XP 惑俊辑 馆靛矫 InitCommonControls()啊 鞘夸钦聪促. 
  41. // InitCommonControls()甫 荤侩窍瘤 臼栏搁 芒阑 父甸 荐 绝嚼聪促.
  42. InitCommonControls();
  43. CWinApp::InitInstance();
  44. GetMonitorInformation();
  45. // OLE 扼捞宏矾府甫 檬扁拳钦聪促.
  46. if (!AfxOleInit())
  47. {
  48. AfxMessageBox(IDP_OLE_INIT_FAILED);
  49. return FALSE;
  50. }
  51. AfxEnableControlContainer();
  52. // 钎霖 檬扁拳
  53. // 捞甸 扁瓷阑 荤侩窍瘤 臼绊 弥辆 角青 颇老狼 农扁甫 临捞妨搁
  54. // 酒贰俊辑 鞘夸 绝绰 漂沥 檬扁拳 风凭阑 力芭秦具 钦聪促.
  55. // 秦寸 汲沥捞 历厘等 饭瘤胶飘府 虐甫 函版窍绞矫坷.
  56. // TODO: 捞 巩磊凯阑 雀荤 肚绰 炼流狼 捞抚苞 鞍篮
  57. // 利例茄 郴侩栏肺 荐沥秦具 钦聪促.
  58. SetRegistryKey(_T("肺拿 览侩 橇肺弊伐 付过荤俊辑 积己等 览侩 橇肺弊伐"));
  59. LoadStdProfileSettings(4);  // MRU甫 器窃窍咯 钎霖 INI 颇老 可记阑 肺靛钦聪促.
  60. // 览侩 橇肺弊伐狼 巩辑 袍敲复阑 殿废钦聪促. 巩辑 袍敲复篮
  61. // 巩辑, 橇饭烙 芒 棺 轰 荤捞狼 楷搬 开且阑 钦聪促.
  62. CMultiDocTemplate* pDocTemplate;
  63. pDocTemplate = new CMultiDocTemplate(IDR_MMTYPE,
  64. RUNTIME_CLASS(CMMDoc),
  65. RUNTIME_CLASS(CChildFrame), // 荤侩磊 瘤沥 MDI 磊侥 橇饭烙涝聪促.
  66. RUNTIME_CLASS(CMMView));
  67. AddDocTemplate(pDocTemplate);
  68. // 林 MDI 橇饭烙 芒阑 父奠聪促.
  69. CMainFrame* pMainFrame = new CMainFrame;
  70. if (!pMainFrame->LoadFrame(IDR_MAINFRAME))
  71. return FALSE;
  72. m_pMainWnd = pMainFrame;
  73. // 立固荤啊 乐阑 版快俊父 DragAcceptFiles甫 龋免钦聪促.
  74. // MDI 览侩 橇肺弊伐俊辑绰 m_pMainWnd甫 汲沥茄 饶 官肺 捞矾茄 龋免捞 惯积秦具 钦聪促.
  75. // 钎霖 夹 疙飞, DDE, 颇老 凯扁俊 措茄 疙飞临阑 备巩 盒籍钦聪促.
  76. CCommandLineInfo cmdInfo;
  77. ParseCommandLine(cmdInfo);
  78. // 疙飞临俊 瘤沥等 疙飞阑 叼胶菩摹钦聪促. 览侩 橇肺弊伐捞 /RegServer, /Register, /Unregserver 肚绰 /Unregister肺 矫累等 版快 FALSE甫 馆券钦聪促.
  79. if (!ProcessShellCommand(cmdInfo))
  80. return FALSE;
  81. // 林 芒捞 檬扁拳登菌栏骨肺 捞甫 钎矫窍绊 诀单捞飘钦聪促.
  82. pMainFrame->ShowWindow(m_nCmdShow);
  83. pMainFrame->UpdateWindow();
  84. return TRUE;
  85. }
  86. // 览侩 橇肺弊伐 沥焊俊 荤侩登绰 CAboutDlg 措拳 惑磊涝聪促.
  87. class CAboutDlg : public CDialog
  88. {
  89. public:
  90. CAboutDlg();
  91. // 措拳 惑磊 单捞磐
  92. enum { IDD = IDD_ABOUTBOX };
  93. protected:
  94. virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV 瘤盔
  95. // 备泅
  96. protected:
  97. DECLARE_MESSAGE_MAP()
  98. };
  99. CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
  100. {
  101. }
  102. void CAboutDlg::DoDataExchange(CDataExchange* pDX)
  103. {
  104. CDialog::DoDataExchange(pDX);
  105. }
  106. BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
  107. END_MESSAGE_MAP()
  108. // 措拳 惑磊甫 角青窍扁 困茄 览侩 橇肺弊伐 疙飞涝聪促.
  109. void CMMApp::OnAppAbout()
  110. {
  111. CAboutDlg aboutDlg;
  112. aboutDlg.DoModal();
  113. }
  114. // CMMApp 皋矫瘤 贸府扁
  115. BOOL CALLBACK MonitorEnumProc(HMONITOR hMonitor,HDC hdcMonitor,LPRECT lprcMonitor,LPARAM dwData)
  116. {
  117. MONITORINFOEX mi;
  118. mi.cbSize=sizeof(MONITORINFOEX);
  119. GetMonitorInfo(hMonitor,&mi);
  120. theApp.m_infoMonitor.aryMonitors.Add(mi);
  121. return TRUE;
  122. }
  123. int CMMApp::GetMonitorInformation(void)
  124. {
  125. m_infoMonitor.nMonitor = ::GetSystemMetrics(SM_CMONITORS); 
  126. XLOGOUT(">>GetMonitorInformation : SM_CMONITORS[%d]", m_infoMonitor.nMonitor);
  127. m_infoMonitor.bSameDisplayFormat = ::GetSystemMetrics(SM_SAMEDISPLAYFORMAT); 
  128. XLOGOUT(">>GetMonitorInformation : SM_SAMEDISPLAYFORMAT[%s]", (m_infoMonitor.bSameDisplayFormat)?"TRUE":"FALSE");
  129. m_infoMonitor.rcVirtual.left=GetSystemMetrics(SM_XVIRTUALSCREEN);
  130. m_infoMonitor.rcVirtual.top=GetSystemMetrics(SM_YVIRTUALSCREEN);
  131. m_infoMonitor.rcVirtual.right=m_infoMonitor.rcVirtual.left+GetSystemMetrics(SM_CXVIRTUALSCREEN);
  132. m_infoMonitor.rcVirtual.bottom=m_infoMonitor.rcVirtual.top+GetSystemMetrics(SM_CYVIRTUALSCREEN);
  133. m_infoMonitor.nWidth = ::GetSystemMetrics(SM_CXSCREEN);             // 葛聪磐狼 秦惑档 x
  134. XLOGOUT(">>GetMonitorInformation : SM_CXSCREEN[%d]", m_infoMonitor.nWidth);
  135. m_infoMonitor.nHeight = ::GetSystemMetrics(SM_CYSCREEN);             // 葛聪磐狼 秦惑档 y
  136. XLOGOUT(">>GetMonitorInformation : SM_CYSCREEN[%d]", m_infoMonitor.nHeight);
  137. m_infoMonitor.nWidthVirtual = ::GetSystemMetrics(SM_CXVIRTUALSCREEN);             // 啊惑葛聪磐狼 秦惑档 x
  138. XLOGOUT(">>GetMonitorInformation : SM_CXVIRTUALSCREEN[%d]", m_infoMonitor.nWidthVirtual);
  139. m_infoMonitor.nHeightVirtual = ::GetSystemMetrics(SM_CYVIRTUALSCREEN);             // 啊惑葛聪磐狼 秦惑档 y
  140. XLOGOUT(">>GetMonitorInformation : SM_CYVIRTUALSCREEN[%d]", m_infoMonitor.nHeightVirtual);
  141. m_infoMonitor.nMegaPixel = (m_infoMonitor.nWidth * m_infoMonitor.nHeight)/(1000*1000);
  142. m_infoMonitor.nMegaPixel = max(1,m_infoMonitor.nMegaPixel);
  143. XLOGOUT(">>GetMonitorInformation : MegaPixel[%d]", m_infoMonitor.nMegaPixel);
  144. HDC hDC=NULL;
  145. hDC = CreateDC("DISPLAY", NULL, NULL, NULL);
  146. if(hDC)
  147. {
  148. EnumDisplayMonitors(NULL,NULL,MonitorEnumProc,(LPARAM)hDC);
  149. m_infoMonitor.nBitPerPixel = GetDeviceCaps(hDC, BITSPIXEL);
  150. XLOGOUT(">>GetMonitorInformation : BITSPIXEL[%d]", m_infoMonitor.nBitPerPixel);
  151. m_infoMonitor.nRefresh = GetDeviceCaps(hDC, VREFRESH);
  152. XLOGOUT(">>GetMonitorInformation : VREFRESH[%d]", m_infoMonitor.nRefresh);
  153. DeleteDC(hDC);
  154. }
  155. else
  156. {
  157. XLOGOUT_LASTERROR;
  158. return -1;
  159. }
  160. for(int i=0;i<m_infoMonitor.aryMonitors.GetCount();i++)
  161. {
  162. XLOGOUT("MONITORS[%d]",i);
  163. XLOGOUT("rcMonitor[%d,%d,%d,%d]",((MONITORINFOEX)m_infoMonitor.aryMonitors.GetAt(i)).rcMonitor.left,
  164. ((MONITORINFOEX)m_infoMonitor.aryMonitors.GetAt(i)).rcMonitor.top,
  165. ((MONITORINFOEX)m_infoMonitor.aryMonitors.GetAt(i)).rcMonitor.right,
  166. ((MONITORINFOEX)m_infoMonitor.aryMonitors.GetAt(i)).rcMonitor.bottom);
  167. XLOGOUT("rcWork[%d,%d,%d,%d]",((MONITORINFOEX)m_infoMonitor.aryMonitors.GetAt(i)).rcWork.left,
  168. ((MONITORINFOEX)m_infoMonitor.aryMonitors.GetAt(i)).rcWork.top,
  169. ((MONITORINFOEX)m_infoMonitor.aryMonitors.GetAt(i)).rcWork.right,
  170. ((MONITORINFOEX)m_infoMonitor.aryMonitors.GetAt(i)).rcWork.bottom);
  171. XLOGOUT("dwFlags[%d]",((MONITORINFOEX)m_infoMonitor.aryMonitors.GetAt(i)).dwFlags);
  172. XLOGOUT("szDevice[%s]",((MONITORINFOEX)m_infoMonitor.aryMonitors.GetAt(i)).szDevice);
  173. }
  174. return 0;
  175. }