-
Notifications
You must be signed in to change notification settings - Fork 77
/
DlgSimple.cpp
168 lines (139 loc) · 5.85 KB
/
DlgSimple.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
/*****************************************************************************/
/* DlgSimple.cpp Copyright (c) Ladislav Zezula 2014 */
/*---------------------------------------------------------------------------*/
/* Description: Common module for a few simple dialogs */
/*---------------------------------------------------------------------------*/
/* Date Ver Who Comment */
/* -------- ---- --- ------- */
/* 18.03.14 1.00 Lad Created */
/*****************************************************************************/
#include "FileTest.h"
#include "resource.h"
//-----------------------------------------------------------------------------
// Local functions
static void SetWindowTextModuleVersion(HWND hWndChild, HMODULE hMod)
{
ULARGE_INTEGER Version;
TCHAR szModName[MAX_PATH + 1];
TCHAR szFormat[255];
TCHAR szText[255];
if(GetModuleFileName(hMod, szModName, MAX_PATH))
{
// Is such window really there ?
if(hWndChild != NULL)
{
GetWindowText(hWndChild, szFormat, _countof(szFormat));
GetModuleVersion(szModName, &Version);
StringCchPrintf(szText, _countof(szText), szFormat,
HIWORD(Version.HighPart),
LOWORD(Version.HighPart),
HIWORD(Version.LowPart),
LOWORD(Version.LowPart));
SetWindowText(hWndChild, szText);
}
}
}
static void SetWindowTextFileTime(HWND hWndChild, LARGE_INTEGER & FileTime)
{
TCHAR szText[0x80];
if(FileTimeToText(szText, &szText[_countof(szText) - 1], (PFILETIME)(&FileTime), FALSE))
{
SetWindowText(hWndChild, szText);
}
}
static void SetWindowTextFileAttributes(HWND hWndChild, DWORD dwAttributes)
{
TFlagString fs(FileAttributesValues, dwAttributes, GetNewLineSeparator());
SetWindowText(hWndChild, fs);
}
//-----------------------------------------------------------------------------
// Event handlers
static int OnInitDialog(HWND hDlg, LPARAM lParam)
{
PFILE_BASIC_INFORMATION pBasicInfo = (PFILE_BASIC_INFORMATION)lParam;
HWND hWndChild;
// Set the dialog icon
SetDialogIcon(hDlg, IDI_FILE_TEST);
// Parse all child windows
// If there is IDC_VERSION static text, supply the 4-digit version from resources
hWndChild = GetDlgItem(hDlg, IDC_FILETEST_WEB);
if(hWndChild != NULL)
InitURLButton(hDlg, IDC_FILETEST_WEB, FALSE);
// If there is IDC_VERSION static text, supply the 4-digit version from resources
hWndChild = GetDlgItem(hDlg, IDC_VERSION);
if(hWndChild != NULL)
SetWindowTextModuleVersion(hWndChild, NULL);
// Last write time
if(pBasicInfo != NULL)
{
if((hWndChild = GetDlgItem(hDlg, IDC_CREATION_TIME)) != NULL)
SetWindowTextFileTime(hWndChild, pBasicInfo->CreationTime);
if((hWndChild = GetDlgItem(hDlg, IDC_LAST_ACCESS_TIME)) != NULL)
SetWindowTextFileTime(hWndChild, pBasicInfo->LastAccessTime);
if((hWndChild = GetDlgItem(hDlg, IDC_LAST_WRITE_TIME)) != NULL)
SetWindowTextFileTime(hWndChild, pBasicInfo->LastWriteTime);
if((hWndChild = GetDlgItem(hDlg, IDC_CHANGE_TIME)) != NULL)
SetWindowTextFileTime(hWndChild, pBasicInfo->ChangeTime);
if((hWndChild = GetDlgItem(hDlg, IDC_FILE_ATTRIBUTES)) != NULL)
SetWindowTextFileAttributes(hWndChild, pBasicInfo->FileAttributes);
}
return TRUE;
}
static BOOL OnCommand(HWND hDlg, HWND hWndFrom, UINT nNotifyCode, UINT nCtrlID)
{
if(nNotifyCode == BN_CLICKED)
{
// An URL button leads to opening its WWW page
if(IsURLButton(hWndFrom))
{
ClickURLButton(hWndFrom);
return TRUE;
}
// Any other button closes the dialog
EndDialog(hDlg, nCtrlID);
return TRUE;
}
return FALSE;
}
//-----------------------------------------------------------------------------
// Message handler
static INT_PTR CALLBACK DialogProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch(uMsg)
{
case WM_INITDIALOG:
return OnInitDialog(hDlg, lParam);
case WM_DRAWITEM:
DrawURLButton(hDlg, (LPDRAWITEMSTRUCT)lParam);
return FALSE;
case WM_COMMAND:
return OnCommand(hDlg, (HWND)lParam, HIWORD(wParam), LOWORD(wParam));
}
return FALSE;
}
//-----------------------------------------------------------------------------
// Dialog functions
INT_PTR HelpAboutDialog(HWND hWndParent)
{
return DialogBox(g_hInst, MAKEINTRESOURCE(IDD_HELP_ABOUT), hWndParent, DialogProc);
}
INT_PTR HelpCommandLineDialog(HWND hWndParent)
{
return DialogBox(g_hInst, MAKEINTRESOURCE(IDD_HELP_COMMAND_LINE), hWndParent, DialogProc);
}
INT_PTR ObjectIDActionDialog(HWND hWndParent)
{
return DialogBox(g_hInst, MAKEINTRESOURCE(IDD_OBJECT_ID_MORE), hWndParent, DialogProc);
}
INT_PTR ObjectGuidHelpDialog(HWND hWndParent)
{
return DialogBox(g_hInst, MAKEINTRESOURCE(IDD_OBJECT_GUID_HELP), hWndParent, DialogProc);
}
INT_PTR FileAttributesDialog(HWND hWndParent, PFILE_BASIC_INFORMATION pBasicInfo)
{
return DialogBoxParam(g_hInst, MAKEINTRESOURCE(IDD_FILE_ATTRIBUTES), hWndParent, DialogProc, (LPARAM)(pBasicInfo));
}
INT_PTR NtAttributesDialog(HWND hWndParent, PFILE_BASIC_INFORMATION pBasicInfo)
{
return DialogBoxParam(g_hInst, MAKEINTRESOURCE(IDD_NT_ATTRIBUTES), hWndParent, DialogProc, (LPARAM)(pBasicInfo));
}