-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTab.cpp
More file actions
588 lines (427 loc) · 13.8 KB
/
Tab.cpp
File metadata and controls
588 lines (427 loc) · 13.8 KB
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
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
// Tab.cpp
#include "Tab.h"
int ShowAboutMessage( HWND hWndParent )
{
int nResult = 0;
MSGBOXPARAMS mbp;
// Clear message box parameter structure
ZeroMemory( &mbp, sizeof( mbp ) );
// Initialise message box parameter structure
mbp.cbSize = sizeof( MSGBOXPARAMS );
mbp.hwndOwner = hWndParent;
mbp.hInstance = GetModuleHandle( NULL );
mbp.lpszText = ABOUT_MESSAGE_TEXT;
mbp.lpszCaption = ABOUT_MESSAGE_CAPTION;
mbp.dwStyle = ( MB_OK | MB_USERICON );
mbp.lpszIcon = MAIN_WINDOW_CLASS_ICON_NAME;
// Show message box
nResult = MessageBoxIndirect( &mbp );
return nResult;
} // End of function ShowAboutMessage
LRESULT CALLBACK MainWindowProcedure( HWND hWndMain, UINT uMsg, WPARAM wParam, LPARAM lParam )
{
LRESULT lr = 0;
// Select message
switch( uMsg )
{
case WM_CREATE:
{
// A create message
HINSTANCE hInstance;
HFONT hFont;
// Get instance
hInstance = ( ( LPCREATESTRUCT )lParam )->hInstance;
// Get font
hFont = ( HFONT )GetStockObject( DEFAULT_GUI_FONT );
// Create tab control window
if( TabControlWindowCreate( hWndMain, hInstance ) )
{
// Successfully created tab control window
// Set tab control window font
TabControlWindowSetFont( hFont );
// Create status bar window
if( StatusBarWindowCreate( hWndMain, hInstance ) )
{
// Successfully created status bar window
// Set status bar window font
StatusBarWindowSetFont( hFont );
} // End of successfully created status bar window
} // End of successfully created tab control window
// Break out of switch
break;
} // End of a create message
case WM_SIZE:
{
// A size message
int nClientWidth;
int nClientHeight;
RECT rcStatus;
int nStatusWindowHeight;
int nTabControlWindowHeight;
// Store client width and height
nClientWidth = ( int )LOWORD( lParam );
nClientHeight = ( int )HIWORD( lParam );
// Size status bar window
StatusBarWindowSize();
// Get status window size
StatusBarWindowGetRect( &rcStatus );
// Calculate window sizes
nStatusWindowHeight = ( rcStatus.bottom - rcStatus.top );
nTabControlWindowHeight = ( nClientHeight - nStatusWindowHeight );
// Move tab control window
TabControlWindowMove( 0, 0, nClientWidth, nTabControlWindowHeight, TRUE );
// Break out of switch
break;
} // End of a size message
case WM_ACTIVATE:
{
// An activate message
// Focus on tab control window
TabControlWindowSetFocus();
// Break out of switch
break;
} // End of an activate message
case WM_GETMINMAXINFO:
{
// A get min max info message
MINMAXINFO FAR *lpMinMaxInfo;
// Get min max info structure
lpMinMaxInfo = ( MINMAXINFO FAR * )lParam;
// Update min max info structure
lpMinMaxInfo->ptMinTrackSize.x = MAIN_WINDOW_MINIMUM_WIDTH;
lpMinMaxInfo->ptMinTrackSize.y = MAIN_WINDOW_MINIMUM_HEIGHT;
// Break out of switch
break;
} // End of a get min max info message
case WM_DROPFILES:
{
// A drop files message
UINT uFileCount;
HDROP hDrop;
UINT uWhichFile;
UINT uFileSize;
// Allocate string memory
LPTSTR lpszFilePath = new char[ STRING_LENGTH ];
// Get drop handle
hDrop = ( HDROP )wParam;
// Count dropped files
uFileCount = DragQueryFile( hDrop, ( UINT )-1, NULL, 0 );
// Loop through dropped files
for( uWhichFile = 0; uWhichFile < uFileCount; uWhichFile ++ )
{
// Get size of dropped file
uFileSize = DragQueryFile( hDrop, uWhichFile, NULL, 0 );
// Ensure that file size is valid
if( uFileSize != 0 )
{
// File size is valid
// Get file path
if( DragQueryFile( hDrop, uWhichFile, lpszFilePath, ( uFileSize + sizeof( char ) ) ) )
{
// Successfully got file path
// Add file path to tab control window
//TabControlWindowAddString( lpszFilePath );
} // End of successfully got file path
} // End of file size is valid
}; // End of loop through dropped files
// Free string memory
delete [] lpszFilePath;
// Break out of switch
break;
} // End of a drop files message
case WM_COMMAND:
{
// A command message
// Select command
switch( LOWORD( wParam ) )
{
case IDM_FILE_EXIT:
{
// A file exit command
// Destroy main window
DestroyWindow( hWndMain );
// Break out of switch
break;
} // End of a file exit command
case IDM_TAB_NEW:
{
// A tab new command
HINSTANCE hInstance;
int nWhichTab;
// Get instance
hInstance = GetModuleHandle( NULL );
// Create new tab
nWhichTab = TabControlWindowAddTab( hInstance );
// Ensure that tab was created
if( nWhichTab >= 0 )
{
// Successfully created new tab
// Select new tab
TabControlWindowSelectTab( nWhichTab, &StatusBarWindowSetText );
} // End of successfully created new tab
// Break out of switch
break;
} // End of a tab new command
case IDM_TAB_REMOVE:
{
// A tab remove command
int nTabCount;
// Count tabs
nTabCount = TabControlWindowCountTabs();
// Ensure that there is at least one tab
if( nTabCount > 1 )
{
// There is at least one tab
int nSelectedTab;
// Get selected tab
nSelectedTab = TabControlWindowGetSelectedItem();
// Ensure that selected tab was got
if( nSelectedTab >= 0 )
{
// Successfully got selected tab
// Delete selected tab
if( TabControlWindowDeleteTab( nSelectedTab ) )
{
// Successfully deleted selected tab
// Select first tab
TabControlWindowSelectTab( 0, &StatusBarWindowSetText );
} // End of successfully deleted selected tab
} // End of successfully got selected tab
} // End of there is at least one tab
// Break out of switch
break;
} // End of a tab remove command
case IDM_HELP_ABOUT:
{
// A help about command
// Show about message
ShowAboutMessage( hWndMain );
// Break out of switch
break;
} // End of a help about command
default:
{
// Default command
// Call default procedure
lr = DefWindowProc( hWndMain, uMsg, wParam, lParam );
// Break out of switch
break;
} // End of default command
}; // End of selection for command
// Break out of switch
break;
} // End of a command message
case WM_SYSCOMMAND:
{
// A system command message
// Select system command
switch( LOWORD( wParam ) )
{
case IDM_HELP_ABOUT:
{
// A help about system command
// Show about message
ShowAboutMessage( hWndMain );
// Break out of switch
break;
} // End of a help about system command
default:
{
// Default system command
// Call default procedure
lr = DefWindowProc( hWndMain, uMsg, wParam, lParam );
// Break out of switch
break;
} // End of default system command
}; // End of selection for system command
// Break out of switch
break;
} // End of a system command message
case WM_NOTIFY:
{
// A notify message
LPNMHDR lpNmHdr;
// Get notify message handler
lpNmHdr = ( LPNMHDR )lParam;
// See if notify message is from tab control window
if( IsTabControlWindow( lpNmHdr->hwndFrom ) )
{
// Notify message is from tab control window
// Handle notify message from tab control window
if( !( TabControlWindowHandleNotifyMessage( wParam, lParam, &StatusBarWindowSetText ) ) )
{
// Notify message was not handled from tab control window
// Call default procedure
lr = DefWindowProc( hWndMain, uMsg, wParam, lParam );
} // End of notify message was not handled from tab control window
} // End of notify message is from tab control window
else
{
// Notify message is not from tab control window
// Call default procedure
lr = DefWindowProc( hWndMain, uMsg, wParam, lParam );
} // End of notify message is not from tab control window
// Break out of switch
break;
} // End of a notify message
case WM_CONTEXTMENU:
{
// A context menu message
HMENU hMenu;
// Load context menu
hMenu = LoadMenu( NULL, MAKEINTRESOURCE( IDR_CONTEXT_MENU ) );
// Show context menu
TrackPopupMenu( GetSubMenu( hMenu, 0 ), ( TPM_LEFTALIGN | TPM_LEFTBUTTON ), LOWORD( lParam ), HIWORD( lParam ), 0, hWndMain, NULL );
// Break out of switch
break;
} // End of a context menu message
case WM_CLOSE:
{
// A close message
// Save tabs
if( TabControlWindowSave( TABS_FILE_NAME ) )
{
// Successfully saved tabs
// Destroy main window
DestroyWindow( hWndMain );
} // End of successfully saved tabs
else
{
// Unable to save tabs
// Ensure that user is ok to close
if( MessageBox( hWndMain, TAB_CONTROL_WINDOW_UNABLE_TO_SAVE_TABS_WARNING_MESSAGE, WARNING_MESSAGE_CAPTION, ( MB_YESNO | MB_DEFBUTTON2 | MB_ICONWARNING ) ) == IDYES )
{
// User is ok to close
// Destroy main window
DestroyWindow( hWndMain );
} // End of user is ok to close
} // End of unable to save tabs
// Break out of switch
break;
} // End of a close message
case WM_DESTROY:
{
// A destroy message
// Terminate thread
PostQuitMessage( 0 );
// Break out of switch
break;
} // End of a destroy message
default:
{
// Default message
// Call default window procedure
lr = DefWindowProc( hWndMain, uMsg, wParam, lParam );
// Break out of switch
break;
} // End of default message
}; // End of selection for message
return lr;
} // End of function MainWindowProcedure
int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE, LPSTR, int nCmdShow )
{
MSG msg;
WNDCLASSEX wcMain;
// Clear message structure
ZeroMemory( &msg, sizeof( msg ) );
// Clear window class structure
ZeroMemory( &wcMain, sizeof( wcMain ) );
// Initialise window class structure
wcMain.cbSize = sizeof( WNDCLASSEX );
wcMain.lpfnWndProc = MainWindowProcedure;
wcMain.hInstance = hInstance;
wcMain.lpszClassName = MAIN_WINDOW_CLASS_NAME;
wcMain.style = MAIN_WINDOW_CLASS_STYLE;
wcMain.hIcon = MAIN_WINDOW_CLASS_ICON;
wcMain.hCursor = MAIN_WINDOW_CLASS_CURSOR;
wcMain.hbrBackground = MAIN_WINDOW_CLASS_BACKGROUND;
wcMain.lpszMenuName = MAIN_WINDOW_CLASS_MENU_NAME;
wcMain.hIconSm = MAIN_WINDOW_CLASS_ICON_SMALL;
// Register main window class
if( RegisterClassEx( &wcMain ) )
{
// Successfully registered main window class
HWND hWndMain;
// Create main window
hWndMain = CreateWindowEx( MAIN_WINDOW_EXTENDED_STYLE, MAIN_WINDOW_CLASS_NAME, MAIN_WINDOW_TEXT, MAIN_WINDOW_STYLE, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInstance, NULL );
// Ensure that main window was created
if( hWndMain )
{
// Successfully created main window
HMENU hMenuSystem;
LPWSTR *lpszArgumentList;
int nArgumentCount;
int nSelectedItem;
// Get system menu
hMenuSystem = GetSystemMenu( hWndMain, FALSE );
// Add separator item to system menu
InsertMenu( hMenuSystem, SYSTEM_MENU_SEPARATOR_ITEM_POSITION, ( MF_BYPOSITION | MF_SEPARATOR ), 0, NULL );
// Add about item to system menu
InsertMenu( hMenuSystem, SYSTEM_MENU_ABOUT_ITEM_POSITION, MF_BYPOSITION, IDM_HELP_ABOUT, SYSTEM_MENU_ABOUT_ITEM_TEXT );
// Get argument list
lpszArgumentList = CommandLineToArgvW( GetCommandLineW(), &nArgumentCount );
// Ensure that argument list was got
if( lpszArgumentList )
{
// Successfully got argument list
int nWhichArgument;
int nSizeNeeded;
int nWideArgumentLength;
// Allocate string memory
LPTSTR lpszArgument = new char[ STRING_LENGTH ];
// Loop through arguments
for( nWhichArgument = 1; nWhichArgument < nArgumentCount; nWhichArgument ++ )
{
// Get wide argument length
nWideArgumentLength = lstrlenW( lpszArgumentList[ nWhichArgument ] );
// Get size required for argument
nSizeNeeded = WideCharToMultiByte( CP_UTF8, 0, lpszArgumentList[ nWhichArgument ], nWideArgumentLength, NULL, 0, NULL, NULL );
// Convert argument to ansi
WideCharToMultiByte( CP_UTF8, 0, lpszArgumentList[ nWhichArgument ], nWideArgumentLength, lpszArgument, nSizeNeeded, NULL, NULL );
// Terminate argument
lpszArgument[ nSizeNeeded ] = ( char )NULL;
// Add argument to tab control window
//TabControlWindowAddString( lpszArgument );
}; // End of loop through arguments
// Free string memory
delete [] lpszArgument;
} // End of successfully got argument list
// Show main window
ShowWindow( hWndMain, nCmdShow );
// Update main window
UpdateWindow( hWndMain );
// Load tabs
TabControlWindowLoad( TABS_FILE_NAME, hInstance );
// Get selected item
nSelectedItem = TabControlWindowGetSelectedItem();
// Ensure that selected item was got
if( nSelectedItem >= 0 )
{
// Successfully got selected item
// Action selected item
TabControlWindowOnTabSelected( nSelectedItem, &StatusBarWindowSetText );
} // End of successfully got selected item
// Message loop
while( GetMessage( &msg, NULL, 0, 0 ) > 0 )
{
// Translate message
TranslateMessage( &msg );
// Dispatch message
DispatchMessage( &msg );
}; // End of message loop
} // End of successfully main created window
else
{
// Unable to create main window
// Display error message
MessageBox( NULL, UNABLE_TO_CREATE_MAIN_WINDOW_ERROR_MESSAGE, ERROR_MESSAGE_CAPTION, ( MB_OK | MB_ICONERROR ) );
} // End of unable to create main window
} // End of successfully registered main window class
else
{
// Unable to register main window class
// Display error message
MessageBox( NULL, UNABLE_TO_REGISTER_MAIN_WINDOW_CLASS_ERROR_MESSAGE, ERROR_MESSAGE_CAPTION, ( MB_OK | MB_ICONERROR ) );
} // End of unable to register main window class
return msg.wParam;
} // End of function WinMain