This repository was archived by the owner on Jan 22, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathHP12c_cDlg.cpp
More file actions
1461 lines (1313 loc) · 44.5 KB
/
HP12c_cDlg.cpp
File metadata and controls
1461 lines (1313 loc) · 44.5 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
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
// Copyright (c) 2007 Hewlett-Packard development company llc
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// - Redistributions of source code must retain the above copyright notice,
// this list of conditions and the disclaimer below.
//
// - Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the disclaimer below in the documentation and/or
// other materials provided with the distribution. Unless a specific license is granted
// to te licencee
//
// HP's name may not be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// DISCLAIMER: THIS SOFTWARE IS PROVIDED BY HP "AS IS" AND ANY EXPRESS OR
// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
// DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
// OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
// EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// ----------------------------------------------------------------------------
#include "stdafx.h"
#include "HP12c_c.h"
#include "HP12c_cDlg.h"
#include "HP12c.h"
#include "system.h"
#include "ScreenHandeling.h"// for LCD data
#include "HP12cButton.h"
#include "graphics.h"
#include "atlimage.h"
// The compiler encountered a function that was marked with deprecated.
// The function may no longer be supported in a future release.
// The warning has been disabled for fopen(...) function
#pragma warning(disable : 4996)
#pragma warning(disable : 4800)
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
extern CVirtualLCD *g_pLCD;
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CAboutDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
virtual BOOL OnInitDialog();
//}}AFX_VIRTUAL
// Implementation
protected:
//{{AFX_MSG(CAboutDlg)
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
private:
CString GetVersionInfo();
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
//{{AFX_DATA_INIT(CAboutDlg)
//}}AFX_DATA_INIT
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
//}}AFX_DATA_MAP
}
/***************************************************************
**
** This member function is called in response to the WM_INITDIALOG message.
**
***************************************************************/
//
BOOL CAboutDlg::OnInitDialog()
{
#ifdef C12
SetWindowText("About HP12C");
SetDlgItemText(IDC_STATIC, CString("PC version of the HP12C calculator"));
#endif
#ifdef C15
SetWindowText("About HP15C");
SetDlgItemText(IDC_STATIC4, CString("PC version of the HP15C calculator"));
#endif
SetDlgItemText(IDC_STATIC_VER_INFO, GetVersionInfo());
return TRUE;
}
/***************************************************************
**
** Function to extract the build date from globally defined
** variable BuildDate in Build.h
**
***************************************************************/
//
CString CAboutDlg::GetVersionInfo()
{
CString ret_val;
u64 b= BuildDate&0xfffffffffffffffLL;
if ((b&0xfff)!=0) b<<=4;
int m,d,y;
m = (int)((b & 0xff00000000000000LL) >> 56);
d = (int)((b & 0x00ff000000000000LL) >> 48);
y = (int)((b & 0x0000ffff00000000LL) >> 32);
ret_val.Format("Version %x %x %x",m ,d ,y );
return ret_val;
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
// No message handlers
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CHP12C_cDlg dialog
CHP12C_cDlg::CHP12C_cDlg(CWnd* pParent /*=NULL*/)
: CDialog(CHP12C_cDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CHP12C_cDlg)
m_nHP12CKeyDown = 0;
m_Touch_Base = NONE;
m_bShiftKeyPressed = false;
m_bHideTitlebar = false;
m_bImgShrinked = false;
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
CHP12C_cDlg::~CHP12C_cDlg()
{
}
void CHP12C_cDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CHP12C_cDlg)
DDX_Control(pDX, IDC_VIRTUAL_LCD, m_VirtualLCD);
DDX_Control(pDX, IDC_STATIC_BG, m_Background);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CHP12C_cDlg, CDialog)
//{{AFX_MSG_MAP(CHP12C_cDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_WM_CHAR()
ON_WM_DESTROY()
ON_WM_LBUTTONUP()
ON_WM_LBUTTONDOWN()
ON_WM_RBUTTONUP()
ON_MESSAGE(WM_MOUSELEAVE, OnMouseLeave)
ON_MESSAGE(WM_DISPLAYCHANGE, OnDisplayChange)
ON_COMMAND(ID_HP20b_ONAF, &CHP12C_cDlg::OnHP12COnOFF)
ON_COMMAND(ID_HP20b_ONC, &CHP12C_cDlg::OnHP12COnC)
ON_COMMAND(ID_HP20b_OND, &CHP12C_cDlg::OnHP12COnD)
ON_COMMAND(ID_HP20b_ONMINUS, &CHP12C_cDlg::OnHP12COnMinus)
ON_COMMAND(ID_HP20b_ONPLUS, &CHP12C_cDlg::OnHP12COnPlus)
ON_COMMAND(ID_HP20b_RESETSTATE, &CHP12C_cDlg::OnHP12CResetState)
//}}AFX_MSG_MAP
ON_COMMAND(ID_HP20b_COPYTOCLIPBOARD, &CHP12C_cDlg::OnHP12CCopytoclipboard)
ON_WM_ACTIVATE()
ON_WM_LBUTTONDBLCLK()
ON_COMMAND(ID_HP20b_EXIT, &CHP12C_cDlg::OnHP12CExit)
ON_COMMAND(ID_HP20b_SHOWCAPTION, &CHP12C_cDlg::OnHP12CShowTitlebar)
//ON_WM_NCLBUTTONUP()
ON_COMMAND(ID_HELP_ABOUTBOX, &CHP12C_cDlg::OnHelpAboutbox)
ON_COMMAND(ID_HELP_HP20BBUSINESSCONSULTANT, &CHP12C_cDlg::OnHelpHp12Cbusinessconsultant)
ON_COMMAND(ID_BUY, &CHP12C_cDlg::OnBuy)
ON_COMMAND(ID_EDIT_COPY_NUMBER, &CHP12C_cDlg::OnEditCopyNumber)
ON_COMMAND(ID_EDIT_PASTE_NUMBER, &CHP12C_cDlg::OnEditPasteNumber)
ON_COMMAND(ID_HP20b_SHOWCAPTION_MENU, &CHP12C_cDlg::OnHP12CShowcaptionMenu)
ON_WM_MOVE()
ON_WM_RBUTTONDOWN()
ON_WM_RBUTTONDBLCLK()
ON_STN_CLICKED(IDC_STATIC_BG, &CHP12C_cDlg::OnStnClickedStaticBg)
ON_COMMAND(ID_CALCULATOR_ASSIGNASDEFAULTHPCALCULATOR, &CHP12C_cDlg::OnCalculatorAssignasdefaulthpcalculator)
ON_COMMAND(ID_CALCULATOR_MANAGEHPCALCULATOREMULATORS, &CHP12C_cDlg::OnCalculatorManagehpcalculatoremulators)
ON_COMMAND(ID_HELP_ADVANCEDHELP, &CHP12C_cDlg::OnHelpAdvancedhelp)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CHP12C_cDlg message handlers
TCalc CALC;
CRITICAL_SECTION criticalsection;
void KeyPressMutex(TCalc *calc)
{
EnterCriticalSection(&criticalsection);
int k= KeyBuffPeek();
if (k>=0) { SendChar(k); execute(calc); }
LeaveCriticalSection(&criticalsection);
}
int TestVoltage(int min, int max)
{
return 30;
}
HANDLE Pipe= 0;
CHP12C_cDlg *dlg;
TCalc *calc= &CALC;
#ifdef executeAnalysis
unsigned int romcoverage[romcoveragesize];
struct sBadCalculationTable badCalcTable[MAX_BAD_CALCULATION];
#endif
int CpuSpeed = 4000;
bool CommunicationPipeConnected= false;
HANDLE ComunicationNamedPipe;
unsigned long __stdcall CommunicationThread(void *p)
{
while (true)
{
if (CommunicationPipeConnected)
{
if (!PeekNamedPipe(ComunicationNamedPipe, NULL, NULL, NULL, NULL, NULL))
{
DWORD er= GetLastError();
if (er=109) CommunicationPipeConnected= false;
}
}
if (!CommunicationPipeConnected)
{
CommunicationPipeConnected= ConnectNamedPipe(ComunicationNamedPipe, NULL);
if (!CommunicationPipeConnected)
{
DWORD er= GetLastError();
if (er==ERROR_PIPE_CONNECTED) CommunicationPipeConnected= true;
if (er==ERROR_NO_DATA) DisconnectNamedPipe(ComunicationNamedPipe);
}
}
if (!CommunicationPipeConnected) { Sleep(100); continue; }
CheckCommunication();
}
}
u32 GetChars(u8 *b, u32 nb, u32 timeout)
{
while (nb!=0)
{
int c= GetChar(300);
if (c==-1) return nb;
*b++= c;
nb--;
}
return 0;
}
void SendChars(u8 const *d, u32 size, bool ForceSend)
{
while (size)
{
if (!CommunicationPipeConnected) return;
DWORD w;
WriteFile(ComunicationNamedPipe, d, size, &w, NULL);
d+= w;
size-= w;
}
}
void SendChar(unsigned char c)
{
if (!CommunicationPipeConnected) return;
DWORD w;
WriteFile(ComunicationNamedPipe, &c, 1, &w, NULL);
}
i32 GetChar()
{
if (!CommunicationPipeConnected) return -1;
DWORD bytes, w;
unsigned char c;
if (!PeekNamedPipe(ComunicationNamedPipe, &c, 1, &bytes, NULL, NULL)) return -1;
if (bytes==0) return -1;
if (!ReadFile(ComunicationNamedPipe, &c, 1, &w, NULL)) return -1;
if (w==0) return -1;
return c;
}
i32 GetChar(u32 timeout)
{
int c= GetChar();
if (c==-1) { Sleep(timeout); c= GetChar(); }
return c;
}
HANDLE KeyEvent;
void UpdateDlgScreen()
{
SendMessage(dlg->m_hWnd, WM_CHAR, '[', 0); //used to force a screen refresh...
}
unsigned long __stdcall CalculationThread(void *p)
{
while (1)
{
WaitForSingleObject(KeyEvent, INFINITE);
while (!KeyBuffEmpty()) KeyPressMutex(calc);
}
}
#ifdef C12
#define PRODUCT_CODE 31
#endif
#ifdef C15
#define PRODUCT_CODE 32
#endif
BOOL CHP12C_cDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
dlg= this;
((CHP12C_cApp *)AfxGetApp())->m_hwndDialog = m_hWnd;
g_pLCD = &m_VirtualLCD;
InitializeCriticalSection(&criticalsection);
initKeyBuffer();
init(calc);
ReadHP12CState(); // load saved state file if exists ....
updatescreen(calc);
KeyEvent= CreateEvent(NULL, false, false, "");
unsigned long id;
CreateThread(NULL, 0, CalculationThread, NULL, 0, &id);
int i= 0;
char name[50];
do {
#ifdef C12
if (i==0) strcpy(name, "\\\\.\\pipe\\hp12c"); else sprintf(name, "\\\\.\\pipe\\hp12c_%d", i);
#endif
#ifdef C15
if (i==0) strcpy(name, "\\\\.\\pipe\\hp15c"); else sprintf(name, "\\\\.\\pipe\\hp15c_%d", i);
#endif
ComunicationNamedPipe= CreateNamedPipe(name, PIPE_ACCESS_DUPLEX, PIPE_TYPE_BYTE|PIPE_READMODE_BYTE|PIPE_WAIT ,1, 8192, 8192, 100, NULL);
i++;
} while (INVALID_HANDLE_VALUE==ComunicationNamedPipe);
CreateThread(NULL, 0, CommunicationThread, NULL, 0, &id);
::GetWindowRect(m_VirtualLCD.m_hWnd, &m_VirtualLCD.m_rcOrgLCDPos);
ScreenToClient(&m_VirtualLCD.m_rcOrgLCDPos);
// if(::GetSystemMetrics(SM_CXSCREEN)<=800){
// ShrinkCalculator();
// }
#ifdef C12
m_Background.SetBitmap(::LoadBitmap(theApp.m_hInstance, MAKEINTRESOURCE(IDB_BITMAP2)) );
#endif
#ifdef C15
m_Background.SetBitmap(::LoadBitmap(theApp.m_hInstance, MAKEINTRESOURCE(IDB_BITMAP1)));
#endif
return TRUE; // return TRUE unless you set the focus to a control
}
/***************************************************************
**
** Function is responsible to remove Test System related menus
**
***************************************************************/
//
void CHP12C_cDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
// If the title bar is hidden, do not accept ALT key
if(m_bHideTitlebar)
if ( nID == SC_KEYMENU )
return;
CDialog::OnSysCommand(nID, lParam);
}
}
/***************************************************************
**
** Override function to filter VK_F10 keystroke. Pressing F10 doesn't generate WM_KEYDOWN.
** F10 is a special key used to activate menu bar.
**
***************************************************************/
//
BOOL CHP12C_cDlg::PreTranslateMessage( MSG* pMsg )
{
if((pMsg->wParam - VK_F1 + 1) == 10/*VK_F10*/) {
if (pMsg->message == WM_SYSKEYDOWN)
HP12CKeyDown(VK_F10);
else if (pMsg->message == WM_SYSKEYUP)
HP12CKeyUp(VK_F10);
return 1;
}
if (pMsg->message == WM_KEYDOWN) { HP12CKeyDown(pMsg->wParam); return 1; }
else if (pMsg->message == WM_KEYUP) { HP12CKeyUp(pMsg->wParam); return 1; }
return CDialog::PreTranslateMessage(pMsg);
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void CHP12C_cDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CHP12C_cDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CHP12C_cDlg::keypress(int a)
{
System.KeyboardMap|= KeyCodeToKeyMap(a);
AddKeyInBuffer(a);
ATLTRACE2("KEY %d added in buffer (buf is %d keys)\r\n", a, (System.BufWrite-System.BufRead) % 16);
SetEvent(KeyEvent);
}
void CHP12C_cDlg::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
{
if (nChar!='[')
keypress(nChar);
else {
UpdateScreenContent(); // copy the graphics on the PC screen
}
}
/***************************************************************
**
** Responsible to add the virtual key code of the current pressed key,
** and fire a WM_KEYUP message for the previous key which the user has
** not released.
**
***************************************************************/
//
void CHP12C_cDlg::ForceHP12CKeyUp(WPARAM wKeyCode)
{
if(m_listKeyCode.size() > 0)
{
list<WPARAM>::iterator iter;
bool already_exists = false;
for (iter = m_listKeyCode.begin(); iter != m_listKeyCode.end(); ++iter){
if(*iter == wKeyCode){ already_exists = true; break ; }
}
if(!already_exists) {
for (iter = m_listKeyCode.begin(); iter != m_listKeyCode.end(); ){
HP12CKeyUp(*iter);
iter = m_listKeyCode.erase(iter);
}
m_listKeyCode.push_back(wKeyCode);
}
}
else
m_listKeyCode.push_back(wKeyCode);
}
/***************************************************************
**
** Responsible to trap keystrokes for non-system keys. Once trapped,
** calls the keypress(...) function
**
***************************************************************/
//
void CHP12C_cDlg::HP12CKeyDown(WPARAM wKeyCode)
{
ForceHP12CKeyUp(wKeyCode);
if(m_Touch_Base == NONE)
{
if(m_wLastVirtualKey != wKeyCode)
{
short key_num = 0;
switch (wKeyCode){
// shift key
case VK_LSHIFT:
case VK_RSHIFT:
case VK_SHIFT: m_bShiftKeyPressed = true; break;
// row1
case 78 : // key N
case VK_F1 : keypress(key_num = 11); break; // key F1
case 89 : // key Y
case VK_F2 : keypress(key_num = 12); break; // key F2
case 80 : // key P
case VK_F3 : keypress(key_num = 13); break; // key F3
case 77 : // key M
case VK_F4 : keypress(key_num = 14); break; // key F4
case 70 : // key F
case VK_F5 : keypress(key_num = 15); break; // key F5
case 65 : // key A
case VK_F6 : keypress(key_num = 16); break; // key F6
//row2
case 67 : // key C
case VK_F7 : keypress(key_num = 21); break; // key F7
case 73 : // key I
case VK_F8 : keypress(key_num = 22); break; // key F8
case 86 : // key V
case VK_F9 : keypress(key_num = 23); break; // key F9
case 66 : // key B
case VK_F10 : keypress(key_num = 24); break; // key F10
case 53 : if(!m_bShiftKeyPressed) keypress(key_num = 53); // key 5
else keypress(key_num = 25); // key %
break;
case VK_F11 : keypress(key_num = 25); break; // key F11
case 82 : // key R
case VK_F12 : keypress(key_num = 26); break; // key F12
//row3
case 13 : keypress(key_num = 31); break;
case 57 : if(!m_bShiftKeyPressed) keypress(key_num = 44); // key 9
else keypress(key_num = 32); // key (
break;
case 48 : if(!m_bShiftKeyPressed) keypress(key_num = 72); // key 0
else keypress(key_num = 33); // key )
break;
case 87 : keypress(key_num = 34); break; //+/-
case 8 : keypress(key_num = 35); break;
//row4
case 38 : keypress(key_num = 41); break; // key Up Arrow
case 103 : keypress(key_num = 42); break; // key Numpad(7)
case 55 : if (!m_bShiftKeyPressed) keypress(key_num = 42); break; // key (7)
case 104 :
case 56 : if(!m_bShiftKeyPressed) keypress(key_num = 43); // key Numpad(8)
else keypress(key_num = 55); // key *
break;
case 105 : keypress(key_num = 44); break; // key Numpad(9)
case 111 : keypress(key_num = 45); break; // key Numpad(/)
case 191 : if (!m_bShiftKeyPressed) keypress(key_num = 45); break; // key (/)
//row5
case 40 : keypress(key_num = 51); break; // key Down Arrow
case 100 : keypress(key_num = 52); break; // key Numpad(4)
case 52 : if (!m_bShiftKeyPressed) keypress(key_num = 52); break; // key (4)
case 101 : keypress(key_num = 53); break; // key Numpad(5)
case 102 : keypress(key_num = 54); break; // key Numpad(6)
case 54 : if (!m_bShiftKeyPressed) keypress(key_num = 54); break; // key (6)
case 106 : keypress(key_num = 55); break; // key Numpad(*)
//row6
case 17 : keypress(key_num = 61); break; // key CTRL
case 97 : keypress(key_num = 62); break; // key Numpad(1)
case 49 : if (!m_bShiftKeyPressed) keypress(key_num = 62); break; // key (1)
case 98 : keypress(key_num = 63); break; // key Numpad(2)
case 50 : if (!m_bShiftKeyPressed) keypress(key_num = 63); break; // key (2)
case 99 : keypress(key_num = 64); break; // key Numpad(3)
case 51 : if (!m_bShiftKeyPressed) keypress(key_num = 64); break; // key (3)
case 109 :
case 189 : keypress(key_num = 65); break; // key Numpad(-)
//row7
case 27 : keypress(key_num = 71); break; // key Esc
case 96 : keypress(key_num = 72); break; // key Numpad(0)
case 110 : keypress(key_num = 73); break; // key Numpad(.)
case 190 : if (!m_bShiftKeyPressed) keypress(key_num = 73); break; // key (.)
case 187 : if(!m_bShiftKeyPressed) keypress(key_num = 74); // key =
else keypress(key_num = 75); // key +
break;
case 107 : keypress(key_num = 75); break; // key Numpad(+)
}
if(key_num > 0){
m_nHP12CKeyDown = key_num;
CHP12CButton HP12C_btn;
m_rgnPressedButton = HP12C_btn.hpGetKeyRegion(m_nHP12CKeyDown);
HDC hDC = ::GetDC(m_Background.m_hWnd);
InvertRgn(hDC, m_rgnPressedButton);
::ReleaseDC(m_Background.m_hWnd, hDC);
m_wLastVirtualKey = wKeyCode;
m_Touch_Base = KEYBOARD;
}
}
}
}
/***************************************************************
**
** Responsible to trap keystrokes for non-system keys. Once trapped,
** calls the keypress(...) function
**
***************************************************************/
//
void CHP12C_cDlg::HP12CKeyUp(WPARAM wKeyCode)
{
if( wKeyCode == VK_LSHIFT || wKeyCode == VK_RSHIFT || wKeyCode == VK_SHIFT)
m_bShiftKeyPressed = false;
if(m_nHP12CKeyDown > 0){
// TRACE1("\n m_nHP12CKeyDown = %d", m_nHP12CKeyDown);
// System.KeyboardMap&= ~KeyCodeToKeyMap(m_nHP12CKeyDown);
CHP12CButton HP12C_btn;
m_rgnPressedButton = HP12C_btn.hpGetKeyRegion(m_nHP12CKeyDown);
HDC hDC = ::GetDC(m_Background.m_hWnd);
InvertRgn(hDC, m_rgnPressedButton);
::ReleaseDC(m_Background.m_hWnd, hDC);
System.KeyboardMap&= ~KeyCodeToKeyMap(m_nHP12CKeyDown);
m_nHP12CKeyDown = 0;
m_wLastVirtualKey = 0;
m_Touch_Base = NONE;
}
}
/***************************************************************
**
** Dump the current HP12C State to the file.
**
***************************************************************/
char *GetSAVEFILE(char *b)
{
GetEnvironmentVariable("APPDATA", b, 256);
#ifdef C12
strcat(b, "\\HP12CState.bin");
#endif
#ifdef C15
strcat(b, "\\HP15CState.bin");
#endif
return b;
}
void CHP12C_cDlg::SaveHP12CState()
{
char buf [300];
FILE *fp;
fp = fopen(GetSAVEFILE(buf), "wb");
if (!fp)
return ;
fwrite(calc, sizeof(CALC),1,fp);
fclose(fp);
}
/***************************************************************
**
** Responsible to read the last saved state
**
***************************************************************/
//
void CHP12C_cDlg::ReadHP12CState()
{
FILE *fp;
char buf [300];
fp = fopen(GetSAVEFILE(buf), "rb");
if (!fp)
return ;
fread(calc, sizeof(CALC),1,fp);
fclose(fp);
UpdateDlgScreen();
ReadRegistry();
}
/***************************************************************
**
** Called to inform the CWnd object that it is being destroyed.
**
***************************************************************/
//
void CHP12C_cDlg::OnDestroy()
{
CDialog::OnDestroy();
SaveHP12CState();
WriteToRegistry();
if(Pipe!= NULL) { CloseHandle(Pipe); Pipe = NULL; }
}
/***************************************************************
**
** Called when the user releases the left mouse button on the button image
** displayed on the calculator. Function is responsible to invert the color
** of the selected button image.
**
***************************************************************/
//
void CHP12C_cDlg::OnLButtonUp(UINT nFlags, CPoint point)
{
if(NULL != m_rgnPressedButton && MOUSE == m_Touch_Base){
HDC hDC = ::GetDC(m_Background.m_hWnd);
InvertRgn(hDC, m_rgnPressedButton);
::ReleaseDC(m_Background.m_hWnd, hDC);
System.KeyboardMap&= ~KeyCodeToKeyMap(m_nCurKeyPadNum);
m_rgnPressedButton = NULL; m_nCurKeyPadNum = 0;
}
if(MOUSE == m_Touch_Base)
m_Touch_Base = NONE;
CDialog::OnLButtonUp(nFlags, point);
}
/***************************************************************
**
** Called when the user presses the left mouse button on the button image
** displayed on the calculator. Function is responsible to invert the color
** of the selected button image.
**
***************************************************************/
//
void CHP12C_cDlg::OnLButtonDown(UINT nFlags, CPoint point)
{
if(m_Touch_Base == NONE) {
CHP12CButton btn;
m_rgnPressedButton = btn.hpGetKeyRegion(&point, &m_nCurKeyPadNum);
if(NULL != m_rgnPressedButton){
keypress(m_nCurKeyPadNum);
HDC hDC = ::GetDC(m_Background.m_hWnd);
InvertRgn(hDC, m_rgnPressedButton);
::ReleaseDC(m_Background.m_hWnd, hDC);
//track when the mouse pointer leaves a window
TRACKMOUSEEVENT tme;
tme.cbSize = sizeof(tme); tme.hwndTrack = m_hWnd; tme.dwFlags = TME_LEAVE;
_TrackMouseEvent(&tme);
}
m_Touch_Base = MOUSE;
}
if(NULL == m_rgnPressedButton){
//To move HP12C without title bar
m_Touch_Base = NONE;
SendMessage(WM_NCLBUTTONDOWN, HTCAPTION, 0);
}
CDialog::OnLButtonDown(nFlags, point);
}
/***************************************************************
**
** Called when the user releases the right mouse button on HP-Logo.
** This function is responsible to display the short cut menu.
**
***************************************************************/
//
void CHP12C_cDlg::OnRButtonUp(UINT nFlags, CPoint point)
{
CHP12CButton btn;
if(btn.hpHitTest(&point)) {
CMenu *pMenu = new CMenu;
pMenu->LoadMenuA(MAKEINTRESOURCE(IDR_MENU3));
// check/uncheck the 'test System' menu item
if(m_bHideTitlebar)
pMenu->CheckMenuItem(ID_HP20b_SHOWCAPTION, MF_BYCOMMAND | MF_CHECKED);
else
pMenu->CheckMenuItem(ID_HP20b_SHOWCAPTION, MF_BYCOMMAND | MF_UNCHECKED);
ClientToScreen(&point);
pMenu->GetSubMenu(0)->TrackPopupMenu(TPM_RIGHTBUTTON, point.x, point.y, this, NULL);
delete pMenu;
}
CDialog::OnRButtonUp(nFlags, point);
}
/***************************************************************
**
** Called when the user presses the right mouse button on GUI
** except LCD Area.
** This function is responsible to sned SHIFT key to calc firmware.
**
***************************************************************/
//
void CHP12C_cDlg::OnRButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
CHP12CButton btn;
if(!btn.hpHitTest(&point))
{
// Forcing to send SHIFT key to calculator firmware
keypress(61);
// HP12CKeyDown(VK_CONTROL );
}
CDialog::OnRButtonDown(nFlags, point);
}
/***************************************************************
**
** Called when the user presses the right mouse button on GUI
** except LCD Area.
** This function is responsible to sned SHIFT key to calc firmware.
**
***************************************************************/
//
void CHP12C_cDlg::OnRButtonDblClk(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
CHP12CButton btn;
if(!btn.hpHitTest(&point))
{
// Forcing to send SHIFT key to calculator firmware
HP12CKeyDown(VK_CONTROL );
HP12CKeyUp(VK_CONTROL );
}
CDialog::OnRButtonDblClk(nFlags, point);
}
/***************************************************************
**
** Called when the mouse pointer leaves a window or hovers over a window for a specified amount of time
**
***************************************************************/
//
LPARAM CHP12C_cDlg::OnMouseLeave(WPARAM wp, LPARAM lp)
{
SendMessage(WM_LBUTTONUP, 0,0);
return 0;
}
/***************************************************************
**
** Called when the user presses 'On OFF' sub-menu
**
***************************************************************/
//
void CHP12C_cDlg::OnHP12COnOFF()
{
keypress(85);
}
/***************************************************************
**
** Called when the user presses 'On C' sub-menu
**
***************************************************************/
//
void CHP12C_cDlg::OnHP12COnC()
{
}
/***************************************************************
**
** Called when the user presses 'On D' sub-menu
**
***************************************************************/
//
void CHP12C_cDlg::OnHP12COnD()
{
}
/***************************************************************
**
** Called when the user presses 'On -' sub-menu
**
***************************************************************/
//
void CHP12C_cDlg::OnHP12COnMinus()
{
}
/***************************************************************
**
** Called when the user presses 'On +' sub-menu
**
***************************************************************/
//
void CHP12C_cDlg::OnHP12COnPlus()
{
}
/***************************************************************
**
** Called when the user presses 'CopyToClipboard' sub-menu
**
***************************************************************/
//
void CHP12C_cDlg::OnHP12CCopytoclipboard()
{
m_VirtualLCD.hpCopyToClipboard();
}
/***************************************************************
**
** Called when the user presses 'Reset State' sub-menu
**
***************************************************************/
void CHP12C_cDlg::OnHP12CResetState()
{
if(AfxMessageBox("Are you sure that you want to reset the calculator?", MB_YESNO | MB_ICONINFORMATION) == IDYES){
init(calc);
updatescreen(calc);
}
}
/***************************************************************
**
** Called when the user double-clicks the left mouse button on the button image
** displayed on the calculator. Function is responsible to invert the color
** of the selected button image.
**
***************************************************************/
//
void CHP12C_cDlg::OnLButtonDblClk(UINT nFlags, CPoint point)
{
CHP12CButton btn;
m_rgnPressedButton = btn.hpGetKeyRegion(&point, &m_nCurKeyPadNum);
if(NULL != m_rgnPressedButton)
{
m_Touch_Base = MOUSE;
keypress(m_nCurKeyPadNum);
HDC hDC = ::GetDC(m_Background.m_hWnd);
InvertRgn(hDC, m_rgnPressedButton);
::ReleaseDC(m_Background.m_hWnd, hDC);