-
Notifications
You must be signed in to change notification settings - Fork 5
/
PuTTYCSDialog.cpp
executable file
·2884 lines (2221 loc) · 65.5 KB
/
PuTTYCSDialog.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
/**
* PuTTYCSDialog.cpp - PuTTYCS Main Dialog
*
* Copyright (c) 2005 - 2008 Jason Millard ([email protected])
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS 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.
*
* REVISION HISTORY:
*
* 11/07/2005: Initial version J. Millard
* 11/17/2005: Added UNICODE support J. Millard
* Added command history clear button
* Added AltGr support
* 11/18/2005: Fixed AltGr support J. Millard
* 12/06/2005: Added mouse Copy/Paste emulation J. Millard
* Navigation through command history
* moves cursor to end of command
* 12/15/2005: Added minimize to system tray J. Millard
* Added tab completion
* 12/19/2005: Added window opacity J. Millard
* 12/21/2005: Fixed password not sending CR J. Millard
* 05/27/2006: Improved system tray logic J. Millard
* Added Windows XP style
* Added close, backspace, and
* delete buttons
* 05/30/2006: Implemented MSDN KB135788 for J. Millard
* system tray context menu
* 11/20/2006: Added support for PuTTYtel and J. Millard
* TuTTY. Added support for user
* defined cascade size. Changed
* scripting to send CR on last line
* if CR button is on.
* 06/21/2007: Added Ctrl-R and Ctrl-D buttons J. Millard
* Added {%CTRL%} command token
* Added {%INC%} command token
* Added scroll command history using
* up/down arrow keys
* Added check for PuTTYCS update
* Added run on system startup
* 02/29/2008: Added horizontal/vertical tiling J. Millard
* Updated cascade logic
* Added post send transition delay
* Added --script command line option
*/
#include "stdafx.h"
#include "PuTTYCS.h"
#include "PuTTYCSDialog.h"
#include "PasswordDialog.h"
#include "PreferencesDialog.h"
#include "FiltersDialog.h"
#include "AboutDialog.h"
#include "Base64.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/**
* CPuTTYCSDialog()::CPuTTYCSDialog()
*/
CPuTTYCSDialog::CPuTTYCSDialog(CWnd* pParent /*=NULL*/)
: CDialog(CPuTTYCSDialog::IDD, pParent)
{
//{{AFX_DATA_INIT(CPuTTYCSDialog)
//}}AFX_DATA_INIT
m_hIcon = AfxGetApp()->LoadIcon( IDR_MAINFRAME );
/**
* Fonts
*/
m_pMarlettNormal = new CFont();
m_pMarlettNormal->CreatePointFont(
100, PUTTYCS_FONT_MARLETT );
m_pMarlettSmall = new CFont();
m_pMarlettSmall->CreatePointFont(
80, PUTTYCS_FONT_MARLETT );
m_pSymbolSmall = new CFont();
m_pSymbolSmall->CreatePointFont(
70, PUTTYCS_FONT_SYMBOL );
/**
* Taskbar Notification Icon
*/
m_pTNI = NULL;
m_uiTaskbarMessage = 0;
/**
* Context Menu
*/
m_pMenu = new CMenu();
m_pMenu->LoadMenu( IDM_SYSTRAY_MENU );
m_bDisablePopup = FALSE;
}
/**
* CPuTTYCSDialog()::~CPuTTYCSDialog()
*/
CPuTTYCSDialog::~CPuTTYCSDialog()
{
SavePreferences();
/**
* Fonts
*/
if ( m_pMarlettNormal )
{
delete m_pMarlettNormal;
}
if ( m_pMarlettSmall )
{
delete m_pMarlettSmall;
}
if ( m_pSymbolSmall )
{
delete m_pSymbolSmall;
}
/**
* Taskbar Notification Icon
*/
if ( m_pTNI )
{
Shell_NotifyIcon( NIM_DELETE,
(NOTIFYICONDATA*) m_pTNI );
delete m_pTNI;
}
/**
* Context Menu
*/
if ( m_pMenu )
{
delete m_pMenu;
}
}
/**
* LoadPreferences()
*/
void CPuTTYCSDialog::LoadPreferences()
{
/**
* PuTTY filters
*/
m_csaFilters.RemoveAll();
for ( int iLoop = 0;
iLoop < PUTTYCS_PREF_FILTER_MAX_SIZE; iLoop++ )
{
CString csAttribute;
csAttribute.Format( PUTTYCS_PREF_FILTER_ENTRY, iLoop );
CString csValue =
AfxGetApp()->GetProfileString(
PUTTYCS_APP_NAME,
csAttribute,
PUTTYCS_EMPTY_STRING );
if ( !csValue.IsEmpty() )
{
m_csaFilters.Add( csValue );
}
}
int size = m_csaFilters.GetSize();
if ( size == 0 )
{
m_csaFilters.Add( PUTTYCS_FILTER_ALL );
m_iFilter = 0;
}
else
{
m_iFilter =
AfxGetApp()->GetProfileInt(
PUTTYCS_APP_NAME, PUTTYCS_PREF_FILTER, 0 );
if ( (m_iFilter + 1) > size )
{
m_iFilter = 0;
}
}
/**
* Command history
*/
m_csaCmdHistory.RemoveAll();
for ( iLoop = 0;
iLoop < PUTTYCS_PREF_CMDHISTORY_MAX_SIZE; iLoop++ )
{
CString csAttribute;
csAttribute.Format( PUTTYCS_PREF_CMDHISTORY_ENTRY, iLoop );
CString csValue =
AfxGetApp()->GetProfileString(
PUTTYCS_APP_NAME,
csAttribute,
PUTTYCS_EMPTY_STRING );
if ( !csValue.IsEmpty() )
{
m_csaCmdHistory.Add( csValue );
}
}
m_iCmdHistory = m_csaCmdHistory.GetSize();
/**
* Window settings
*/
m_iToolWindow =
AfxGetApp()->GetProfileInt(
PUTTYCS_APP_NAME, PUTTYCS_PREF_WINDOW_TOOL, 1 );
m_iAlwaysOnTop =
AfxGetApp()->GetProfileInt(
PUTTYCS_APP_NAME, PUTTYCS_PREF_WINDOW_ALWAYS_ON_TOP, 1 );
m_iMinimizeToSysTray =
AfxGetApp()->GetProfileInt(
PUTTYCS_APP_NAME, PUTTYCS_PREF_MINIMIZE_TO_SYSTRAY, 1 );
m_iOpacity =
AfxGetApp()->GetProfileInt(
PUTTYCS_APP_NAME, PUTTYCS_PREF_WINDOW_OPACITY,
PUTTYCS_OPACITY_MAX );
/**
* Auto arrange
*/
m_iAutoArrange =
AfxGetApp()->GetProfileInt(
PUTTYCS_APP_NAME, PUTTYCS_PREF_AUTO_ARRANGE, 1 );
m_iAutoMinimize =
AfxGetApp()->GetProfileInt(
PUTTYCS_APP_NAME, PUTTYCS_PREF_AUTO_MINIMIZE, 0 );
m_iArrangeOnStartup =
AfxGetApp()->GetProfileInt(
PUTTYCS_APP_NAME, PUTTYCS_PREF_ARRANGE_ON_STARTUP, 0 );
m_iUnhideOnExit =
AfxGetApp()->GetProfileInt(
PUTTYCS_APP_NAME, PUTTYCS_PREF_UNHIDE_ON_EXIT, 1 );
/**
* Tile method
*/
m_iTileMethod =
AfxGetApp()->GetProfileInt(
PUTTYCS_APP_NAME, PUTTYCS_PREF_TILE_METHOD, PUTTYCS_TILE_METHOD_DEFAULT );
/**
* Cascade dimensions
*/
m_iCascadeWidth =
AfxGetApp()->GetProfileInt(
PUTTYCS_APP_NAME, PUTTYCS_PREF_CASCADE_WIDTH, PUTTYCS_CASCADE_DEFAULT_WIDTH );
m_iCascadeHeight =
AfxGetApp()->GetProfileInt(
PUTTYCS_APP_NAME, PUTTYCS_PREF_CASCADE_HEIGHT, PUTTYCS_CASCADE_DEFAULT_HEIGHT );
/**
* Send CR
*/
m_iSendCR =
AfxGetApp()->GetProfileInt(
PUTTYCS_APP_NAME, PUTTYCS_PREF_SEND_CR, 1 );
/**
* Keyboard/Mouse
*/
m_iEmulateCopyPaste =
AfxGetApp()->GetProfileInt(
PUTTYCS_APP_NAME, PUTTYCS_PREF_EMULATE_COPY_PASTE, 1 );
m_iCmdHistoryScrollThrough =
AfxGetApp()->GetProfileInt(
PUTTYCS_APP_NAME, PUTTYCS_PREF_CMDHISTORY_SCROLL_THROUGH, 1 );
m_iTabCompletion =
AfxGetApp()->GetProfileInt(
PUTTYCS_APP_NAME, PUTTYCS_PREF_TAB_COMPLETION, 0 );
/**
* Miscellenous
*/
m_iSavePassword =
AfxGetApp()->GetProfileInt(
PUTTYCS_APP_NAME, PUTTYCS_PREF_SAVE_PASSWORD, 0 );
if ( m_iSavePassword )
{
m_csPassword =
AfxGetApp()->GetProfileString(
PUTTYCS_APP_NAME,
PUTTYCS_PREF_PASSWORD,
PUTTYCS_EMPTY_STRING );
}
else
{
m_csPassword = PUTTYCS_EMPTY_STRING;
}
m_iRunOnSystemStartup =
AfxGetApp()->GetProfileInt(
PUTTYCS_APP_NAME, PUTTYCS_PREF_RUN_ON_SYSTEM_STARTUP, 0 );
SetRunOnSystemStartup( m_iRunOnSystemStartup ? true : false );
m_iCheckForUpdates =
AfxGetApp()->GetProfileInt(
PUTTYCS_APP_NAME, PUTTYCS_PREF_CHECK_FOR_UPDATES, 1 );
/**
* Transition Delays
*/
m_iTransition =
AfxGetApp()->GetProfileInt(
PUTTYCS_APP_NAME, PUTTYCS_PREF_WINDOW_TRANSITION, 25 );
m_iPostSendDelay =
AfxGetApp()->GetProfileInt(
PUTTYCS_APP_NAME, PUTTYCS_PREF_POST_SEND_DELAY, 100 );
}
/**
* SavePreferences()
*/
void CPuTTYCSDialog::SavePreferences()
{
/**
* PuTTY filters
*/
for ( int iLoop = 0; iLoop < PUTTYCS_PREF_FILTER_MAX_SIZE; iLoop++ )
{
CString csAttribute;
csAttribute.Format( PUTTYCS_PREF_FILTER_ENTRY, iLoop );
CString csValue = PUTTYCS_EMPTY_STRING;
if ( iLoop < m_csaFilters.GetSize() )
{
csValue = m_csaFilters.GetAt( iLoop );
}
AfxGetApp()->WriteProfileString(
PUTTYCS_APP_NAME, csAttribute, csValue );
}
AfxGetApp()->WriteProfileInt(
PUTTYCS_APP_NAME, PUTTYCS_PREF_FILTER, m_iFilter );
/**
* Command history
*/
for ( iLoop = 0;
iLoop < PUTTYCS_PREF_CMDHISTORY_MAX_SIZE; iLoop++ )
{
CString csAttribute;
csAttribute.Format( PUTTYCS_PREF_CMDHISTORY_ENTRY, iLoop );
CString csValue = PUTTYCS_EMPTY_STRING;
if ( iLoop < m_csaCmdHistory.GetSize() )
{
csValue = m_csaCmdHistory.GetAt(iLoop);
}
AfxGetApp()->WriteProfileString(
PUTTYCS_APP_NAME, csAttribute, csValue );
}
/**
* Window settings
*/
AfxGetApp()->WriteProfileInt( PUTTYCS_APP_NAME,
PUTTYCS_PREF_WINDOW_TOOL, m_iToolWindow );
AfxGetApp()->WriteProfileInt( PUTTYCS_APP_NAME,
PUTTYCS_PREF_WINDOW_ALWAYS_ON_TOP, m_iAlwaysOnTop );
AfxGetApp()->WriteProfileInt( PUTTYCS_APP_NAME,
PUTTYCS_PREF_MINIMIZE_TO_SYSTRAY, m_iMinimizeToSysTray );
AfxGetApp()->WriteProfileInt( PUTTYCS_APP_NAME,
PUTTYCS_PREF_WINDOW_OPACITY, m_iOpacity );
/**
* Auto arrange
*/
AfxGetApp()->WriteProfileInt( PUTTYCS_APP_NAME,
PUTTYCS_PREF_AUTO_ARRANGE, m_iAutoArrange );
AfxGetApp()->WriteProfileInt( PUTTYCS_APP_NAME,
PUTTYCS_PREF_AUTO_MINIMIZE, m_iAutoMinimize );
AfxGetApp()->WriteProfileInt( PUTTYCS_APP_NAME,
PUTTYCS_PREF_ARRANGE_ON_STARTUP, m_iArrangeOnStartup );
AfxGetApp()->WriteProfileInt( PUTTYCS_APP_NAME,
PUTTYCS_PREF_UNHIDE_ON_EXIT, m_iUnhideOnExit );
/**
* Tile method
*/
AfxGetApp()->WriteProfileInt( PUTTYCS_APP_NAME,
PUTTYCS_PREF_TILE_METHOD, m_iTileMethod );
/**
* Cascade dimensions
*/
AfxGetApp()->WriteProfileInt( PUTTYCS_APP_NAME,
PUTTYCS_PREF_CASCADE_WIDTH, m_iCascadeWidth );
AfxGetApp()->WriteProfileInt( PUTTYCS_APP_NAME,
PUTTYCS_PREF_CASCADE_HEIGHT, m_iCascadeHeight );
/**
* Send CR
*/
AfxGetApp()->WriteProfileInt( PUTTYCS_APP_NAME,
PUTTYCS_PREF_SEND_CR, m_iSendCR );
/**
* Keyboard/Mouse
*/
AfxGetApp()->WriteProfileInt( PUTTYCS_APP_NAME,
PUTTYCS_PREF_TAB_COMPLETION, m_iTabCompletion );
AfxGetApp()->WriteProfileInt( PUTTYCS_APP_NAME,
PUTTYCS_PREF_CMDHISTORY_SCROLL_THROUGH, m_iCmdHistoryScrollThrough );
AfxGetApp()->WriteProfileInt( PUTTYCS_APP_NAME,
PUTTYCS_PREF_EMULATE_COPY_PASTE, m_iEmulateCopyPaste );
/**
* Miscellaneous
*/
AfxGetApp()->WriteProfileInt( PUTTYCS_APP_NAME,
PUTTYCS_PREF_SAVE_PASSWORD, m_iSavePassword );
if ( m_iSavePassword )
{
AfxGetApp()->WriteProfileString( PUTTYCS_APP_NAME,
PUTTYCS_PREF_PASSWORD, m_csPassword );
}
else
{
AfxGetApp()->WriteProfileString( PUTTYCS_APP_NAME,
PUTTYCS_PREF_PASSWORD, PUTTYCS_EMPTY_STRING );
}
AfxGetApp()->WriteProfileInt( PUTTYCS_APP_NAME,
PUTTYCS_PREF_RUN_ON_SYSTEM_STARTUP, m_iRunOnSystemStartup );
SetRunOnSystemStartup( m_iRunOnSystemStartup ? true : false);
AfxGetApp()->WriteProfileInt( PUTTYCS_APP_NAME,
PUTTYCS_PREF_CHECK_FOR_UPDATES, m_iCheckForUpdates );
/**
* Transition Delays
*/
AfxGetApp()->WriteProfileInt( PUTTYCS_APP_NAME,
PUTTYCS_PREF_WINDOW_TRANSITION, m_iTransition );
AfxGetApp()->WriteProfileInt( PUTTYCS_APP_NAME,
PUTTYCS_PREF_POST_SEND_DELAY, m_iPostSendDelay );
}
/**
* DoDataExchange()
*/
void CPuTTYCSDialog::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CPuTTYCSDialog)
DDX_Control(pDX, IDC_COMMAND_EDIT, m_cceCommandEdit);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CPuTTYCSDialog, CDialog)
//{{AFX_MSG_MAP(CPuTTYCSDialog)
ON_WM_CREATE()
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_COMMAND(IDMI_SYSTRAYABOUT_MENUITEM, OnAboutButton)
ON_CBN_SELCHANGE(IDC_FILTERS_COMBOBOX, OnSelChangeFiltersCombobox)
ON_BN_CLICKED(IDC_CASCADE_BUTTON, OnCascadeButton)
ON_BN_CLICKED(IDC_TILE_BUTTON, OnTileButton)
ON_BN_CLICKED(IDC_MINIMIZE_BUTTON, OnMinimizeButton)
ON_BN_CLICKED(IDC_HIDE_BUTTON, OnHideButton)
ON_BN_CLICKED(IDC_FILTERS_BUTTON, OnFiltersButton)
ON_BN_CLICKED(IDC_SENDCR_PUSHBUTTON, OnSendCRPushButton)
ON_BN_CLICKED(IDC_CMDHISTORYUP_BUTTON, OnCmdHistoryUpButton)
ON_BN_CLICKED(IDC_CMDHISTORYDOWN_BUTTON, OnCmdHistoryDownButton)
ON_BN_CLICKED(IDC_UP_BUTTON, OnUpButton)
ON_BN_CLICKED(IDC_DOWN_BUTTON, OnDownButton)
ON_BN_CLICKED(IDC_RIGHT_BUTTON, OnRightButton)
ON_BN_CLICKED(IDC_LEFT_BUTTON, OnLeftButton)
ON_BN_CLICKED(IDC_CLEAR_BUTTON, OnClearButton)
ON_BN_CLICKED(IDC_BREAK_BUTTON, OnBreakButton)
ON_BN_CLICKED(IDC_ENDTELNET_BUTTON, OnEndTelnetButton)
ON_BN_CLICKED(IDC_ESCAPE_BUTTON, OnEscapeButton)
ON_BN_CLICKED(IDC_ENTER_BUTTON, OnEnterButton)
ON_BN_CLICKED(IDC_PASSWORD_BUTTON, OnPasswordButton)
ON_BN_CLICKED(IDC_PREFERENCES_BUTTON, OnPreferencesButton)
ON_BN_CLICKED(IDC_SCRIPT_BUTTON, OnScriptButton)
ON_BN_CLICKED(IDC_SEND_BUTTON, OnSendButton)
ON_MESSAGE(WM_USER_TNI_MESSAGE, OnTrayNotify)
ON_WM_HELPINFO()
ON_BN_CLICKED(IDC_CMDHISTORYCLEAR_BUTTON, OnCmdHistoryClearButton)
ON_COMMAND(IDMI_SYSTRAYOPEN_MENUITEM, OnOpenMenuItem)
ON_BN_CLICKED(IDC_BACKSPACE_BUTTON, OnBackspaceButton)
ON_BN_CLICKED(IDC_DELETE_BUTTON, OnDeleteButton)
ON_BN_CLICKED(IDC_CLOSE_BUTTON, OnCloseButton)
ON_BN_CLICKED(IDC_CTRL_BUTTON, OnCtrlButton)
ON_BN_CLICKED(IDC_INC_BUTTON, OnIncButton)
ON_COMMAND(IDMI_SYSTRAYCHECKFORUPDATES_MENUITEM, OnCheckForUpdates)
ON_BN_CLICKED(IDC_CTRLD_BUTTON, OnCtrlDButton)
ON_BN_CLICKED(IDC_CTRLR_BUTTON, OnCtrlRButton)
ON_COMMAND(IDMI_SYSTRAYCASCADE_MENUITEM, OnCascadeButton)
ON_COMMAND(IDMI_SYSTRAYTILE_MENUITEM, OnTileButton)
ON_COMMAND(IDMI_SYSTRAYMINIMIZE_MENUITEM, OnMinimizeButton)
ON_COMMAND(IDMI_SYSTRAYHIDE_MENUITEM, OnHideButton)
ON_COMMAND(IDMI_SYSTRAYPREFERENCES_MENUITEM, OnPreferencesButton)
ON_COMMAND(IDMI_SYSTRAYEXIT_MENUITEM, OnOK)
ON_WM_COPYDATA()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/**
* CPuTTYCSDialog::SetSysTrayTip()
*/
void CPuTTYCSDialog::SetSysTrayTip( CString csTip )
{
DWORD dwMessage = NIM_MODIFY;
if ( !m_pTNI )
{
m_pTNI = new NOTIFYICONDATA;
ZeroMemory(
m_pTNI, sizeof(NOTIFYICONDATA) );
m_pTNI->hWnd =
((CWnd*) this)->GetSafeHwnd();
m_pTNI->cbSize = sizeof( NOTIFYICONDATA );
m_pTNI->uCallbackMessage = WM_USER_TNI_MESSAGE;
m_pTNI->uFlags = NIF_ICON | NIF_TIP | NIF_MESSAGE;
m_pTNI->hIcon = m_hIcon;
m_pTNI->uTimeout = 1000;
m_pTNI->uID = 1;
dwMessage = NIM_ADD;
}
_tcscpy( m_pTNI->szTip, csTip );
Shell_NotifyIcon( dwMessage,
(NOTIFYICONDATA*) m_pTNI );
}
/**
* CPuTTYCSDialog::WindowProc()
*/
LRESULT CPuTTYCSDialog::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
{
if ( message == m_uiTaskbarMessage )
{
if ( m_pTNI )
{
delete m_pTNI;
m_pTNI = NULL;
}
if ( m_iMinimizeToSysTray )
{
SetSysTrayTip( PUTTYCS_WINDOW_TITLE_APP );
}
}
return CDialog::WindowProc(message, wParam, lParam);
}
/**
* CPuTTYCSDialog::PreTranslateMessage()
*/
BOOL CPuTTYCSDialog::PreTranslateMessage(MSG* pMsg)
{
if ( pMsg->message == WM_KEYDOWN )
{
if ( pMsg->wParam == VK_ESCAPE )
{
pMsg->wParam = NULL;
}
else
{
UINT uiCtrlId =
((CWnd*) GetFocus())->GetDlgCtrlID();
if ( uiCtrlId == IDC_COMMAND_EDIT )
{
if ( pMsg->wParam == VK_TAB )
{
if ( m_iTabCompletion )
{
CString csCommand =
m_cceCommandEdit.GetText();
sendCommand( csCommand, true );
pMsg->wParam = NULL;
}
}
else if ( pMsg->wParam == VK_UP )
{
if ( m_iCmdHistoryScrollThrough )
{
OnCmdHistoryUpButton();
}
}
else if ( pMsg->wParam == VK_DOWN )
{
if ( m_iCmdHistoryScrollThrough )
{
OnCmdHistoryDownButton();
}
}
}
}
}
return CDialog::PreTranslateMessage(pMsg);
}
/**
* CPuTTYCSDialog::DestroyWindow()
*/
BOOL CPuTTYCSDialog::DestroyWindow()
{
m_bIsClosing = true;
if ( m_iUnhideOnExit )
{
m_obaWindows.RemoveAll();
::EnumWindows( enumwindowsProc, (LPARAM) this );
SortWindows();
for ( int iLoop = 0;
iLoop < m_obaWindows.GetSize(); iLoop++ )
{
CWnd* pWnd =
(CWnd*) m_obaWindows.GetAt( iLoop );
if ( !pWnd->IsWindowVisible() )
{
pWnd->ShowWindow( SW_SHOW );
}
}
}
return CDialog::DestroyWindow();
}
/**
* CPuTTYCSDialog::OnCreate()
*/
int CPuTTYCSDialog::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CDialog::OnCreate(lpCreateStruct) == -1)
return -1;
m_uiTaskbarMessage =
RegisterWindowMessage( PUTTYCS_MSG_TASKBAR_CREATED );
return 0;
}
/**
* CPuTTYCSDialog::OnInitDialog()
*/
BOOL CPuTTYCSDialog::OnInitDialog()
{
CDialog::OnInitDialog();
SetIcon(m_hIcon, TRUE);
SetIcon(m_hIcon, FALSE);
m_bIsClosing = false;
m_bFindAll = false;
/**
* Preferences
*/
LoadPreferences();
/**
* Check for updates
*/
if ( m_iCheckForUpdates )
{
CheckForUpdates();
}
/**
* PuTTY filters
*/
for ( int iLoop = 0; iLoop < m_csaFilters.GetSize(); iLoop++ )
{
CString csFilter = m_csaFilters.GetAt(iLoop);
((CComboBox*) GetDlgItem(IDC_FILTERS_COMBOBOX))->
AddString(csFilter.Mid(0,
csFilter.Find( PUTTYCS_FILTER_NAME_SEPARATOR)) );
}
((CComboBox*) GetDlgItem(IDC_FILTERS_COMBOBOX))->
SetCurSel( m_iFilter );
/**
* Arrows
*/
((CButton*) GetDlgItem(IDC_CMDHISTORYUP_BUTTON))->
SetFont( m_pMarlettNormal );
((CButton*) GetDlgItem(IDC_CMDHISTORYDOWN_BUTTON))->
SetFont( m_pMarlettNormal );
((CButton*) GetDlgItem(IDC_CMDHISTORYCLEAR_BUTTON))->
SetFont( m_pMarlettSmall );
((CButton*) GetDlgItem(IDC_UP_BUTTON))->
SetFont( m_pMarlettNormal );
((CButton*) GetDlgItem(IDC_DOWN_BUTTON))->
SetFont( m_pMarlettNormal );
((CButton*) GetDlgItem(IDC_LEFT_BUTTON))->
SetFont( m_pMarlettNormal );
((CButton*) GetDlgItem(IDC_RIGHT_BUTTON))->
SetFont( m_pMarlettNormal );
/**
* Clear button
*/
((CButton*) GetDlgItem(IDC_CLEAR_BUTTON))->
SetFont( m_pMarlettSmall );
/**
* Command edit
*/
m_cceCommandEdit.SetEmulateCopyPaste( m_iEmulateCopyPaste );
m_cceCommandEdit.SetCmdHistoryScrollThrough( m_iCmdHistoryScrollThrough );
/**
* Send CR
*/
((CButton*) GetDlgItem(IDC_SENDCR_PUSHBUTTON))->
SetFont( m_pSymbolSmall );
((CButton*) GetDlgItem(IDC_SENDCR_PUSHBUTTON))->
SetCheck( m_iSendCR );
/**
* System Menu
*/
CMenu* pMenu = GetSystemMenu( FALSE );
if (pMenu != NULL)
{
pMenu->RemoveMenu( SC_MAXIMIZE, MF_BYCOMMAND );
pMenu->AppendMenu( MF_SEPARATOR );
pMenu->AppendMenu( MF_STRING,
IDM_ABOUT_PUTTYCS, PUTTYCS_WINDOW_TITLE_ABOUT );
}
/**
* Dialog size
*/
CRect dialogRect;
GetWindowRect(&dialogRect);
m_iDialogHeight = dialogRect.Height();
/**
* Auto arrange
*/
if ( m_iArrangeOnStartup )
{
OnSelChangeFiltersCombobox();
}
/**
* Minimize to SysTray
*/
if ( m_iMinimizeToSysTray )
{
SetSysTrayTip( PUTTYCS_WINDOW_TITLE_APP );
}
/**
* Update dialog
*/
UpdateDialog();
/**
* Parse command line options
*/
ParseCmdLineOptions();
return TRUE;
}
/**
* CPuTTYCSDialog::OnSysCommand()
*/
void CPuTTYCSDialog::OnSysCommand(UINT nID, LPARAM lParam)
{
UINT nCmd = (nID & 0xFFF0);
if ( nCmd == IDM_ABOUT_PUTTYCS )
{
OnAboutButton();
}
else
{
if ( (m_iMinimizeToSysTray) &&
((nCmd == SC_MINIMIZE)
|| (nCmd == SC_CLOSE)) )
{
ShowWindow( SW_HIDE );
SetSysTrayTip( PUTTYCS_WINDOW_TITLE_APP );
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
}
/**
* CPuTTYCSDialog::OnPaint()
*/
void CPuTTYCSDialog::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
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;
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}
/**
* CPuTTYCSDialog::OnQueryDragIcon()
*/
HCURSOR CPuTTYCSDialog::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
/**
* CPuTTYCSDialog::OnHelpInfo()
*/
BOOL CPuTTYCSDialog::OnHelpInfo(HELPINFO* pHelpInfo)
{
ShellExecute( NULL,
PUTTYCS_SHELL_EXECUTE_OPEN,
PUTTYCS_URL_HOMEPAGE,
NULL,
NULL,
SW_SHOWNORMAL );
return TRUE;
}
/**
* CPuTTYCSDialog::ParseCmdLineOptions()
*/
void CPuTTYCSDialog::ParseCmdLineOptions(LPTSTR pCmdLine)
{