-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMySETIviewer.cpp
More file actions
751 lines (639 loc) · 28.1 KB
/
Copy pathMySETIviewer.cpp
File metadata and controls
751 lines (639 loc) · 28.1 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
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
//
// MySETIviewer, an application for viewing, overlaying and manipulating images for display
// relative to eath other for the purpose of examining images generated by MySETIapp
// MySETIviewer.cpp
// (C) 2023, Mark Stegall
// Author: Mark Stegall
//
// This file is part of MySETIviewer.
//
// MySETIviewer is free software : you can redistribute it and /or modify it under
// the terms of the GNU General Public License as published by the Free Software Foundation,
// either version 3 of the License, or (at your option) any later version.
//
// MySETIviewer is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
// without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
// See the GNU General Public License for more details.
// You should have received a copy of the GNU General Public License along with MySETIapp.
// If not, see < https://www.gnu.org/licenses/>.
//
// Background:
// From the 'A Sign in Space' website, https://asignin.space/:
// A Sign in Space is an interdisciplinary project by media artist Daniela de Paulis,
// in collaboration with the SETI Institute, the European Space Agency,
// the Green Bank Observatory and INAF, the Italian National Institute for Astrophysics.
// The project consists in transmitting a simulated extraterrestrial message as part
// of a live performance, using an ESA spacecraft as celestial source.The objective
// of the project is to involve the world - wide Search for Extraterrestrial
// Intelligence community, professionals from different fieldsand the broader public
// in the reception, decodingand interpretation of the message.This process will
// require global cooperation, bridging a conversation around the topics of SETI,
// space researchand society, across multiple culturesand fields of expertise.
// https://www.seti.org/event/sign-space
//
// The message was transmitted from the ESA's ExoMars Trace Gas Orbiter (TGO)
// on May 24 at 19:16 UTC/12:15 pm PDT.
//
// It was received by three radio telescopes on earth May 24,2023.
// A group of individuals in the Discord 'A Sign in Space' channel
// unscrambled the message from the radio telemetry.
// The message published as Data17.bin is the correctly transcribed
// bitstream of the message payload given to ESA.
//
// The next step in the problem is the decoding of the payload bitstream into
// the next level of the message.
//
// The MySETI programs is a set of tools to help in this process.
// This conssists of:
// MySETIapp Addresses various messgae extraction and image manipultation
// methods the have been tried or are being tried for the purpose
// of fruther decoding the 'A Sign In Space' message
// MySETIviewer Viewer program to load the image files (.raw, .bmp(8 bit)) that the MySETIapp
// application generates. It allows the overlay, alignment, and
// display of theses file with an interactrive GUI.
//
// Future expansion:
// Change Layers, display dialog to modeless to support better live interaction
// Add .bin files, binary file used on Discord channel
// Add overlay shapes, rectangle, circle, line, text to annotate image
//
// The MySETIviewer covers many of the problems people have had in the Discord group visualizing
// the image data being generated in the decoding process.
//
// V1.0.1 2023-12-20 Initial release
// V1.0.2 2023-12-20 Added Y direction flag for which direction to move image
// Changed color mixing formula when pixels are overlapped.
// V1.1.0 2023-12-20 Changed the Layer dialog to be modeless
// Moved Add layer to Layers dialog
// Deleted Remove Layer from menu
// Correction, do not save anything when there are no layers
// V1.1.1 2023-12-27 Fixed parameter in IDC_BMP_GENERATE when x,y sizes are the same
// Added, status bar to Image window
// Added, bitmap position to status bar
// Changed, zoom, pan behaviour of bitmap
// Changed window resize of image display
// Added reset window positions on restart
// V1.1.2 2024-01-07 Added option to turn the grid on or off
// Added window position reset
// Added Action menu to Image Window
// Reset Pan
// Reset Zoom
// Close
// Changed Image Window, does not close with ESC or Enter keys
//
// This appliction stores user parameters in a Windows style .ini file
// The MySETIviewer.ini file must be in the same directory as the exectable
//
// A lot of this application code is really to support the framework
// of the application for the user interface.
//
// The application code that does the image overlays and formatting
// are implemented in the Display class and the Layers class:
// Display.h,Display.cpp, Layers.h, Layers.cpp
//
// Everything else is support code
//
#include "framework.h"
#include <atlstr.h>
#include <strsafe.h>
#include <atlpath.h>
#include <string.h>
#include "AppErrors.h"
#include "MySETIviewer.h"
#include "Layers.h"
#include "Display.h"
#include "ImageDialog.h"
#include "AppFunctions.h"
#include "imageheader.h"
#include "FileFunctions.h"
#define MAX_LOADSTRING 100
// Global Variables:
HINSTANCE hInst; // current instance
WCHAR szTitle[MAX_LOADSTRING]; // The title bar text
WCHAR szWindowClass[MAX_LOADSTRING]; // the main window class name
// working filenames
WCHAR szBMPFilename[MAX_PATH] = L""; // used to save last results file
WCHAR szCurrentFilename[MAX_PATH] = L""; // used to save last results file
WCHAR szTempDir[MAX_PATH] = L""; // used as a temporary storage location
// global Class declarations
Layers* ImageLayers = NULL; // This class loads the image layers, combines them into the Overlay image
Display* Displays = NULL; // This class creates a refernce image based on the display format paraneters
// and then inserts the Overlay image to create the Dislay image
ImageDialog* ImgDlg = NULL; // This class is used to support displaying the Display image in a window
// on the desktop. This also includes scaling and panning of the displayed image
// global flags
BOOL AutoPNG = FALSE; // generate a PNG file when a BMP file is saved
BOOL KeepOpen = TRUE; // keep Display and Layers dialog open when clicking OK or Cancel
BOOL ShowStatusBar = TRUE; // Display Status bar
// handles for modeless dialogs and windows
HWND hwndImage = NULL; // Handle for modeless Image Dialog window (this displays the image in a window)
HWND hwndDisplay = NULL; // Handle for the Display dialog (sets the grid and gap, and
// creates the Display image used in the Image Dialog
HWND hwndLayers = NULL; // Handle for the Layers dialog, this creates the Overlayed image from
// the specified layer, colors amd position, the overlay image is
// then used in the Display dialog
// color picker dialog custom color list
COLORREF CustomColorTable[16] = { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }; // array of custom colors
// The following is from the version information in the resource file
CString strProductName;
CString strProductVersion;
CString strName;
CString strCopyright;
CString strAppNameEXE;
CString strAppNameINI;
// handle to the main application window
// needed to do things like check or uncheck a menu item in the main app
HWND hwndMain = NULL;
// Forward declarations of functions included in this code module:
ATOM MyRegisterClass(HINSTANCE hInstance);
BOOL InitInstance(HINSTANCE, int);
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
// Declaration for callback dialog procedures in other modules
INT_PTR CALLBACK AboutDlg(HWND, UINT, WPARAM, LPARAM);
INT_PTR CALLBACK SettingsDisplayDlg(HWND, UINT, WPARAM, LPARAM);
INT_PTR CALLBACK SettingsLayersDlg(HWND, UINT, WPARAM, LPARAM);
INT_PTR CALLBACK SettingsGlobalDlg(HWND, UINT, WPARAM, LPARAM);
INT_PTR CALLBACK ImageDlg(HWND, UINT, WPARAM, LPARAM);
INT_PTR CALLBACK Text2StreamDlg(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam);
INT_PTR CALLBACK BitImageDlg(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam);
//*******************************************************************************
//
// int APIENTRY wWinMain
//
//*******************************************************************************
int APIENTRY wWinMain(_In_ HINSTANCE hInstance,
_In_opt_ HINSTANCE hPrevInstance,
_In_ LPWSTR lpCmdLine,
_In_ int nCmdShow)
{
UNREFERENCED_PARAMETER(hPrevInstance);
UNREFERENCED_PARAMETER(lpCmdLine);
HeapSetInformation(NULL, HeapEnableTerminationOnCorruption, NULL, 0);
//
// Get version information, executable name including path to executable location
if (!GetProductAndVersion(&strProductName,
&strProductVersion,
&strName,
&strCopyright,
&strAppNameEXE))
return FALSE;
// create INI file name for application settings
// The INI file has the same name as the executable.
// It is located in the same directory as the exectable
CPath path(strAppNameEXE);
path.RenameExtension(_T(".ini"));
strAppNameINI.SetString(path);
// Initialize global strings
LoadStringW(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
LoadStringW(hInstance, IDC_MYSETIVIEWER, szWindowClass, MAX_LOADSTRING);
MyRegisterClass(hInstance);
// Perform application initialization:
if (!InitInstance (hInstance, nCmdShow))
{
return FALSE;
}
HACCEL hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_MYSETIVIEWER));
MSG msg;
BOOL bRet;
// Main message loop:
while ((bRet = GetMessage(&msg, nullptr, 0, 0))!=0)
{
if (bRet == -1) {
// error handling if required
}
else {
// Modeless dialog need to process messages intended for the modeless dialog only.
// Check that message is not for each modeless dialog box.
// Modeless Image Dialog window
if (IsWindow(hwndImage) && IsDialogMessage(hwndImage, &msg)) {
continue;
}
// Modeless Display window
if (IsWindow(hwndDisplay) && IsDialogMessage(hwndDisplay, &msg)) {
continue;
}
// Modeless Layer window ( not yet implemented )
if (IsWindow(hwndLayers) && IsDialogMessage(hwndLayers, &msg)) {
continue;
}
// process all other applications messages
if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
}
return (int) msg.wParam;
}
//*******************************************************************************
//
// FUNCTION: MyRegisterClass()
//
// PURPOSE: Registers the window class. This is not the same as a c++ class
//
//*******************************************************************************
ATOM MyRegisterClass(HINSTANCE hInstance)
{
WNDCLASSEXW wcex;
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.style = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc = WndProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = hInstance;
wcex.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_MYSETIVIEWER));
wcex.hCursor = LoadCursor(nullptr, IDC_ARROW);
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wcex.lpszMenuName = MAKEINTRESOURCEW(IDC_MYSETIVIEWER);
wcex.lpszClassName = szWindowClass; // loaded from the resource file IDC_MYSETIVIEWER string
wcex.hIconSm = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_MYSETIVIEWER));
return RegisterClassExW(&wcex);
}
//*******************************************************************************
//
// FUNCTION: InitInstance(HINSTANCE, int)
//
// PURPOSE: Saves instance handle and creates main window
//
// COMMENTS:
//
// In this function, we save the instance handle in a global variable and
// create and display the main program window.
//
//*******************************************************************************
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
hInst = hInstance; // Store instance handle in our global variable
// Just using default size and position since this will be overwritten
// when restorewindow is called
HWND hWnd = CreateWindowW(szWindowClass, szTitle,
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, 0, // initial x,y position
CW_USEDEFAULT, 0, // initial x,ysize
nullptr, nullptr,
hInstance, nullptr);
if (!hWnd)
{
// if can not create window just die
return FALSE;
}
int ResetWindows = GetPrivateProfileInt(L"GlobalSettings", L"ResetWindows", 0, (LPCTSTR)strAppNameINI);
// restore main window position from last execution
if (!ResetWindows) {
CString csString = L"MainWindow";
RestoreWindowPlacement(hWnd, csString);
}
ShowWindow(hWnd, nCmdShow);
UpdateWindow(hWnd);
// load globals
// this must be done before ImageDialog class created
ShowStatusBar = GetPrivateProfileInt(L"SettingsGlobalDlg", L"ShowStatusBar", 1, (LPCTSTR)strAppNameINI);
hwndMain = hWnd;
ImgDlg = new ImageDialog;
ImageLayers = new Layers;
Displays = new Display;
// create display window
hwndImage = CreateDialog(hInst, MAKEINTRESOURCE(IDD_IMAGE), hwndMain, ImageDlg);
// strings
WCHAR szString[MAX_PATH];
GetPrivateProfileString(L"SettingsGlobalDlg", L"TempDir", L"", szString, MAX_PATH, (LPCTSTR)strAppNameINI);
wcscpy_s(szTempDir, szString);
GetPrivateProfileString(L"SettingsGlobalDlg", L"CurrentFIlename", L"", szString, MAX_PATH, (LPCTSTR)strAppNameINI);
wcscpy_s(szCurrentFilename, szString);
// variables
AutoPNG = GetPrivateProfileInt(L"SettingsGlobalDlg", L"AutoPNG", 1, (LPCTSTR)strAppNameINI);
KeepOpen = GetPrivateProfileInt(L"SettingsGlobalDlg", L"KeepOpen", 0, (LPCTSTR)strAppNameINI);
int ydir = GetPrivateProfileInt(L"SettingsGlobalDlg", L"yposDir", 1, (LPCTSTR)strAppNameINI);
ImageLayers->SetYdir(ydir);
for (int i = 0; i < 16; i++) {
WCHAR CustomColor[20];
swprintf_s(CustomColor, 20, L"CustomColorTable%d", i);
CustomColorTable[i] = (COLORREF) GetPrivateProfileInt(L"SettingsDlg", CustomColor, 0, (LPCTSTR)strAppNameINI);
}
// These are Display class settings
COLORREF BackGroundColor = (COLORREF)GetPrivateProfileInt(L"SettingsDisplayDlg", L"rgbBackground", 131586, (LPCTSTR)strAppNameINI);
COLORREF GapMajorColor = (COLORREF)GetPrivateProfileInt(L"SettingsDisplayDlg", L"rgbGapMajor", 2621521, (LPCTSTR)strAppNameINI);
COLORREF GapMinorColor = (COLORREF)GetPrivateProfileInt(L"SettingsDisplayDlg", L"rgbGapMinor", 1973790, (LPCTSTR)strAppNameINI);
Displays->SetColors(BackGroundColor, GapMajorColor, GapMinorColor);
int ValueX, ValueY;
ValueX = GetPrivateProfileInt(L"SettingsDisplayDlg", L"GridXmajor", 8, (LPCTSTR)strAppNameINI);
ValueY = GetPrivateProfileInt(L"SettingsDisplayDlg", L"GridYmajor", 8, (LPCTSTR)strAppNameINI);
Displays->SetGridMajor(ValueX, ValueY);
ValueX = GetPrivateProfileInt(L"SettingsDisplayDlg", L"GridXminor", 4, (LPCTSTR)strAppNameINI);
ValueY = GetPrivateProfileInt(L"SettingsDisplayDlg", L"GridYminor", 4, (LPCTSTR)strAppNameINI);
Displays->SetGridMinor(ValueX, ValueY);
ValueX = GetPrivateProfileInt(L"SettingsDisplayDlg", L"GapXmajor", 1, (LPCTSTR)strAppNameINI);
ValueY = GetPrivateProfileInt(L"SettingsDisplayDlg", L"GapYmajor", 1, (LPCTSTR)strAppNameINI);
Displays->SetGapMajor(ValueX, ValueY);
ValueX = GetPrivateProfileInt(L"SettingsDisplayDlg", L"GapXminor", 1, (LPCTSTR)strAppNameINI);
ValueY = GetPrivateProfileInt(L"SettingsDisplayDlg", L"GapYminor", 1, (LPCTSTR)strAppNameINI);
Displays->SetGapMinor(ValueX, ValueY);
int Enable = GetPrivateProfileInt(L"SettingsDisplayDlg", L"EnableGrid", 1, (LPCTSTR)strAppNameINI);
Displays->EnableGrid(Enable);
// These are Layer class settings
COLORREF Color;
// This is the color of the overlay background anywhere it hasn't been replaced by image data
Color = (COLORREF) GetPrivateProfileInt(L"LayersDlg", L"BackGround", 2763306, (LPCTSTR)strAppNameINI);
ImageLayers->SetBackgroundColor(Color);
Color = (COLORREF)GetPrivateProfileInt(L"LayersDlg", L"OverlayColor", 65793, (LPCTSTR)strAppNameINI);
ImageLayers->SetOverlayColor(Color);
Color = (COLORREF)GetPrivateProfileInt(L"LayersDlg", L"DefaultLayerColor", 16777215, (LPCTSTR)strAppNameINI);
ImageLayers->SetDefaultLayerColor(Color);
hwndDisplay = CreateDialog(hInst, MAKEINTRESOURCE(IDD_SETTINGS_DISPLAY), hWnd, SettingsDisplayDlg);
if (GetPrivateProfileInt(L"SettingsGlobalDlg", L"StartLast", 0, (LPCTSTR)strAppNameINI) != 0) {
// load the last layer cinfiguration
WCHAR szString[MAX_PATH];
GetPrivateProfileString(L"GlobalSettings", L"LastConfigFile", L"", szString, MAX_PATH, (LPCTSTR)strAppNameINI);
//wcscpy_s(ImageLayers->ConfigurationFile, MAX_PATH, szString);
int iRes = ImageLayers->LoadConfiguration(szString);
if (iRes != APP_SUCCESS) {
wcscpy_s(ImageLayers->ConfigurationFile, MAX_PATH, L"");
}
}
else {
wcscpy_s(ImageLayers->ConfigurationFile, MAX_PATH, L"");
}
hwndLayers = CreateDialog(hInst, MAKEINTRESOURCE(IDD_SETTINGS_LAYERS), hWnd, SettingsLayersDlg);
// clear windows reset
WritePrivateProfileString(L"GlobalSettings", L"ResetWindows", L"0", (LPCTSTR)strAppNameINI);
return TRUE;
}
//*******************************************************************************
//
// FUNCTION: WndProc(HWND, UINT, WPARAM, LPARAM)
//
// PURPOSE: Processes messages for the main window.
//
// WM_COMMAND - process the application menu
// WM_PAINT - Paint the main window
// WM_DESTROY - post a quit message and return
//
//
//*******************************************************************************
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_COMMAND:
{
int wmId = LOWORD(wParam);
// Parse the menu selections:
switch (wmId)
{
case IDM_LOAD_CONFIGURATION:
{
int iRes;
WCHAR szFilename[MAX_PATH];
PWSTR pszFilename;
COMDLG_FILTERSPEC AllType[] =
{
{ L"Image files", L"*.cfg" },
{ L"All Files", L"*.*" },
};
if (!CCFileOpen(hWnd, ImageLayers->ConfigurationFile, &pszFilename, FALSE, 2, AllType, L".cfg")) {
break;
}
wcscpy_s(szFilename, pszFilename);
CoTaskMemFree(pszFilename);
iRes = ImageLayers->LoadConfiguration(szFilename);
if (iRes != APP_SUCCESS) {
MessageBox(hWnd, L"Load configuration file failed\nCheck file for correct filenames in file", L"Layers", MB_OK);
break;
}
Displays->LoadConfiguration(szFilename);
SendMessage(hwndDisplay, WM_COMMAND, ID_UPDATE,0); // do not apply
SendMessage(hwndLayers, WM_COMMAND, ID_UPDATE, 1); // apply
break;
}
case IDM_SAVE_CONFIGURATION:
{
int iRes;
if (ImageLayers->GetNumLayers() == 0) {
MessageBox(hWnd, L"No layers loaded", L"Layers", MB_OK);
break;
}
if (wcslen(ImageLayers->ConfigurationFile) != 0) {
iRes = ImageLayers->SaveConfiguration();
iRes = Displays->SaveConfiguration(ImageLayers->ConfigurationFile);
if (iRes == APP_SUCCESS) {
break;
}
}
// go ahead with IDM_SAVE_AS_CONFIGURATION
}
case IDM_SAVE_AS_CONFIGURATION:
{
int iRes;
if (ImageLayers->GetNumLayers() == 0) {
MessageBox(hWnd, L"No layers loaded", L"Layers", MB_OK);
break;
}
WCHAR szFilename[MAX_PATH];
PWSTR pszFilename;
COMDLG_FILTERSPEC AllType[] =
{
{ L"Image files", L"*.cfg" },
{ L"All Files", L"*.*" },
};
if (!CCFileSave(hWnd, ImageLayers->ConfigurationFile, &pszFilename, FALSE, 2, AllType, L".cfg")) {
break;
}
wcscpy_s(szFilename, pszFilename);
CoTaskMemFree(pszFilename);
iRes = ImageLayers->SaveConfiguration(szFilename);
if (iRes == APP_SUCCESS) {
wcscpy_s(ImageLayers->ConfigurationFile, MAX_PATH, szFilename);
}
iRes = Displays->SaveConfiguration(szFilename);
break;
}
case IDM_LAYER_SAVEBMP:
{
if (ImageLayers->GetNumLayers() == 0) {
MessageBox(hWnd, L"No layers, nothing to save", L"Layers", MB_OK);
break;
}
if (!ImageLayers->OverlayValid) {
MessageBox(hWnd, L"Overlay is not valid to save\nmake sure to 'Apply' current layers configuration", L"Layers", MB_OK);
break;
}
PWSTR pszFilename;
COMDLG_FILTERSPEC AllType[] =
{
{ L"BMP files", L"*.bmp" },
{ L"All Files", L"*.*" }
};
if (!CCFileSave(hWnd, szCurrentFilename, &pszFilename, FALSE, 2, AllType, L".bmp")) {
break;
}
wcscpy_s(szCurrentFilename, pszFilename);
CoTaskMemFree(pszFilename);
int iRes;
iRes = ImageLayers->SaveBMP(szCurrentFilename);
if (iRes != APP_SUCCESS) {
MessageBox(hWnd, L"Save Failed", L"Layers", MB_OK);
}
break;
}
case IDM_DISPLAY_SAVEBMP:
{
if (ImageLayers->GetNumLayers() == 0) {
MessageBox(hWnd, L"No layers, nothing to save", L"Display", MB_OK);
break;
}
PWSTR pszFilename;
COMDLG_FILTERSPEC AllType[] =
{
{ L"BMP files", L"*.bmp" },
{ L"All Files", L"*.*" }
};
if (!CCFileSave(hWnd, szCurrentFilename, &pszFilename, FALSE, 2, AllType, L".bmp")) {
break;
}
wcscpy_s(szCurrentFilename, pszFilename);
CoTaskMemFree(pszFilename);
int iRes;
iRes = Displays->SaveBMP(szCurrentFilename, 0);
if (iRes != APP_SUCCESS) {
MessageBox(hWnd, L"Save Failed", L"Layers", MB_OK);
}
break;
}
case IDM_REFERENCE_SAVEBMP:
{
PWSTR pszFilename;
COMDLG_FILTERSPEC AllType[] =
{
{ L"BMP files", L"*.bmp" },
{ L"All Files", L"*.*" }
};
if (!CCFileSave(hWnd, szCurrentFilename, &pszFilename, FALSE, 2, AllType, L".bmp")) {
break;
}
wcscpy_s(szCurrentFilename, pszFilename);
CoTaskMemFree(pszFilename);
int iRes;
iRes = Displays->SaveBMP(szCurrentFilename, 1);
if (iRes != APP_SUCCESS) {
MessageBox(hWnd, L"Save Failed", L"Layers", MB_OK);
}
break;
}
case IDM_BITTOOLS_TEXT2BITSTREAM:
DialogBox(hInst, MAKEINTRESOURCE(IDD_BITTOOLS_TEXT2STREAM), hWnd, Text2StreamDlg);
break;
case IDM_BITTOOLS_BINARYIMAGE:
DialogBox(hInst, MAKEINTRESOURCE(IDD_BITTOOLS_BINARYIMAGE), hWnd, BitImageDlg);
break;
case IDM_EXIT:
{
if (hwndImage) {
// save window position/size data
CString csString = L"ImageWindow";
SaveWindowPlacement(hwndImage, csString);
// this must be done to ensure Direct2D factory is released
DestroyWindow(hwndImage);
}
DestroyWindow(hWnd);
break;
}
case IDM_SETTINGS_GLOBAL:
DialogBox(hInst, MAKEINTRESOURCE(IDD_SETTINGS_GLOBAL), hWnd, SettingsGlobalDlg);
break;
case IDM_SETTINGS_DISPLAY:
{
if (wcslen(szTempDir) == 0) {
MessageBox(hWnd, L"Working file folder needs to be set\nin Settings->Global first", L"Layers", MB_OK);
break;
}
if (hwndDisplay) {
ShowWindow(hwndDisplay, SW_SHOW);
}
break;
}
case IDM_SETTINGS_LAYERS:
{
if (wcslen(szTempDir) == 0) {
MessageBox(hWnd, L"Working file folder needs to be set\nin Settings->Global first", L"Layers", MB_OK);
break;
}
if (hwndLayers) {
ShowWindow(hwndLayers, SW_SHOW);
}
//DialogBox(hInst, MAKEINTRESOURCE(IDD_SETTINGS_LAYERS), hWnd, SettingsLayersDlg);
break;
}
case IDM_SETTINGS_RESET_WINDOWS:
WritePrivateProfileString(L"GlobalSettings", L"ResetWindows", L"1", (LPCTSTR)strAppNameINI);
break;
case IDM_ABOUT:
DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, AboutDlg);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
break;
} // This is the end of WM_COMMAND
case WM_CLOSE:
{
if (hwndImage) {
// save window position/size data
CString csString = L"ImageWindow";
SaveWindowPlacement(hwndImage, csString);
// this must be done to ensure Direct2D factory is released
DestroyWindow(hwndImage);
}
if (hwndDisplay) {
// save window position/size data for the Image Dialog window
CString csString = L"ImageDisplay";
SaveWindowPlacement(hwndDisplay, csString);
DestroyWindow(hwndDisplay);
}
if (hwndLayers) {
// save window position/size data for the Image Dialog window
CString csString = L"LayerWindow";
SaveWindowPlacement(hwndLayers, csString);
DestroyWindow(hwndLayers);
}
DestroyWindow(hWnd);
break;
}
case WM_DESTROY:
{
WritePrivateProfileString(L"GlobalSettings", L"CurrentFilename", szCurrentFilename, (LPCTSTR)strAppNameINI);
WritePrivateProfileString(L"GlobalSettings", L"LastConfigFile", ImageLayers->ConfigurationFile, (LPCTSTR)strAppNameINI);
// save window position/size data for the Main window
CString csString = L"MainWindow";
SaveWindowPlacement(hWnd, csString);
// release Image Dialog
if (hwndImage) {
// save window position/size data for the Image Dialog window
CString csString = L"ImageWindow";
SaveWindowPlacement(hwndImage, csString);
DestroyWindow(hwndImage);
}
if (hwndDisplay) {
// save window position/size data for the Image Dialog window
CString csString = L"ImageDisplay";
SaveWindowPlacement(hwndDisplay, csString);
DestroyWindow(hwndDisplay);
}
if (hwndLayers) {
// save window position/size data for the Image Dialog window
CString csString = L"LayerWindow";
SaveWindowPlacement(hwndDisplay, csString);
DestroyWindow(hwndLayers);
}
// delete the global classes;
if (ImageLayers != NULL) delete ImageLayers;
if (Displays != NULL) delete Displays;
if (ImgDlg != NULL) delete ImgDlg;
PostQuitMessage(0);
break;
}
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}