-
Notifications
You must be signed in to change notification settings - Fork 0
/
BiskupovskaTabulecka.cpp
1244 lines (1078 loc) · 37.2 KB
/
BiskupovskaTabulecka.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
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
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//--------------------------------------------------------------------
// FILENAME: BiskupovskaTabulecka.cpp
//
// Copyright(c) 2008 Motorola, Inc. All rights reserved.
// Copyright(c) 2023, 2024 Richard Gráèik - Morc
//
// DESCRIPTION: Defines the entry point for the application.
//
// PLATFORMS: Windows CE
//
// NOTES: Public
//
//
//--------------------------------------------------------------------
#include <windows.h>
#include <commctrl.h>
#include <ScanCAPI.h>
#include <aygshell.h>
#include <wininet.h>
#include <msxml2.h>
#include <comutil.h>
#include <vector>
#include <set>
#include "resource.h"
#define MAX_LOADSTRING 100
#define THREAD_TIMEOUT 7000
// Global Variables:
HINSTANCE g_hInst; // The current instance
HWND g_hwndCB; // The command bar handle
HWND g_hwnd; // The main window handle
HMENU g_hSubMenu; // the 'File' menu handle
HWND g_hwndList; // The list view of GUI
HWND g_hwndEntryBox; // The entrybox handle for add/edit dlg
static SHACTIVATEINFO s_sai;
HFONT g_hfont = NULL; // The handle for display font
LOGFONT g_lf; // Font structure
// Forward declarations of functions included in this code module:
ATOM MyRegisterClass (HINSTANCE, LPTSTR);
BOOL InitInstance (HINSTANCE, int);
LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK About (HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK Settings (HWND, UINT, WPARAM, LPARAM);
//add/edit entrybox related
LRESULT CALLBACK AddEntry (HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK EditEntry (HWND, UINT, WPARAM, LPARAM);
LRESULT AddEditEntryBoxNotifyHandler(HWND, UINT, WPARAM, LPARAM);
TCHAR entryBoxTemp[2000];
TCHAR entryBoxURLGen[65535];
TCHAR uploadURLFinal[65535];
int selectedDevice = 255;
void PatchEntry(HWND hDlg, bool addingMode);
void MouseHack(BOOL wait);
bool entryBoxRetry = false;
HWND CreateRpCommandBar(HWND);
void CreateDisplayFont(LONG lHeight, LONG lWeight, LPTSTR szFont);
void CreateListView(HWND hDlg);
void ErrorExit(HWND, UINT, LPTSTR);
void SetScanParams();
TCHAR* HTTPReq(wchar_t*);
HANDLE hScanner = NULL;
LPSCAN_BUFFER lpScanBuffer = NULL;
TCHAR szScannerName[MAX_PATH] = TEXT("SCN1:"); // default scanner name
DWORD dwScanSize = 7095; // default scan buffer size
DWORD dwScanTimeout = 2000; // default timeout value (0 means no timeout)
BOOL bRequestPending = FALSE;
BOOL bStopScanning = FALSE;
//table specific
void RequestTable(HWND hDlg);
std::set<_bstr_t> deviceColumns;
std::vector<_bstr_t> deviceData;
int deviceDataCount, deviceCount = 0;
int columnCount = 0;
BOOL tableRefresh = FALSE;
BOOL firstLoad = TRUE;
BOOL tableRefreshFailed = FALSE;
//REGISTRY DEFAULT VALUES
BOOL bUseSound = FALSE;
_bstr_t downloadURL = _bstr_t("http://192.168.1.3/tabulecka_xml.php");
_bstr_t uploadURL = _bstr_t("http://192.168.1.3/tabulecka_edit.php");
#define countof(x) sizeof(x)/sizeof(x[0])
enum tagUSERMSGS
{
UM_SCAN = WM_USER + 0x200,
UM_STARTSCANNING,
UM_STOPSCANNING
};
int WINAPI WinMain( HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow)
{
MSG msg;
HACCEL hAccelTable;
// Perform application initialization:
if (!InitInstance (hInstance, nCmdShow))
{
return FALSE;
}
hAccelTable = LoadAccelerators(hInstance, (LPCTSTR)IDC_BISKUPOVSKATABULECKA);
// Main message loop:
while (GetMessage(&msg, NULL, 0, 0))
{
if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
return msg.wParam;
}
// **************************************************************************
// FUNCTION: MyRegisterClass()
//
// PURPOSE: Registers the window class.
//
// COMMENTS:
//
// It is important to call this function so that the application
// will get 'well formed' small icons associated with it.
// **************************************************************************
ATOM MyRegisterClass(HINSTANCE hInstance, LPTSTR szWindowClass)
{
WNDCLASS wc;
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc = (WNDPROC) WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_BISKUPOVSKATABULECKA));
wc.hCursor = 0;
wc.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH);
wc.lpszMenuName = 0;
wc.lpszClassName = szWindowClass;
return RegisterClass(&wc);
}
// **************************************************************************
// FUNCTION: InitInstance(HANDLE, 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)
{
HWND hWnd = NULL;
TCHAR szTitle[MAX_LOADSTRING]; // The title bar text
TCHAR szWindowClass[MAX_LOADSTRING]; // The window class name
g_hInst = hInstance; // Store instance handle in our global variable
//set beachball to entertain user while the app is loading
SetCursor(LoadCursor(NULL, IDC_WAIT));
LoadString(hInstance, IDC_BISKUPOVSKATABULECKA, szWindowClass, MAX_LOADSTRING);
LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
hWnd = FindWindow(szWindowClass, szTitle);
if (hWnd)
{
SetForegroundWindow((HWND)((ULONG) hWnd | 0x00000001));
return FALSE;
}
MyRegisterClass(hInstance, szWindowClass);
hWnd = CreateWindow(szWindowClass, szTitle, WS_VISIBLE ,
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInstance, NULL);
if (!hWnd)
{
return FALSE;
}
g_hwnd = hWnd;
if (g_hwndCB)
{
RECT rc;
RECT rcMenuBar;
GetWindowRect(hWnd, &rc);
GetWindowRect(g_hwndCB, &rcMenuBar);
rc.bottom -= (rcMenuBar.bottom - rcMenuBar.top);
MoveWindow(hWnd, rc.left, rc.top, rc.right-rc.left, rc.bottom-rc.top, FALSE);
}
//registry shitzzzz
HKEY key;
DWORD keyDisp;
BYTE UseSoundReg = bUseSound;
LONG keyStatus = RegCreateKeyEx(HKEY_CURRENT_USER, _T("Software\\BiskupovskaTabulecka"), 0, NULL,
REG_OPTION_NON_VOLATILE, 0, NULL, &key, &keyDisp);
if (keyStatus != ERROR_SUCCESS)
{
OutputDebugString(_T("reg create+open failed\n"));
MessageBox(hWnd, _T("RegCreateKey failed"), _T("Tabuleèka"), MB_OK | MB_ICONERROR);
}
if (keyDisp == REG_CREATED_NEW_KEY)
{
OutputDebugString(_T("reg writing default values\n"));
LONG regWrite = RegSetValueEx(key, _T("UseSound"), 0, REG_DWORD, &UseSoundReg, 1);
if (regWrite == ERROR_SUCCESS)
MessageBox(hWnd, _T("First run, loading default settings"), _T("Tabuleèka"), MB_OK | MB_ICONERROR);
else
MessageBox(hWnd, _T("Loading default settings failed"), _T("Tabuleèka"), MB_OK | MB_ICONERROR);
//god, I hate these conversions
const BYTE* BYTEDlURLKey = reinterpret_cast<const BYTE*>(downloadURL.GetBSTR());
int BYTEDlURLKeyLength = SysStringByteLen(downloadURL.GetBSTR());
const BYTE* BYTEUpURLKey = reinterpret_cast<const BYTE*>(uploadURL.GetBSTR());
int BYTEUpURLKeyLength = SysStringByteLen(uploadURL.GetBSTR());
RegSetValueEx(key, _T("DownloadURL"), 0, REG_SZ, BYTEDlURLKey, BYTEDlURLKeyLength);
RegSetValueEx(key, _T("UploadURL"), 0, REG_SZ, BYTEUpURLKey, BYTEUpURLKeyLength);
}
else if (keyDisp == REG_OPENED_EXISTING_KEY)
{
OutputDebugString(_T("reg reading values\n"));
DWORD regData;
LONG regRead = RegQueryValueEx(key, _T("UseSound"), 0, NULL, &UseSoundReg, ®Data);
bUseSound = (regData == 1) ? TRUE : FALSE;
//god, why
TCHAR downloadURLTCHAR[255];
unsigned long downloadURLdataLength = sizeof(char) * 255;
RegQueryValueEx(key, _T("DownloadURL"), 0, NULL, (LPBYTE)downloadURLTCHAR,
&downloadURLdataLength);
downloadURL = _bstr_t(downloadURLTCHAR);
TCHAR uploadURLTCHAR[255];
unsigned long uploadURLdataLength = sizeof(char) * 255;
RegQueryValueEx(key, _T("UploadURL"), 0, NULL, (LPBYTE)uploadURLTCHAR, &uploadURLdataLength);
uploadURL = _bstr_t(uploadURLTCHAR);
}
RegCloseKey(key);
ShowWindow(hWnd, nCmdShow);
UpdateWindow(hWnd);
return TRUE;
}
// **************************************************************************
// FUNCTION: WndProc(HWND, unsigned, WORD, LONG)
//
// 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)
{
int wmId, wmEvent, nRet = 0;
DWORD dwResult;
TCHAR szMsgBuf[256];
LPSCAN_BUFFER lpScanBuf;
static HWND hDlg;
switch (message)
{
case WM_COMMAND:
wmId = LOWORD(wParam);
wmEvent = HIWORD(wParam);
// Parse the menu selections:
switch (wmId)
{
case IDM_ABOUT:
DialogBox(g_hInst, (LPCTSTR)IDD_ABOUTBOX, hWnd, (DLGPROC)About);
break;
case IDM_SETTINGS:
DialogBox(g_hInst, (LPCTSTR)IDD_SETTINGS, hWnd, (DLGPROC)Settings);
break;
case IDM_ADDNEWENTRY:
DialogBox(g_hInst, (LPCTSTR)IDD_ADDEDIT, hWnd, (DLGPROC)AddEntry);
break;
case IDM_EDITSELECTED:
case IDM_EDIT:
DialogBox(g_hInst, (LPCTSTR)IDD_ADDEDIT, hWnd, (DLGPROC)EditEntry);
break;
case IDCLOSE:
case IDCANCEL:
case IDOK:
case IDM_EXIT:
SendMessage(hWnd, WM_DESTROY, 0, 0);
SendMessage(hWnd, WM_CLOSE, 0, 0);
break;
case IDM_REFRESH:
SetCursor(LoadCursor(NULL, IDC_WAIT));
selectedDevice = ListView_GetSelectionMark(g_hwndList);
deviceColumns.clear();
deviceData.clear();
deviceDataCount = 0;
deviceCount = 0;
tableRefreshFailed = FALSE;
RequestTable(hDlg);
ListView_DeleteAllItems(g_hwndList);
for(int col = 0; col <= columnCount; col++)
//this actually still leaves three columns in the lv, workaround in UpdateListView()
ListView_DeleteColumn(g_hwndList, col);
columnCount = 0;
tableRefresh = TRUE;
CreateListView(hDlg);
SetCursor(LoadCursor(NULL, IDC_ARROW));
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
break;
case WM_CREATE:
g_hwndCB = CreateRpCommandBar(hWnd);
PostMessage(hWnd,UM_STARTSCANNING,0,0L);
memset (&s_sai, 0, sizeof (s_sai));
s_sai.cbSize = sizeof (s_sai);
hDlg = CreateDialogParam(g_hInst,MAKEINTRESOURCE(IDD_INFOPAGE), hWnd, (DLGPROC)WndProc,
NULL);
g_hSubMenu = (HMENU)SendMessage(g_hwndCB, SHCMBM_GETSUBMENU, 0, IDM_MENU);
break;
case WM_PAINT:
break;
case WM_DESTROY:
EndDialog(hDlg, nRet);
if (g_hfont != NULL)
DeleteObject(g_hfont);
CommandBar_Destroy(g_hwndCB);
PostQuitMessage(0);
break;
case WM_ACTIVATE:
// Notify shell of our activate message
SHHandleWMActivate(hWnd, wParam, lParam, &s_sai, FALSE);
if (firstLoad)
{
RequestTable(hDlg);
CreateListView(hDlg);
SetCursor(LoadCursor(NULL, IDC_ARROW));
firstLoad = FALSE;
}
if(LOWORD(wParam) != WA_INACTIVE)
{
SetFocus(g_hwndList);
}
switch(LOWORD(wParam))
{
case WA_INACTIVE:
if (bRequestPending)
dwResult = SCAN_Flush(hScanner);
break;
default:
if (!bRequestPending && lpScanBuffer != NULL && !bStopScanning)
{
dwResult = SCAN_ReadLabelMsg(hScanner,
lpScanBuffer,
hWnd,
UM_SCAN,
dwScanTimeout,
NULL);
if ( dwResult != E_SCN_SUCCESS )
ErrorExit(hWnd, IDS_SCAN_FAIL, TEXT("SCAN_ReadLabelMsg"));
else
bRequestPending = TRUE;
}
break;
}
break;
case WM_SETTINGCHANGE:
SHHandleWMSettingChange(hWnd, wParam, lParam, &s_sai);
break;
case WM_CLOSE:
break;
case WM_SIZE:
{
INT nWidth = LOWORD(lParam);
INT nHeight = HIWORD(lParam);
MoveWindow(g_hwndList, -3, -5, nWidth+8, nHeight+9, TRUE);
}
break;
case UM_SCAN:
bRequestPending = FALSE;
lpScanBuf = (LPSCAN_BUFFER)lParam;
if ( lpScanBuf == NULL )
ErrorExit(hWnd, IDS_SCAN_FAIL, 0);
switch (SCNBUF_GETSTAT(lpScanBuf))
{
case E_SCN_READCANCELLED:
if (bStopScanning)
{ // complete the second step of UM_STOPSCANNING
SendMessage(hWnd,UM_STOPSCANNING,0,0L);
return TRUE;
}
if (!GetFocus())
break; // Do nothing if read was cancelled while deactivation
break;
case E_SCN_SUCCESS:
wsprintf(szMsgBuf, (LPTSTR)SCNBUF_GETDATA(lpScanBuffer));
//OutputDebugString(szMsgBuf);
int scan;
try
{
scan = _ttoi(szMsgBuf);
}
catch (int)
{
MessageBox(g_hwnd, _T("Scan ID parser failed"), _T("Tabuleèka"), MB_OK | MB_ICONERROR);
}
int actualDeviceID = (deviceCount-scan);
ListView_EnsureVisible(g_hwndList, actualDeviceID, FALSE);
ListView_SetItemState(g_hwndList, ListView_GetSelectionMark(g_hwndList), 0,
LVIS_SELECTED);
ListView_SetSelectionMark(g_hwndList, actualDeviceID);
ListView_SetItemState(g_hwndList, actualDeviceID, LVIS_SELECTED, LVIS_SELECTED);
break;
}
if (GetFocus())
{
dwResult = SCAN_ReadLabelMsg(hScanner,
lpScanBuffer,
hWnd,
message,
dwScanTimeout,
NULL);
if ( dwResult != E_SCN_SUCCESS )
ErrorExit(hWnd, IDS_SCAN_FAIL, TEXT("SCAN_ReadLabelMsg"));
else
bRequestPending = TRUE;
}
return TRUE;
case UM_STARTSCANNING:
dwResult = SCAN_Open(szScannerName, &hScanner);
if ( dwResult != E_SCN_SUCCESS )
{
ErrorExit(hWnd, IDS_COMMAND1, TEXT("SCAN_Open"));
break;
}
dwResult = SCAN_Enable(hScanner);
if ( dwResult != E_SCN_SUCCESS )
{
ErrorExit(hWnd, IDS_COMMAND1, TEXT("SCAN_Enable"));
break;
}
SetScanParams();
lpScanBuffer = SCAN_AllocateBuffer(TRUE, dwScanSize);
if (lpScanBuffer == NULL)
{
ErrorExit(hWnd, IDS_COMMAND1, TEXT("SCAN_AllocateBuffer"));
return TRUE;
}
dwResult = SCAN_ReadLabelMsg(hScanner,
lpScanBuffer,
hWnd,
UM_SCAN,
dwScanTimeout,
NULL);
if ( dwResult != E_SCN_SUCCESS )
ErrorExit(hWnd, IDS_COMMAND1, TEXT("SCAN_ReadLabelMsg"));
else
bRequestPending = TRUE;
break;
return TRUE;
case UM_STOPSCANNING:
if (!bStopScanning && bRequestPending)
SCAN_Flush(hScanner);
if (!bRequestPending)
{
SCAN_Disable(hScanner);
if (lpScanBuffer)
SCAN_DeallocateBuffer(lpScanBuffer);
SCAN_Close(hScanner);
EndDialog(hWnd, 0);
}
bStopScanning = TRUE;
return TRUE;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}
// **************************************************************************
// Function Name: CreateRpCommandBar
//
// Arguments: The window handle to hold the menu bar
//
// Return Values: The Window Handle of the Menu Bar
//
// Description: To create the menu
// **************************************************************************
HWND CreateRpCommandBar(HWND hwnd)
{
SHMENUBARINFO mbi;
memset(&mbi, 0, sizeof(SHMENUBARINFO));
mbi.cbSize = sizeof(SHMENUBARINFO);
mbi.hwndParent = hwnd;
mbi.nToolBarId = IDM_MENU;
mbi.hInstRes = g_hInst;
mbi.dwFlags = SHCMBF_HMENU;
mbi.nBmpId = 0;
mbi.cBmpImages = 0;
if (!SHCreateMenuBar(&mbi))
return NULL;
return mbi.hwndMB;
}
// **************************************************************************
// Function Name: About
//
// Arguments: Please refer to the MSDN help
//
// Return Values:
//
// Description: call back function for About Box
// **************************************************************************
LRESULT CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
SHINITDLGINFO shidi;
TCHAR szVersion[MAX_LOADSTRING];
switch (message)
{
case WM_INITDIALOG:
// Create a Done button and size it.
shidi.dwMask = SHIDIM_FLAGS;
shidi.dwFlags = SHIDIF_DONEBUTTON | SHIDIF_SIPDOWN | SHIDIF_SIZEDLGFULLSCREEN;
shidi.hDlg = hDlg;
SHInitDialog(&shidi);
LoadStringW(g_hInst, IDS_VERSION, szVersion, MAX_LOADSTRING);
SetDlgItemTextW(hDlg, IDC_VERSION, szVersion);
CreateDisplayFont(30, 800, _T("MS Sans Serif"));
SendMessageW(GetDlgItem(hDlg, IDC_APPNAME),WM_SETFONT, (WPARAM)g_hfont, (LPARAM) TRUE);
return TRUE;
case WM_COMMAND:
if (LOWORD(wParam) == IDOK)
{
EndDialog(hDlg, LOWORD(wParam));
return TRUE;
}
break;
}
return FALSE;
}
// **************************************************************************
// Function Name: Settings
//
// Arguments: Please refer to the MSDN help
//
// Return Values:
//
// Description: call back function for settings dialog popup
// **************************************************************************
LRESULT CALLBACK Settings(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_INITDIALOG:
{
//set checkmark to the current Use Sound state
CheckDlgButton(hDlg, IDC_USESOUND, bUseSound);
//set smaller font to edit controls so we can fit more text
CreateDisplayFont(18, 500, _T("MS Sans Serif"));
SendMessageW(GetDlgItem(hDlg, IDC_DOWNEDIT),WM_SETFONT, (WPARAM)g_hfont, (LPARAM) TRUE);
SendMessageW(GetDlgItem(hDlg, IDC_UPEDIT),WM_SETFONT, (WPARAM)g_hfont, (LPARAM) TRUE);
//not these conversions again, whyyy
HWND downloadEdit = GetDlgItem(hDlg, IDC_DOWNEDIT);
BSTR downloadEditBSTR = SysAllocString(downloadURL);
LPCWSTR downloadEditText = static_cast<LPCWSTR>(downloadEditBSTR);
SetWindowText(downloadEdit, downloadEditText);
HWND uploadEdit = GetDlgItem(hDlg, IDC_UPEDIT);
BSTR uploadEditBSTR = SysAllocString(uploadURL);
LPCWSTR uploadEditText = static_cast<LPCWSTR>(uploadEditBSTR);
SetWindowText(uploadEdit, uploadEditText);
return TRUE;
}
case WM_COMMAND:
switch (LOWORD(wParam))
{
case IDOK:
HKEY key;
DWORD keyDisp;
BYTE UseSoundReg = 0;
HWND useSoundHandle = GetDlgItem(hDlg, IDC_USESOUND);
if(SendMessage(useSoundHandle, BM_GETCHECK, 0,0))
{
OutputDebugString(_T("usesound checked\n"));
UseSoundReg = 1;
bUseSound = TRUE;
}
else
{
bUseSound = FALSE;
}
//what did I do to you lol
//what even is this lol, LPWSTR > TCHAR > _bstr_t > BYTE
HWND downloadEdit = GetDlgItem(hDlg, IDC_DOWNEDIT);
TCHAR downloadEditTCHAR[255];
unsigned long downloadEditdataLength = sizeof(char) * 255;
GetWindowText(downloadEdit, downloadEditTCHAR, downloadEditdataLength);
_bstr_t downloadEditBSTR = _bstr_t(downloadEditTCHAR);
const BYTE* downloadEditBYTE = reinterpret_cast<const BYTE*>(downloadEditBSTR.GetBSTR());
int downloadEditBYTELength = SysStringByteLen(downloadEditBSTR.GetBSTR());
HWND uploadEdit = GetDlgItem(hDlg, IDC_UPEDIT);
TCHAR uploadEditTCHAR[255];
unsigned long uploadEditdataLength = sizeof(char) * 255;
GetWindowText(uploadEdit, uploadEditTCHAR, uploadEditdataLength);
_bstr_t uploadEditBSTR = _bstr_t(uploadEditTCHAR);
const BYTE* uploadEditBYTE = reinterpret_cast<const BYTE*>(uploadEditBSTR.GetBSTR());
int uploadEditBYTELength = SysStringByteLen(uploadEditBSTR.GetBSTR());
downloadURL = downloadEditBSTR;
uploadURL = uploadEditBSTR;
SetScanParams();
// write entries
RegCreateKeyEx(HKEY_CURRENT_USER, _T("Software\\BiskupovskaTabulecka"), 0, NULL, REG_OPTION_NON_VOLATILE, 0, NULL, &key, &keyDisp);
RegSetValueEx(key, _T("UseSound"), 0, REG_DWORD, &UseSoundReg, 1);
RegSetValueEx(key, _T("DownloadURL"), 0, REG_SZ, downloadEditBYTE, downloadEditBYTELength);
RegSetValueEx(key, _T("UploadURL"), 0, REG_SZ, uploadEditBYTE, uploadEditBYTELength);
RegCloseKey(key);
EndDialog(hDlg, 1);
return TRUE;
}
break;
}
return FALSE;
}
// **************************************************************************
// Function Name: AddEntry
//
// Arguments: Please refer to the MSDN help
//
// Return Values:
//
// Description: call back function for addentry dialog popup
// **************************************************************************
LRESULT CALLBACK AddEntry(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
HWND g_hwndEntryBoxLocal;
switch (message)
{
case WM_INITDIALOG:
{
EnableWindow(g_hwndList, false);
EnableWindow(g_hwnd, false);
int selectedDeviceLocal = ListView_GetSelectionMark(g_hwndList);
SetWindowText(hDlg, _T("Adding new entry N/A"));
g_hwndEntryBoxLocal = CreateWindow(WC_LISTVIEW, NULL, WS_VISIBLE | LVS_REPORT | LVS_EDITLABELS, 0, 0, 480, 420, hDlg, (HMENU) 500, g_hInst, NULL);
ListView_SetExtendedListViewStyle(g_hwndEntryBoxLocal, ListView_GetExtendedListViewStyle(g_hwndEntryBoxLocal) | LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES);
LVCOLUMN lvColumn;
lvColumn.mask = LVCF_FMT | LVCF_SUBITEM | LVCF_WIDTH | LVCF_TEXT;
lvColumn.fmt = LVCFMT_LEFT;
lvColumn.pszText = _T("Device entry");
lvColumn.iSubItem = 0;
lvColumn.cx = 2000;
ListView_InsertColumn(g_hwndEntryBoxLocal, 0, &lvColumn);
g_hwndEntryBox = g_hwndEntryBoxLocal; //HACK! HACK!
selectedDevice = selectedDeviceLocal; //HACH!!!!! WHAT?????!??!
//this part of the code is really interesting due to quirks on the MSVC/WIN32/WM/CE kernel side
//it's chaotic evil, HACK!!! HACK!!!
LVITEM lvI;
lvI.mask = LVIF_TEXT | LVIF_STATE;
lvI.iItem = 0;
lvI.cchTextMax = 31999;
lvI.state = 0;
lvI.stateMask = 0;
for (int i = 0; i < columnCount; i++)
{
//printf("columnIndex %d, data: %s\n", i, deviceData[selectedDevice *columnCount + i].GetBSTR());
ListView_InsertItem(g_hwndEntryBoxLocal, &lvI);
}
std::set<_bstr_t>::iterator it;
int counter = 0;
for (it = deviceColumns.begin(); it != deviceColumns.end(); ++it, ++counter){
_bstr_t column = *it;
OutputDebugString(column.GetBSTR()); //HACK!!!!!
_bstr_t colText = column.GetBSTR()+2; //HACK!!!!
ListView_SetItemText(g_hwndEntryBoxLocal,counter, 0, colText);
}
return TRUE;
}
case WM_NOTIFY: //listview change handling, uses the HACK above!
{
LV_DISPINFO *pLvdi = (LV_DISPINFO *)lParam;
switch(pLvdi->hdr.code)
{
case LVN_ENDLABELEDIT:
if ((pLvdi->item.iItem != -1) && (pLvdi->item.pszText != NULL))
ListView_SetItemText(g_hwndEntryBox,ListView_GetSelectionMark(g_hwndEntryBox), 0, pLvdi->item.pszText);
return true;
}
}
case WM_COMMAND:
switch (wParam)
{
case IDOK:
printf("preparing to save changes!");
MouseHack(true);
entryBoxRetry = false;
wsprintf(entryBoxURLGen, _T("?add"), selectedDevice);
for (int i = 0; i < columnCount; i++)
{
//printf("columnIndex %d, data: %s\n", i, entryBoxTemp);
ListView_GetItemText(g_hwndEntryBox, i, 0, entryBoxTemp, sizeof(entryBoxTemp));
wsprintf(entryBoxURLGen, _T("%s&%d=%s"), entryBoxURLGen, i, entryBoxTemp);
}
PatchEntry(hDlg, true);
//OutputDebugString(entryBoxURLGen);
EnableWindow(g_hwndList, true);
EnableWindow(g_hwnd, true);
SendMessage(g_hwnd, WM_COMMAND, IDM_REFRESH, NULL);
MouseHack(false);
EndDialog(hDlg, 1);
break;
default: //setting title afterwards in a WM_COMMAND as a HACK!!!! Again due to some win32 quirk
TCHAR entryTitle[25];
wsprintf(entryTitle, _T("Adding new entry %d"), deviceCount+1);
SetWindowText(hDlg, entryTitle);
break;
}
break;
}
return FALSE;
}
// **************************************************************************
// Function Name: EditEntry
//
// Arguments: Please refer to the MSDN help
//
// Return Values:
//
// Description: call back function for editentry dialog popup
// **************************************************************************
LRESULT CALLBACK EditEntry(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
HWND g_hwndEntryBoxLocal;
switch (message)
{
case WM_INITDIALOG:
{
EnableWindow(g_hwndList, false);
EnableWindow(g_hwnd, false);
int selectedDeviceLocal = ListView_GetSelectionMark(g_hwndList);
SetWindowText(hDlg, _T("Editing entry N/A"));
g_hwndEntryBoxLocal = CreateWindow(WC_LISTVIEW, NULL, WS_VISIBLE | LVS_REPORT | LVS_EDITLABELS, 0, 0, 480, 420, hDlg, (HMENU) 500, g_hInst, NULL);
ListView_SetExtendedListViewStyle(g_hwndEntryBoxLocal, ListView_GetExtendedListViewStyle(g_hwndEntryBoxLocal) | LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES);
LVCOLUMN lvColumn;
lvColumn.mask = LVCF_FMT | LVCF_SUBITEM | LVCF_WIDTH | LVCF_TEXT;
lvColumn.fmt = LVCFMT_LEFT;
lvColumn.pszText = _T("Device entry");
lvColumn.iSubItem = 0;
lvColumn.cx = 2000;
ListView_InsertColumn(g_hwndEntryBoxLocal, 0, &lvColumn);
g_hwndEntryBox = g_hwndEntryBoxLocal; //HACK! HACK!
selectedDevice = selectedDeviceLocal; //HACH!!!!! WHAT?????!??!
//this part of the code is really interesting due to quirks on the MSVC/WIN32/WM/CE kernel side
//it's chaotic evil, HACK!!! HACK!!!
LVITEM lvI;
lvI.mask = LVIF_TEXT | LVIF_STATE;
lvI.iItem = 0;
lvI.cchTextMax = 31999;
lvI.state = 0;
lvI.stateMask = 0;
for (int i = 0; i < columnCount; i++)
{
//printf("columnIndex %d, data: %s\n", i, deviceData[selectedDevice *columnCount + i].GetBSTR());
ListView_InsertItem(g_hwndEntryBoxLocal, &lvI);
}
for (int i = 0; i < columnCount; i++) //HACK!!!!! HACK!!!
{
ListView_SetItemText(g_hwndEntryBoxLocal,i, 0, deviceData[selectedDeviceLocal *columnCount + i].GetBSTR());
}
return TRUE;
}
case WM_NOTIFY: //listview change handling, uses the HACK above!
{
LV_DISPINFO *pLvdi = (LV_DISPINFO *)lParam;
switch(pLvdi->hdr.code)
{
case LVN_ENDLABELEDIT:
if ((pLvdi->item.iItem != -1) && (pLvdi->item.pszText != NULL))
ListView_SetItemText(g_hwndEntryBox,ListView_GetSelectionMark(g_hwndEntryBox), 0, pLvdi->item.pszText);
return true;
}
}
case WM_COMMAND:
switch (wParam)
{
case IDOK:
printf("preparing to save changes!");
MouseHack(true);
entryBoxRetry = false;
wsprintf(entryBoxURLGen, _T("?id=%d"), selectedDevice);
for (int i = 0; i < columnCount; i++)
{
//printf("columnIndex %d, data: %s\n", i, entryBoxTemp);
ListView_GetItemText(g_hwndEntryBox, i, 0, entryBoxTemp, sizeof(entryBoxTemp));
wsprintf(entryBoxURLGen, _T("%s&%d=%s"), entryBoxURLGen, i, entryBoxTemp);
}
PatchEntry(hDlg, false);
//OutputDebugString(entryBoxURLGen);
EnableWindow(g_hwndList, true);
EnableWindow(g_hwnd, true);
SendMessage(g_hwnd, WM_COMMAND, IDM_REFRESH, NULL);
MouseHack(false);
EndDialog(hDlg, 1);
break;
default: //setting title afterwards in a WM_COMMAND as a HACK!!!! Again due to some win32 quirk
TCHAR entryTitle[25];
wsprintf(entryTitle, _T("Editing entry %d"), selectedDevice);
SetWindowText(hDlg, entryTitle);
break;
}
break;
}
return FALSE;
}
// **************************************************************************
// Function Name: PatchEntry
//
// Arguments: handle, adding mode
//
// Return Values:
//
// Description: patches the entry in tabuleèka
// **************************************************************************
void PatchEntry(HWND hDlg, bool addingMode)
{
if(!entryBoxRetry)
wsprintf(uploadURLFinal, _T("%s%s"), uploadURL.GetBSTR(), entryBoxURLGen);
//OutputDebugString(uploadURLFinal);
DWORD dwSize = 0;
char *lpBufferA;
TCHAR *lpBufferW;
HINTERNET hInternet = InternetOpen(L"HTTP Request", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
if (hInternet)
{
HINTERNET hConnect = InternetOpenUrl(hInternet, uploadURLFinal, NULL, 0, INTERNET_FLAG_RELOAD, 0);
if (hConnect)
{
lpBufferA = new CHAR [32000];
if (InternetReadFile(hConnect, (LPVOID)lpBufferA, 31999, &dwSize))
{
if(dwSize != 0)
{
lpBufferA [dwSize] = '\0';
dwSize = MultiByteToWideChar (CP_ACP, 0, lpBufferA, -1, NULL, 0);
lpBufferW = new TCHAR [dwSize];
MultiByteToWideChar (CP_ACP, 0, lpBufferA, -1, lpBufferW, dwSize);
}
}
InternetCloseHandle(hConnect);
}
InternetCloseHandle(hInternet);
}
lpBufferW[3] = '\0';
if (_tcscmp(lpBufferW, _T("200")) != 0){
TCHAR szMsg[256];
if(addingMode)
wsprintf(szMsg, TEXT("Adding this entry failed!\nCode: %s"), lpBufferW);
else
wsprintf(szMsg, TEXT("Editing this entry failed!\nCode: %s"), lpBufferW);
if (MessageBox(hDlg, szMsg, _T("Tabuleèka"), MB_RETRYCANCEL | MB_ICONERROR) == IDRETRY){
entryBoxRetry = true;
PatchEntry(hDlg, addingMode);
}
}
}
// **************************************************************************
// Function Name: MouseHack
//
// Arguments: bool
//
// Return Values:
//
// Description: HACK!!!!!! another win32/compiler quirk
// **************************************************************************
void MouseHack(BOOL wait)
{
//HACK!)!!!!