forked from ladislav-zezula/FileTest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Page00Transaction.cpp
208 lines (175 loc) · 7.33 KB
/
Page00Transaction.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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
/*****************************************************************************/
/* Page00Transaction.cpp Copyright (c) Ladislav Zezula 2006 */
/*---------------------------------------------------------------------------*/
/* Description: */
/*---------------------------------------------------------------------------*/
/* Date Ver Who Comment */
/* -------- ---- --- ------- */
/* 02.05.06 1.00 Lad The first version of Page00Transaction.cpp */
/*****************************************************************************/
#include "FileTest.h"
#include "resource.h"
static void UpdateDialog(HWND hDlg, DWORD dwErrCode)
{
TFileTestData * pData = GetDialogData(hDlg);
BOOL bEnable;
if(pfnCreateTransaction != NULL)
{
// CreateTransaction is allowed when no transaction is created
bEnable = (BOOL)(IsHandleInvalid(pData->hTransaction));
EnableDlgItems(hDlg, bEnable, IDC_CREATE_TRANSACTION, IDC_CREATE_TRANSACTION_HINT, 0);
// CommitTransaction and RollbackTransaction are allowed when a transaction is assigned
bEnable = (BOOL)(IsHandleValid(pData->hTransaction));
EnableDlgItems(hDlg, bEnable, IDC_COMMIT_TRANSACTION, IDC_COMMIT_TRANSACTION_HINT,
IDC_ROLLBACK_TRANSACTION, IDC_ROLLBACK_TRANSACTION_HINT,
0);
SetResultInfo(hDlg, RSI_LAST_ERROR | RSI_HANDLE, dwErrCode, pData->hTransaction);
}
else
{
EnableDlgItems(hDlg, FALSE, IDC_CREATE_TRANSACTION, IDC_CREATE_TRANSACTION_HINT,
IDC_COMMIT_TRANSACTION, IDC_COMMIT_TRANSACTION_HINT,
IDC_ROLLBACK_TRANSACTION, IDC_ROLLBACK_TRANSACTION_HINT,
IDC_CLOSE_HANDLE, IDC_CLOSE_HANDLE_HINT,
0);
}
}
//-----------------------------------------------------------------------------
// Message handlers
static TAnchors * pAnchors = NULL;
static int OnInitDialog(HWND hDlg, LPARAM lParam)
{
PROPSHEETPAGE * pPage = (PROPSHEETPAGE *)lParam;
TFileTestData * pData = (TFileTestData *)pPage->lParam;
// Load the transaction APIs, as they are only supported in Vista and later
SetDialogData(hDlg, pPage->lParam);
pData->hTransaction = INVALID_HANDLE_VALUE;
// Configure dialog resizing
if(pData->bEnableResizing)
{
pAnchors = new TAnchors();
pAnchors->AddAnchor(hDlg, IDC_MAIN_FRAME, akLeft | akTop | akRight);
pAnchors->AddAnchor(hDlg, IDC_CREATE_TRANSACTION, akLeft | akTop | akRight);
pAnchors->AddAnchor(hDlg, IDC_CREATE_TRANSACTION_HINT, akLeft | akTop | akRight);
pAnchors->AddAnchor(hDlg, IDC_COMMIT_TRANSACTION, akLeft | akTop | akRight);
pAnchors->AddAnchor(hDlg, IDC_COMMIT_TRANSACTION_HINT, akLeft | akTop | akRight);
pAnchors->AddAnchor(hDlg, IDC_ROLLBACK_TRANSACTION, akLeft | akTop | akRight);
pAnchors->AddAnchor(hDlg, IDC_ROLLBACK_TRANSACTION_HINT, akLeft | akTop | akRight);
pAnchors->AddAnchor(hDlg, IDC_CLOSE_HANDLE, akLeft | akTop | akRight);
pAnchors->AddAnchor(hDlg, IDC_CLOSE_HANDLE_HINT, akLeft | akTop | akRight);
pAnchors->AddAnchor(hDlg, IDC_RESULT_FRAME, akLeft | akRight | akBottom);
pAnchors->AddAnchor(hDlg, IDC_ERROR_CODE_TITLE, akLeft | akBottom);
pAnchors->AddAnchor(hDlg, IDC_ERROR_CODE, akLeft | akRight | akBottom);
pAnchors->AddAnchor(hDlg, IDC_HANDLE_TITLE, akLeft | akBottom);
pAnchors->AddAnchor(hDlg, IDC_HANDLE, akLeft | akRight | akBottom);
}
return TRUE;
}
static int OnCreateTransaction(HWND hDlg)
{
TFileTestData * pData = GetDialogData(hDlg);
int dwErrCode = ERROR_SUCCESS;
// Create new transaction
if(dwErrCode == ERROR_SUCCESS && pfnCreateTransaction != NULL)
{
pData->hTransaction = pfnCreateTransaction(NULL,
NULL,
0,
0,
0,
NULL,
_T("Transaction for FileTest"));
if(IsHandleValid(pData->hTransaction))
pData->bTransactionActive = TRUE;
else
dwErrCode = GetLastError();
}
UpdateDialog(hDlg, dwErrCode);
return TRUE;
}
static int OnCommitTransaction(HWND hDlg)
{
TFileTestData * pData = GetDialogData(hDlg);
DWORD dwErrCode = ERROR_SUCCESS;
// Commit the transaction
if(IsHandleValid(pData->hTransaction))
{
if(!pfnCommitTransaction(pData->hTransaction))
dwErrCode = GetLastError();
pData->bTransactionActive = FALSE;
pData->bUseTransaction = FALSE;
UpdateDialog(hDlg, dwErrCode);
}
return TRUE;
}
static int OnRollbackTransaction(HWND hDlg)
{
TFileTestData * pData = GetDialogData(hDlg);
DWORD dwErrCode = ERROR_SUCCESS;
// Rollback the transaction
if(IsHandleValid(pData->hTransaction))
{
if(!pfnRollbackTransaction(pData->hTransaction))
dwErrCode = GetLastError();
pData->bTransactionActive = FALSE;
pData->bUseTransaction = FALSE;
UpdateDialog(hDlg, dwErrCode);
}
return TRUE;
}
static int OnCloseTransaction(HWND hDlg)
{
TFileTestData * pData = GetDialogData(hDlg);
DWORD dwErrCode = ERROR_SUCCESS;
// Assign the transaction to the current thread
if(IsHandleValid(pData->hTransaction))
CloseHandle(pData->hTransaction);
// Clear information about transaction
pData->hTransaction = INVALID_HANDLE_VALUE;
UpdateDialog(hDlg, dwErrCode);
return TRUE;
}
static int OnCommand(HWND hDlg, UINT nNotify, UINT nIDCtrl)
{
if(nNotify == BN_CLICKED)
{
switch(nIDCtrl)
{
case IDC_CREATE_TRANSACTION:
OnCreateTransaction(hDlg);
return TRUE;
case IDC_COMMIT_TRANSACTION:
OnCommitTransaction(hDlg);
return TRUE;
case IDC_ROLLBACK_TRANSACTION:
OnRollbackTransaction(hDlg);
return TRUE;
case IDC_CLOSE_HANDLE:
OnCloseTransaction(hDlg);
return TRUE;
}
}
return FALSE;
}
//-----------------------------------------------------------------------------
// Public page callback
INT_PTR CALLBACK PageProc00(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch(uMsg)
{
case WM_INITDIALOG:
return OnInitDialog(hDlg, lParam);
case WM_SIZE:
if(pAnchors != NULL)
pAnchors->OnSize();
return FALSE;
case WM_COMMAND:
return OnCommand(hDlg, HIWORD(wParam), LOWORD(wParam));
case WM_DESTROY:
if(pAnchors != NULL)
delete pAnchors;
pAnchors = NULL;
return FALSE;
}
return FALSE;
}