-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
185 lines (150 loc) · 3.86 KB
/
main.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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
#include <windows.h>
#include <process.h>
#include <commctrl.h>
#include <tchar.h>
#include "RESOURCE.H"
#include "C_WIN.H"
#pragma comment(lib,"comctl32.lib")
#define TIMER_ID_DISPLAY_REQUIRE_SET 100
#define TIMER_ID_CHECK_TIME 200
class C_DLG :public CMDialog
{
public:
LRESULT CALLBACK DlgProc(HWND hwnd, UINT uMsg, WPARAM wP, LPARAM lP);
private:
BOOL mIsControl;
BOOL ChangeControlStatus();
};
BOOL C_DLG::ChangeControlStatus()
{
if (this->IsCheckedItem(IDC_CHECK_ENABLE))
{
::SetTimer(this->mHwnd, TIMER_ID_DISPLAY_REQUIRE_SET, 1000 * 30, NULL);
this->SetWindowText(L"Don't Sleep Timer (Enable)");
}
else{
::KillTimer(mHwnd, 100);
this->SetWindowText(L"Don't Sleep Timer");
}
return TRUE;
}
//---------------------------------------------------------------------
// Main Dialog
//---------------------------------------------------------------------
LRESULT CALLBACK
C_DLG::DlgProc(HWND hwnd, UINT uMsg, WPARAM wP, LPARAM lP){
switch (uMsg) {
case WM_INITDIALOG:
{
::SetTimer(mHwnd, TIMER_ID_CHECK_TIME, 500, NULL);
::InitCommonControls();
this->SetDlgItemInt(IDC_EDIT_H, 20, FALSE);
this->SetDlgItemInt(IDC_EDIT_M, 0, FALSE);
::SendMessage(
(HWND)this->GetDlgItem(IDC_SPIN_H),
(UINT)UDM_SETBUDDY,
(WPARAM)IDC_EDIT_H,
0
);
HICON hIcon = ::LoadIcon(this->GetInst(),MAKEINTRESOURCE(IDI_ICON1));
::SendMessage(mHwnd, WM_SETICON, ICON_SMALL,(LPARAM) hIcon);
}
break;
case WM_NOTIFY:
{
if (wP == (WPARAM)IDC_SPIN_H || wP == (WPARAM)IDC_SPIN_M)
{
int target;
int maxnum;
if (wP == (WPARAM)IDC_SPIN_H)
{
target = IDC_EDIT_H;
maxnum = 23;
}
if (wP == (WPARAM)IDC_SPIN_M)
{
target = IDC_EDIT_M;
maxnum = 59;
}
LPNMUPDOWN lpnmud = (LPNMUPDOWN)lP;
if (lpnmud->hdr.code == UDN_DELTAPOS)
{
TCHAR szBuf_edit1[100];
GetDlgItemText(target,
(LPTSTR)szBuf_edit1, (int)sizeof(szBuf_edit1));
int nNo = _ttoi(szBuf_edit1);
if ((lpnmud->iDelta) < 0)
{
nNo++;
if (nNo >= maxnum){
nNo = 0;
}
}
else if ((lpnmud->iDelta) > 0)
{
nNo -= 1;
if (nNo <= 0)
{
nNo = maxnum;
}
}
_stprintf_s(szBuf_edit1, 10, TEXT("%d"), nNo);
SetDlgItemText(target, (LPCTSTR)szBuf_edit1);
}
}
}
case WM_TIMER:
{
if (wP == TIMER_ID_DISPLAY_REQUIRE_SET){
::SetThreadExecutionState(ES_DISPLAY_REQUIRED);
INPUT input[1];
::ZeroMemory(input, sizeof(INPUT));
input[0].type = INPUT_MOUSE;
input[0].mi.dwFlags = MOUSEEVENTF_MOVE;
input[0].mi.dx = 0;
input[0].mi.dy = 0;
::SendInput(1, input, sizeof(INPUT));
}
else if (wP == TIMER_ID_CHECK_TIME){
if (this->IsCheckedItem(IDC_CHECK_TIMER))
{
TCHAR timeHstr[100];
TCHAR timeMstr[100];
this->GetDlgItemText(IDC_EDIT_H, timeHstr, 100);
this->GetDlgItemText(IDC_EDIT_M, timeMstr, 100);
SYSTEMTIME st;
::GetLocalTime(&st);
if (st.wHour == _ttoi(timeHstr) && st.wMinute == _ttoi(timeMstr))
{
this->SetCheckItem(IDC_CHECK_ENABLE, FALSE);
this->SetCheckItem(IDC_CHECK_TIMER, FALSE);
this->ChangeControlStatus();
}
}
}
}
break;
case WM_COMMAND:
switch (LOWORD(wP)){
case IDC_CHECK_ENABLE:
this->ChangeControlStatus();
break;
case IDOK:
break;
case IDCANCEL:
::EndDialog(hwnd, 0);
break;
}
break;
}
return 0;
};
/*//////////////////////////////////////////////////////////////////////
// WinMain()
/*//////////////////////////////////////////////////////////////////////
int WINAPI WinMain(HINSTANCE hThisInst, HINSTANCE hPrevInst,
LPSTR lpszArgs, int nWinMode){
C_DLG *c_dlg = new C_DLG;
c_dlg->OpenRes(hThisInst, IDD_DIALOG1, GetDesktopWindow());
return 0;
}