基于WINDOWS 32API封装的显示器类: (2) 源文件
1#include "stdafx.h"
2#include "monitor.h"
3#include <stack>
4#include <cassert>
5using namespace std;
6
7/***************************************************************************************
8 2009-12-5 当显示器不存在时,要删除窗口记录信息
9 2009-12-8 改为使用相对于父窗口的位置来恢复子窗口,这样当父窗口位置和大小变化时,
10 子窗口都能正确恢复
11****************************************************************************************/
12
13//CMonitor实现
14CMonitor::CMonitor(HMONITOR hMonitor, DWORD dwIndex):
15m_hMonitor(hMonitor),
16m_dwIndex(dwIndex)
17{
18 MONITORINFOEX mi;
19 mi.cbSize = sizeof( mi );
20 ::GetMonitorInfo( m_hMonitor, &mi );
21 m_strName = mi.szDevice;
22}
23
24//获取显示器的整个区域
25void CMonitor::GetMonitorRect(RECT& rect) const
26{
27 MONITORINFO mi;
28 RECT rc;
29 mi.cbSize = sizeof( mi );
30 ::GetMonitorInfo( m_hMonitor, &mi );
31 rc = mi.rcMonitor;
32
33 ::SetRect(&rect, rc.left, rc.top, rc.right, rc.bottom );
34}
35//获取显示器的工作区域
36void CMonitor::GetWorkAreaRect(RECT& rect) const
37{
38 MONITORINFO mi;
39 RECT rc;
40 mi.cbSize = sizeof( mi );
41 ::GetMonitorInfo( m_hMonitor, &mi );
42 rc = mi.rcWork;
43
44 ::SetRect(&rect, rc.left, rc.top, rc.right, rc.bottom );
45}
46//获取显示器的像素高度
47DWORD CMonitor::GetPixelHeight() const
48{
49 DEVMODE devmode;
50 devmode.dmSize = sizeof(DEVMODE);
51 EnumDisplaySettings(m_strName.c_str(), ENUM_CURRENT_SETTINGS, &devmode);
52 return devmode.dmPelsHeight;
53}
54//获取显示器的像素宽度
55DWORD CMonitor::GetPixelWidth() const
56{
57 DEVMODE devmode;
58 devmode.dmSize = sizeof(DEVMODE);
59 EnumDisplaySettings(m_strName.c_str(), ENUM_CURRENT_SETTINGS, &devmode);
60 return devmode.dmPelsWidth;
61}
62//获取显示器每单位像素的位数
63DWORD CMonitor::GetBitsPerPixel() const
64{
65 DEVMODE devmode;
66 devmode.dmSize = sizeof(DEVMODE);
67 EnumDisplaySettings(m_strName.c_str(), ENUM_CURRENT_SETTINGS, &devmode);
68 return devmode.dmBitsPerPel;
69}
70//获取显示器的显示频率
71DWORD CMonitor::GetDisplayFrequency() const
72{
73 DEVMODE devmode;
74 devmode.dmSize = sizeof(DEVMODE);
75 EnumDisplaySettings(m_strName.c_str(), ENUM_CURRENT_SETTINGS, &devmode);
76 return devmode.dmDisplayFrequency;
77}
78//获取显示器的左上角X位置
79DWORD
- 发表评论
-
- 最新评论 更多>>