-
Notifications
You must be signed in to change notification settings - Fork 0
/
winmain.c
2002 lines (1785 loc) · 67.1 KB
/
winmain.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
/*
* ReactOS Calc (main program)
*
* Copyright 2007-2017, Carlo Bramini
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "calc.h"
#define HTMLHELP_PATH(_pt) _T("%systemroot%\\Help\\calc.chm::") _T(_pt)
#define MAKE_BITMASK4(_show_b16, _show_b10, _show_b8, _show_b2) \
(((_show_b2) << 0) | \
((_show_b8) << 1) | \
((_show_b10) << 2) | \
((_show_b16) << 3))
#define MAKE_BITMASK5(_transl, _is_stats, _is_ctrl, _show_b16, _show_b10, _show_b8, _show_b2) \
(((_show_b2) << 0) | \
((_show_b8) << 1) | \
((_show_b10) << 2) | \
((_show_b16) << 3) | \
((_is_ctrl) << 5) | \
((_is_stats) << 6) | \
((_transl) << 7))
#define KEY_IS_UP 0x80000000
#define KEY_WAS_DOWN 0x40000000
#define BITMASK_IS_ASCII 0x80
#define BITMASK_IS_STATS 0x40
#define BITMASK_IS_CTRL 0x20
#define BITMASK_HEX_MASK 0x08
#define BITMASK_DEC_MASK 0x04
#define BITMASK_OCT_MASK 0x02
#define BITMASK_BIN_MASK 0x01
#define CALC_CLR_RED RGB(0xFF, 0x00, 0x00)
#define CALC_CLR_BLUE RGB(0x00, 0x00, 0xFF)
#define CALC_CLR_PURP RGB(0xFF, 0x00, 0xFF)
typedef struct {
CHAR key; // Virtual key identifier
WORD idc; // IDC for posting message
} key2code_t;
typedef struct {
WORD idc; // IDC for posting message
CHAR key; // Virtual key identifier
BYTE mask; // enable/disable into the various modes.
COLORREF col; // color used for drawing the text
} key3code_t;
#define CTRL_FLAG 0x100
#define ALT_FLAG 0x200
#define CTRL_A (0x0001+'A'-'A')
#define CTRL_C (0x0001+'C'-'A')
#define CTRL_D (0x0001+'D'-'A')
#define CTRL_L (0x0001+'L'-'A')
#define CTRL_M (0x0001+'M'-'A')
#define CTRL_P (0x0001+'P'-'A')
#define CTRL_R (0x0001+'R'-'A')
#define CTRL_S (0x0001+'S'-'A')
#define CTRL_T (0x0001+'T'-'A')
#define CTRL_V (0x0001+'V'-'A')
#define CTRL_Z (0x0001+'Z'-'A')
static const key3code_t key2code[] = {
/* CONTROL-ID Key asc sta ctl hex dec oct bin */
{ IDC_BUTTON_STA, CTRL_S, MAKE_BITMASK5( 1, 0, 1, 1, 1, 1, 1), CALC_CLR_BLUE, },
{ IDC_BUTTON_AVE, CTRL_A, MAKE_BITMASK5( 1, 1, 1, 1, 1, 1, 1), CALC_CLR_BLUE, },
{ IDC_BUTTON_SUM, CTRL_T, MAKE_BITMASK5( 1, 1, 1, 1, 1, 1, 1), CALC_CLR_BLUE, },
{ IDC_BUTTON_S, CTRL_D, MAKE_BITMASK5( 1, 1, 1, 1, 1, 1, 1), CALC_CLR_BLUE, },
{ IDC_BUTTON_MS, CTRL_M, MAKE_BITMASK5( 1, 0, 1, 1, 1, 1, 1), CALC_CLR_RED, },
{ IDC_BUTTON_MR, CTRL_R, MAKE_BITMASK5( 1, 0, 1, 1, 1, 1, 1), CALC_CLR_RED, },
{ IDC_BUTTON_MP, CTRL_P, MAKE_BITMASK5( 1, 0, 1, 1, 1, 1, 1), CALC_CLR_RED, },
{ IDC_BUTTON_MC, CTRL_L, MAKE_BITMASK5( 1, 0, 1, 1, 1, 1, 1), CALC_CLR_RED, },
{ IDC_BUTTON_0, '0', MAKE_BITMASK5( 1, 0, 0, 1, 1, 1, 1), CALC_CLR_BLUE, },
{ IDC_BUTTON_1, '1', MAKE_BITMASK5( 1, 0, 0, 1, 1, 1, 1), CALC_CLR_BLUE, },
{ IDC_BUTTON_2, '2', MAKE_BITMASK5( 1, 0, 0, 1, 1, 1, 0), CALC_CLR_BLUE, },
{ IDC_BUTTON_3, '3', MAKE_BITMASK5( 1, 0, 0, 1, 1, 1, 0), CALC_CLR_BLUE, },
{ IDC_BUTTON_4, '4', MAKE_BITMASK5( 1, 0, 0, 1, 1, 1, 0), CALC_CLR_BLUE, },
{ IDC_BUTTON_5, '5', MAKE_BITMASK5( 1, 0, 0, 1, 1, 1, 0), CALC_CLR_BLUE, },
{ IDC_BUTTON_6, '6', MAKE_BITMASK5( 1, 0, 0, 1, 1, 1, 0), CALC_CLR_BLUE, },
{ IDC_BUTTON_7, '7', MAKE_BITMASK5( 1, 0, 0, 1, 1, 1, 0), CALC_CLR_BLUE, },
{ IDC_BUTTON_8, '8', MAKE_BITMASK5( 1, 0, 0, 1, 1, 0, 0), CALC_CLR_BLUE, },
{ IDC_BUTTON_9, '9', MAKE_BITMASK5( 1, 0, 0, 1, 1, 0, 0), CALC_CLR_BLUE, },
{ IDC_BUTTON_DOT, '.', MAKE_BITMASK5( 1, 0, 0, 0, 1, 0, 0), CALC_CLR_BLUE, },
{ IDC_BUTTON_DOT, ',', MAKE_BITMASK5( 1, 0, 0, 0, 1, 0, 0), -1, },
{ IDC_BUTTON_ADD, '+', MAKE_BITMASK5( 1, 0, 0, 1, 1, 1, 1), CALC_CLR_RED, },
{ IDC_BUTTON_SUB, '-', MAKE_BITMASK5( 1, 0, 0, 1, 1, 1, 1), CALC_CLR_RED, },
{ IDC_BUTTON_MULT, '*', MAKE_BITMASK5( 1, 0, 0, 1, 1, 1, 1), CALC_CLR_RED, },
{ IDC_BUTTON_DIV, '/', MAKE_BITMASK5( 1, 0, 0, 1, 1, 1, 1), CALC_CLR_RED, },
{ IDC_BUTTON_AND, '&', MAKE_BITMASK5( 1, 0, 0, 1, 1, 1, 1), CALC_CLR_RED, },
{ IDC_BUTTON_OR, '|', MAKE_BITMASK5( 1, 0, 0, 1, 1, 1, 1), CALC_CLR_RED, },
{ IDC_BUTTON_XOR, '^', MAKE_BITMASK5( 1, 0, 0, 1, 1, 1, 1), CALC_CLR_RED, },
{ IDC_BUTTON_LSH, '<', MAKE_BITMASK5( 1, 0, 0, 1, 1, 1, 1), CALC_CLR_RED, },
{ IDC_BUTTON_NOT, '~', MAKE_BITMASK5( 1, 0, 0, 1, 1, 1, 1), CALC_CLR_RED, },
{ IDC_BUTTON_INT, ';', MAKE_BITMASK5( 1, 0, 0, 0, 1, 0, 0), CALC_CLR_RED, },
{ IDC_BUTTON_EQU, '=', MAKE_BITMASK5( 1, 0, 0, 1, 1, 1, 1), CALC_CLR_RED, },
{ IDC_BUTTON_A, 'A', MAKE_BITMASK5( 1, 0, 0, 1, 0, 0, 0), CALC_CLR_BLUE, },
{ IDC_BUTTON_B, 'B', MAKE_BITMASK5( 1, 0, 0, 1, 0, 0, 0), CALC_CLR_BLUE, },
{ IDC_BUTTON_C, 'C', MAKE_BITMASK5( 1, 0, 0, 1, 0, 0, 0), CALC_CLR_BLUE, },
{ IDC_BUTTON_D, 'D', MAKE_BITMASK5( 1, 0, 0, 1, 0, 0, 0), CALC_CLR_BLUE, },
{ IDC_BUTTON_E, 'E', MAKE_BITMASK5( 1, 0, 0, 1, 0, 0, 0), CALC_CLR_BLUE, },
{ IDC_BUTTON_F, 'F', MAKE_BITMASK5( 1, 0, 0, 1, 0, 0, 0), CALC_CLR_BLUE, },
{ IDC_CHECK_HYP, 'H', MAKE_BITMASK5( 1, 0, 0, 1, 1, 1, 1), -1, },
{ IDC_CHECK_INV, 'I', MAKE_BITMASK5( 1, 0, 0, 1, 1, 1, 1), -1, },
{ IDC_BUTTON_LOG, 'L', MAKE_BITMASK5( 1, 0, 0, 0, 1, 0, 0), CALC_CLR_PURP, },
{ IDC_BUTTON_DMS, 'M', MAKE_BITMASK5( 1, 0, 0, 0, 1, 0, 0), CALC_CLR_PURP, },
{ IDC_BUTTON_LN, 'N', MAKE_BITMASK5( 1, 0, 0, 0, 1, 0, 0), CALC_CLR_PURP, },
{ IDC_BUTTON_PI, 'P', MAKE_BITMASK5( 1, 0, 0, 0, 1, 0, 0), CALC_CLR_BLUE, },
{ IDC_BUTTON_RX, 'R', MAKE_BITMASK5( 1, 0, 0, 0, 1, 0, 0), CALC_CLR_PURP, },
{ IDC_BUTTON_SIN, 'S', MAKE_BITMASK5( 1, 0, 0, 0, 1, 0, 0), CALC_CLR_PURP, },
{ IDC_BUTTON_COS, 'O', MAKE_BITMASK5( 1, 0, 0, 0, 1, 0, 0), CALC_CLR_PURP, },
{ IDC_BUTTON_TAN, 'T', MAKE_BITMASK5( 1, 0, 0, 0, 1, 0, 0), CALC_CLR_PURP, },
{ IDC_BUTTON_FE, 'V', MAKE_BITMASK5( 1, 0, 0, 0, 1, 0, 0), CALC_CLR_PURP, },
{ IDC_BUTTON_EXP, 'X', MAKE_BITMASK5( 1, 0, 0, 0, 1, 0, 0), CALC_CLR_PURP, },
{ IDC_BUTTON_XeY, 'Y', MAKE_BITMASK5( 1, 0, 0, 1, 1, 1, 1), CALC_CLR_PURP, },
{ IDC_BUTTON_SQRT, '@', MAKE_BITMASK5( 1, 0, 0, 0, 1, 0, 0), CALC_CLR_BLUE, },
{ IDC_BUTTON_Xe2, '@', MAKE_BITMASK5( 1, 0, 0, 1, 1, 1, 1), CALC_CLR_PURP, },
{ IDC_BUTTON_Xe3, '#', MAKE_BITMASK5( 1, 0, 0, 1, 1, 1, 1), CALC_CLR_PURP, },
{ IDC_BUTTON_NF, '!', MAKE_BITMASK5( 1, 0, 0, 1, 1, 1, 1), CALC_CLR_PURP, },
{ IDC_BUTTON_LEFTPAR, '(', MAKE_BITMASK5( 1, 0, 0, 1, 1, 1, 1), CALC_CLR_PURP, },
{ IDC_BUTTON_RIGHTPAR, ')', MAKE_BITMASK5( 1, 0, 0, 1, 1, 1, 1), CALC_CLR_PURP, },
{ IDC_BUTTON_MOD, '%', MAKE_BITMASK5( 1, 0, 0, 1, 1, 1, 1), CALC_CLR_RED, },
{ IDC_BUTTON_PERCENT, '%', MAKE_BITMASK5( 1, 0, 0, 0, 1, 0, 0), CALC_CLR_BLUE, },
/*----------------------------------------------------------------------*/
{ IDC_BUTTON_DAT, VK_INSERT, MAKE_BITMASK5( 0, 1, 0, 1, 1, 1, 1), CALC_CLR_BLUE, },
{ IDC_BUTTON_EQU, VK_RETURN, MAKE_BITMASK5( 0, 0, 0, 1, 1, 1, 1), CALC_CLR_RED, },
{ IDC_BUTTON_CANC, VK_ESCAPE, MAKE_BITMASK5( 0, 0, 0, 1, 1, 1, 1), CALC_CLR_RED, },
{ IDC_BUTTON_CE, VK_DELETE, MAKE_BITMASK5( 0, 0, 0, 1, 1, 1, 1), CALC_CLR_RED, },
{ IDC_BUTTON_BACK, VK_BACK, MAKE_BITMASK5( 0, 0, 0, 1, 1, 1, 1), CALC_CLR_RED, },
{ IDC_RADIO_HEX, VK_F5, MAKE_BITMASK5( 0, 0, 0, 1, 1, 1, 1), -1, },
{ IDC_RADIO_DEC, VK_F6, MAKE_BITMASK5( 0, 0, 0, 1, 1, 1, 1), -1, },
{ IDC_RADIO_OCT, VK_F7, MAKE_BITMASK5( 0, 0, 0, 1, 1, 1, 1), -1, },
{ IDC_RADIO_BIN, VK_F8, MAKE_BITMASK5( 0, 0, 0, 1, 1, 1, 1), -1, },
{ IDC_BUTTON_SIGN, VK_F9, MAKE_BITMASK5( 0, 0, 0, 1, 1, 1, 1), CALC_CLR_BLUE, },
};
static const key2code_t key2code_base16[] = {
{ VK_F2, IDC_RADIO_DWORD, },
{ VK_F3, IDC_RADIO_WORD, },
{ VK_F4, IDC_RADIO_BYTE, },
{ VK_F12, IDC_RADIO_QWORD, },
};
static const key2code_t key2code_base10[] = {
{ VK_F2, IDC_RADIO_DEG, },
{ VK_F3, IDC_RADIO_RAD, },
{ VK_F4, IDC_RADIO_GRAD, },
};
static const WORD operator_codes[] = {
/* CONTROL-ID operator */
(WORD)IDC_STATIC, // RPN_OPERATOR_PARENT
IDC_BUTTON_PERCENT, // RPN_OPERATOR_PERCENT
IDC_BUTTON_EQU, // RPN_OPERATOR_EQUAL
IDC_BUTTON_OR, // RPN_OPERATOR_OR
IDC_BUTTON_XOR, // RPN_OPERATOR_XOR
IDC_BUTTON_AND, // RPN_OPERATOR_AND
IDC_BUTTON_LSH, // RPN_OPERATOR_LSH
IDC_BUTTON_RSH, // RPN_OPERATOR_RSH
IDC_BUTTON_ADD, // RPN_OPERATOR_ADD
IDC_BUTTON_SUB, // RPN_OPERATOR_SUB
IDC_BUTTON_MULT, // RPN_OPERATOR_MULT
IDC_BUTTON_DIV, // RPN_OPERATOR_DIV
IDC_BUTTON_MOD, // RPN_OPERATOR_MOD
IDC_BUTTON_XeY, // RPN_OPERATOR_POW
IDC_BUTTON_XrY, // RPN_OPERATOR_SQR
};
typedef void (*rpn_callback1)(calc_number_t *);
typedef struct {
WORD idc;
BYTE range;
BYTE check_nan;
rpn_callback1 direct;
rpn_callback1 inverse;
rpn_callback1 hyperb;
rpn_callback1 inv_hyp;
} function_table_t;
static void run_fe(calc_number_t *number);
static void run_dat_sta(calc_number_t *number);
static void run_mp(calc_number_t *c);
static void run_mm(calc_number_t *c);
static void run_ms(calc_number_t *c);
static void run_mw(calc_number_t *c);
static void run_canc(calc_number_t *c);
static void run_rpar(calc_number_t *c);
static void run_lpar(calc_number_t *c);
static const function_table_t function_table[] = {
{ IDC_BUTTON_SIN, MODIFIER_INV|MODIFIER_HYP, 1, rpn_sin, rpn_asin, rpn_sinh, rpn_asinh },
{ IDC_BUTTON_COS, MODIFIER_INV|MODIFIER_HYP, 1, rpn_cos, rpn_acos, rpn_cosh, rpn_acosh },
{ IDC_BUTTON_TAN, MODIFIER_INV|MODIFIER_HYP, 1, rpn_tan, rpn_atan, rpn_tanh, rpn_atanh },
{ IDC_BUTTON_INT, MODIFIER_INV, 1, rpn_int, rpn_frac, NULL, NULL },
{ IDC_BUTTON_RX, 0, 1, rpn_reci, NULL, NULL, NULL },
{ IDC_BUTTON_NOT, 0, 1, rpn_not, NULL, NULL, NULL },
{ IDC_BUTTON_PI, MODIFIER_INV, 0, rpn_pi, rpn_2pi, NULL, NULL },
{ IDC_BUTTON_Xe2, MODIFIER_INV, 1, rpn_exp2, rpn_sqrt, NULL, NULL },
{ IDC_BUTTON_Xe3, MODIFIER_INV, 1, rpn_exp3, rpn_cbrt, NULL, NULL },
{ IDC_BUTTON_LN, MODIFIER_INV, 1, rpn_ln, rpn_exp, NULL, NULL },
{ IDC_BUTTON_LOG, MODIFIER_INV, 1, rpn_log, rpn_exp10, NULL, NULL },
{ IDC_BUTTON_NF, 0, 1, rpn_fact, NULL, NULL, NULL },
{ IDC_BUTTON_AVE, MODIFIER_INV, 0, rpn_ave, rpn_ave2, NULL, NULL },
{ IDC_BUTTON_SUM, MODIFIER_INV, 0, rpn_sum, rpn_sum2, NULL, NULL },
{ IDC_BUTTON_S, MODIFIER_INV, 0, rpn_s_m1, rpn_s, NULL, NULL },
{ IDC_BUTTON_SQRT, MODIFIER_INV, 1, rpn_sqrt, NULL, NULL, NULL },
{ IDC_BUTTON_DMS, MODIFIER_INV, 1, rpn_dec2dms, rpn_dms2dec, NULL, NULL },
{ IDC_BUTTON_FE, 0, 1, run_fe, NULL, NULL, NULL },
{ IDC_BUTTON_DAT, 0, 1, run_dat_sta, NULL, NULL, NULL, },
{ IDC_BUTTON_MP, MODIFIER_INV|NO_CHAIN, 1, run_mp, run_mm, NULL, NULL, },
{ IDC_BUTTON_MS, MODIFIER_INV|NO_CHAIN, 1, run_ms, run_mw, NULL, NULL, },
{ IDC_BUTTON_CANC, NO_CHAIN, 0, run_canc, NULL, NULL, NULL, },
{ IDC_BUTTON_RIGHTPAR, NO_CHAIN, 1, run_rpar, NULL, NULL, NULL, },
{ IDC_BUTTON_LEFTPAR, NO_CHAIN, 0, run_lpar, NULL, NULL, NULL, },
};
/* Sub-classing information for theming support */
typedef struct{
BOOL bHover;
WNDPROC oldProc;
} BTNINFO,*LPBTNINFO;
/*
* Global variable declaration
*/
calc_t calc;
/* Hot-state info for theming support */
BTNINFO BtnInfo[255];
UINT BtnCount;
static void UpdateNumberIntl(void)
{
/* Get current user defaults */
if (!GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SDECIMAL, calc.sDecimal, SIZEOF(calc.sDecimal)))
StringCbCopy(calc.sDecimal, sizeof(calc.sDecimal), _T("."));
if (!GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_STHOUSAND, calc.sThousand, SIZEOF(calc.sThousand)))
StringCbCopy(calc.sThousand, sizeof(calc.sThousand), _T(","));
/* get the string lengths */
calc.sDecimal_len = _tcslen(calc.sDecimal);
calc.sThousand_len = _tcslen(calc.sThousand);
}
static int LoadRegInt(LPCTSTR lpszApp, LPCTSTR lpszKey, int iDefault)
{
HKEY hKey;
int iValue;
DWORD tmp;
if (RegOpenKeyEx(HKEY_CURRENT_USER, lpszApp, 0, KEY_QUERY_VALUE, &hKey) == ERROR_SUCCESS)
{
/* Try to load integer value */
tmp = sizeof(int);
if (RegQueryValueEx(hKey, lpszKey, NULL, NULL, (LPBYTE)&iValue, &tmp) == ERROR_SUCCESS)
iDefault = iValue;
/* close the key */
RegCloseKey(hKey);
}
return iDefault;
}
static void SaveRegInt(LPCTSTR lpszApp, LPCTSTR lpszKey, int iValue)
{
HKEY hKey;
if (RegCreateKeyEx(HKEY_CURRENT_USER, lpszApp, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_SET_VALUE, NULL, &hKey, NULL) == ERROR_SUCCESS)
{
RegSetValueEx(hKey, lpszKey, 0, REG_DWORD, (const BYTE*)&iValue, sizeof(int));
/* close the key */
RegCloseKey(hKey);
}
}
static void load_config(void)
{
OSVERSIONINFO osvi;
osvi.dwOSVersionInfoSize = sizeof(osvi);
GetVersionEx(&osvi);
switch (osvi.dwPlatformId) {
case VER_PLATFORM_WIN32s:
case VER_PLATFORM_WIN32_WINDOWS:
/* Try to load last selected layout */
calc.layout = GetProfileInt(_T("SciCalc"), _T("layout"), CALC_LAYOUT_STANDARD);
/* Try to load last selected formatting option */
calc.usesep = (GetProfileInt(_T("SciCalc"), _T("UseSep"), FALSE)) ? TRUE : FALSE;
break;
default: /* VER_PLATFORM_WIN32_NT */
/* Try to load last selected layout */
calc.layout = LoadRegInt(_T("SOFTWARE\\Microsoft\\Calc"), _T("layout"), CALC_LAYOUT_STANDARD);
/* Try to load last selected formatting option */
calc.usesep = (LoadRegInt(_T("SOFTWARE\\Microsoft\\Calc"), _T("UseSep"), FALSE)) ? TRUE : FALSE;
break;
}
/* memory is empty at startup */
calc.is_memory = FALSE;
/* Get locale info for numbers */
UpdateNumberIntl();
}
static void save_config(void)
{
TCHAR buf[32];
OSVERSIONINFO osvi;
osvi.dwOSVersionInfoSize = sizeof(osvi);
GetVersionEx(&osvi);
switch (osvi.dwPlatformId) {
case VER_PLATFORM_WIN32s:
case VER_PLATFORM_WIN32_WINDOWS:
StringCbPrintf(buf, sizeof(buf), _T("%lu"), calc.layout);
WriteProfileString(_T("SciCalc"), _T("layout"), buf);
WriteProfileString(_T("SciCalc"), _T("UseSep"), (calc.usesep==TRUE) ? _T("1") : _T("0"));
break;
default: /* VER_PLATFORM_WIN32_NT */
SaveRegInt(_T("SOFTWARE\\Microsoft\\Calc"), _T("layout"), calc.layout);
SaveRegInt(_T("SOFTWARE\\Microsoft\\Calc"), _T("UseSep"), calc.usesep);
break;
}
}
static LRESULT post_key_press(LPARAM lParam, WORD idc)
{
HWND hCtlWnd = GetDlgItem(calc.hWnd,idc);
TCHAR ClassName[64];
/* check if the key is enabled! */
if (!IsWindowEnabled(hCtlWnd))
return 1;
if (!GetClassName(hCtlWnd, ClassName, SIZEOF(ClassName)))
return 1;
if (!_tcscmp(ClassName, WC_BUTTON)) {
DWORD dwStyle = GetWindowLongPtr(hCtlWnd, GWL_STYLE) & 0xF;
/* Set states for press/release, but only for push buttons */
if (dwStyle == BS_PUSHBUTTON || dwStyle == BS_DEFPUSHBUTTON || dwStyle == BS_OWNERDRAW) {
if (!(lParam & KEY_WAS_DOWN)) {
PostMessage(hCtlWnd, BM_SETSTATE, 1, 0);
} else
if ((lParam & KEY_IS_UP)) {
PostMessage(hCtlWnd, BM_SETSTATE, 0, 0);
PostMessage(hCtlWnd, BM_CLICK, 0, 0);
}
return 1;
}
}
/* default action: simple click event at key release */
if ((lParam & KEY_IS_UP)) {
PostMessage(hCtlWnd, BM_CLICK, 0, 0);
}
return 1;
}
static int vk2ascii(unsigned int vk)
{
unsigned short int s;
int scan;
BYTE state[256];
HKL layout=GetKeyboardLayout(0);
if(!GetKeyboardState(state))
return 0;
scan=MapVirtualKeyEx(vk, 0, layout);
s = 0;
if (ToAsciiEx(vk, scan, state, &s, 0, layout)>0) {
/* convert to upper case */
if (s >= 'a' && s <= 'z')
s = s - 'a' + 'A';
/* add check to CTRL key */
if (vk >= 'A' && vk <= 'Z' &&
s >= CTRL_A && s <= CTRL_Z)
s |= CTRL_FLAG;
else
if (GetAsyncKeyState(VK_MENU) < 0)
s |= ALT_FLAG;
return s;
}
return 0;
}
static int process_vk_key(WPARAM wParam, LPARAM lParam)
{
const key2code_t *k;
unsigned int x;
unsigned short int ch;
ch = vk2ascii(LOWORD(wParam));
if ((lParam & KEY_IS_UP)) {
/* Test for "copy" to clipboard */
if (ch == (CTRL_C|CTRL_FLAG)) {
SendMessage(calc.hWnd, WM_COMMAND, IDM_EDIT_COPY, 0);
return 1;
}
/* Test for "paste" from clipboard */
if (ch == (CTRL_V|CTRL_FLAG)) {
SendMessage(calc.hWnd, WM_COMMAND, IDM_EDIT_PASTE, 0);
return 1;
}
/* Test of help menu */
if (LOWORD(wParam) == VK_F1) {
SendMessage(calc.hWnd, WM_COMMAND, IDM_HELP_HELP, 0);
return 1;
}
}
for (x=0; x<SIZEOF(key2code); x++) {
int key = key2code[x].key;
if (key2code[x].mask & BITMASK_IS_CTRL)
key |= CTRL_FLAG;
if ((key == ch && (key2code[x].mask & BITMASK_IS_ASCII)) ||
(key == LOWORD(wParam) && !(key2code[x].mask & BITMASK_IS_ASCII))
) {
if (GetDlgItem(calc.hWnd, key2code[x].idc) == NULL)
continue;
return post_key_press(lParam, key2code[x].idc);
}
}
if (calc.layout == CALC_LAYOUT_SCIENTIFIC) {
if (calc.base == IDC_RADIO_DEC) {
k = key2code_base10;
x = SIZEOF(key2code_base10);
} else {
k = key2code_base16;
x = SIZEOF(key2code_base16);
}
do {
if (k->key == LOWORD(wParam)) {
return post_key_press(lParam, k->idc);
}
k++;
} while (--x);
}
return 0;
}
#ifdef USE_KEYBOARD_HOOK
static LRESULT CALLBACK
KeyboardHookProc(int nCode, WPARAM wParam, LPARAM lParam)
{
if(nCode<0 || calc.is_menu_on)
return CallNextHookEx(calc.hKeyboardHook,nCode,wParam,lParam);
if(nCode==HC_ACTION)
if (process_vk_key(wParam, lParam))
return;
return CallNextHookEx(calc.hKeyboardHook,nCode,wParam,lParam);
}
#endif
static void update_lcd_display(HWND hwnd)
{
/*
* multiply size of calc.buffer by 2 because it may
* happen that separator is used between each digit.
* Also added little additional space for dot and '\0'.
*/
TCHAR tmp[MAX_CALC_SIZE * 2 + 2];
if (calc.buffer[0] == _T('\0'))
StringCbCopy(tmp, sizeof(tmp), _T("0"));
else
StringCbCopy(tmp, sizeof(tmp), calc.buffer);
/* Add final '.' in decimal mode (if it's missing), but
* only if it's a result: no append if it prints "ERROR".
*/
if (calc.base == IDC_RADIO_DEC && !calc.is_nan) {
if (_tcschr(tmp, _T('.')) == NULL)
StringCbCat(tmp, sizeof(tmp), _T("."));
}
/* if separator mode is on, let's add an additional space */
if (calc.usesep && !calc.sci_in && !calc.sci_out && !calc.is_nan) {
/* go to the integer part of the string */
TCHAR *p = _tcschr(tmp, _T('.'));
TCHAR *e = _tcschr(tmp, _T('\0'));
int n=0, t;
if (p == NULL) p = e;
switch (calc.base) {
case IDC_RADIO_HEX:
case IDC_RADIO_BIN:
t = 4;
break;
default:
/* fall here for:
IDC_RADIO_DEC:
IDC_RADIO_OCT: */
t = 3;
break;
}
while (--p > tmp) {
if (++n == t && *(p-1) != _T('-')) {
memmove(p+1, p, (e-p+1)*sizeof(TCHAR));
e++;
*p = _T(' ');
n = 0;
}
}
/* if decimal mode, apply regional settings */
if (calc.base == IDC_RADIO_DEC) {
TCHAR *p = tmp;
TCHAR *e = _tcschr(tmp, _T('.'));
/* searching for thousands default separator */
while (p < e) {
if (*p == _T(' ')) {
memmove(p+calc.sThousand_len, p+1, _tcslen(p)*sizeof(TCHAR));
memcpy(p, calc.sThousand, calc.sThousand_len*sizeof(TCHAR));
p += calc.sThousand_len;
} else
p++;
}
/* update decimal point too. */
memmove(p+calc.sDecimal_len, p+1, _tcslen(p)*sizeof(TCHAR));
memcpy(p, calc.sDecimal, calc.sDecimal_len*sizeof(TCHAR));
}
} else {
TCHAR *p = _tcschr(tmp, _T('.'));
/* update decimal point when usesep is false */
if (p != NULL) {
memmove(p+calc.sDecimal_len, p+1, _tcslen(p)*sizeof(TCHAR));
memcpy(p, calc.sDecimal, calc.sDecimal_len*sizeof(TCHAR));
}
}
SetDlgItemText(hwnd, IDC_TEXT_OUTPUT, tmp);
}
static void update_parent_display(HWND hWnd)
{
TCHAR str[8];
int n = eval_parent_count();
if (!n)
str[0] = _T('\0');
else
StringCbPrintf(str, sizeof(str), _T("(=%d"), n);
SetDlgItemText(hWnd, IDC_TEXT_PARENT, str);
}
static void build_operand(HWND hwnd, DWORD idc)
{
unsigned int i = 0, n;
size_t cbPtr;
if (idc == IDC_BUTTON_DOT) {
/* if dot is the first char, it's added automatically */
if (calc.buffer == calc.ptr) {
*calc.ptr++ = _T('0');
*calc.ptr++ = _T('.');
*calc.ptr = _T('\0');
update_lcd_display(hwnd);
return;
}
/* if pressed dot and it's already in the string, then return */
if (_tcschr(calc.buffer, _T('.')) != NULL)
return;
}
if (idc != IDC_STATIC) {
while (idc != key2code[i].idc) i++;
}
n = calc.ptr - calc.buffer;
if (idc == IDC_BUTTON_0 && n == 0) {
/* no need to put the dot because it's handled by update_lcd_display() */
calc.buffer[0] = _T('0');
calc.buffer[1] = _T('\0');
update_lcd_display(hwnd);
return;
}
switch (calc.base) {
case IDC_RADIO_HEX:
if (n >= 16)
return;
break;
case IDC_RADIO_DEC:
if (n >= SIZEOF(calc.buffer)-1)
return;
if (calc.sci_in) {
if (idc != IDC_STATIC)
calc.esp = (calc.esp * 10 + (key2code[i].key-'0')) % LOCAL_EXP_SIZE;
if (calc.ptr == calc.buffer)
StringCbPrintf(calc.ptr, sizeof(calc.buffer), _T("0.e%+d"), calc.esp);
else {
/* adds the dot at the end if the number has no decimal part */
if (!_tcschr(calc.buffer, _T('.')))
*calc.ptr++ = _T('.');
cbPtr = sizeof(calc.buffer) - ((BYTE*)calc.ptr - (BYTE*)calc.buffer);
StringCbPrintf(calc.ptr, cbPtr, _T("e%+d"), calc.esp);
}
update_lcd_display(hwnd);
return;
}
break;
case IDC_RADIO_OCT:
if (n >= 22)
return;
break;
case IDC_RADIO_BIN:
if (n >= 64)
return;
break;
}
cbPtr = sizeof(calc.buffer) - ((BYTE*)calc.ptr - (BYTE*)calc.buffer);
StringCbPrintfEx(calc.ptr, cbPtr, &calc.ptr, NULL, STRSAFE_FILL_ON_FAILURE,
_T("%C"), key2code[i].key);
update_lcd_display(hwnd);
}
static void prepare_rpn_result(calc_number_t *rpn, TCHAR *buffer, int size, int base)
{
if (calc.is_nan) {
rpn_zero(&calc.code);
LoadString(calc.hInstance, IDS_MATH_ERROR, buffer, size);
return;
}
prepare_rpn_result_2(rpn, buffer, size, base);
}
static void set_rpn_result(HWND hwnd, calc_number_t *rpn)
{
calc.sci_in = FALSE;
prepare_rpn_result(rpn, calc.buffer, SIZEOF(calc.buffer), calc.base);
calc.ptr = calc.buffer + _tcslen(calc.buffer);
update_lcd_display(hwnd);
update_parent_display(hwnd);
}
static void display_rpn_result(HWND hwnd, calc_number_t *rpn)
{
set_rpn_result(hwnd, rpn);
calc.ptr = calc.buffer;
}
static int get_modifiers(HWND hWnd)
{
int modifiers = 0;
if (IsDlgButtonChecked(hWnd, IDC_CHECK_INV) == BST_CHECKED)
modifiers |= MODIFIER_INV;
if (IsDlgButtonChecked(hWnd, IDC_CHECK_HYP) == BST_CHECKED)
modifiers |= MODIFIER_HYP;
return modifiers;
}
static void convert_text2number(calc_number_t *a)
{
/* if the screen output buffer is empty, then */
/* the operand is taken from the last input */
if (calc.buffer == calc.ptr) {
/* if pushed valued is ZERO then we should grab it */
if (!_tcscmp(calc.buffer, _T("0.")) ||
!_tcscmp(calc.buffer, _T("0")))
/* this zero is good for both integer and decimal */
rpn_zero(a);
else
rpn_copy(a, &calc.code);
return;
}
/* ZERO is the default value for all numeric bases */
rpn_zero(a);
convert_text2number_2(a);
}
static const struct _update_check_menus {
DWORD *sel;
WORD idm;
WORD idc;
} upd[] = {
{ &calc.layout, IDM_VIEW_STANDARD, CALC_LAYOUT_STANDARD },
{ &calc.layout, IDM_VIEW_SCIENTIFIC, CALC_LAYOUT_SCIENTIFIC },
{ &calc.layout, IDM_VIEW_CONVERSION, CALC_LAYOUT_CONVERSION },
/*-----------------------------------------*/
{ &calc.base, IDM_VIEW_HEX, IDC_RADIO_HEX, },
{ &calc.base, IDM_VIEW_DEC, IDC_RADIO_DEC, },
{ &calc.base, IDM_VIEW_OCT, IDC_RADIO_OCT, },
{ &calc.base, IDM_VIEW_BIN, IDC_RADIO_BIN, },
/*-----------------------------------------*/
{ &calc.degr, IDM_VIEW_DEG, IDC_RADIO_DEG, },
{ &calc.degr, IDM_VIEW_RAD, IDC_RADIO_RAD, },
{ &calc.degr, IDM_VIEW_GRAD, IDC_RADIO_GRAD, },
/*-----------------------------------------*/
{ &calc.size, IDM_VIEW_QWORD, IDC_RADIO_QWORD, },
{ &calc.size, IDM_VIEW_DWORD, IDC_RADIO_DWORD, },
{ &calc.size, IDM_VIEW_WORD, IDC_RADIO_WORD, },
{ &calc.size, IDM_VIEW_BYTE, IDC_RADIO_BYTE, },
};
static void update_menu(HWND hWnd)
{
HMENU hMenu = GetSubMenu(GetMenu(hWnd), 1);
unsigned int x;
for (x=0; x<SIZEOF(upd); x++) {
if (*(upd[x].sel) != upd[x].idc) {
CheckMenuItem(hMenu, upd[x].idm, MF_BYCOMMAND|MF_UNCHECKED);
CheckDlgButton(hWnd, upd[x].idc, BST_UNCHECKED);
} else {
CheckMenuItem(hMenu, upd[x].idm, MF_BYCOMMAND|MF_CHECKED);
CheckDlgButton(hWnd, upd[x].idc, BST_CHECKED);
}
}
CheckMenuItem(hMenu, IDM_VIEW_GROUP, MF_BYCOMMAND|(calc.usesep ? MF_CHECKED : MF_UNCHECKED));
}
typedef struct {
WORD idc;
WORD mask;
} radio_config_t;
static const radio_config_t radio_setup[] = {
/* CONTROL-ID hex dec oct bin */
{ IDC_RADIO_QWORD, MAKE_BITMASK4( 1, 0, 1, 1) },
{ IDC_RADIO_DWORD, MAKE_BITMASK4( 1, 0, 1, 1) },
{ IDC_RADIO_WORD, MAKE_BITMASK4( 1, 0, 1, 1) },
{ IDC_RADIO_BYTE, MAKE_BITMASK4( 1, 0, 1, 1) },
{ IDC_RADIO_DEG, MAKE_BITMASK4( 0, 1, 0, 0) },
{ IDC_RADIO_RAD, MAKE_BITMASK4( 0, 1, 0, 0) },
{ IDC_RADIO_GRAD, MAKE_BITMASK4( 0, 1, 0, 0) },
};
static void enable_allowed_controls(HWND hwnd, DWORD base)
{
BYTE mask;
int n;
switch (base) {
case IDC_RADIO_DEC:
mask = BITMASK_DEC_MASK;
break;
case IDC_RADIO_HEX:
mask = BITMASK_HEX_MASK;
break;
case IDC_RADIO_OCT:
mask = BITMASK_OCT_MASK;
break;
case IDC_RADIO_BIN:
mask = BITMASK_BIN_MASK;
break;
default:
return;
}
for (n=0; n<SIZEOF(key2code); n++) {
if (key2code[n].mask != 0) {
HWND hCtlWnd = GetDlgItem(hwnd, key2code[n].idc);
BOOL current;
if ((key2code[n].mask & BITMASK_IS_STATS))
current = IsWindow(calc.hStatWnd) ? TRUE : FALSE;
else
current = (key2code[n].mask & mask) ? TRUE : FALSE;
if (IsWindowEnabled(hCtlWnd) != current)
EnableWindow(hCtlWnd, current);
}
}
}
static void update_radio(HWND hwnd, unsigned int base)
{
HMENU hMenu;
LPCTSTR lpMenuId;
WORD mask;
int n;
switch (base) {
case IDC_RADIO_DEC:
lpMenuId = MAKEINTRESOURCE(IDR_MENU_SCIENTIFIC_1);
mask = BITMASK_DEC_MASK;
break;
case IDC_RADIO_HEX:
lpMenuId = MAKEINTRESOURCE(IDR_MENU_SCIENTIFIC_2);
mask = BITMASK_HEX_MASK;
break;
case IDC_RADIO_OCT:
lpMenuId = MAKEINTRESOURCE(IDR_MENU_SCIENTIFIC_2);
mask = BITMASK_OCT_MASK;
break;
case IDC_RADIO_BIN:
lpMenuId = MAKEINTRESOURCE(IDR_MENU_SCIENTIFIC_2);
mask = BITMASK_BIN_MASK;
break;
default:
return;
}
if (calc.base != base) {
convert_text2number(&calc.code);
convert_real_integer(base);
calc.base = base;
display_rpn_result(hwnd, &calc.code);
hMenu = GetMenu(hwnd);
DestroyMenu(hMenu);
hMenu = LoadMenu(calc.hInstance, lpMenuId);
SetMenu(hwnd, hMenu);
update_menu(hwnd);
for (n=0; n<SIZEOF(radio_setup); n++)
ShowWindow(GetDlgItem(hwnd, radio_setup[n].idc), (radio_setup[n].mask & mask) ? SW_SHOW : SW_HIDE);
enable_allowed_controls(hwnd, base);
}
CheckRadioButton(hwnd, IDC_RADIO_HEX, IDC_RADIO_BIN, calc.base);
if (base == IDC_RADIO_DEC)
CheckRadioButton(hwnd, IDC_RADIO_DEG, IDC_RADIO_GRAD, calc.degr);
else
CheckRadioButton(hwnd, IDC_RADIO_QWORD, IDC_RADIO_BYTE, calc.size);
}
static void update_memory_flag(HWND hWnd, BOOL mem_flag)
{
calc.is_memory = mem_flag;
SetDlgItemText(hWnd, IDC_TEXT_MEMORY, mem_flag ? _T("M") : _T(""));
}
static void update_n_stats_items(HWND hWnd, TCHAR *buffer, size_t cbBuffer)
{
unsigned int n = SendDlgItemMessage(hWnd, IDC_LIST_STAT, LB_GETCOUNT, 0, 0);
StringCbPrintf(buffer, cbBuffer, _T("n=%u"), n);
SetDlgItemText(hWnd, IDC_TEXT_NITEMS, buffer);
}
static void clean_stat_list(void)
{
statistic_t *p = calc.stat;
while (p != NULL) {
statistic_t *s = p;
p = (statistic_t *)(p->next);
rpn_free(&s->num);
free(s);
}
calc.stat = p;
}
static void delete_stat_item(int n)
{
statistic_t *p = calc.stat;
statistic_t *s;
if (n == 0) {
calc.stat = (statistic_t *)p->next;
rpn_free(&p->num);
free(p);
} else {
s = (statistic_t *)p->next;
while (--n) {
p = s;
s = (statistic_t *)p->next;
}
p->next = s->next;
rpn_free(&s->num);
free(s);
}
}
static char *ReadConversion(const char *formula)
{
size_t len = strlen(formula);
char *str = (char *)malloc(len+3);
if (str == NULL)
return NULL;
str[0] = '(';
memcpy(str+1, formula, len);
str[len+1] = ')';
str[len+2] = '\0';
StringCbCopy(calc.source, sizeof(calc.source), (*calc.buffer == _T('\0')) ? _T("0") : calc.buffer);
/* clear display content before proceeding */
calc.ptr = calc.buffer;
calc.buffer[0] = _T('\0');
return str;
}
static INT_PTR CALLBACK DlgStatProc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp)
{
TCHAR buffer[SIZEOF(calc.buffer)];
DWORD n;
switch (msg) {
case WM_INITDIALOG:
return TRUE;
case WM_COMMAND:
switch (LOWORD(wp)) {
case IDC_LIST_STAT:
if (HIWORD(wp) == CBN_DBLCLK)
SendMessage(hWnd, WM_COMMAND, (WPARAM)IDC_BUTTON_LOAD, 0);
return TRUE;
case IDC_BUTTON_RET:
SetFocus(GetDlgItem(GetParent(hWnd), IDC_BUTTON_FOCUS));
return TRUE;
case IDC_BUTTON_LOAD:
n = SendDlgItemMessage(hWnd, IDC_LIST_STAT, LB_GETCURSEL, 0, 0);
if (n == LB_ERR)
return TRUE;
PostMessage(GetParent(hWnd), WM_LOAD_STAT, (WPARAM)n, 0);
return TRUE;
case IDC_BUTTON_CD:
n = SendDlgItemMessage(hWnd, IDC_LIST_STAT, LB_GETCURSEL, 0, 0);
if (n == LB_ERR)
return TRUE;
SendDlgItemMessage(hWnd, IDC_LIST_STAT, LB_DELETESTRING, (WPARAM)n, 0);
update_n_stats_items(hWnd, buffer, sizeof(buffer));
delete_stat_item(n);
return TRUE;
case IDC_BUTTON_CAD:
SendDlgItemMessage(hWnd, IDC_LIST_STAT, LB_RESETCONTENT, 0, 0);
clean_stat_list();
update_n_stats_items(hWnd, buffer, sizeof(buffer));
return TRUE;
}
break;
case WM_CLOSE:
DestroyWindow(hWnd);
return TRUE;
case WM_DESTROY:
clean_stat_list();
PostMessage(GetParent(hWnd), WM_CLOSE_STATS, 0, 0);
return TRUE;
case WM_INSERT_STAT:
prepare_rpn_result(&(((statistic_t *)lp)->num),
buffer, SIZEOF(buffer),
((statistic_t *)lp)->base);
SendDlgItemMessage(hWnd, IDC_LIST_STAT, LB_ADDSTRING, 0, (LPARAM)buffer);
update_n_stats_items(hWnd, buffer, sizeof(buffer));
return TRUE;
}
return FALSE;
}
static WPARAM idm_2_idc(int idm)
{
int x;
for (x=0; x<SIZEOF(upd); x++) {
if (upd[x].idm == idm)
break;
}
return (WPARAM)(upd[x].idc);
}
static void CopyMemToClipboard(void *ptr)
{
if(OpenClipboard(NULL)) {
HGLOBAL clipbuffer;
TCHAR *buffer;
size_t cbBuffer;
EmptyClipboard();
cbBuffer = (_tcslen(ptr) + 1) * sizeof(TCHAR);
clipbuffer = GlobalAlloc(GMEM_DDESHARE, cbBuffer);