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
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
| #define _CRT_SECURE_NO_WARNINGS
#define _UNICODE
#define UNICODE
#include <windows.h>
#include <windowsx.h>
#include <uxtheme.h>
#include <tchar.h>
//#include <stdlib.h>
#include <commctrl.h>
#include "global.h"
#include "resource.h"
#include "listview.h"
#include "statusBar.h"
#include "workFromDir.h"
#pragma comment(lib, "comctl32.lib")
#pragma comment(lib, "UxTheme.lib")
HWND hWndToolbar;
HWND hButton;
HWND CreateSimpleToolbar(HWND hWndParent);
HINSTANCE hInstance;
LPCWSTR szClassName = _TEXT("Window"); // имя класса главного окна.
LPCWSTR szWindowName = _TEXT("Файловый Менеджер."); // Название приложения.
LRESULT CALLBACK WndProc(HWND hWnd, UINT Message, WPARAM wParam, LPARAM lParam);
int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpszCmdParam, int nCmdShow)
{
WNDCLASSEXW wcex;
HWND hWnd;
MSG Message;
memset(&wcex,0,sizeof(wcex));
wcex.cbSize = sizeof(WNDCLASSEXW);
wcex.style = CS_HREDRAW|CS_VREDRAW;
wcex.lpfnWndProc = WndProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = hInstance;
wcex.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH);
wcex.lpszMenuName = MAKEINTRESOURCE(IDC_WINAPI64);
wcex.lpszClassName = szClassName;
wcex.hIconSm = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_FILEMENEDGER));
if(!RegisterClassEx(&wcex))
{
MessageBox(NULL, _TEXT("Window Registration Failed!"), _TEXT("Error!"), MB_ICONEXCLAMATION|MB_OK);
return 0;
}
hWnd = CreateWindowEx(0L, szClassName, szWindowName,
WS_OVERLAPPEDWINDOW, CW_USEDEFAULT,
CW_USEDEFAULT, 699,
600, NULL, NULL,
hInstance, NULL);
if(hWnd == NULL)
{
MessageBox(NULL, _TEXT("Window Creation Failed!"), _TEXT("Error"), MB_OK);
return 0;
}
//SetWindowTheme(hWnd, L" ", L" ");
ShowWindow(hWnd, nCmdShow);
UpdateWindow(hWnd);
while(GetMessageW(&Message, NULL, 0, 0))
{
TranslateMessage(&Message);
DispatchMessageW(&Message);
}
return Message.wParam;
}
LRESULT CALLBACK WndProc(HWND hWnd, UINT Message, WPARAM wParam, LPARAM lParam)
{
RECT rcl;
int cParts = 2;
switch(Message)
{
case WM_CREATE:
{
CreateSimpleToolbar(hWnd);
// Здесь!
hButton = CreateWindowEx(0L,
L"BUTTON",
L"c:\\",
BS_PUSHBUTTON | WS_VISIBLE | WS_CHILD | WS_TABSTOP,
570,
10,
25,
25,
hWnd,
(HMENU)ID_BUTTON_DISC,
hInstance,
NULL);
if(hButton == NULL)
{
MessageBox(NULL, _TEXT("hButton failed!"), _TEXT("Error"), MB_OK);
return 0;
}
CreateListView(hWnd, hInstance);
workFromDir::setStartDir();
workFromDir::readDirectoryInfilesArray();
InitListViewColumns(hWndListView);
//InitListViewImageLists(hWndListView, workFromDir::pathDirectory);
InsertListViewItems(hWndListView, /*hInstance,*/ workFromDir::g_dirfilesVec.size());
statusBar::CreateStatusBar(hWnd, hInstance, cParts);
//SetWindowTheme(statusBar::hWndSb, L" ", L" ");
statusBar::writeSb(workFromDir::pathDirectory);
}
break;
case WM_NOTIFY:
NotifyHandlerToolbar(hWndToolbar, wParam, lParam);
NotifyHandler(hWndListView, /*Message,*/ wParam, lParam);
break;
case WM_COMMAND:
switch(wParam)
{
case ID_BUTTON_DISC:
SetWindowText(hButton, _TEXT("ok"));
return 0;
}
case WM_SIZE:
MoveWindow(hWndToolbar, 0, 0, LOWORD(lParam), HIWORD(lParam), TRUE);
MoveWindow(hWndListView, 0, 44, LOWORD(lParam), HIWORD(lParam) - 66, TRUE);
statusBar::sizeSb(hWnd, cParts, lParam);
break;
case WM_CLOSE:
{
DestroyWindow(hWnd);
//DestroyWindow(hWndListView);
}
break;
case WM_DESTROY:
{
PostQuitMessage(0);
return 0;
}
default:
return DefWindowProc(hWnd, Message, wParam, lParam);
}
return 0;
}
HWND CreateSimpleToolbar(HWND hWndParent)
{
HIMAGELIST g_hImageList = NULL;
// Declare and initialize local constants.
const int ImageListID = 0;
const int numButtons = 12;
const int bitmapSize = 16;
const DWORD buttonStyles = BTNS_AUTOSIZE;
// Create the toolbar.
hWndToolbar = CreateWindowEx(0, TOOLBARCLASSNAME, NULL,
WS_CHILD | CCS_NOPARENTALIGN | /*TBSTYLE_WRAPABLE |*/ TBSTYLE_FLAT, 0, 0, 0, 0,
hWndParent, NULL, hInstance, NULL);
if (hWndToolbar == NULL)
return NULL;
// Create the image list.
g_hImageList = ImageList_Create(bitmapSize, bitmapSize, // Dimensions of individual bitmaps.
ILC_COLOR24 | ILC_MASK, // Ensures transparent background.
numButtons, 0);
HBITMAP hBmp = (HBITMAP)LoadImage(::GetModuleHandle(NULL), MAKEINTRESOURCE(IDB_TOOLBAR), IMAGE_BITMAP, 144, 16, NULL/*LR_CREATEDIBSECTION*/ /*LR_DEFAULTCOLOR*/);
int index = ImageList_AddMasked(g_hImageList, hBmp, /*NULL*/CLR_DEFAULT/*RGB(256, 256, 256)*/);
//int index = ImageList_Add(g_hImageList, hBmp, NULL);
if(index == -1)
MessageBox(NULL, _TEXT("NO Add"), _TEXT("Error"), MB_OK | MB_ICONERROR);
DeleteObject(hBmp);
// Set the image list.
SendMessage(hWndToolbar, TB_SETIMAGELIST /*| TBSTYLE_EX_DOUBLEBUFFER*/,
(WPARAM)ImageListID,
(LPARAM)g_hImageList);
TBBUTTON tbButtons[numButtons] =
{
{ 0, IDM_FORWARD, TBSTATE_ENABLED, buttonStyles, {0}, 0, (INT_PTR)_TEXT(" Назад")},
{ 1, IDM_BACK, TBSTATE_ENABLED, buttonStyles, {0}, 0, (INT_PTR)_TEXT("Вперед")},
{ 2, IDM_UPDATE, TBSTATE_ENABLED, buttonStyles, {0}, 0, (INT_PTR)_TEXT("Обновить")},
{ 3, IDM_CLEAR, TBSTATE_ENABLED, buttonStyles, {0}, 0, (INT_PTR)_TEXT("Очистить")},
{ 4, IDM_SEARCH, TBSTATE_ENABLED, buttonStyles, {0}, 0, (INT_PTR)_TEXT("Найти")},
{ 0, 0, TBSTATE_ENABLED, TBSTYLE_SEP, 0, 0 },
{ 5, IDM_HIDE, TBSTATE_ENABLED, buttonStyles, {0}, 0, (INT_PTR)_TEXT("Скрыть")},
{ 0, 0, TBSTATE_ENABLED, TBSTYLE_SEP, 0, 0},
{ 6, IDM_FORMATDISC, TBSTATE_ENABLED, buttonStyles, {0}, 0, (INT_PTR)_TEXT("Формат диск")},
{ 7, IDM_EXTRACTUSB, TBSTATE_ENABLED, buttonStyles, {0}, 0, (INT_PTR)_TEXT("Извлечь USB")},
{ 0, 0, TBSTATE_ENABLED, TBSTYLE_SEP, 0, 0},
{ 8, IDM_HELP, TBSTATE_ENABLED, buttonStyles, {0}, 0, (INT_PTR)_TEXT("Помощь")},
};
// Add buttons.
SendMessage(hWndToolbar, TB_BUTTONSTRUCTSIZE, (WPARAM)sizeof(TBBUTTON), 0);
SendMessage(hWndToolbar, TB_ADDBUTTONS, (WPARAM)numButtons, (LPARAM)&tbButtons);
// Resize the toolbar, and then show it.
SendMessage(hWndToolbar, TB_AUTOSIZE, 0, 0);
ShowWindow(hWndToolbar, TRUE);
return hWndToolbar;
}
LRESULT NotifyHandlerToolbar(HWND hWnd, WPARAM wParam, LPARAM lParam)
{
LPNMHDR lpnmhdr = (LPNMHDR)lParam;
LPNMMOUSE lpnmm = (LPNMMOUSE)lParam;
if(lpnmhdr->hwndFrom == hWndToolbar)
{
switch(lpnmhdr->code)
{
case NM_CLICK:
switch(lpnmm->dwItemSpec)
{
case IDM_FORWARD:
{
break;
}
case IDM_BACK:
{
break;
}
case IDM_UPDATE:
{
break;
}
case IDM_CLEAR:
{
break;
}
case IDM_SEARCH:
{
MessageBox(NULL, _TEXT("Имя файла:"), _TEXT("Поиск."), MB_OK | MB_ICONINFORMATION);
break;
}
case IDM_HIDE:
{
break;
}
case IDM_FORMATDISC:
{
break;
}
case IDM_EXTRACTUSB:
{
break;
}
case IDM_HELP:
{
MessageBox(NULL, _TEXT("(с), все права защищены."), _TEXT("Помощь."), MB_OK | MB_ICONINFORMATION | MB_HELP);
break;
}
default:
break;
}
default:
break;
}
}
return 0L;
} |