-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathACDVirtualCP.cpp
executable file
·134 lines (107 loc) · 3.38 KB
/
ACDVirtualCP.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
// Copyright (C) 2005 Laurent Morichetti
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "StdAfx.h"
#include "ACDVirtualCP.h"
#include <setupapi.h>
#include <cfgmgr32.h>
CACDVirtualCP::EnumHelper::ENUMPROC_STATUS
CACDVirtualCP::EnumHelper::Callback (IN CACDVirtualCP* pVCP) {
ENUMPROC_STATUS status = CBase::Callback (&pVCP->m_Device);
if (status != ENUMPROC_STATUS_SUCCESS)
return status;
//
// Find out the HID parents's name and hardware instance id.
//
SP_DEVINFO_DATA devInfo;
devInfo.cbSize = sizeof (devInfo);
if (!SetupDiEnumDeviceInfo (m_hDevInfo, m_dwCurrentIndex, &devInfo))
return ENUMPROC_STATUS_CONTINUE;
DEVINST devInst;
CM_Get_Parent (&devInst, devInfo.DevInst, 0);
CHAR buffer[128];
_snprintf_s(buffer, sizeof(buffer), " (HID%d)", m_dwCurrentIndex);
buffer [sizeof (buffer) - 1] = '\0';
ULONG length = 0;
CM_Get_DevNode_Registry_Property (
devInst, /* devInst */
CM_DRP_DEVICEDESC, /* property */
NULL, /* registry data type */
NULL, /* buffer */
&length, /* length */
0 /* flags */
);
const char* lpcVirtualPanel = "Virtual Panel on ";
LPSTR name = (LPSTR) malloc(strlen (lpcVirtualPanel) + length + strlen(buffer));
if (!name)
return ENUMPROC_STATUS_CONTINUE;
name [0] = '\0';
strcat (name, lpcVirtualPanel);
char *start = &name [strlen (name)];
if (CM_Get_DevNode_Registry_Property (
devInst, /* devInst */
CM_DRP_DEVICEDESC, /* property */
NULL, /* registry data type */
start, /* buffer */
&length, /* length */
0 /* flags */
) != CR_SUCCESS)
return ENUMPROC_STATUS_CONTINUE;
start [length - 1] = '\0';
strcat (start, buffer);
pVCP->m_lpDeviceName = name;
if (CM_Get_Device_ID (
devInfo.DevInst, /* devInst */
buffer, /* buffer */
sizeof (buffer), /* length */
0 /* flags */
) != CR_SUCCESS)
return ENUMPROC_STATUS_CONTINUE;
pVCP->m_lpDeviceID = strdup (buffer);
pVCP->InitializeFeatures ();
m_Array.Add (pVCP);
return ENUMPROC_STATUS_SUCCESS;
}
CACDVirtualCP::~CACDVirtualCP (void)
{
delete m_lpDeviceName;
delete m_lpDeviceID;
}
BOOL
CACDVirtualCP::InitializeFeatures (void)
{
BOOL bRet = m_Device.GetBrightness (&m_bBrightness);
if (bRet)
m_bInitialBrightness = m_bBrightness;
return bRet;
}
BOOL
CACDVirtualCP::Reset (void)
{
m_bModified = FALSE;
if (!CheckBrightness ())
return InitializeFeatures ();
m_bBrightness = m_bInitialBrightness;
return m_Device.SetBrightness (m_bBrightness);
}
BOOL
CACDVirtualCP::Apply (void)
{
m_bModified = FALSE;
if (!CheckBrightness ())
return InitializeFeatures ();
m_bInitialBrightness = m_bBrightness;
return TRUE;
}