Solution46
CMonitor.cpp
[詳解]
1 //=============================================================================
2 /// @file
3 /// モニタクラス実装ファイル
4 ///
5 /// モニタクラス実装ファイルです。
6 ///
7 /// $Id: CMonitor.cpp 245 2019-03-20 15:03:41Z admin $
8 /// $Date: 2019-03-21 00:03:41 +0900 (2019/03/21 (木)) $
9 /// $Author: admin $
10 ///
11 /// @attention なし
12 
13 #pragma managed( push, off )
14 
15 //=============================================================================
16 // インクルードファイル
17 #include <CMonitor.h>
18 #include <LibUtility.h>
19 
20 //=============================================================================
21 // 共通ライブラリ名前空間
22 namespace LibCommon {
23  //=========================================================================
24  // モニタクラス
25  //=========================================================================
26  // 構築子と解体子
27  //-------------------------------------------------------------------------
28  // コンストラクタ
29  CMonitor::CMonitor() noexcept
30  // メンバ変数初期化
31  : m_nCount( 0 )
32  , m_hMonitor()
33  {
34  // コンストラクタ実行通知
36 
37  // 処理ブロック
38  do {
39  // モニタハンドルリストを取得する
40  ::EnumDisplayMonitors( nullptr, nullptr, MonitorEnumProc, reinterpret_cast< LPARAM >( this ) );
41  } while ( false );
42  }
43 
44  //-------------------------------------------------------------------------
45  // デストラクタ
46  CMonitor::~CMonitor() noexcept {
47  // デストラクタ実行通知
49  }
50 
51  //=========================================================================
52  // 公開関数
53  //-------------------------------------------------------------------------
54  // モニタサイズ取得関数
55  bool CMonitor::GetSize( int nIndex, int& nWidth, int& nHeight ) const noexcept {
56  // 処理ブロック
57  bool result = false;
58  do {
59  // インデックスを調べる
60  if ( m_nCount <= nIndex ) {
61  // 失敗!
62  break;
63  }
64 
65  // モニタ情報を取得する
66  MONITORINFO sMonitorInfo = { sizeof( MONITORINFO ) };
67  if ( 0 == ::GetMonitorInfoW( m_hMonitor[ nIndex ], &sMonitorInfo ) ) {
68  // 失敗!
69  break;
70  }
71 
72  // モニタサイズを取得する
73  nWidth = ( sMonitorInfo.rcMonitor.right - sMonitorInfo.rcMonitor.left );
74  nHeight = ( sMonitorInfo.rcMonitor.bottom - sMonitorInfo.rcMonitor.top );
75 
76  // 成功!
77  result = true;
78  } while ( false );
79 
80  // 実行結果を返す
81  return result;
82  }
83 
84  //-------------------------------------------------------------------------
85  // モニタ作業領域サイズ取得関数
86  bool CMonitor::GetWorkSize( int nIndex, int& nWidth, int& nHeight ) const noexcept {
87  // 処理ブロック
88  bool result = false;
89  do {
90  // インデックスを調べる
91  if ( m_nCount <= nIndex ) {
92  // 失敗!
93  break;
94  }
95 
96  // モニタ情報を取得する
97  MONITORINFO sMonitorInfo = { sizeof( MONITORINFO ) };
98  if ( 0 == ::GetMonitorInfoW( m_hMonitor[ nIndex ], &sMonitorInfo ) ) {
99  // 失敗!
100  break;
101  }
102 
103  // 作業領域サイズを取得する
104  nWidth = ( sMonitorInfo.rcWork.right - sMonitorInfo.rcWork.left );
105  nHeight = ( sMonitorInfo.rcWork.bottom - sMonitorInfo.rcWork.top );
106 
107  // 成功!
108  result = true;
109  } while ( false );
110 
111  // 実行結果を返す
112  return result;
113  }
114 
115  //=========================================================================
116  // 静的限定公開関数
117  //-------------------------------------------------------------------------
118  // モニタ列挙コールバック関数
119  BOOL CMonitor::MonitorEnumProc( HMONITOR hMonitor, HDC hdcMonitor, LPRECT lprcMonitor, LPARAM dwData ) noexcept {
120  // 処理ブロック
121  BOOL result = FALSE;
122  do {
123  // インスタンスポインタを取得する
124  CMonitor*& rpcInstance = reinterpret_cast< CMonitor*& >( dwData );
125  if ( nullptr == rpcInstance ) {
126  // 失敗!
127  break;
128  }
129  // モニタカウントを調べる
130  else if ( MONITOR_MAX <= rpcInstance->m_nCount ) {
131  // 失敗!
132  break;
133  }
134 
135  // モニタハンドルを追加する
136  rpcInstance->m_hMonitor[ rpcInstance->m_nCount++ ] = hMonitor;
137 
138  // 成功!
139  result = TRUE;
140  } while ( false );
141 
142  // 実行結果を返す
143  return result;
144  }
145 }
146 
147 #pragma managed( pop )
#define NotifyConstructor()
コンストラクタ実行通知マクロ
Definition: LibUtility.h:24
virtual bool GetWorkSize(int nIndex, int &nWidth, int &nHeight) const noexcept
モニタ作業領域サイズ取得関数
Definition: CMonitor.cpp:86
#define NotifyDestructor()
デストラクタ実行通知マクロ
Definition: LibUtility.h:25
CMonitor() noexcept
コンストラクタ
Definition: CMonitor.cpp:29
モニタクラスヘッダファイル
共通ライブラリ名前空間
Definition: CArray.h:23
モニタクラス
Definition: CMonitor.h:37
static BOOL CALLBACK MonitorEnumProc(HMONITOR hMonitor, HDC hdcMonitor, LPRECT lprcMonitor, LPARAM dwData) noexcept
モニタ列挙コールバック関数
Definition: CMonitor.cpp:119
virtual ~CMonitor() noexcept
デストラクタ
Definition: CMonitor.cpp:46
virtual bool GetSize(int nIndex, int &nWidth, int &nHeight) const noexcept
モニタサイズ取得関数
Definition: CMonitor.cpp:55
HMONITOR m_hMonitor[MONITOR_MAX]
モニタハンドル配列
Definition: CMonitor.h:138
ユーティリティライブラリヘッダファイル
int m_nCount
モニタカウント
Definition: CMonitor.h:137