summaryrefslogtreecommitdiff
path: root/DspControl/plugin/DspControl.asm
blob: 54b2a5018c61eda5acf751b73ec2bdac6f0e35c3 (plain)
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
;Display Control plugin for Miranda. Turns on the screen if in power saving mode, when a message arives
;Copyright © 2006-2007 A. Chilaru
;
;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 2
;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, write to the Free Software
;Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.

.386
.model flat,stdcall
option casemap:none
include \masm32\include\windows.inc
include \masm32\include\kernel32.inc
include \masm32\include\user32.inc
include \masm32\include\comctl32.inc
include \masm32\include\gdi32.inc
include ..\inc\IcoLib.inc
include ..\inc\m_clist.inc
include ..\inc\m_clc.inc
include ..\inc\m_database.inc
include ..\inc\m_langpack.inc
include ..\inc\m_options.inc
include ..\inc\m_protocols.inc
include ..\inc\m_protosvc.inc
include ..\inc\m_updater.inc
include ..\inc\newpluginapi.inc
include ..\inc\statusmodes.inc

includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\user32.lib
includelib \masm32\lib\comctl32.lib
includelib \masm32\lib\gdi32.lib

				;function definitions for debuggers
				;hook functions are C-style functions. The rest are stdcall
OptInit proto C wParam:DWORD, lParam:DWORD
Message proto C wParam:DWORD, lParam:DWORD
MdLoaded proto C wParam:DWORD, lParam:DWORD
IcoLibEv proto C wParam:DWORD, lParam: DWORD

CallService proto lpServiceName:DWORD, wParam:DWORD, lParam:DWORD
ServiceExists proto lpServiceName:DWORD
HookEvent proto lpHookName:DWORD, lpFunction:DWORD
UnhookEvent proto HookHandle:DWORD

Translate proto lpStr:DWORD
Error proto lpStr:DWORD
IgnoreCheck proto pStri:DWORD
ResetListOptions proto hCList:DWORD
SetAllContactIcons proto hCList:DWORD
SetListGroupIcons proto hCList:DWORD, hFirstItem:DWORD, hParentItem:DWORD, groupChildCount:DWORD
SetAllChildIcons proto hCList:DWORD, hFirstItem:DWORD, iColumn:DWORD, iImage:DWORD
MetaConClick proto hContact:DWORD, iCount:DWORD, iValue: DWORD
MetaSubClick proto hContact:DWORD

DLGHDR struct		;Structure to hold info about tabs
	hDlg		dd	?
    hTab		dd	?
    hDisplay	dd	?
    rcDisplay	RECT <>
    hTab1		dd	?
    hTab2		dd	?
DLGHDR ends

					;Macro to create lParam DWORD from two WORDs (low WORDs used if DWORD given)
MAKELPARAM macro lowWord, highWord
	push ebx
	mov ebx, lowWord
	mov eax, highWord
	shl eax, 16
	mov ax, bx
	pop ebx
	ENDM

.const
				;option controls
IDC_ENABLED				equ		40071			;Plugin enables checkbox ID
IDC_PROTO				equ		40081			;Protocol listbox ID
IDC_STARTTIME			equ		40088			;time selector
IDC_ENDTIME				equ		40089			;time selector
IDC_SHOWHIDDEN			equ		50071			;Show hidden contacts

IDC_CLIST				equ		3000			;CList component

IDI_PC					equ		101				;PC icon

				;const from miranda resource file (small dot in CListControl)
IDI_SMALLDOT			equ		211

				;const from skin header
SKINICON_EVENT_MESSAGE	equ		100

WM_IMGLIST				equ		WM_USER+273

.data
hInstance				dd		0				;Plugin hWnd
hApp					dd		0				;Miranda .exe hWnd
hDlgWnd					dd		0				;Option dialog hWnd
hIcoLibEv				dd		0				;IcoLib dialog hWnd
hIml					dd		0				;Image list
hItemAll				dd		0				;CListControl "Group" ** All contacts **"
hItemUnk				dd		0				;CListControl "Group" ** Unknown contacts **"

ddRetAddr				dd		0				;Miranda proto ret. address
ddRetStack				dd		0				;Miranda proto EBP backup

hMsgHook				dd		0				;Message hook hWnd
hOptHook				dd		0				;Options hook hWnd
hMdLHook				dd		0				;Modules loaded hook

ddVar1					dd		0
ddVar2					dd		0				;Just three DWORD variables ;)
ddVar3					dd		0
ddInt					dd		0
ddFlags					dd		0				;Various flags. Descriptions (starting from the lower bit)
							;Reserved
							;OptEditing2		On while options are loaded from the DB
							;OptEditing2		On while options are loaded from the DB
							;noUniConvert		Don't convert to Unicode while translating

sPluginInfo				PLUGININFO <0>			;plugin info structure
sPluginLink				PLUGINLINK <>			;miranda procedure adresses structure
sOptionsPage			OPTIONSDIALOGPAGE <0>	;options struct
sDBVariant				DBVARIANT <>			;DB write/get variable struct
sDBGetSetting			DBCONTACTGETSETTING <>	;DB get struct
sDBWriteSetting			DBCONTACTWRITESETTING <>;DB write struct
sDBEventInfo			DBEVENTINFO <>			;Event ifnfo struct
sUpdate					UPDATE <0>				;Updater struct
sTCITEM					TCITEM	<0>				;struct for tabbing
sDlgHdr					DLGHDR <0>				;struct for tabbing
sSystemTime				SYSTEMTIME <>			;datetime struct
sLngPackDialog			LANGPACKTRANSLATEDIALOG <> ;langpack dialog struct
sClcInfoItem			CLCINFOITEM <>			;contact list child item info
sSkinIconDesc			SKINICONDESC <>			;IcoLib struct

				;plugin details
szShortName				db	"Display Control",0
szShortNamev			db	"Display Control "
IFDEF _UNICODE
	szPlVer				db	"(Unicode)",0
ELSE
	szPlVer				db	"(ANSI)",0
ENDIF
ddVersion				dd	0001011Eh
szDescription			db	"The plugin turns your monitor power on as soon as a message arrives.",10,13,"Uses triggers, such as time, protocol, message type, status and individual contact, as rules.",0
szAuthor				db	"A. Chilaru",0
szAthorEmail			db	"flexlabs@gmail.com",0
szCopyright				db	"© 2007 A. Chilaru (FlexLabs Inc.)",0
szHomepage				db	"http://dev.mirandaim.ru/dspcontrol",0

				;additional details for updater
IFDEF _UNICODE
	szURL				db	"http://addons.miranda-im.org/details.php?action=viewfile&id=3232",0
	szURLKey			db	"<span class=",22h,"fileNameHeader",22h,">Display Control (Unicode) ",0
	ddURLKeyLen			dd	37h
	szDnURL				db	"http://addons.miranda-im.org/feed.php?dlfile=3232",0
ELSE
	szURL				db	"http://addons.miranda-im.org/details.php?action=viewfile&id=3261",0
	szURLKey			db	"<span class=",22h,"fileNameHeader",22h,">Display Control (ANSI) ",0
	ddURLKeyLen			dd	34h
	szDnURL				db	"http://addons.miranda-im.org/feed.php?dlfile=3261",0
ENDIF
szBetaURL				db	"http://svn.mirandaim.ru/mainrepo/dspcontrol/trunk/BETA",0
szBetaURLKey			db	"DspControl_v.",0
ddBetaURLKeyLen			dd	0Dh
IFDEF _UNICODE
	szBetaDnURL			db	"http://svn.mirandaim.ru/mainrepo/dspcontrol/trunk/bin/Unicode/DspControl.dll",0
ELSE
	szBetaDnURL			db	"http://svn.mirandaim.ru/mainrepo/dspcontrol/trunk/bin/ANSI/DspControl.dll",0
ENDIF
szVersion				db	"0.1.1.30",0
ddVersionLen			dd	08h
ddBeta					dd	0		;If plugin is beta - 1. Else - 0
szBetaChangelogURL		db	"http://svn.mirandaim.ru/mainrepo/dspcontrol/trunk/CHANGELOG.txt",0

				;miranda functions
MS_DB_CONTACT_GETSETTING	db	"DB/Contact/GetSetting",0
MS_DB_CONTACT_WRITESETTING	db	"DB/Contact/WriteSetting",0
MS_DB_CONTACT_FINDFIRST		db	"DB/Contact/FindFirst",0
MS_DB_CONTACT_FINDNEXT		db	"DB/Contact/FindNext",0
MS_DB_EVENT_GET				db	"DB/Event/Get",0
MS_DB_EVENT_GETBLOBSIZE		db	"DB/Event/GetBlobSize",0
MS_DB_EVENT_GETCONTACT		db	"DB/Event/GetContact",0
MS_PROTO_GETCONTACTBASEPROTO db "Proto/GetContactBaseProto",0
MS_CLIST_ADDMAINMENUITEM	db	"CList/AddMainMenuItem",0
MS_CLIST_GETSTATUSMODE		db	"CList/GetStatusMode",0
MS_OPT_ADDPAGE				db	"Opt/AddPage",0
MS_PROTO_ENUMPROTOCOLS		db	"Proto/EnumProtocols",0
MS_MC_GETMETACONTACT		db	"MetaContacts/GetMeta",0
MS_MC_GETSUBCONTACT			db	"MetaContacts/GetSubContact",0
ME_SYSTEM_MODULESLOADED		db	"Miranda/System/ModulesLoaded",0
MS_SKIN_LOADICON			db	"Skin/Icons/Load",0
MS_SKIN2_ADDICON			db	"Skin2/Icons/AddIcon",0
MS_SKIN2_GETICON			db	"Skin2/Icons/GetIcon",0
MS_UPDATE_REGISTER			db	"Update/Register",0
MS_LANGPACK_TRANSLATESTRING	db	"LangPack/TranslateString",0
MS_LANGPACK_TRANSLATEDIALOG	db	"LangPack/TranslateDialog",0

PS_GETCAPS					db	"/GetCaps",0		;Takes form of "PROTO/GetCaps",0 (GetCapabilities of a PROTO)

				;miranda events
ME_DB_EVENT_ADDED			db	"DB/Event/Added",0
ME_OPT_INITIALISE			db	"Opt/Initialise",0
ME_SKIN2_ICONSCHANGED		db	"Skin2/IconsChanged",0

				;options
szOptGroup				db	"Events",0
szOptGroupW				db	"Unicod",0
szOptTitle				db	"Display Control",0
szOptTitleW				db	"UnicodeUnicodeU",0
szOModule				db	"DspControl",0
szOFlags				db	"Flags",0
szOTime					db	"Time",0
szOEnabled				db	"Enabled",0
szONotOnList			db	"NotOnList",0
szOCList				db	"CList",0
szOShowHidden			db	"ShowHidden",0
szOMetaContacts			db	"MetaContacts",0
szOMetaCount			db	"NumContacts",0
szOMetaLink				db	"MetaLink",0

				;tab captions
szTab1					db	"Triggers",0
szTab1W					db	"UnicodeU",0
szTab2					db	"Contacts",0
szTab2W					db	"UnicodeU",0

				;IcoLib
szIlDesc					db	"Enabled",0
szIlName					db	"dspc_screen",0

				;other strings
szDtFormat				db	"HH':'mm",0
szError					db	"Default error message",0
szAllContacts			db	"** All contacts **",0
szAllContactsW			db	"UnicodeUnicodeUnic",0
szUnkContacts			db	"** Unknown contacts **",0
szUnkContactsW			db	"UnicodeUnicodeUnicodeU",0

				;option control info
IDC_ETYPE_MESSAGE		dd		40082
IDC_ETYPE_MESSAGE_V		dd		EVENTTYPE_MESSAGE
IDC_ETYPE_URL			dd		40083
IDC_ETYPE_URL_V			dd		EVENTTYPE_URL
IDC_ETYPE_CONTACTS		dd		40084
IDC_ETYPE_CONTACTS_V	dd		EVENTTYPE_CONTACTS
IDC_ETYPE_ADDED			dd		40085
IDC_ETYPE_ADDED_V		dd		EVENTTYPE_ADDED
IDC_ETYPE_AUTHREQUEST	dd		40086
IDC_ETYPE_AUTHREQUEST_V	dd		EVENTTYPE_AUTHREQUEST
IDC_ETYPE_FILE			dd		40087
IDC_ETYPE_FILE_V		dd		EVENTTYPE_FILE

.data?
				;option control hWnd's
HC_CLIST				dd		?
HC_ENABLED				dd		?
HC_STATUS_ONLINE		dd		?
HC_STATUS_AWAY			dd		?
HC_STATUS_DND			dd		?
HC_STATUS_NA			dd		?
HC_STATUS_OCCUPIED		dd		?
HC_STATUS_FREECHAT		dd		?
HC_STATUS_INVISIBLE 	dd		?
HC_STATUS_ONTHEPHONE	dd		?
HC_STATUS_OUTTOLUNCH	dd		?
HC_PROTO				dd		?
HC_ETYPE_MESSAGE		dd		?
HC_ETYPE_URL			dd		?
HC_ETYPE_CONTACTS		dd		?
HC_ETYPE_ADDED			dd		?
HC_ETYPE_AUTHREQUEST	dd		?
HC_ETYPE_FILE			dd		?
HC_STARTTIME			dd		?
HC_ENDTIME				dd		?

HC_SHOWHIDDEN			dd		?

				;empty string space
szGeneral				db		256 DUP(?)

.code
DllMain proc hInst:HINSTANCE, reason:DWORD, reserved1:DWORD
	push hInst
	pop hInstance										;save hWnd of the library
	invoke GetModuleHandle, NULL
	mov hApp, eax										;save hWnd of Miranda

	mov sPluginInfo.cbSize, sizeof PLUGININFO			;set the library's info
	mov sPluginInfo.shortName, offset szShortNamev
	push ddVersion
	pop sPluginInfo.version
	mov sPluginInfo.description, offset szDescription
	mov sPluginInfo.author, offset szAuthor
	mov sPluginInfo.authorEmail, offset szAthorEmail
	mov sPluginInfo.copyright, offset szCopyright
	mov sPluginInfo.homepage, offset szHomepage

    mov  eax, TRUE
    ret
DllMain Endp

MirandaPluginInfo proc
    mov eax, offset sPluginInfo		;return plugin info struct
    ret
MirandaPluginInfo Endp

					;internal miranda functions. Not necessary, but allow viewing them in the debugger
CallService proc lpServiceName:DWORD, wParam:DWORD, lParam:DWORD
	pop ddRetStack
	pop ddRetAddr
	call sPluginLink.lpCallService
	push ddRetAddr
	push ddRetStack
	ret
CallService endp

ServiceExists proc lpServiceName:DWORD
	pop ddRetStack
	pop ddRetAddr
	call sPluginLink.lpServiceExists
	push ddRetAddr
	push ddRetStack
	ret
ServiceExists endp

HookEvent proc lpHookName:DWORD, lpFunction:DWORD
	pop ddRetStack
	pop ddRetAddr
	call sPluginLink.lpHookEvent
	push ddRetAddr
	push ddRetStack
	ret
HookEvent endp

UnhookEvent proc HookHandle:DWORD
	pop ddRetStack
	pop ddRetAddr
	call sPluginLink.lpUnhookEvent
	push ddRetAddr
	push ddRetStack
	ret
UnhookEvent endp

					;call to Miranda translate module
Translate proc lpString:DWORD
	LOCAL ddLng:DWORD
	
	mov eax, ddFlags
	and eax, 8
	.IF eax==0
		IFDEF _UNICODE
			mov ddLng, LANG_UNICODE
		ELSE
			mov ddLng, 0
		ENDIF
	.ELSE
		and ddFlags, -9
		mov ddLng, 0
	.ENDIF
	invoke CallService, offset MS_LANGPACK_TRANSLATESTRING, ddLng, lpString		;translate the string
	ret
Translate endp

					;Just an info func. Shows a message or Default error if NULL
Error proc lpString:DWORD
	.IF lpString==0
		mov lpString, offset szError
	.ENDIF
	invoke MessageBox, NULL, lpString, addr szShortName, MB_OK
	ret
Error endp

					;ignores protocols that can't receive messages...
IgnoreCheck proc pStri:DWORD
	invoke lstrcpy, offset szGeneral, pStri
	invoke lstrcat, offset szGeneral, offset PS_GETCAPS
	invoke CallService, offset szGeneral, PFLAGNUM_1, 0
	and eax, PF1_IMRECV
	.IF eax!=0
		mov eax, 1
	.ENDIF
	ret
IgnoreCheck endp

Load proc link:DWORD
	invoke RtlMoveMemory, addr sPluginLink, link, sizeof PLUGINLINK		;get miranda proc struct

	IFDEF _UNICODE
		invoke lstrcpy, offset szGeneral, offset szOptGroup
		invoke MultiByteToWideChar, CP_ACP, MB_PRECOMPOSED, offset szGeneral, -1, offset szOptGroup, 7
		invoke lstrcpy, offset szGeneral, offset szOptTitle
		invoke MultiByteToWideChar, CP_ACP, MB_PRECOMPOSED, offset szGeneral, -1, offset szOptTitle, 16
		invoke lstrcpy, offset szGeneral, offset szTab1
		invoke MultiByteToWideChar, CP_ACP, MB_PRECOMPOSED, offset szGeneral, -1, offset szTab1, 9
		invoke lstrcpy, offset szGeneral, offset szTab2
		invoke MultiByteToWideChar, CP_ACP, MB_PRECOMPOSED, offset szGeneral, -1, offset szTab2, 9
		invoke lstrcpy, offset szGeneral, offset szAllContacts
		invoke MultiByteToWideChar, CP_ACP, MB_PRECOMPOSED, offset szGeneral, -1, offset szAllContacts, 19
		invoke lstrcpy, offset szGeneral, offset szUnkContacts
		invoke MultiByteToWideChar, CP_ACP, MB_PRECOMPOSED, offset szGeneral, -1, offset szUnkContacts, 23
	ENDIF

	mov sSystemTime.wYear, 1870
	mov sSystemTime.wMonth, 1
	mov sSystemTime.wDay, 1
	mov sOptionsPage.cbSize, sizeof OPTIONSDIALOGPAGE					;set the option dialog's properties
	invoke Translate, offset szOptTitle
	IFDEF _UNICODE
		mov sOptionsPage.flags, ODPF_UNICODE
	ENDIF
	mov sOptionsPage.pszTitle, eax
	mov sOptionsPage.pfnDlgProc, offset TabOptions
	mov sOptionsPage.pszTemplate, 100
	push hInstance
	pop sOptionsPage.hInstance
	push offset szOptGroup
	pop sOptionsPage.pszGroup
	
	invoke HookEvent, offset ME_DB_EVENT_ADDED, offset Message			;set the message hook
	mov hMsgHook, eax													;save hook hWnd
	invoke HookEvent, offset ME_OPT_INITIALISE, offset OptInit			;set the options hook
	mov hOptHook, eax													;save hook hWnd
	invoke HookEvent, offset ME_SYSTEM_MODULESLOADED, offset MdLoaded	;set the ModulesLoaded hook
	mov hMdLHook, eax													;save hook hWnd

    xor eax, eax
    ret
Load Endp

IcoLibEv proc C wParam:DWORD, lParam: DWORD
	invoke SendMessage, hDlgWnd, WM_IMGLIST, 0, 0
	xor eax, eax
	ret
IcoLibEv endp

;##############################
;  Runs when all modules are loaded
;##############################
MdLoaded proc C wParam:DWORD, lParam:DWORD
	invoke UnhookEvent, hMdLHook				;unhook

	invoke ServiceExists, offset MS_UPDATE_REGISTER
	.IF eax!=0
		mov sUpdate.cbSize, sizeof UPDATE						;initialize updater struct
		mov sUpdate.szComponentName, offset szShortNamev
		.IF ddBeta==0
			mov sUpdate.szVersionURL, offset szURL			;check if is Beta
		.ENDIF
		mov sUpdate.pbVersionPrefix, offset szURLKey
		push ddURLKeyLen
		pop sUpdate.cpbVersionPrefix
		mov sUpdate.szUpdateURL, offset szDnURL
		mov sUpdate.szBetaVersionURL, offset szBetaURL
		mov sUpdate.pbBetaVersionPrefix, offset szBetaURLKey
		push ddBetaURLKeyLen
		pop sUpdate.cpbBetaVersionPrefix
		mov sUpdate.szBetaUpdateURL, offset szBetaDnURL
		mov sUpdate.pbVersion, offset szVersion
		push ddVersionLen
		pop sUpdate.cpbVersion
		mov sUpdate.szBetaChangelogURL, offset szBetaChangelogURL
		invoke CallService, offset MS_UPDATE_REGISTER, 0, offset sUpdate	;register updater service
	.ENDIF	

				;registering icon in IcoLib
	invoke ServiceExists, offset MS_SKIN2_ADDICON
	.IF eax!=0
		invoke GetModuleFileNameA, hInstance, offset szGeneral, 255
		mov sSkinIconDesc.cbSize, sizeof SKINICONDESC
		mov sSkinIconDesc.pszSection, offset szShortName
		or ddFlags, 8
		invoke Translate, offset szIlDesc
		mov sSkinIconDesc.pszDescription, eax
		mov sSkinIconDesc.pszName, offset szIlName
		mov sSkinIconDesc.pszDefaultFile, offset szGeneral
		mov sSkinIconDesc.iDefaultIndex, -IDI_PC
		invoke CallService, offset MS_SKIN2_ADDICON, 0, offset sSkinIconDesc	
		invoke HookEvent, offset ME_SKIN2_ICONSCHANGED, offset IcoLibEv		;set the IconChanged hook
		mov hIcoLibEv, eax													;save hook hWnd
	.ENDIF

	xor eax, eax
	ret
MdLoaded endp

				;set CListControl style defaults
ResetListOptions proc hCList:DWORD
	LOCAL Col, i:DWORD

	invoke SendMessage, hCList, CLM_SETBKBITMAP, 0, 0
	invoke GetSysColor, COLOR_WINDOW
	mov Col, eax
	invoke SendMessage, hCList, CLM_SETBKCOLOR, Col, 0
	invoke SendMessage, hCList, CLM_SETGREYOUTFLAGS, 0, 0
	invoke SendMessage, hCList, CLM_SETLEFTMARGIN, 2, 0
	invoke SendMessage, hCList, CLM_SETINDENT, 10, 0
	invoke GetSysColor, COLOR_WINDOWTEXT
	mov Col, eax
	mov i, FONTID_MAX
	.WHILE i!=0
		invoke SendMessage, hCList, CLM_SETTEXTCOLOR, i, Col
		dec i
	.ENDW
    mov sDBGetSetting.szModule, offset szOModule			;load the flags
	mov sDBGetSetting.szSetting, offset szOShowHidden
    mov sDBGetSetting.pValue, offset sDBVariant
	mov sDBVariant.VAR1, DBVT_DWORD
	invoke CallService, offset MS_DB_CONTACT_GETSETTING, 0, offset sDBGetSetting
	.IF eax==0
		.IF sDBVariant.VAR2!=0
			invoke GetWindowLong, hCList, GWL_STYLE
			or eax, CLS_SHOWHIDDEN
			invoke SetWindowLong, hCList, GWL_STYLE, eax
		.ENDIF
	.ENDIF
	xor eax, eax
	ret
ResetListOptions endp

				;load per contact trigger settings from DB
SetAllContactIcons proc hCList:DWORD
	LOCAL hContact, hItem, szProto, flags, flag:DWORD

	invoke CallService, offset MS_DB_CONTACT_FINDFIRST, 0, 0
	mov hContact, eax
	invoke SendMessage, hCList, WM_TIMER, 14, 0		;Note: Hack. Wait for the CList To be ready. Thanks to FYR
	.WHILE hContact!=0
		invoke SendMessage, hCList, CLM_FINDCONTACT, hContact, 0
		mov hItem, eax
		.IF eax!=0
			invoke CallService, offset MS_PROTO_GETCONTACTBASEPROTO, hContact, 0	;get PROTO for each contact
			mov szProto, eax
			.IF eax==0
				mov flag, 1
				mov flags, 1
			.ELSE
				invoke IgnoreCheck, szProto						;Check PROTO Capabilities
				mov flags, eax
				mov sDBGetSetting.szModule, offset szOModule		;load settings
				mov sDBGetSetting.szSetting, offset szOEnabled
				mov sDBGetSetting.pValue, offset sDBVariant
				mov sDBVariant.VAR1, DBVT_WORD
				invoke CallService, offset MS_DB_CONTACT_GETSETTING, hContact, offset sDBGetSetting
				.IF eax==0
					push sDBVariant.VAR2
					pop flag
				.ELSE
					mov flag, 1
				.ENDIF
			.ENDIF
			.IF flags!=0			;finally set the necesarry image
				xor eax, eax		;Use (MAKELPARAM "column", "image") instead of just 0
				invoke SendMessage, hCList, CLM_GETEXTRAIMAGE, hItem, eax
				.IF eax==0FFh
					.IF flag!=0
						mov flag, 1
					.ENDIF
					MAKELPARAM 0, flag
					invoke SendMessage, hCList, CLM_SETEXTRAIMAGE, hItem, eax
				.ENDIF
			.ENDIF
		.ENDIF
		invoke CallService, offset MS_DB_CONTACT_FINDNEXT, hContact, 0
		mov hContact, eax
	.ENDW
	ret
SetAllContactIcons endp

				;Set group icons according to the contacts inside
SetListGroupIcons proc hCList:DWORD, hFirstItem:DWORD, hParentItem:DWORD, groupChildCount:DWORD
	LOCAL typeOfFirst, iconOn, childCount, iImage, hItem, hChildItem:DWORD

	mov iconOn, 1						;assume all are enabled
	mov childCount, 0
	invoke SendMessage, hCList, CLM_GETITEMTYPE,hFirstItem, 0
	mov typeOfFirst, eax

	;check groups
	.IF typeOfFirst==CLCIT_GROUP
		push hFirstItem
		pop hItem
	.ELSE
		invoke SendMessage, hCList, CLM_GETNEXTITEM, CLGN_NEXTGROUP, hFirstItem
		mov hItem, eax
	.ENDIF
	.WHILE hItem!=NULL
		invoke SendMessage, hCList, CLM_GETNEXTITEM, CLGN_CHILD, hItem
		mov hChildItem, eax
		.IF eax!=0
			invoke SetListGroupIcons, hCList, hChildItem, hItem, addr childCount
		.ENDIF
		.IF iconOn!=0
			invoke SendMessage, hCList, CLM_GETEXTRAIMAGE, hItem, 0
			.IF eax==0
				mov iconOn, 0
			.ENDIF
		.ENDIF
		invoke SendMessage, hCList, CLM_GETNEXTITEM, CLGN_NEXTGROUP, hItem
		mov hItem, eax
	.ENDW

	;check contacts
	.IF typeOfFirst==CLCIT_CONTACT
		push hFirstItem
		pop hItem
	.ELSE
		invoke SendMessage, hCList, CLM_GETNEXTITEM, CLGN_NEXTCONTACT, hFirstItem
		mov hItem, eax
	.ENDIF
	.WHILE hItem!=0
		invoke SendMessage, hCList, CLM_GETEXTRAIMAGE, hItem, 0
		.IF iconOn!=0
			.IF eax==0
				mov iconOn, 0
			.ENDIF
		.ENDIF
		.IF eax!=0FFh
			inc childCount
		.ENDIF
		invoke SendMessage, hCList, CLM_GETNEXTITEM, CLGN_NEXTCONTACT, hItem
		mov hItem, eax
	.ENDW

	;set group icons
	.IF childCount==0
		mov eax, 0FFh
	.ELSEIF iconOn==0
		mov eax, 0
	.ELSE
		mov eax, 1
	.ENDIF
	MAKELPARAM 0, eax
	invoke SendMessage, hCList, CLM_SETEXTRAIMAGE, hParentItem, eax
	.IF groupChildCount!=0
		mov eax, [groupChildCount]
		add eax, childCount
		mov [groupChildCount], eax
	.ENDIF
	ret
SetListGroupIcons endp

				;set group child icons
SetAllChildIcons proc hCList:DWORD, hFirstItem:DWORD, iColumn:DWORD, iImage:DWORD
	LOCAL typeOfFirst, iOldIcon, hItem, hChildItem:DWORD

	invoke SendMessage, hCList, CLM_GETITEMTYPE, hFirstItem, 0
	mov typeOfFirst, eax

	;set icons for groups
	.IF typeOfFirst==CLCIT_GROUP
		push hFirstItem
		pop hItem
	.ELSE
		invoke SendMessage, hCList, CLM_GETNEXTITEM, CLGN_NEXTGROUP, hFirstItem
		mov hItem, eax
	.ENDIF
	.WHILE hItem!=0
		invoke SendMessage, hCList, CLM_GETNEXTITEM, CLGN_CHILD, hItem
		mov hChildItem, eax
		.IF hChildItem!=0
			invoke SetAllChildIcons, hCList, hChildItem, iColumn, iImage
		.ENDIF
		invoke SendMessage, hCList, CLM_GETNEXTITEM, CLGN_NEXTGROUP, hItem
		mov hItem, eax
	.ENDW

	;set icons for contacts
	.IF typeOfFirst==CLCIT_CONTACT
		push hFirstItem
		pop hItem
	.ELSE
		invoke SendMessage, hCList, CLM_GETNEXTITEM, CLGN_NEXTCONTACT, hFirstItem
		mov hItem, eax
	.ENDIF
	.WHILE hItem!=0
		invoke SendMessage, hCList, CLM_GETEXTRAIMAGE, hItem, iColumn
		mov iOldIcon, eax
		.IF iOldIcon!=0FFh
			mov eax, iImage
			.IF iOldIcon!=eax
				MAKELPARAM iColumn, iImage
				invoke SendMessage, hCList, CLM_SETEXTRAIMAGE, hItem, eax
				mov sDBGetSetting.szModule, offset szOMetaContacts		;load settings
				mov sDBGetSetting.szSetting, offset szOMetaCount
				mov sDBGetSetting.pValue, offset sDBVariant
				mov sDBVariant.VAR1, DBVT_WORD
				invoke CallService, offset MS_DB_CONTACT_GETSETTING, hItem, offset sDBGetSetting
				.IF eax==0
					invoke MetaConClick, hItem, sDBVariant.VAR2, iImage
				.ENDIF
			.ENDIF
		.ENDIF
		invoke SendMessage, hCList, CLM_GETNEXTITEM, CLGN_NEXTCONTACT, hItem
		mov hItem, eax
	.ENDW
	ret
SetAllChildIcons endp

				;set icons to contacts Not on list
SetUnkChildIcons proc hCList:DWORD, hFirstItem:DWORD, iColumn:DWORD, iImage:DWORD
	LOCAL typeOfFirst, iOldIcon, hItem, hChildItem:DWORD

	invoke SendMessage, hCList, CLM_GETITEMTYPE, hFirstItem, 0
	mov typeOfFirst, eax

	;set icons for groups
	.IF typeOfFirst==CLCIT_GROUP
		push hFirstItem
		pop hItem
	.ELSE
		invoke SendMessage, hCList, CLM_GETNEXTITEM, CLGN_NEXTGROUP, hFirstItem
		mov hItem, eax
	.ENDIF
	.WHILE hItem!=0
		invoke SendMessage, hCList, CLM_GETNEXTITEM, CLGN_CHILD, hItem
		mov hChildItem, eax
		.IF hChildItem!=0
			invoke SetUnkChildIcons, hCList, hChildItem, iColumn, iImage
		.ENDIF
		invoke SendMessage, hCList, CLM_GETNEXTITEM, CLGN_NEXTGROUP, hItem
		mov hItem, eax
	.ENDW

	;set icons for contacts
	.IF typeOfFirst==CLCIT_CONTACT
		push hFirstItem
		pop hItem
	.ELSE
		invoke SendMessage, hCList, CLM_GETNEXTITEM, CLGN_NEXTCONTACT, hFirstItem
		mov hItem, eax
	.ENDIF
	.WHILE hItem!=0
		invoke SendMessage, hCList, CLM_GETEXTRAIMAGE, hItem, iColumn
		mov iOldIcon, eax
		.IF iOldIcon!=0FFh
			mov eax, iImage
			.IF iOldIcon!=eax
				mov sDBGetSetting.szModule, offset szOCList
				mov sDBGetSetting.szSetting, offset szONotOnList
				mov sDBGetSetting.pValue, offset sDBVariant
				mov sDBVariant.VAR1, DBVT_BYTE
				invoke CallService, offset MS_DB_CONTACT_GETSETTING, hItem, offset sDBGetSetting
				.IF eax==0
					lea esi, sDBVariant.VAR2
					mov al, [esi]
					.IF al!=0
						MAKELPARAM iColumn, iImage
						invoke SendMessage, hCList, CLM_SETEXTRAIMAGE, hItem, eax
					.ENDIF
				.ENDIF
			.ENDIF
		.ENDIF
		invoke SendMessage, hCList, CLM_GETNEXTITEM, CLGN_NEXTCONTACT, hItem
		mov hItem, eax
	.ENDW
	ret
SetUnkChildIcons endp

MetaConClick proc hContact:DWORD, iCount:DWORD, iValue: DWORD
	dec iCount
	.WHILE iCount!=-1
		invoke CallService, offset MS_MC_GETSUBCONTACT, hContact, iCount
		.IF eax!=0
			mov ebx, eax
			MAKELPARAM 0, 0
			invoke SendDlgItemMessage, hDlgWnd, IDC_CLIST, CLM_GETEXTRAIMAGE, ebx, eax
			.IF eax!= 0FFh
				MAKELPARAM 0, iValue
				invoke SendDlgItemMessage, hDlgWnd, IDC_CLIST, CLM_SETEXTRAIMAGE, ebx, eax
			.ENDIF
		.ENDIF
		dec iCount
	.ENDW
	ret
MetaConClick endp

MetaSubClick proc hContact:DWORD
	LOCAL iVal, iCounter:DWORD

	invoke CallService, offset MS_MC_GETMETACONTACT, hContact, 0
	.IF eax!=0
		mov hContact, eax
		mov sDBGetSetting.szModule, offset szOMetaContacts		;load settings
		mov sDBGetSetting.szSetting, offset szOMetaCount
		mov sDBGetSetting.pValue, offset sDBVariant
		mov sDBVariant.VAR1, DBVT_WORD
		invoke CallService, offset MS_DB_CONTACT_GETSETTING, hContact, offset sDBGetSetting
		.IF eax==0
			push sDBVariant.VAR2
			pop iCounter
			dec iCounter
			mov iVal, 1
			.WHILE iCounter!=-1
				invoke CallService, offset MS_MC_GETSUBCONTACT, hContact, iCounter
				.IF eax!=0
					mov ebx, eax
					MAKELPARAM 0, 0
					invoke SendDlgItemMessage, hDlgWnd, IDC_CLIST, CLM_GETEXTRAIMAGE, ebx, eax
					.IF eax==0
						mov iVal, 0
					.ENDIF
				.ENDIF
				dec iCounter
			.ENDW
		.ENDIF
	.ENDIF
	MAKELPARAM 0, iVal
	invoke SendDlgItemMessage, hDlgWnd, IDC_CLIST, CLM_SETEXTRAIMAGE, hContact, eax
	ret
MetaSubClick endp

;##############################
;	Options hook proc
;##############################
OptInit proc C wParam:DWORD, lParam:DWORD
	mov	eax, wParam			;init the options dialog
	invoke CallService, addr MS_OPT_ADDPAGE, eax, addr sOptionsPage
    xor eax, eax
    ret
OptInit Endp

;##############################
;	Message hook proc
;##############################
Message proc C wParam:DWORD, lParam:DWORD
	LOCAL hContact:DWORD

	push lParam											;save hDBEvent
	pop ddVar1
    invoke CallService, offset MS_DB_EVENT_GETCONTACT, ddVar1, 0
    mov hContact, eax
    mov sDBGetSetting.szModule, offset szOModule			;load the flags
    mov sDBGetSetting.szSetting, offset szOEnabled
    mov sDBGetSetting.pValue, offset sDBVariant
	mov sDBVariant.VAR1, DBVT_DWORD
	invoke CallService, offset MS_DB_CONTACT_GETSETTING, hContact, offset sDBGetSetting
	.IF eax==0
		.IF sDBVariant.VAR2==0
			ret
		.ENDIF
	.ENDIF
	mov sDBGetSetting.szModule, offset szOCList
	mov sDBGetSetting.szSetting, offset szONotOnList
	mov sDBVariant.VAR1, DBVT_BYTE
	invoke CallService, offset MS_DB_CONTACT_GETSETTING, hContact, offset sDBGetSetting
	.IF eax==0
		push esi
		lea esi, sDBVariant.VAR2
		mov al, [esi]
		pop esi
		.IF al!=0
			mov sDBGetSetting.szModule, offset szOModule
			mov sDBVariant.VAR1, DBVT_DWORD
			invoke CallService, offset MS_DB_CONTACT_GETSETTING, 0, offset sDBGetSetting
			.IF eax==0
				.IF sDBVariant.VAR2==0
					ret
				.ENDIF
			.ENDIF
		.ENDIF
	.ENDIF
	mov sDBGetSetting.szModule, offset szOModule
	mov sDBGetSetting.szSetting, offset szOFlags
	mov sDBVariant.VAR1, DBVT_DWORD
	invoke CallService, offset MS_DB_CONTACT_GETSETTING, 0, offset sDBGetSetting
	push sDBVariant.VAR2								;backup the value
	pop ddVar3
	push ddVar3
	pop ddVar2
	and sDBVariant.VAR2, 1								;select a flag
	.IF eax==0
		.IF sDBVariant.VAR2==0
			ret
		.ENDIF
	.ENDIF
	invoke CallService, offset MS_CLIST_GETSTATUSMODE, 0, 0
	.IF eax!=0										;on error, status=offline
		sub eax, IDC_ENABLED
	.ENDIF
	push esi
	mov esi, 1
	.WHILE eax!=0									;generate flag from status
		shl esi, 1
		dec eax
	.ENDW
	and ddVar3, esi									;check status filter
	pop esi
	.IF ddVar3==0
		xor eax, eax
		ret
	.ENDIF
	mov sDBEventInfo.cbSize, sizeof DBEVENTINFO	;load message info and protocol
	mov sDBEventInfo.cbBlob, 150
	mov sDBEventInfo.pBlob, offset szGeneral
	invoke CallService, offset MS_DB_EVENT_GET, ddVar1, offset sDBEventInfo
	mov sDBGetSetting.szModule, offset szOModule	;load protocol settings
	push sDBEventInfo.szModule
	pop sDBGetSetting.szSetting
	mov sDBGetSetting.pValue, offset sDBVariant
	mov sDBVariant.VAR1, DBVT_DWORD
	invoke CallService, offset MS_DB_CONTACT_GETSETTING, 0, offset sDBGetSetting
	.IF eax==0
		.IF sDBVariant.VAR2==0
			ret
		.ENDIF
	.ENDIF
	mov eax, sDBEventInfo.eventType			;check for message type
	push esi
	push edi
	mov edi, offset IDC_ETYPE_MESSAGE_V
	mov esi, 800h
	.WHILE esi!=20000h &&  eax!=[edi]		;list message types
		add edi, 08h
		shl esi, 1
	.ENDW
	and esi, 1FFFFh
	and esi, ddVar2
	mov ddVar3, esi
	pop edi
	pop esi
	.IF ddVar3==0
		ret
	.ENDIF
	push ecx							;check time trigger
	push ebx
	invoke GetSystemTime, addr sSystemTime	;local time
	xor eax, eax
	mov ax, sSystemTime.wHour
	shl eax, 16
	mov ax, sSystemTime.wMinute
	shl ax, 8
	shr eax, 8
	mov ddVar2, eax
	mov sDBGetSetting.szSetting, offset szOTime	;load DB settings
	invoke CallService, offset MS_DB_CONTACT_GETSETTING, 0, offset sDBGetSetting
	.IF eax==0
		mov eax, sDBVariant.VAR2
		xor ebx, ebx								;check time
		mov bx, ax
		shr eax, 16
		mov ecx, ddVar2
		mov ddVar3, 0
		.IF eax<ebx
			.IF eax<=ecx
				.IF ecx<=ebx
					mov ddVar3, 1
				.ENDIF
			.ENDIF
		.ELSEIF eax>ebx
			.IF ecx>=eax
				mov ddVar3, 1
			.ELSEIF ebx>=ecx
				mov ddVar3, 1
			.ENDIF
		.ELSE
			mov ddVar3, 1
		.ENDIF
	.ENDIF
	pop ebx
	pop ecx
	.IF ddVar3
		invoke SendMessage, HWND_BROADCAST, WM_SYSCOMMAND, SC_MONITORPOWER, -1	;turn monitor on
	.ENDIF

	xor eax, eax
    ret
Message Endp

;##############################
;	First tab event proc
;##############################
Options1 proc, dhWnd:DWORD, uMsg:DWORD, wParam:DWORD, lParam:DWORD
	.IF uMsg==WM_INITDIALOG								;if user opens options
		invoke SetWindowPos, dhWnd, HWND_TOP, sDlgHdr.rcDisplay.left, sDlgHdr.rcDisplay.top, 0, 0, SWP_NOSIZE
		.IF ddInt==0
			or ddFlags, 2
			push esi
			push edi
			mov edi, offset HC_ENABLED						;get control hWnd's from ID's
			mov esi, IDC_ENABLED
			.WHILE esi<=IDC_ENDTIME
					invoke	GetDlgItem, dhWnd, esi
					mov	[edi], eax
					inc	esi
					add	edi,4
			.ENDW
			pop edi
			pop esi
			mov ddInt, 1
			invoke SendMessage, HC_STARTTIME, DTM_SETFORMAT, 0, addr szDtFormat	;datetime pickers format
			invoke SendMessage, HC_ENDTIME, DTM_SETFORMAT, 0, addr szDtFormat
			mov sDBGetSetting.szModule, offset szOModule		;load time triggers
			mov sDBGetSetting.szSetting, offset szOTime
			mov sDBGetSetting.pValue, offset sDBVariant
			mov sDBVariant.VAR1, DBVT_DWORD
			invoke CallService, offset MS_DB_CONTACT_GETSETTING, 0, offset sDBGetSetting
			mov eax, sDBVariant.VAR2						;get start and end time
			push ax
			and ax, 00FFh
			mov sSystemTime.wMinute, ax
			pop ax
			shr ax, 8
			mov sSystemTime.wHour, ax
			push eax
			invoke SendMessage, HC_ENDTIME, DTM_SETSYSTEMTIME, GDT_VALID, addr sSystemTime
			pop eax
			shr eax, 16		
			push ax
			and ax, 00FFh
			mov sSystemTime.wMinute, ax
			pop ax
			shr ax, 8
			mov sSystemTime.wHour, ax
			invoke SendMessage, HC_STARTTIME, DTM_SETSYSTEMTIME, GDT_VALID, addr sSystemTime
			mov sDBGetSetting.szModule, offset szOModule
			mov sDBGetSetting.szSetting, offset szOFlags		;load flags
			mov sDBGetSetting.pValue, offset sDBVariant
			mov sDBVariant.VAR1, DBVT_DWORD
			invoke CallService, offset MS_DB_CONTACT_GETSETTING, 0, offset sDBGetSetting
			push edi
			push ebx
			mov edi, offset HC_ENABLED						;disable controls if plugin disabled
			push sDBVariant.VAR2
			pop sDBVariant.VAR3
			mov ebx, 01h
			.WHILE edi<=offset HC_ETYPE_FILE
				and sDBVariant.VAR2, ebx
				.IF eax!=0 || (eax==0 && sDBVariant.VAR2 !=0)
					push eax
					Invoke SendMessage, [edi], BM_SETCHECK, BST_CHECKED, 0
					pop eax
				.ENDIF
				shl ebx, 1
				push sDBVariant.VAR3
				pop sDBVariant.VAR2
				add edi, 04h
			.ENDW	
			pop ebx
			pop edi
			invoke CallService, offset MS_PROTO_ENUMPROTOCOLS, offset ddVar1, offset ddVar2	;get protocol list
			push esi										;then load them into list box
			push edi
			push ebx
			mov esi, ddVar1
			mov edi, esi
			dec edi
			shl edi, 2
			add edi, ddVar2
			mov sDBGetSetting.szModule, offset szOModule		;and also check if it's enabled
			mov sDBGetSetting.pValue, offset sDBVariant
			mov sDBVariant.VAR1, DBVT_DWORD
			.WHILE esi!=0
				mov ebx, [edi]
				invoke IgnoreCheck, [ebx+04h]			;check for ignore list
				.IF eax!=0
					mov eax, [ebx+08h]
					.IF eax==03E8h						;check if it really is a protocol
						push [ebx+04h]
						pop sDBGetSetting.szSetting
						invoke CallService, offset MS_DB_CONTACT_GETSETTING, 0, offset sDBGetSetting
						.IF eax!=0
							mov sDBVariant.VAR2, 01h
						.ENDIF
						invoke SendMessage, HC_PROTO, LB_INSERTSTRING, 0, [ebx+04h]		;add it to the list
						invoke SendMessage, HC_PROTO, LB_SETSEL, sDBVariant.VAR2, 0
					.ENDIF
				.ENDIF
				sub edi, 04h
				dec esi
			.ENDW
			pop ebx
			pop edi
			pop esi
			or ddFlags, 6
			invoke PostMessage, dhWnd, WM_COMMAND, IDC_ENABLED, dhWnd
		.ENDIF
	.ELSEIF uMsg==WM_COMMAND							;if sth. happened in the dialog
		mov eax, wParam
		.IF lParam!=0
			.IF ax==IDC_ENABLED
				push edi								;enable/disable the controls on the dialog
				push esi
				invoke IsDlgButtonChecked, dhWnd, IDC_ENABLED
				mov esi, eax
				mov edi, offset HC_STATUS_ONLINE
				.WHILE edi<=offset HC_ENDTIME
					invoke EnableWindow, [edi], esi
					add edi, 04h
				.ENDW
				pop esi
				pop edi
			.ENDIF
		.ENDIF
		mov eax, ddFlags
		and eax, 6
		.IF eax==0
			invoke GetParent, dhWnd
			invoke GetParent, eax
			push eax
			invoke SendMessage, eax, PSM_CHANGED, 0, 0		;enable the Apply button
			pop eax
			invoke GetParent, eax
			invoke SendMessage, eax, PSM_CHANGED, 0, 0		;enable the Apply button
		.ELSEIF ddFlags==6
			and ddFlags, -7
		.ENDIF
	.ELSEIF uMsg==WM_NOTIFY
		.IF wParam==IDC_STARTTIME || wParam==IDC_ENDTIME		;if a message from time controls
			mov edi, lParam
			assume edi:ptr NMHDR
				.IF [edi].code==DTN_DATETIMECHANGE
					invoke GetParent, dhWnd
					invoke GetParent, eax
					push eax
					invoke SendMessage, eax, PSM_CHANGED, 0, 0		;enable the Apply button
					pop eax
					invoke GetParent, eax
					invoke SendMessage, eax, PSM_CHANGED, 0, 0		;enable the Apply button
				.ENDIF
			assume edi:nothing
		.ENDIF
		mov eax, lParam									;check if apply or OK pressed
		.IF eax==0
			xor eax, eax
			ret
		.ENDIF
		mov	eax, [eax+8]
		add	eax, 201
		.IF eax==0
			push esi
			mov esi, offset HC_ETYPE_FILE						;start saving all the settings
			xor ebx, ebx
			.WHILE esi>=offset HC_ENABLED
				shl	ebx, 1								;shift ebx, to make room for next
				invoke SendMessage, [esi], BM_GETCHECK, 0, 0	;get state of buttons, 1=checked, 0=unchecked
				.IF eax==BST_CHECKED
					xor eax, eax
					inc eax
				.ELSE
					xor eax, eax
				.ENDIF
				or ebx, eax								;add it to ebx
				sub	esi, 4
			.ENDW
			mov sDBWriteSetting.szModule, offset szOModule	;save them
			mov sDBWriteSetting.szSetting, offset szOFlags
			mov sDBWriteSetting.VAR1, DBVT_DWORD
			mov sDBWriteSetting.VAR2, ebx
			invoke CallService, offset MS_DB_CONTACT_WRITESETTING, 0, offset sDBWriteSetting
			invoke SendMessage, HC_STARTTIME, DTM_GETSYSTEMTIME, 0, addr sSystemTime	;get start time
			mov ax, sSystemTime.wHour
			shl eax, 16
			mov ax, sSystemTime.wMinute
			shl ax, 8
			shl eax, 8
			push eax
			invoke SendMessage, HC_ENDTIME, DTM_GETSYSTEMTIME, 0, addr sSystemTime		;get end time
			pop eax
			mov bx, sSystemTime.wHour
			shl ebx, 16
			mov bx, sSystemTime.wMinute
			shl bx, 8
			shr ebx, 8
			mov ax, bx
			mov sDBWriteSetting.szSetting, offset szOTime					;save time options in DB
			mov sDBWriteSetting.VAR2, eax
			invoke CallService, offset MS_DB_CONTACT_WRITESETTING, 0, offset sDBWriteSetting
			
			invoke CallService, offset MS_PROTO_ENUMPROTOCOLS, offset ddVar1, offset ddVar2	;get protocol list
			push esi										;then load them into list box
			push edi
			push ebx
			mov esi, ddVar1
			mov edi, ddVar2
			mov ddVar3, 0
			mov sDBWriteSetting.szModule, offset szOModule		;and also check if it's enabled
			mov sDBWriteSetting.VAR1, DBVT_DWORD
			.WHILE esi!=0
				mov ebx, [edi]
				invoke IgnoreCheck, [ebx+04h]			;check for ignore list
				.IF eax!=0
					mov eax, [ebx+08h]
					.IF eax==03E8h						;check if it really is a protocol
						invoke SendMessage, HC_PROTO, LB_GETSEL, ddVar3, 0
						mov sDBWriteSetting.VAR2, eax
						push [ebx+04h]
						pop sDBWriteSetting.szSetting
						invoke CallService, offset MS_DB_CONTACT_WRITESETTING, 0, offset sDBWriteSetting
						inc ddVar3
					.ENDIF
				.ENDIF
				add edi, 04h
				dec esi
			.ENDW
			pop ebx
			pop edi
			pop esi
		.ENDIF
	.ENDIF
	xor	eax,eax
	ret
Options1 endp

;##############################
;	Second tab event proc
;##############################
Options2 proc, dhWnd:DWORD, uMsg:DWORD, wParam:DWORD, lParam:DWORD
	LOCAL hContact, hItem, hitFlags, iImage, itemType, i:DWORD
	
	push dhWnd
	pop hDlgWnd
	.IF uMsg==WM_INITDIALOG
		invoke SetWindowPos, dhWnd, HWND_TOP, sDlgHdr.rcDisplay.left, sDlgHdr.rcDisplay.top, 0, 0, SWP_NOSIZE
		invoke	GetDlgItem, dhWnd, IDC_SHOWHIDDEN
		mov HC_SHOWHIDDEN, eax
	    mov sDBGetSetting.szModule, offset szOModule			;load the flags
		mov sDBGetSetting.szSetting, offset szOShowHidden
		mov sDBGetSetting.pValue, offset sDBVariant
		mov sDBVariant.VAR1, DBVT_DWORD
		invoke CallService, offset MS_DB_CONTACT_GETSETTING, 0, offset sDBGetSetting
		.IF eax==0
			.IF sDBVariant.VAR2!=0
				Invoke SendMessage, HC_SHOWHIDDEN, BM_SETCHECK, BST_CHECKED, 0
			.ENDIF
		.ENDIF
		invoke SendMessage, dhWnd, WM_IMGLIST, wParam, lParam
		invoke GetDlgItem, dhWnd, IDC_CLIST
		mov HC_CLIST, eax
		invoke ResetListOptions, HC_CLIST
		invoke SendDlgItemMessage, dhWnd, IDC_CLIST, CLM_SETEXTRACOLUMNS, 1, 0			;set no of icon columns
		mov sClcInfoItem.cbSize, sizeof CLCINFOITEM							;add additional items
		mov sClcInfoItem.flags, CLCIIF_GROUPFONT
		invoke Translate, offset szAllContacts								;** All contacts **
		mov sClcInfoItem.pszText, eax
		invoke SendDlgItemMessage, dhWnd, IDC_CLIST, CLM_ADDINFOITEM, 0, addr sClcInfoItem
		mov hItemAll, eax
		invoke Translate, offset szUnkContacts								;** Unknown contacts **
		mov sClcInfoItem.pszText, eax
		invoke SendDlgItemMessage, dhWnd, IDC_CLIST, CLM_ADDINFOITEM, 0, addr sClcInfoItem
		mov hItemUnk, eax
		
		invoke SetAllContactIcons, HC_CLIST									;Init control values
		invoke SendDlgItemMessage, dhWnd, IDC_CLIST, CLM_GETNEXTITEM, CLGN_ROOT, 0
		invoke SetListGroupIcons, HC_CLIST, eax, hItemAll, NULL
	    mov sDBGetSetting.szModule, offset szOModule			;load the flags
		mov sDBGetSetting.szSetting, offset szONotOnList
		mov sDBGetSetting.pValue, offset sDBVariant
		mov sDBVariant.VAR1, DBVT_DWORD
		invoke CallService, offset MS_DB_CONTACT_GETSETTING, 0, offset sDBGetSetting
		.IF eax==0
			.IF sDBVariant.VAR2!=0
				mov eax, 1
			.ENDIF
		.ELSE
			mov eax, 1
		.ENDIF
		push eax
		invoke SetUnkChildIcons, HC_CLIST, hItemUnk, 0, eax
		pop eax
		MAKELPARAM 0, eax
		invoke SendDlgItemMessage, dhWnd, IDC_CLIST, CLM_SETEXTRAIMAGE, hItemUnk, eax
	.ELSEIF uMsg==WM_IMGLIST
		invoke GetVersion			;check win version
		.IF al==5
			.IF ah!=0
				mov eax, ILC_COLOR32 or ILC_MASK
			.ELSEIF
				mov eax, ILC_COLOR16 or ILC_MASK
			.ENDIF
		.ENDIF
		invoke ImageList_Create, 16, 16, eax, 3, 3		;create image list
		mov hIml, eax
		invoke LoadIcon, hApp, IDI_SMALLDOT				;add icon
		push eax
		invoke ImageList_AddIcon, hIml, eax
		pop eax
		invoke DeleteObject, eax
		invoke CallService, offset MS_SKIN2_GETICON, 0, offset szIlName
		invoke ImageList_AddIcon, hIml, eax
		invoke SendDlgItemMessage, dhWnd, IDC_CLIST, CLM_SETEXTRAIMAGELIST, 0, hIml		;link image list to CList
	.ELSEIF uMsg==WM_SETFOCUS
		invoke SetFocus, HC_CLIST
	.ELSEIF uMsg==WM_COMMAND
		mov eax, wParam
		.IF lParam!=0
			.IF ax==IDC_SHOWHIDDEN
				mov sDBWriteSetting.szModule, offset szOModule
				mov sDBWriteSetting.szSetting, offset szOShowHidden
				mov sDBWriteSetting.VAR1, DBVT_DWORD
				invoke SendMessage, HC_SHOWHIDDEN, BM_GETCHECK, 0, 0
				.IF eax==BST_CHECKED
					mov sDBWriteSetting.VAR2, 1
					invoke GetWindowLong, HC_CLIST, GWL_STYLE
					or eax, CLS_SHOWHIDDEN
				.ELSE
					mov sDBWriteSetting.VAR2, 0
					invoke GetWindowLong, HC_CLIST, GWL_STYLE
					mov ebx, -CLS_SHOWHIDDEN
					dec ebx
					and eax, ebx
				.ENDIF
				invoke SetWindowLong, HC_CLIST, GWL_STYLE, eax
				invoke CallService, offset MS_DB_CONTACT_WRITESETTING, 0, offset sDBWriteSetting
				invoke SendMessage, HC_CLIST, CLM_SETUSEGROUPS, 1, 0
				invoke SetAllContactIcons, HC_CLIST
				invoke SendDlgItemMessage, dhWnd, IDC_CLIST, CLM_GETNEXTITEM, CLGN_ROOT, 0
				invoke SetListGroupIcons, HC_CLIST, eax, hItemAll, NULL
			.ENDIF
		.ENDIF
	.ELSEIF uMsg==WM_NOTIFY				;if sth changes
		mov edi, lParam
		assume edi:ptr NMHDR
		.IF [edi].idFrom==IDC_CLIST
			.IF [edi].code==CLN_NEWCONTACT
				invoke SetAllContactIcons, HC_CLIST
				invoke SendDlgItemMessage, dhWnd, IDC_CLIST, CLM_GETNEXTITEM, CLGN_ROOT, 0
				invoke SetListGroupIcons, HC_CLIST, eax, hItemAll, NULL
			.ELSEIF [edi].code==CLN_LISTREBUILT
				invoke SendDlgItemMessage, dhWnd, IDC_CLIST, CLM_GETNEXTITEM, CLGN_ROOT, 0
				invoke SetListGroupIcons, HC_CLIST, eax, hItemAll, NULL
			.ELSEIF [edi].code==CLN_CONTACTMOVED
				invoke SendDlgItemMessage, dhWnd, IDC_CLIST, CLM_GETNEXTITEM, CLGN_ROOT, 0
				invoke SetListGroupIcons, HC_CLIST, eax, hItemAll, NULL
			.ELSEIF [edi].code==CLN_OPTIONSCHANGED
				invoke ResetListOptions, HC_CLIST
			.ELSEIF [edi].code==NM_CLICK		;Click on the CList
				assume edi:ptr NMCLISTCONTROL
				.IF [edi].iColumn!=-1
					MAKELPARAM [edi].pt.x, [edi].pt.y
					invoke SendDlgItemMessage, dhWnd, IDC_CLIST, CLM_HITTEST, addr hitFlags, eax
					mov hItem, eax
					.IF hItem!=0
						and hitFlags, CLCHT_ONITEMEXTRA		;if click on icon, then analyze and edit
						.IF hitFlags!=0
							invoke SendDlgItemMessage, dhWnd, IDC_CLIST, CLM_GETEXTRAIMAGE, hItem, [edi].iColumn
							.IF eax==0
								mov iImage, 1
							.ELSE
								mov iImage, 0
							.ENDIF
							MAKELPARAM [edi].iColumn, 0
							invoke SendDlgItemMessage, dhWnd, IDC_CLIST, CLM_GETEXTRAIMAGE, hItem, eax
							.IF eax!= 0FFh
								MAKELPARAM [edi].iColumn, iImage
								invoke SendDlgItemMessage, dhWnd, IDC_CLIST, CLM_SETEXTRAIMAGE, hItem, eax
								invoke SendDlgItemMessage, dhWnd, IDC_CLIST, CLM_GETITEMTYPE, hItem, 0
								mov itemType, eax
								.IF itemType==CLCIT_CONTACT		;if click on contact
									MAKELPARAM [edi].iColumn, iImage
									invoke SendDlgItemMessage, dhWnd, IDC_CLIST, CLM_SETEXTRAIMAGE, hItem, eax
									mov sDBGetSetting.szModule, offset szOMetaContacts		;load settings
									mov sDBGetSetting.szSetting, offset szOMetaCount
									mov sDBGetSetting.pValue, offset sDBVariant
									mov sDBVariant.VAR1, DBVT_WORD
									invoke CallService, offset MS_DB_CONTACT_GETSETTING, hItem, offset sDBGetSetting
									.IF eax==0
										;is MetaContact
										invoke MetaConClick, hItem, sDBVariant.VAR2, iImage
									.ELSE
										mov sDBGetSetting.szSetting, offset szOMetaLink
										invoke CallService, offset MS_DB_CONTACT_GETSETTING, hItem, offset sDBGetSetting
										.IF eax==0
											;is subcontact
											invoke MetaSubClick, hItem
										.ENDIF
									.ENDIF
								.ENDIF
								.IF itemType==CLCIT_INFO		;if click on extra item
									mov eax, hItem
									.IF eax==hItemAll
										invoke SetAllChildIcons, HC_CLIST, hItem, [edi].iColumn, iImage
									.ELSEIF eax==hItemUnk
										invoke SetUnkChildIcons, HC_CLIST, hItem, [edi].iColumn, iImage
									.ENDIF
								.ENDIF
								.IF itemType==CLCIT_GROUP		;if click on group
									invoke SendDlgItemMessage, dhWnd, IDC_CLIST, CLM_GETNEXTITEM, CLGN_CHILD, hItem
									mov hItem, eax
									.IF hItem!=0
										invoke SetAllChildIcons, HC_CLIST, hItem, [edi].iColumn, iImage
									.ENDIF
								.ENDIF
								invoke SendDlgItemMessage, dhWnd, IDC_CLIST, CLM_GETNEXTITEM, CLGN_ROOT, 0
								invoke SetListGroupIcons, HC_CLIST, eax, hItemAll, NULL
								invoke GetParent, dhWnd
								invoke GetParent, eax
								push eax
								invoke SendMessage, eax, PSM_CHANGED, 0, 0		;enable the Apply button
								pop eax
								invoke GetParent, eax
								invoke SendMessage, eax, PSM_CHANGED, 0, 0		;enable the Apply button
							.ENDIF
						.ENDIF
					.ENDIF
				.ENDIF
				assume edi:ptr NMHDR
			.ENDIF
		.ELSEIF [edi].idFrom==0
			.IF [edi].code==PSN_APPLY					;if OK/Apply pressed. Save options
				invoke CallService, addr MS_DB_CONTACT_FINDFIRST, 0, 0
				mov hContact, eax
				.WHILE hContact!=0
					invoke SendDlgItemMessage, dhWnd, IDC_CLIST, CLM_FINDCONTACT, hContact, 0
					mov hItem, eax
					.IF eax!=0
						xor eax, eax			;Use (MAKELPARAM "column", "image") instead of just 0
						invoke SendDlgItemMessage, dhWnd, IDC_CLIST, CLM_GETEXTRAIMAGE, hItem, eax
						mov sDBWriteSetting.szModule, offset szOModule
						mov sDBWriteSetting.szSetting, offset szOEnabled
						mov sDBWriteSetting.VAR1, DBVT_DWORD
						mov sDBWriteSetting.VAR2, eax
						invoke CallService, offset MS_DB_CONTACT_WRITESETTING, hContact, offset sDBWriteSetting
					.ENDIF
					invoke CallService, addr MS_DB_CONTACT_FINDNEXT, hContact, 0
					mov hContact, eax
				.ENDW
				invoke SendDlgItemMessage, dhWnd, IDC_CLIST, CLM_GETEXTRAIMAGE, hItemUnk, 0
				mov sDBWriteSetting.szModule, offset szOModule
				mov sDBWriteSetting.szSetting, offset szONotOnList
				mov sDBWriteSetting.VAR1, DBVT_DWORD
				mov sDBWriteSetting.VAR2, eax
				invoke CallService, offset MS_DB_CONTACT_WRITESETTING, 0, offset sDBWriteSetting
			.ENDIF
		.ENDIF
		assume edi:nothing
	.ELSEIF uMsg==WM_DESTROY
		invoke ImageList_Destroy, hIml				;Free used resources
	.ENDIF
	xor eax, eax
	ret
Options2 endp

TabOptions proc, dhWnd:DWORD, uMsg:DWORD, wParam:DWORD, lParam:DWORD
	push dhWnd
	pop sDlgHdr.hDlg
	.IF uMsg==WM_INITDIALOG								;if user opens options
		mov ddInt, 0
		invoke InitCommonControls
		invoke	GetDlgItem, dhWnd, 1000					;get hWnd of tabs control
		mov sDlgHdr.hTab, eax
		mov edi, offset sTCITEM							;insert tabs
		mov eax, TCIF_TEXT
		mov [edi], eax
		invoke Translate, offset szTab1								;translate Tab name
		IFDEF _UNICODE
			mov sTCITEM.pszText, eax
			invoke SendMessage, sDlgHdr.hTab, TCM_INSERTITEMW, 0, addr sTCITEM
		ELSE
			mov sTCITEM.pszText, eax
			invoke SendMessage, sDlgHdr.hTab, TCM_INSERTITEMA, 0, addr sTCITEM
		ENDIF
		mov sDlgHdr.hDisplay, NULL
		
		invoke SetRectEmpty, addr sDlgHdr.rcDisplay
		invoke SendMessage, sDlgHdr.hTab, TCM_ADJUSTRECT, FALSE, addr sDlgHdr.rcDisplay

		invoke FindResource, hInstance, 101, RT_DIALOG	;load first tab in memory
		invoke LoadResource, hInstance, eax
		invoke LockResource, eax
		invoke CreateDialogIndirectParam, hInstance, eax, sDlgHdr.hTab, Options1, NULL
		mov sDlgHdr.hTab1, eax
		mov sDlgHdr.hDisplay, eax
		
		invoke Translate, offset szTab2								;translate Tab name
		IFDEF _UNICODE
			mov sTCITEM.pszText, eax
			invoke SendMessage, sDlgHdr.hTab, TCM_INSERTITEMW, 1, addr sTCITEM
		ELSE
			mov sTCITEM.pszText, eax
			invoke SendMessage, sDlgHdr.hTab, TCM_INSERTITEMA, 1, addr sTCITEM
		ENDIF
		invoke FindResource, hInstance, 102, RT_DIALOG	;load second tab in memory
		invoke LoadResource, hInstance, eax
		invoke LockResource, eax
		invoke CreateDialogIndirectParam, hInstance, eax, sDlgHdr.hTab, Options2, NULL
		mov sDlgHdr.hTab2, eax
		invoke ShowWindow, sDlgHdr.hTab2, SW_HIDE
		
		mov sLngPackDialog.cbSize, sizeof LANGPACKTRANSLATEDIALOG
		mov sLngPackDialog.flags, 0
		push dhWnd
		pop sLngPackDialog.hwndDlg
		mov sLngPackDialog.ignoreControls, 0
		invoke CallService, offset MS_LANGPACK_TRANSLATEDIALOG, LPTDF_NOTITLE, offset sLngPackDialog		;translate dialogs
		
	.ELSEIF uMsg==WM_NOTIFY
		.IF wParam==1000								;if message from tab control
			mov edi, lParam
			assume edi:ptr NMHDR
				.IF [edi].code==TCN_SELCHANGE			;if tab changed
					.IF sDlgHdr.hDisplay!=0
						invoke ShowWindow, sDlgHdr.hDisplay, SW_HIDE	;hide old tab
					.ENDIF
					invoke SendMessage, sDlgHdr.hTab, TCM_GETCURSEL, 0, 0	;get current tab and show it
					.IF eax==0
						mov eax, sDlgHdr.hTab1
					.ELSEIF eax==1
						mov eax, sDlgHdr.hTab2
					.ELSE
						invoke Error, 0
					.ENDIF
					mov sDlgHdr.hDisplay, eax
					invoke ShowWindow, sDlgHdr.hDisplay, SW_SHOW
				.ENDIF
			assume edi:nothing
		.ELSEIF
			invoke SendMessage, sDlgHdr.hTab1, WM_NOTIFY, wParam, lParam
			invoke SendMessage, sDlgHdr.hTab2, WM_NOTIFY, wParam, lParam
		.ENDIF
	.ENDIF
	xor eax, eax
	ret
TabOptions endp

Unload proc
    invoke UnhookEvent, hMsgHook			;unhook events and exit
    invoke UnhookEvent, hOptHook
    invoke UnhookEvent, hIcoLibEv
    xor eax, eax
    ret
Unload Endp

End DllMain