-
Notifications
You must be signed in to change notification settings - Fork 0
/
common.c
1356 lines (1046 loc) · 39.2 KB
/
common.c
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
//***************************************************************************
// NARS2000 -- Common Processing Routines
//***************************************************************************
/***************************************************************************
NARS2000 -- An Experimental APL Interpreter
Copyright (C) 2006-2016 Sudley Place Software
This program 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.
This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
***************************************************************************/
#define STRICT
#include <windows.h>
#include <stdio.h>
#include <direct.h>
#include "headers.h"
//************************************************************************
// $ClientToWindowSize
//
// Convert client area size to window size
//************************************************************************
SIZE ClientToWindowSize
(HWND hWnd,
SIZE Size)
{
RECT rc;
// Create a rectangle
rc.left = 0;
rc.right = rc.left + Size.cx;
rc.top = 0;
rc.bottom = rc.top + Size.cy;
// Adjust the rectangle from client to window
AdjustWindowRectEx (&rc,
GetWindowLongW (hWnd, GWL_STYLE),
GetClassLongPtrW (hWnd, GCLP_MENUNAME) NE 0,
GetWindowLongW (hWnd, GWL_EXSTYLE)
);
Size.cx = rc.right - rc.left;
Size.cy = rc.bottom - rc.top;
return Size;
} // End ClientToWindowSize
//************************************************************************
// $MoveWindowPos
//
// Move the window to a position based upon the previous center
//************************************************************************
void MoveWindowPos
(HWND hWnd,
POINT PosCtr)
{
RECT rcWnd;
long lWidth, lHeight;
GetWindowRect (hWnd, &rcWnd); // Get the window's RECT
lWidth = rcWnd.right - rcWnd.left; // Calc the width
lHeight = rcWnd.bottom - rcWnd.top; // Calc the height
MoveWindow (hWnd,
PosCtr.x - lWidth/2, // Left coordinate
PosCtr.y - lHeight/2, // Top ...
lWidth, // Width
lHeight, // Height
FALSE); // No re-paint
} // End MoveWindowPos
//************************************************************************
// $MoveWindowPosSize
//
// Move the window to a position based upon the previous center and size
//************************************************************************
void MoveWindowPosSize
(HWND hWnd,
POINT PosCtr,
SIZE Size)
{
MoveWindow (hWnd,
PosCtr.x - Size.cx/2, // Left coordinate
PosCtr.y - Size.cy/2, // Top ...
Size.cx, // Width
Size.cy, // Height
FALSE); // No re-paint
} // End MoveWindowPosSize
//************************************************************************
// $EnumCallbackMonitors
//
// Callback routine for EnumDisplayMonitors
//************************************************************************
UBOOL CALLBACK EnumCallbackMonitors
(HMONITOR hMonitor, // Handle to display monitor
HDC hdcMonitor, // Handle to monitor DC
LPRECT lprcMonitor, // Monitor intersection rectangle
LPARAM dwData) // Data
{
// Save the monitor coordinates
*((LPRECT) dwData) = *lprcMonitor;
// Tell W to stop enumerating
return FALSE;
} // End EnumCallbackMonitors
//************************************************************************
// $CenterWindow
//
// Center a window on the monitor that contains
// the center of the Master Frame
//************************************************************************
void CenterWindow
(HWND hWndCT) // Window to center
{
RECT rcWndMF, // Master Frame window rect
rcWndCT; // Window-to-center rect
POINT PosCtr; // Position of the center of the window-to-center
HMONITOR hMonitor; // Monitor handle
MONITORINFO monInfo; // Monitor info struct
int iOff; // Non-negative offset to avoid top of window
// being out-of-sight
// Get the window rect of the Master Frame
GetWindowRect (hWndMF, &rcWndMF);
// Get the window rect of the window-to-center
GetWindowRect (hWndCT, &rcWndCT);
// Get the point in the center of the Master Frame.
PosCtr.x = (rcWndMF.left + rcWndMF.right ) / 2;
PosCtr.y = (rcWndMF.top + rcWndMF.bottom) / 2;
// Get the handle of the monitor that contains this point
hMonitor = MonitorFromPoint (PosCtr, MONITOR_DEFAULTTONEAREST);
// Get the monitor rectangle
monInfo.cbSize = sizeof (monInfo);
GetMonitorInfo (hMonitor, &monInfo);
// Ensure that the top of the window-to-center
// isn't above the top of the selected monitor
iOff = monInfo.rcMonitor.top - min (monInfo.rcMonitor.top, PosCtr.y - (rcWndCT.bottom - rcWndCT.top) / 2);
// Move the monitor rectangle down as necessary
PosCtr.y += iOff;
// Move the window into position
MoveWindowPos (hWndCT, PosCtr);
} // End CenterWindow
//****************************************************************************
// $IsWhite
//
// Determine if a char is white space
//****************************************************************************
UBOOL IsWhite
(char c)
{
return (c EQ ' ' || c EQ '\t');
} // End IsWhite
//****************************************************************************
// $IsWhiteW
//
// Determine if a wide char is white space
//****************************************************************************
UBOOL IsWhiteW
(WCHAR wc)
{
return (wc EQ L' ' || wc EQ WC_HT);
} // End IsWhiteW
//****************************************************************************
// $SkipWhite
//
// Skip over leading white space
//****************************************************************************
LPCHAR SkipWhite
(LPCHAR lp)
{
// Skip over white space
while (IsWhite (*lp))
lp++;
return lp;
} // End SkipWhite
//****************************************************************************
// $SkipWhiteW
//
// Skip over leading white space
//****************************************************************************
LPWCHAR SkipWhiteW
(LPWCHAR lpw)
{
// Skip over white space
while (IsWhiteW (*lpw))
lpw++;
return lpw;
} // End SkipWhiteW
//***************************************************************************
// $SkipBlackW
//
// Skip over leading black space
//***************************************************************************
LPWCHAR SkipBlackW
(LPWCHAR lpw)
{
// Skip over non-white space
while (*lpw && !IsWhiteW (*lpw))
lpw++;
return lpw;
} // End SkipBlackW
//************************************************************************
// $SkipToCharW
//
// Skip to a given WCHAR taking into account EOL
//************************************************************************
LPWCHAR SkipToCharW
(LPWCHAR lpwChar,
WCHAR wChar)
{
LPWCHAR lpw; // Temporary ptr
// Find the char
lpw = strchrW (lpwChar, wChar);
// If it's not found (EOL instead), ...
if (lpw EQ NULL)
lpw = &lpwChar[lstrlenW (lpwChar)];
return lpw;
} // End SkipToCharW
//************************************************************************
// $SkipToStrW
//
// Skip to the first in a given set of WCHARs taking into account EOL
//************************************************************************
LPWCHAR SkipToStrW
(LPWCHAR lpwChar,
LPWCHAR lpwSet)
{
LPWCHAR lpw; // Temporary ptr
// Find the char
lpw = strpbrkW (lpwChar, lpwSet);
// If it's not found (EOL instead), ...
if (lpw EQ NULL)
lpw = &lpwChar[lstrlenW (lpwChar)];
return lpw;
} // End SkipToStrW
//************************************************************************
// $SkipToCharDQW
//
// Skip to a given WCHAR taking into account Double Quotes and EOL
//************************************************************************
LPWCHAR SkipToCharDQW
(LPWCHAR lpwChar,
WCHAR wChar)
{
LPWCHAR lpw; // Temporary ptr
UBOOL uState = FALSE; // DQ state: FALSE = outside DQs,
// TRUE = inside DQs
Assert (wChar NE WC_DQ);
// Loop through the string
for (lpw = lpwChar; *lpw; lpw++)
// Split cases based upon the char
switch (*lpw)
{
case WC_DQ:
// Toggle the DQ state
uState = !uState;
break;
default:
if (!uState // If we're outside DQs
&& *lpw EQ wChar) // and it's a match, ...
return lpw; // Return a ptr to the match
break;
} // End FOR/SWITCH
// If it's not found (EOL instead), ...
if (lpw EQ NULL)
lpw = &lpwChar[lstrlenW (lpwChar)];
return lpw;
} // End SkipToCharDQW
//************************************************************************
// $SkipPastCharW
//
// Skip past a given WCHAR taking into account EOL
//************************************************************************
LPWCHAR SkipPastCharW
(LPWCHAR lpwChar,
WCHAR wChar)
{
LPWCHAR lpw; // Temporary ptr
// Find the char
lpw = strchrW (lpwChar, wChar);
// If it's not found (EOL instead), ...
if (lpw EQ NULL)
// Point to the trailing zero
lpw = &lpwChar[lstrlenW (lpwChar)];
else
// Skip over the trailing char
lpw++;
return lpw;
} // End SkipPastCharW
//************************************************************************
// $SkipPastStr
//
// Skip past a given set of chars taking into account EOL
//************************************************************************
LPCHAR SkipPastStr
(LPCHAR lpChar,
LPCHAR lpStr)
{
LPCHAR lp; // Temporary ptr
size_t iSpn;
// Find the span of the set of chars
iSpn = strspn (lpChar, lpStr);
// If it's not found (EOL instead), ...
if (iSpn EQ 0)
// Point to the trailing zero
lp = &lpChar[lstrlen (lpChar)];
else
// Skip over the trailing chars
lp = &lpChar[iSpn];
return lp;
} // End SkipPastChar
//************************************************************************
// $SkipPastStrW
//
// Skip past a given set of WCHARs taking into account EOL
//************************************************************************
LPWCHAR SkipPastStrW
(LPWCHAR lpwChar,
LPWCHAR lpwStr)
{
LPWCHAR lpw; // Temporary ptr
size_t iSpn;
// Find the span of the set of WCHARs
iSpn = strspnW (lpwChar, lpwStr);
// If it's not found (EOL instead), ...
if (iSpn EQ 0)
// Point to the trailing zero
lpw = &lpwChar[lstrlenW (lpwChar)];
else
// Skip over the trailing chars
lpw = &lpwChar[iSpn];
return lpw;
} // End SkipPastCharW
//***************************************************************************
// $StripDQ
//
// Strip off leading/trailing DQs
//***************************************************************************
LPWCHAR StripDQ
(LPWCHAR lpwszTail)
{
LPWCHAR lpwTemp;
UINT uLen;
if (lpwszTail[0] EQ WC_DQ)
{
// Skip over it
lpwszTail++;
// Skip over leading blanks
lpwszTail = SkipWhiteW (lpwszTail);
// Find the matching DQ
lpwTemp = strchrW (lpwszTail, WC_DQ);
// If present, ...
if (lpwTemp)
// Zap it
*lpwTemp = WC_EOS;
// Get the string length
uLen = lstrlenW (lpwszTail);
// Skip back over trailing white space
while (uLen && IsWhiteW (lpwszTail[uLen - 1]))
uLen --;
// Zap the trailing white space
lpwszTail[uLen] = WC_EOS;
} // End IF
return lpwszTail;
} // End StripDQ
//***************************************************************************
// $GetModuleFileNames
//
// Construct file name(s) based upon where the module is on disk
//***************************************************************************
void GetModuleFileNames
(HINSTANCE hInstance)
{
WCHAR wszDir [_MAX_DIR],
wszDrive[_MAX_DRIVE],
wszFname[_MAX_FNAME],
wszExt [_MAX_EXT];
if (GetModuleFileNameW (hInstance, wszAppDPFE, sizeof (wszAppDPFE)))
{
// Split out the drive and path from the module filename
_wsplitpath (wszAppDPFE, wszDrive, wszDir, wszFname, wszExt);
// Create the .HLP file name
_wmakepath (wszHlpDPFE, wszDrive, wszDir, wszFname, L".HLP");
// Create the APL Font file name
_wmakepath (wszFntDPFE, wszDrive, wszDir, DEF_APLFONT_EXTNAME, DEF_APLFONT_EXT);
// Read in the application's File Version String
LclFileVersionStrW (wszAppDPFE, wszFileVer, sizeof (wszFileVer));
// Read in the COMCTL32.DLL File Version String
LclFileVersionStrW (L"comctl32.dll", wszComctl32FileVer, sizeof (wszComctl32FileVer));
// Get the Comctl32.dll major and minor file version #s
sscanfW (wszComctl32FileVer,
L"%f",
&fComctl32FileVer);
} // End IF
} // End GetModuleFileNames
//***************************************************************************
// $W2A
//
// Convert and copy a wide char string to a multibyte char string
//***************************************************************************
void W2A
(LPSTR lpDest,
LPWSTR lpSrc,
DWORD dwSize)
{
int iLen;
iLen = 1 + lstrlenW (lpSrc); // Get source length
WideCharToMultiByte (CP_ACP, // ANSI code page
0, // No flags
lpSrc, // Source
iLen, // Source length
lpDest, // Destin
dwSize, // Size of destin buffer
NULL, // Use system default char
NULL); // Skip notification
} // End W2A
//***************************************************************************
// $A2W
//
// Convert and copy a multibyte char string to a wide char string
//***************************************************************************
void A2W
(LPWSTR lpDest,
LPSTR lpSrc,
DWORD dwSize)
{
int iLen;
iLen = 1 + lstrlenA (lpSrc); // Get source length
MultiByteToWideChar (CP_ACP, // ANSI code page
0, // No flags
lpSrc, // Source
iLen, // Source length
lpDest, // Destin
dwSize); // Size of destin buffer
} // End A2W
//***************************************************************************
// $FillMemoryW
//
// Fill memory with a wide char
//***************************************************************************
LPWCHAR FillMemoryW
(LPWCHAR lpMemDest,
APLU3264 uLen,
WCHAR wc)
{
while (uLen--)
*lpMemDest++ = wc;
return lpMemDest;
} // End FillMemoryW
//***************************************************************************
// $FillBitMemory
//
// Fill in memory with all 1s handling the last byte specially
//***************************************************************************
void FillBitMemory
(LPAPLBOOL lpMemRes, // Ptr to memory to fill
APLNELM aplNELMRes) // # bits to fill
{
// Fill the leading bytes with 0xFF
FillMemory (lpMemRes, (APLU3264) aplNELMRes >> LOG2NBIB, 0xFF);
// If there are extra bits at the end, ...
if (MASKLOG2NBIB & (UINT) aplNELMRes)
lpMemRes[aplNELMRes >> LOG2NBIB] =
((BIT0 << (MASKLOG2NBIB & (UINT) aplNELMRes)) - 1);
} // End FillBitMemory
#ifdef NEED_IOB_FUNC
//***************************************************************************
// $__iob_func
//***************************************************************************
//FILE _iob[] = {*stdin, *stdout, *stderr};
FILE * __cdecl __iob_func
(void)
{
DbgStop ();
return NULL;
////return _iob;
} // End __iob_func
#endif
#ifdef DEBUG
//***************************************************************************
// $nop
//***************************************************************************
void nop
(void)
{
} // End nop
#endif
#ifdef DEBUG
//***************************************************************************
// $DbgNop
//***************************************************************************
void DbgNop
(void)
{
DbgBrk (); // #ifdef DEBUG
} // End DbgNop
#endif
//***************************************************************************
// $IsValidHandle
//
// Return TRUE iff the given handle is valid
//***************************************************************************
UBOOL IsValidHandle
(HGLOBAL hGlbSrc)
{
__try
{
return ((hGlbSrc NE NULL) && (GlobalFlags (ClrPtrTypeDir (hGlbSrc)) NE GMEM_INVALID_HANDLE));
} __except (EXCEPTION_EXECUTE_HANDLER)
{
return FALSE;
} // End __try/__except
} // End IsValidHandle
//***************************************************************************
// $IsValidPtr
//
// Return TRUE iff the given ptr is valid
//***************************************************************************
UBOOL IsValidPtr
(LPVOID lpMemSrc,
UINT uLen)
{
if (lpMemSrc EQ (LPVOID) -1
|| ((LPBYTE) lpMemSrc) < (LPBYTE) (64*1024))
return FALSE;
__try
{
return !IsBadReadPtr (lpMemSrc, uLen);
} __except (EXCEPTION_EXECUTE_HANDLER)
{
return FALSE;
} // End __try/__except
return FALSE;
} // End IsValidPtr
//***************************************************************************
// $GetDlgUnitsInPixels
//
// Get a dialog's base units in pixels
//***************************************************************************
SIZE GetDlgUnitsInPixels
(HWND hWnd)
{
RECT rcDlg;
SIZE sDlg;
// Set to the unit divisors
rcDlg.left =
rcDlg.top = 0;
rcDlg.right = 4;
rcDlg.bottom = 8;
MapDialogRect (hWnd, &rcDlg);
sDlg.cx = rcDlg.right;
sDlg.cy = rcDlg.bottom;
return sDlg;
} // End GetDlgUnitsInPixels
//************************************************************************
// DrawBitmap
//
// Draw a bitmap in a DC
//************************************************************************
void DrawBitmap
(HDC hDC, // Destination DC
HBITMAP hBitmap, // The bitmap to draw
UINT xDstOrg, // Destin bit origin
UINT yDstOrg) // ...
{
BITMAP bm;
HDC hDCMem;
POINT ptSize, ptOrg;
HBITMAP hBitmapOld;
// Get a Client Area DC for the bitmap
hDCMem = MyCreateCompatibleDC (hDC);
// Select the bitmap into the DC
hBitmapOld = SelectObject (hDCMem, hBitmap);
// Copy the mapping mode from the original DC
SetMapMode (hDCMem, GetMapMode (hDC));
// Get the size of the bitmap
GetObjectA (hBitmap, sizeof (BITMAP), (LPSTR) &bm);
// Save it as a POINT
ptSize.x = bm.bmWidth;
ptSize.y = bm.bmHeight;
// Map the coords from Device to Logical
DPtoLP (hDC, &ptSize, 1);
// Initialize to the upper left corner
ptOrg.x = ptOrg.y = 0;
// Map the coords from Device to Logical
DPtoLP (hDCMem, &ptOrg, 1);
// Copy the bitmap from the memory DC to the destin DC
BitBlt (hDC,
xDstOrg, yDstOrg,
ptSize.x, ptSize.y,
hDCMem,
ptOrg.x, ptOrg.y,
SRCCOPY);
// Restore the old object
SelectObject (hDCMem, hBitmapOld);
// We no longer need this resource
MyDeleteDC (hDCMem); hDCMem = NULL;
} // End DrawBitmap
//***************************************************************************
// $signum
//
// Return -1, 0, +1 depending upon the sign of a given integer
//***************************************************************************
int signum
(APLINT val)
{
if (val < 0)
return -1;
else
return (val > 0);
} // End signum
//***************************************************************************
// $signumint
//
// Return -1, 0, +1 depending upon the sign of a given integer
//***************************************************************************
int signumint
(APLINT val) // Source
{
return (val < 0) ? -1 : (val > 0);
} // End signumint
//***************************************************************************
// $signumflt
//
// Return -1, 0, +1 depending upon the sign of a given float
//***************************************************************************
int signumflt
(APLFLOAT val)
{
return SIGN_APLFLOAT (val) ? -1 : (val > 0);
} // End signumflt
//***************************************************************************
// $signumrat
//
// Is an alias for mpq_sgn which already returns -1, 0, or 1.
//***************************************************************************
//***************************************************************************
// $signumvfp
//
// Return -1, 0, +1 depending upon the sign of a given VFP
//***************************************************************************
int signumvfp
(LPAPLVFP val)
{
return (SIGN_APLVFP (val) ? -1 : mpfr_sgn (val) > 0);
} // End signumvfp
//***************************************************************************
// $GetSystemDate
//
// Fill in the system date with the time set to zero
//***************************************************************************
void GetSystemDate
(LPSYSTEMTIME lpst)
{
// Fill in the date & time
GetSystemTime (lpst);
// Zero the time
lpst->wHour =
lpst->wMinute =
lpst->wSecond =
lpst->wMilliseconds = 0;
} // End GetSystemDate
//***************************************************************************
// $GetDlgItemInt64
//
// 64-bit version of GetDlgItemInt
//***************************************************************************
APLINT GetDlgItemInt64
(HWND hDlg, // Dialog box handle
int nIDDlgItem, // Identifier of the control
UBOOL *lpTranslated, // Return value of success (TRUE) or failure (FALSE) (may be NULL)
UBOOL bSigned) // TRUE iff the result may be signed
{
WCHAR wszTemp[32]; // Output save area
LPWCHAR lpw; // Temporary ptr
APLINT aplInt; // The result
// Get the value as text
if (GetDlgItemTextW (hDlg, nIDDlgItem, wszTemp, strcountof (wszTemp)) NE 0)
{
// Skip over leading blanks
lpw = SkipPastCharW (wszTemp, L' ');
if (bSigned
&& lpw[0] EQ UTF16_OVERBAR)
lpw[0] = L'-';
// Convert to a number
if (sscanfW (lpw, L"%I64u", &aplInt) EQ 1)
{
// Mark as successful
if (lpTranslated)
*lpTranslated = TRUE;
// Return the result
return aplInt;
} // End IF
} // End IF
// Mark as in error
if (lpTranslated)
*lpTranslated = FALSE;
// Return a result of zero
return 0;
} // End GetDlgItemInt64
//***************************************************************************
// $CharFromPos
//
// Handle EM_CHARFROMPOS result, taking into account 16-bit integer overflow
//***************************************************************************
void CharFromPos
(HWND hWndEC, // Edit Ctrl window handle
LRESULT lResult, // The result from SendMessage
LPLONG lplLineNum, // Ptr to Line # (may be NULL)
LPLONG lplCharPos) // Ptr to Char Position (may be NULL)
{
LONG lLineNum, // The line #
lCharPos; // The char position
// Split out the values
lLineNum = HIWORD (lResult);
lCharPos = LOWORD (lResult);
// If the result is valid, ...
if (lResult != -1)
{
LONG lLineVis, // The # of the first visible line
lLinePos; // The char position of the start of the line
lLineVis = (LONG) SendMessageW (hWndEC, EM_GETFIRSTVISIBLELINE, 0, 0);
while (lLineNum < lLineVis)
lLineNum += 65536;
lLinePos = (LONG) SendMessageW (hWndEC, EM_LINEINDEX, lLineNum, 0);
while (lCharPos < lLinePos)
lCharPos += 65536;
} // End IF
// Return the values
if (lplLineNum NE NULL)
*lplLineNum = lLineNum;
if (lplCharPos NE NULL)
*lplCharPos = lCharPos;
} // End CharFromPos
//***************************************************************************
// $MySprintf
//
// String safe version of <wsprintf>
//***************************************************************************
int MySprintf
(LPCHAR lpBuffer, // Ptr to buffer
size_t iCount, // Size of buffer (in bytes)
LPCHAR lpszFmt, // Ptr to format string
...) // The variable list
{
HRESULT hResult; // The result of <StringCbVPrintfW>
va_list vl; // Ptr to variable list
// Initialize the variable list
va_start (vl, lpszFmt);
// wsprintfW the list
hResult = StringCbVPrintf (lpBuffer,
iCount,
lpszFmt,
vl);
// End the variable list
va_end (vl);
#ifdef DEBUG
// If it failed, ...
if (FAILED (hResult))
DbgBrk (); // #ifdef DEBUG
#endif
return lstrlen (lpBuffer);
} // End MySprintf
//***************************************************************************