summaryrefslogtreecommitdiff
path: root/plugins/Actman/i_opt_dlg2.inc
blob: a15d79f84348b2a22d7cead7a64562ebddabe587 (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
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
{}

const
  inoutfilter:pWideChar = 'XML files'#0'*.xml'#0'All files'#0'*.*'#0#0;
const
  NoChainText:PWideChar = 'not defined';
const
  ActionNames:array [0..ACT_MAXTYPE] of pWideChar=(
    'Unknown','Contact','Service','Program','Text','Advanced','Action','Profile','Message');
const
  checknames:array [BST_UNCHECKED..BST_CHECKED] of PAnsiChar=(
    ACI_VAR_UNCHECKED,ACI_VAR_CHECKED);
const
  MaxDescrLen = 128;
const
  hlpContact      = 0;
  hlpService      = 1;
  hlpProgram      = 2;
  hlpText         = 3;
  hlpAdvance      = 4;
  hlpChain        = 5;
  hlpDBRW         = 6;
  hlpMessage      = 7;
  hlpVariables    = 30;
  hlpAdvVariables = 31;
const
  ptNumber  = 0;
  ptString  = 1;
  ptUnicode = 2;
  ptCurrent = 3;
  ptResult  = 4;
  ptParam   = 5;
  ptStruct  = 6;

var
  wstruct,lstruct:pAnsiChar;
  DontReact:bool;
  OldGroupTableProc,
  OldActTableProc:pointer;
  ChMask:dword;

function GetNumValue(wnd:HWND;usevar:boolean;var dst):boolean;
var
  tmp:pWideChar;
begin
  result:=false;
  pWideChar(dst):=GetDlgText(wnd);
  if Pointer(dst)=nil then exit;
  if not usevar then
  begin
    tmp:=PWideChar(dst);
    if pWideChar(dst)^='$' then
    begin
      integer(dst):=HexToInt(pWideChar(dst)+1);
      result:=true;
    end
    else
      integer(dst):=StrToInt(pWideChar(dst));
    mFreeMem(tmp);
  end;
end;

function GetGroupName(id:dword):pWideChar;
var
  i:integer;
begin
  for i:=0 to NewMaxGroups-1 do
  begin
    if ((NewGroupList^[i].flags and ACF_ASSIGNED)<>0) and (id=NewGroupList^[i].id) then
    begin
      result:=NewGroupList^[i].descr;
      exit;
    end;
  end;
  result:=NoChainText;
end;

function AddGroup(Dialog:HWND;HKnum:dword):integer;
var
  li:LV_ITEMW;
  list:HWND;
begin
  with NewGroupList^[HKnum] do
  begin
    if (flags and ACF_ASSIGNED)<>0 then
    begin
      list:=GetDlgItem(Dialog,IDC_ACTION_GROUP);
      li.mask     :=LVIF_PARAM+LVIF_TEXT;
      li.iItem    :=SendMessage(list,LVM_GETNEXTITEM,-1,LVNI_FOCUSED)+1;
      li.iSubItem :=0;
      li.lParam   :=HKnum;
      if descr=nil then
        li.pszText:=NoDescription
      else
        li.pszText:=descr;
      li.iItem    :=SendMessageW(list,LVM_INSERTITEMW,0,lparam(@li));
      if li.iItem>0 then
        dec(li.iItem);
      ListView_SetItemState(list,li.iItem,LVIS_FOCUSED or LVIS_SELECTED,
          LVIS_FOCUSED or LVIS_SELECTED);
      result:=li.iItem;
    end
    else
      result:=-1;
  end;
end;

// Fill action type combobox
procedure FillActTypeList(list:hwnd);
var
  cbei:TCOMBOBOXEXITEMW;
  il:HIMAGELIST;
  i:integer;
  buf:array [0..127] of WideChar;
begin
  SendMessage(list,CB_RESETCONTENT,0,0);
  il:=ImageList_Create(16,16,ILC_COLOR32 or ILC_MASK,0,1);

  cbei.mask:=CBEIF_IMAGE or CBEIF_SELECTEDIMAGE or CBEIF_TEXT; //!!
  for i:=0 to ACT_MAXTYPE-1 do
  begin
    ImageList_AddIcon(il,CallService(MS_SKIN2_GETICON,0,lparam(ActIds[i].icon)));

    cbei.pszText       :=TranslateW(FastAnsiToWideBuf(ActIds[i].text,buf));
    cbei.iItem         :=i;
    cbei.iImage        :=i;
    cbei.iSelectedImage:=i;
    if SendMessageW(list,CBEM_INSERTITEMW,0,lparam(@cbei))=-1 then break;
  end;
  ImageList_Destroy(SendMessage(list,CBEM_SETIMAGELIST,0,il));
  SendMessage(list,CB_SETCURSEL,0,0);
end;

procedure FillSubList(Dialog:hwnd);
var
  list,wnd:HWND;
  i,act:integer;
  arr:array [0..127] of WideChar;
  li:LV_ITEMW;
begin
  wnd:=GetDlgItem(Dialog,IDC_ADV_VAL2);

  SendMessage(wnd,CB_RESETCONTENT,0,0);

  list:=GetDlgItem(Dialog,IDC_ACTION_LIST);
  act:=SendMessageW(list,LVM_GETITEMCOUNT,0,0);
  i:=0;
  li.mask      :=LVIF_TEXT;
  li.iSubItem  :=0;
  li.pszText   :=@arr;
  li.cchTextMax:=SizeOf(arr) div SizeOf(WideChar);
  while i<act do
  begin
    li.iItem:=i;
    SendMessageW(list,LVM_GETITEMW,0,lparam(@li));
    SendMessageW(wnd,CB_ADDSTRING,0,lparam(PWideChar(@arr)));
    inc(i);
  end;
  SendMessage(wnd,CB_SETCURSEL,0,0);
end;

procedure FillChainList(Dialog:hwnd);
var
  wnd:HWND;
  i:integer;
//  num:integer;
begin
  wnd:=GetDlgItem(Dialog,IDC_GROUP_LIST);
//  for current chain exclude
//  num:=SendDlgItemMessage(Dialog,IDC_ACTION_GROUP,LVM_GETNEXTITEM,-1,LVNI_FOCUSED);

  SendMessage(wnd,CB_RESETCONTENT,0,0);
  SendMessage(wnd,CB_SETITEMDATA,
    SendMessageW(wnd,CB_ADDSTRING,0,lparam(TranslateW(NoChainText))),0);
  for i:=0 to NewMaxGroups-1 do
  begin
    if (NewGroupList^[i].flags and (ACF_ASSIGNED or ACF_VOLATILE))=ACF_ASSIGNED then
    begin
      SendMessage(wnd,CB_SETITEMDATA,
        SendMessageW(wnd,CB_ADDSTRING,0,lparam(NewGroupList^[i].descr)),
        NewGroupList^[i].id);
    end;
  end;
end;

// action group table procedure (key hook)
function NewGroupTableProc(Dialog:HWnd;hMessage:uint;wParam:WPARAM;lParam:LPARAM):lresult; stdcall;
var
  i:integer;
begin
  result:=0;
  case hMessage of
    WM_KEYDOWN: begin
      if (lParam and (1 shl 30))=0 then
      begin
        case wParam of
          VK_F2: begin
            i:=SendMessage(Dialog,LVM_GETNEXTITEM,-1,LVNI_FOCUSED);
            if i>=0 then
              PostMessageW(Dialog,LVM_EDITLABELW,i,0);
            exit;
          end;
          VK_INSERT: begin
            PostMessage(GetParent(Dialog),WM_COMMAND,(BN_CLICKED shl 16)+IDC_GROUP_NEW,0);
            exit;
          end;
          VK_DELETE: begin
            PostMessage(GetParent(Dialog),WM_COMMAND,(BN_CLICKED shl 16)+IDC_GROUP_DELETE,0);
            exit;
          end;
          VK_UP: begin
            if (GetKeyState(VK_CONTROL) and $8000)<>0 then
            begin
              PostMessage(GetParent(Dialog),WM_COMMAND,(BN_CLICKED shl 16)+IDC_GROUP_UP,0);
              exit;
            end;
          end;
          VK_DOWN: begin
            if (GetKeyState(VK_CONTROL) and $8000)<>0 then
            begin
              PostMessage(GetParent(Dialog),WM_COMMAND,(BN_CLICKED shl 16)+IDC_GROUP_DOWN,0);
              exit;
            end;
          end;
        end;
      end;
    end;
  end;
  result:=CallWindowProc(OldGroupTableProc,Dialog,hMessage,wParam,lParam);
end;

// action (chain) table procedure (key hook)
function NewActTableProc(Dialog:HWnd;hMessage:uint;wParam:WPARAM;lParam:LPARAM):lresult; stdcall;
var
  i:integer;
begin
  result:=0;
  case hMessage of
    WM_KEYDOWN: begin
      if (lParam and (1 shl 30))=0 then
      begin
        case wParam of
          VK_F2: begin
            i:=SendMessage(Dialog,LVM_GETNEXTITEM,-1,LVNI_FOCUSED);
            if i>=0 then
              PostMessageW(Dialog,LVM_EDITLABELW,i,0);
            exit;
          end;
          VK_UP: begin
            if (GetKeyState(VK_CONTROL) and $8000)<>0 then
            begin
              PostMessage(GetParent(Dialog),WM_COMMAND,(BN_CLICKED shl 16)+IDC_ACTION_UP,0);
              exit;
            end;
          end;
          VK_DOWN: begin
            if (GetKeyState(VK_CONTROL) and $8000)<>0 then
            begin
              PostMessage(GetParent(Dialog),WM_COMMAND,(BN_CLICKED shl 16)+IDC_ACTION_DOWN,0);
              exit;
            end;
          end;
          VK_INSERT: begin
            PostMessage(GetParent(Dialog),WM_COMMAND,(BN_CLICKED shl 16)+IDC_ACTION_NEW,0);
            exit;
          end;
          VK_DELETE: begin
            PostMessage(GetParent(Dialog),WM_COMMAND,(BN_CLICKED shl 16)+IDC_ACTION_DELETE,0);
            exit;
          end;
        end;
      end;
    end;
  end;
  result:=CallWindowProc(OldActTableProc,Dialog,hMessage,wParam,lParam);
end;

// miranda button icon paint
procedure SetButtonIcons2(Dialog:HWND);
var
  ti:TTOOLINFOW;
  hwndTooltip:HWND;
begin
  hwndTooltip:=CreateWindowW(TOOLTIPS_CLASS,nil,TTS_ALWAYSTIP,
      integer(CW_USEDEFAULT),integer(CW_USEDEFAULT),
      integer(CW_USEDEFAULT),integer(CW_USEDEFAULT),
      Dialog,0,hInstance,nil);

  FillChar(ti,SizeOf(ti),0);
  ti.cbSize  :=sizeof(TOOLINFO);
  ti.uFlags  :=TTF_IDISHWND or TTF_SUBCLASS;
  ti.hwnd    :=Dialog;
  ti.hinst   :=hInstance;

  ti.uId     :=GetDlgItem(Dialog,IDC_ACTION_HELP);
  ti.lpszText:=TranslateW('Help');
  SendMessage(ti.uId,BM_SETIMAGE,IMAGE_ICON,
      CallService(MS_SKIN_LOADICON,SKINICON_OTHER_HELP,0));
  SendMessageW(hwndTooltip,TTM_ADDTOOLW,0,lparam(@ti));

  ti.uId     :=GetDlgItem(Dialog,IDC_ACTION_NEW);
  ti.lpszText:=TranslateW('New');
  SetButtonIcon(ti.uId,ACI_NEW);
  SendMessageW(hwndTooltip,TTM_ADDTOOLW,0,lparam(@ti));

  ti.uId     :=GetDlgItem(Dialog,IDC_GROUP_NEW);
  SetButtonIcon(ti.uId,ACI_NEW);
  SendMessageW(hwndTooltip,TTM_ADDTOOLW,0,lparam(@ti));

  ti.uId     :=GetDlgItem(Dialog,IDC_ACTION_UP);
  ti.lpszText:=TranslateW('Up');
  SetButtonIcon(ti.uId,ACI_UP);
  SendMessageW(hwndTooltip,TTM_ADDTOOLW,0,lparam(@ti));

  ti.uId     :=GetDlgItem(Dialog,IDC_GROUP_UP);
  SetButtonIcon(ti.uId,ACI_UP);
  SendMessageW(hwndTooltip,TTM_ADDTOOLW,0,lparam(@ti));

  ti.uId     :=GetDlgItem(Dialog,IDC_ACTION_DOWN);
  ti.lpszText:=TranslateW('Down');
  SetButtonIcon(ti.uId,ACI_DOWN);
  SendMessageW(hwndTooltip,TTM_ADDTOOLW,0,lparam(@ti));

  ti.uId     :=GetDlgItem(Dialog,IDC_GROUP_DOWN);
  SetButtonIcon(ti.uId,ACI_DOWN);
  SendMessageW(hwndTooltip,TTM_ADDTOOLW,0,lparam(@ti));

  ti.uId     :=GetDlgItem(Dialog,IDC_ACTION_DELETE);
  ti.lpszText:=TranslateW('Delete');
  SetButtonIcon(ti.uId,ACI_DELETE);
  SendMessageW(hwndTooltip,TTM_ADDTOOLW,0,lparam(@ti));

  ti.uId     :=GetDlgItem(Dialog,IDC_GROUP_DELETE);
  SetButtonIcon(ti.uId,ACI_DELETE);
  SendMessageW(hwndTooltip,TTM_ADDTOOLW,0,lparam(@ti));

  ti.uId     :=GetDlgItem(Dialog,IDC_GROUP_RELOAD);
  ti.lpszText:=TranslateW('Reload');
  SetButtonIcon(ti.uId,ACI_RELOAD);
  SendMessageW(hwndTooltip,TTM_ADDTOOLW,0,lparam(@ti));

  ti.uId     :=GetDlgItem(Dialog,IDC_GROUP_TEST);
  ti.lpszText:=TranslateW('Test');
  SetButtonIcon(ti.uId,ACI_TEST);
  SendMessageW(hwndTooltip,TTM_ADDTOOLW,0,lparam(@ti));

  ti.uId     :=GetDlgItem(Dialog,IDC_CNT_APPLY);
  ti.lpszText:=TranslateW('Apply format');
  SetButtonIcon(ti.uId,ACI_FORMAT);
  SendMessageW(hwndTooltip,TTM_ADDTOOLW,0,lparam(@ti));

  ti.uId     :=GetDlgItem(Dialog,IDC_GROUP_IMPORT);
  ti.lpszText:=TranslateW('Import');
  SetButtonIcon(ti.uId,ACI_IMPORT);
  SendMessageW(hwndTooltip,TTM_ADDTOOLW,0,lparam(@ti));

  ti.uId     :=GetDlgItem(Dialog,IDC_GROUP_EXPORT);
  ti.lpszText:=TranslateW('Export');
  SetButtonIcon(ti.uId,ACI_EXPORT);
  SendMessageW(hwndTooltip,TTM_ADDTOOLW,0,lparam(@ti));

  ti.lpszText:=TranslateW('Use Variables');
  ti.uId:=GetDlgItem(Dialog,IDC_SRV_WPAR);
  SetButtonIcon(ti.uId,ACI_VAR_UNCHECKED);
  SendMessageW(hwndTooltip,TTM_ADDTOOLW,0,lparam(@ti));

{
  pc:=TranslateW('');
  wnd:=GetDlgItem(Dialog,IDC_NEW);
  SendMessage(hNew,BUTTONADDTOOLTIP,TWPARAM(pc),BATF_UNICODE);
  SetButtonIcon(wnd,QS_NEW);
}
  ti.uId:=GetDlgItem(Dialog,IDC_SRV_LPAR);
  SetButtonIcon(ti.uId,ACI_VAR_UNCHECKED);
  SendMessageW(hwndTooltip,TTM_ADDTOOLW,0,lparam(@ti));

  ti.uId:=GetDlgItem(Dialog,IDC_SRV_SRVC);
  SetButtonIcon(ti.uId,ACI_VAR_UNCHECKED);
  SendMessageW(hwndTooltip,TTM_ADDTOOLW,0,lparam(@ti));

  ti.uId:=GetDlgItem(Dialog,IDC_PRG_PRG);
  SetButtonIcon(ti.uId,ACI_VAR_UNCHECKED);
  SendMessageW(hwndTooltip,TTM_ADDTOOLW,0,lparam(@ti));

  ti.uId:=GetDlgItem(Dialog,IDC_PRG_ARG);
  SetButtonIcon(ti.uId,ACI_VAR_UNCHECKED);
  SendMessageW(hwndTooltip,TTM_ADDTOOLW,0,lparam(@ti));

  ti.uId:=GetDlgItem(Dialog,IDC_TXT_FILE);
  SetButtonIcon(ti.uId,ACI_VAR_UNCHECKED);
  SendMessageW(hwndTooltip,TTM_ADDTOOLW,0,lparam(@ti));

  ti.uId:=GetDlgItem(Dialog,IDC_TXT_TEXT);
  SetButtonIcon(ti.uId,ACI_VAR_UNCHECKED);
  SendMessageW(hwndTooltip,TTM_ADDTOOLW,0,lparam(@ti));

  ti.uId:=GetDlgItem(Dialog,IDC_RW_MVAR);
  SetButtonIcon(ti.uId,ACI_VAR_UNCHECKED);
  SendMessageW(hwndTooltip,TTM_ADDTOOLW,0,lparam(@ti));

  ti.uId:=GetDlgItem(Dialog,IDC_RW_SVAR);
  SetButtonIcon(ti.uId,ACI_VAR_UNCHECKED);
  SendMessageW(hwndTooltip,TTM_ADDTOOLW,0,lparam(@ti));

  ti.uId:=GetDlgItem(Dialog,IDC_RW_TVAR);
  SetButtonIcon(ti.uId,ACI_VAR_UNCHECKED);
  SendMessageW(hwndTooltip,TTM_ADDTOOLW,0,lparam(@ti));

  ti.uId:=GetDlgItem(Dialog,IDC_MSG_TTL);
  SetButtonIcon(ti.uId,ACI_VAR_UNCHECKED);
  SendMessageW(hwndTooltip,TTM_ADDTOOLW,0,lparam(@ti));

  ti.uId:=GetDlgItem(Dialog,IDC_MSG_TXT);
  SetButtonIcon(ti.uId,ACI_VAR_UNCHECKED);
  SendMessageW(hwndTooltip,TTM_ADDTOOLW,0,lparam(@ti));

end;

function MoveLVItem(list:HWND;num:integer;incr:integer):integer;
var
  li:LV_ITEM;
  buf:array [0..127] of WideChar;
begin
  li.mask      :=LVIF_PARAM+LVIF_STATE+LVIF_TEXT;
  li.iItem     :=num;
  li.iSubItem  :=0;
  li.StateMask :=dword(-1);
  li.pszText   :=@buf;
  li.cchTextMax:=127;
  SendMessageW(list,LVM_GETITEMW,0,lparam(@li));
  SendMessageW(list,LVM_DELETEITEM,li.iItem,0);
  inc(li.iItem,incr);

  SendMessageW(list,LVM_INSERTITEMW,0,lparam(@li));
  SendMessageW(list,LVM_SETITEMSTATE,li.iItem,lparam(@li));
  result:=li.iItem;
end;

function MoveGroup(list:HWND;num:integer=-1;incr:integer=0):integer;
var
  i,j:integer;
begin
  if num<0 then
  begin
    result:=-1;
    j:=SendMessage(list,LVM_GETITEMCOUNT,0,0)-1;
    if incr<0 then // up, from beginning
    begin
      for i:=0 to j do
      begin
        if SendMessage(list,LVM_GETITEMSTATE,i,LVIS_SELECTED)<>0 then
        begin
          if i=0 then break;
          LV_MoveItem(list,incr,i);
//          MoveLVItem(list,i,incr);
          if result<0 then result:=i+incr;
        end;
      end;
    end
    else           // down, from the end
    begin
      for i:=j downto 0 do
      begin
        if SendMessage(list,LVM_GETITEMSTATE,i,LVIS_SELECTED)<>0 then
        begin
          if i=j then break;
          LV_MoveItem(list,incr,i);
//          MoveLVItem(list,i,incr);
          if result<0 then result:=i+incr;
        end;
      end;
    end;
  end
  else
  begin
    MoveLVItem(list,num,incr);
    result:=num;
  end;
end;

{$include i_dlglists.inc}

procedure SetNumValue(wnd:HWND;value:dword;isvar:boolean;ishex:boolean);
var
  buf:array [0..31] of WideChar;
begin
  if isvar then
    SendMessageW(wnd,WM_SETTEXT,0,value)
  else if ishex then
  begin
    buf[0]:='$';
    IntToHex(PWideChar(@buf[1]),value);
    SendMessageW(wnd,WM_SETTEXT,0,tlparam(@buf));
  end
  else
    SendMessageW(wnd,WM_SETTEXT,0,tlparam(IntToStr(buf,value)));
end;

function DlgProcOpt2(Dialog:HWnd;hMessage:uint;wParam:WPARAM;lParam:LPARAM):lresult; stdcall;

  {$include i_visual.inc}

  procedure ShowHelp(code:integer);
  var
    buf:PAnsiChar;
    vhi:TVARHELPINFO;
  begin
    case code of
      hlpVariables: begin
        FillChar(vhi,SizeOf(vhi),0);
        with vhi do
        begin
          cbSize:=SizeOf(vhi);
          flags:=VHF_NOINPUTDLG;
        end;
        CallService(MS_VARS_SHOWHELPEX,Dialog,tlparam(@vhi));
      end;
      hlpAdvVariables: begin
        FillChar(vhi,SizeOf(vhi),0);
        with vhi do
        begin
          cbSize       :=SizeOf(vhi);
          flags        :=VHF_FULLDLG or VHF_SETLASTSUBJECT;
          hwndCtrl     :=GetDlgItem(Dialog,IDC_ADV_VARS);
          szSubjectDesc:='test your variables';
        end;
        CallService(MS_VARS_SHOWHELPEX,Dialog,tlparam(@vhi));
      end;
      hlpContact: begin
        MessageBoxW(0,
          TranslateW('Select contact to open it''s window'),
          TranslateW('Contacts'),0);
      end;
      hlpService: begin
        buf:=GetDlgText(Dialog,IDC_EDIT_SERVICE,true);
//!!        if buf<>nil then
        begin
          ApiCard.Service:=buf;
          mFreeMem(buf);
          ApiCard.Show;
        end;
      end;
      hlpProgram: begin
        MessageBoxW(0,
          TranslateW('Text <last> replacing'#13#10+
            'by last result'#13#10#13#10+
            'Text <param> replacing'#13#10+
            'by parameter'),
          TranslateW('Text'),0);
      end;
      hlpText: begin
        MessageBoxW(0,
          TranslateW('^s - selected (and replaced) part'#13#10+
          '^e - replaced by empty string'#13#10+
          '^v - paste text from Clipboard'#13#10+
          '^t - replaced by tabulation'#13#10+
          '^l - replaced by last result as unicode'#13#10+
          '^h - replaced by last result as hex'#13#10+
          '^a - in the end: autosend'#13#10+
          '^f(name[,str])'#13#10+
          '     paste line from text file.'#13#10+
          '     brackets contents must be w/o spaces'),
          TranslateW('Text'),0);
      end;
      hlpAdvance: begin
      end;
      hlpChain: begin
        MessageBoxW(0,
          TranslateW('You can select another group from combobox, '+
                     'then it will be executed, after that current '+
                     'action group will be continued.'),
          TranslateW('Macros'),0);
      end;
      hlpDBRW: begin
      end;
      hlpMessage: begin
        MessageBoxW(0,
          TranslateW(
            'Text <last> replacing'#13#10+
            'by last result'#13#10#13#10+
            'Returns:'#13#10+
            '--------'#13#10+
            'OK'#9'= 1'#13#10+
            'CANCEL'#9'= 2'#13#10+
            'ABORT'#9'= 3'#13#10+
            'RETRY'#9'= 4'#13#10+
            'IGNORE'#9'= 5'#13#10+
            'YES'#9'= 6'#13#10+
            'NO'#9'= 7'#13#10+
            'CLOSE'#9'= 8'),
          TranslateW('MessageBox'),0);
      end;
    end;
  end;

  // enable/disable navigation chain buttons
  procedure CheckGrpList(num:integer=-1);
  var
    wnd:HWND;
    dir:integer;
    okup,okdown:boolean;
  begin
    wnd:=GetDlgItem(Dialog,IDC_ACTION_GROUP);
//    if num<0 then
    begin
      dir:=LV_CheckDirection(wnd);
      okup  :=odd(loword(dir));
      okdown:=(loword(dir) and 2)<>0;
    end;
{
    else
    begin
      okup  :=num>0;
      okdown:=(num+1)<SendMessage(wnd,LVM_GETITEMCOUNT,0,0);
      SendMessage(wnd,LVM_ENSUREVISIBLE,num,0);
    end;
}
    EnableWindow(GetDlgItem(Dialog,IDC_GROUP_UP  ),okup);
    EnableWindow(GetDlgItem(Dialog,IDC_GROUP_DOWN),okdown);
    SendMessage(wnd,LVM_ENSUREVISIBLE,hiword(dir)-1,0);
(*
    wnd:=GetDlgItem(Dialog,IDC_ACTION_GROUP);
    if num<0 then
      num:=SendMessage(wnd,LVM_GETNEXTITEM,-1,LVNI_FOCUSED);
    EnableWindow(GetDlgItem(Dialog,IDC_GROUP_UP),num>0);
    EnableWindow(GetDlgItem(Dialog,IDC_GROUP_DOWN),
        (num+1)<SendMessage(wnd,LVM_GETITEMCOUNT,0,0));
    SendMessage(wnd,LVM_ENSUREVISIBLE,num,0);
    result:=num;
*)
  end;
  procedure CheckActList(num:integer=-1);
  var
    wnd:HWND;
    dir:integer;
    okup,okdown:boolean;
  begin
    wnd:=GetDlgItem(Dialog,IDC_ACTION_LIST);
//    if num<0 then
    begin
      dir:=LV_CheckDirection(wnd);
      okup  :=odd(loword(dir));
      okdown:=(loword(dir) and 2)<>0;
    end;
{
    else
    begin
      okup  :=num>0;
      okdown:=(num+1)<SendMessage(wnd,LVM_GETITEMCOUNT,0,0);
      SendMessage(wnd,LVM_ENSUREVISIBLE,num,0);
    end;
}
    EnableWindow(GetDlgItem(Dialog,IDC_ACTION_UP  ),okup);
    EnableWindow(GetDlgItem(Dialog,IDC_ACTION_DOWN),okdown);
    SendMessage(wnd,LVM_ENSUREVISIBLE,hiword(dir)-1,0);
(*
    wnd:=GetDlgItem(Dialog,IDC_ACTION_LIST);
    if num<0 then
      num:=SendMessage(wnd,LVM_GETNEXTITEM,-1,LVNI_FOCUSED);
    EnableWindow(GetDlgItem(Dialog,IDC_ACTION_UP),num>0);
    EnableWindow(GetDlgItem(Dialog,IDC_ACTION_DOWN),
        (num+1)<SendMessage(wnd,LVM_GETITEMCOUNT,0,0));
    SendMessage(wnd,LVM_ENSUREVISIBLE,num,0);
*)
  end;

  // change current action name (by type)
  procedure ChangeActionName(num:integer=-1;acttype:integer=0;str:PWideChar=nil);
  var
    li:LV_ITEMW;
    wnd:HWND;
    str1:pWideChar;
  begin
    wnd:=GetDlgItem(Dialog,IDC_ACTION_LIST);
    if num<0 then
      li.iItem:=SendMessage(wnd,LVM_GETNEXTITEM,-1,LVNI_FOCUSED)
    else
      li.iItem:=num;
    if li.iItem>=0 then
    begin
      li.iSubItem:=0;
      // getting SubAction number
      li.mask:=LVIF_PARAM;
      SendMessage(wnd,LVM_GETITEM,0,tlparam(@li));

      // changing to default name
      if str=nil then
      begin
        if num>=0 then // new item - screen only
          str1:=TranslateW(ActionNames[ACT_CONTACT])
        else // change action type
        begin
          str1:=NewActionList[li.lParam].descr;
          if str1=nil then // not in memory yet
            str1:=TranslateW(ActionNames[acttype])
          else
            exit;
        end;
      end
      else  // rename
      begin
        str1:=str;
        mFreeMem(NewActionList[li.lParam].descr);
        StrDupW (NewActionList[li.lParam].descr,str);
      end;

// screen
      li.mask   :=LVIF_TEXT;
      li.pszText:=str1;
      SendMessageW(wnd,LVM_SETITEMW,0,tlparam(@li));
    end;
  end;

  // Fill Chain list
  procedure MakeActionList(HK:pHKRecord);
  var
    i,idx:integer;
    wnd:HWND;
    li:LV_ITEMW;
    p:pWideChar;
  begin
    wnd:=GetDlgItem(Dialog,IDC_ACTION_LIST);
    SendMessage(wnd,LVM_DELETEALLITEMS,0,0);

    EnableWindow(GetDlgItem(Dialog,IDC_ACTION_UP),false);
    if (HK=nil) or (HK^.firstAction=0) then
    begin
      SHWindows;
      SHActButtons(SW_HIDE);
      EnableWindow(GetDlgItem(Dialog,IDC_ACTION_LIST  ),false);
      EnableWindow(GetDlgItem(Dialog,IDC_GROUP_TEST   ),false);
      EnableWindow(GetDlgItem(Dialog,IDC_ACTION_HELP  ),false);
      EnableWindow(GetDlgItem(Dialog,IDC_ACTION_DELETE),false);
      EnableWindow(GetDlgItem(Dialog,IDC_ACTION_DOWN  ),false);
      exit;
    end;
    SHActButtons(SW_SHOW);

    li.mask    :=LVIF_TEXT or LVIF_PARAM;
    li.iSubitem:=0;
    i:=HK^.firstAction;
    idx:=0;
    repeat
      p:=NewActionList^[i].descr;
      if p=nil then
        p:=TranslateW(ActionNames[NewActionList^[i].actionType]);
      li.pszText:=p;
      li.iItem  :=idx;
      li.lParam :=i;
      SendMessageW(wnd,LVM_INSERTITEMW,0,tlparam(@li));
      ListView_SetCheckState(wnd,idx,(NewActionList^[i].flags and ACF_DISABLED)=0);

      i:=NewActionList^[i].next;
      inc(idx);
    until i=0;

    Listview_SetItemState(wnd,0,
        LVIS_FOCUSED or LVIS_SELECTED,
        LVIS_FOCUSED or LVIS_SELECTED);
    EnableWindow(GetDlgItem(Dialog,IDC_ACTION_LIST  ),true);
    EnableWindow(GetDlgItem(Dialog,IDC_GROUP_TEST   ),true);
    EnableWindow(GetDlgItem(Dialog,IDC_ACTION_HELP  ),true);
    EnableWindow(GetDlgItem(Dialog,IDC_ACTION_DELETE),true);
    EnableWindow(GetDlgItem(Dialog,IDC_ACTION_DOWN),idx>1);
//    FillSubList(Dialog);
    FillAction(HK^.firstAction);
    CheckActList(0);
  end;

  procedure SaveAction(listnum,actnum:integer);
  var
    wnd:HWND;
    i:integer;
    tmp:pWideChar;
    arr: array [0..255] of WideChar;
    li:LV_ITEMW;
  begin
    if (ChMask and ACTM_ACT)=0 then exit;
    ChMask:=ChMask and not ACTM_ACT;
    wnd:=GetDlgItem(Dialog,IDC_ACTION_LIST);
    if listnum<0 then
    begin
      listnum:=SendMessageW(wnd,LVM_GETNEXTITEM,-1,LVNI_FOCUSED);
      if listnum<0 then
        exit;
    end;
    if actnum<0 then
      actnum:=LV_GetLParam(wnd,listnum);
    StrDupW(tmp,NewActionList^[actnum].descr); // keeping old name
    FreeAction(@NewActionList^[actnum]);
    with NewActionList^[actnum] do
    begin
      flags :=ACF_ASSIGNED;
      flags2:=0;

      descr:=tmp;
      if descr=nil then
      begin
        li.iItem     :=listnum;
        li.mask      :=LVIF_TEXT;
        li.iSubItem  :=0;
        li.pszText   :=@arr;
        li.cchTextMax:=SizeOf(arr) div SizeOf(WideChar);
        SendDlgItemMessageW(Dialog,IDC_ACTION_LIST,LVM_GETITEMW,0,tlparam(@li));
        StrDupW(descr,arr);
      end;

      if ListView_GetCheckState(wnd,listnum)=0 then
        flags:=flags or ACF_DISABLED;

      actionType:=ActIds[SendDlgItemMessage(Dialog,IDC_ACTION_TYPE,CB_GETCURSEL,0,0)].code;
      case actionType of
        ACT_CONTACT: begin
          contact:=SendDlgItemMessage(Dialog,IDC_CONTACTLIST,CB_GETITEMDATA,
              SendDlgItemMessage(Dialog,IDC_CONTACTLIST,CB_GETCURSEL,0,0),0);
          if IsDlgButtonChecked(Dialog,IDC_CNT_KEEP)=BST_CHECKED then
            flags:=flags or ACF_KEEPONLY;
        end;

        ACT_SERVICE: begin
          if IsDlgButtonChecked(Dialog,IDC_SRV_WPAR)=BST_CHECKED then
            flags2:=flags2 or ACF2_SRV_WPAR;
          if IsDlgButtonChecked(Dialog,IDC_SRV_LPAR)=BST_CHECKED then
            flags2:=flags2 or ACF2_SRV_LPAR;
          if IsDlgButtonChecked(Dialog,IDC_SRV_SRVC)=BST_CHECKED then
            flags2:=flags2 or ACF2_SRV_SRVC;

          case CB_GetData(GetDlgItem(Dialog,IDC_FLAG_WPAR)) of
            ptParam: begin
              flags:=flags or ACF_WPARAM
            end;
            ptResult: begin
              flags:=flags or ACF_WRESULT
            end;
            ptCurrent: begin
              flags:=flags or ACF_WPARNUM or ACF_WCURRENT
            end;
            ptNumber: begin
              flags:=flags or ACF_WPARNUM;
              if GetNumValue(GetDlgItem(Dialog,IDC_EDIT_WPAR),
                 (flags2 and ACF2_SRV_WPAR)<>0,wparam) then
                flags2:=flags2 or ACF2_SRV_WHEX;
//              wparam:=GetDlgItemInt(Dialog,IDC_EDIT_WPAR,pbool(nil)^,true);
            end;
            ptStruct: begin
              flags:=flags or ACF_WSTRUCT;
              StrDup(pAnsiChar(wparam),wstruct);
            end;
            ptUnicode: begin
              flags:=flags or ACF_WUNICODE;
              pointer(wparam):=GetDlgText(Dialog,IDC_EDIT_WPAR);
            end;
            ptString: pointer(wparam):=GetDlgText(Dialog,IDC_EDIT_WPAR,true);
          end;

          case CB_GetData(GetDlgItem(Dialog,IDC_FLAG_LPAR)) of
            ptParam: begin
              flags:=flags or ACF_LPARAM
            end;
            ptResult: begin
              flags:=flags or ACF_LRESULT
            end;
            ptCurrent: begin
              flags:=flags or ACF_LPARNUM or ACF_LCURRENT
            end;
            ptNumber: begin
              flags:=flags or ACF_LPARNUM;
              if GetNumValue(GetDlgItem(Dialog,IDC_EDIT_LPAR),
                 (flags2 and ACF2_SRV_LPAR)<>0,lparam) then
                flags2:=flags2 or ACF2_SRV_LHEX;
//              lparam:=GetDlgItemInt(Dialog,IDC_EDIT_LPAR,pbool(nil)^,true);
            end;
            ptStruct: begin
              flags:=flags or ACF_LSTRUCT;
              StrDup(pAnsiChar(lparam),lstruct);
            end;
            ptUnicode: begin
              flags:=flags or ACF_LUNICODE;
              pointer(lparam):=GetDlgText(Dialog,IDC_EDIT_LPAR);
            end;
            ptString: pointer(lparam):=GetDlgText(Dialog,IDC_EDIT_LPAR,true);
          end;

          if IsDlgButtonChecked(Dialog,IDC_RES_INSERT)=BST_CHECKED then
            flags:=flags or ACF_INSERT;
          if IsDlgButtonChecked(Dialog,IDC_RES_MESSAGE)=BST_CHECKED then
            flags:=flags or ACF_MESSAGE;
          if IsDlgButtonChecked(Dialog,IDC_RES_POPUP)=BST_CHECKED then
            flags:=flags or ACF_POPUP;

          case CB_GetData(GetDlgItem(Dialog,IDC_SRV_RESULT)) of
            sresHex: flags:=flags or ACF_HEX;
            sresInt: begin
              if IsDlgButtonChecked(Dialog,IDC_RES_SIGNED)=BST_CHECKED then
                flags:=flags or ACF_SIGNED;
            end;
            sresString: begin
              flags:=flags or ACF_STRING;
              if IsDlgButtonChecked(Dialog,IDC_RES_UNICODE)=BST_CHECKED then
                flags:=flags or ACF_UNICODE;
              if IsDlgButtonChecked(Dialog,IDC_RES_FREEMEM)=BST_CHECKED then
                flags2:=flags2 or ACF2_FREEMEM;
            end;
            sresStruct: flags:=flags or ACF_STRUCT;
          end;

          service:=GetDlgText(Dialog,IDC_EDIT_SERVICE,true);

        end;

        ACT_PROGRAM: begin
          prgname:=GetDlgText(Dialog,IDC_EDIT_PRGPATH);
          args:=GetDlgText(Dialog,IDC_EDIT_PRGARGS);
          if IsDlgButtonChecked(Dialog,IDC_FLAG_PARALLEL)=BST_CHECKED then
            flags:=flags or ACF_PRTHREAD;
          if IsDlgButtonChecked(Dialog,IDC_FLAG_CURPATH)=BST_CHECKED then
            flags:=flags or ACF_CURPATH;
          time:=GetDlgItemInt(Dialog,IDC_EDIT_PROCTIME,pbool(nil)^,false);
          if IsDlgButtonChecked(Dialog,IDC_FLAG_MINIMIZE)=BST_CHECKED then
            show:=SW_SHOWMINIMIZED
          else if IsDlgButtonChecked(Dialog,IDC_FLAG_MAXIMIZE)=BST_CHECKED then
            show:=SW_SHOWMAXIMIZED
          else if IsDlgButtonChecked(Dialog,IDC_FLAG_HIDDEN)=BST_CHECKED then
            show:=SW_HIDE
          else //if IsDlgButtonChecked(Dialog,IDC_FLAG_NORMAL)=BST_CHECKED then
            show:=SW_SHOWNORMAL;

          if IsDlgButtonChecked(Dialog,IDC_PRG_PRG)=BST_CHECKED then
            flags2:=flags2 or ACF2_PRG_PRG;
          if IsDlgButtonChecked(Dialog,IDC_PRG_ARG)=BST_CHECKED then
            flags2:=flags2 or ACF2_PRG_ARG;
        end;

        ACT_TEXT: begin
          if IsDlgButtonChecked(Dialog,IDC_FLAG_CLIP)<>BST_UNCHECKED then
          begin
            flags:=flags or ACF_CLIPBRD;
            if IsDlgButtonChecked(Dialog,IDC_CLIP_COPYTO)<>BST_UNCHECKED then
              flags:=flags or ACF_COPYTO;
          end
          else
          begin
            if IsDlgButtonChecked(Dialog,IDC_TXT_TEXT)=BST_CHECKED then
              flags2:=flags2 or ACF2_TXT_TEXT;
            text:=GetDlgText(Dialog,IDC_EDIT_INSERT);
            if IsDlgButtonChecked(Dialog,IDC_FLAG_FILE)<>BST_UNCHECKED then
            begin
              flags:=flags or ACF_FILE;
              case CB_GetData(GetDlgItem(Dialog,IDC_FILE_ENC)) of
                0: flags:=flags or ACF_ANSI;
                1: flags:=flags or ACF_UTF8;
                2: flags:=flags or ACF_UTF8 or ACF_SIGN;
                3: flags:=flags or 0;
                4: flags:=flags or ACF_SIGN;
              end;

              if IsDlgButtonChecked(Dialog,IDC_TXT_FILE)=BST_CHECKED then
                flags2:=flags2 or ACF2_TXT_FILE;
              tfile:=GetDlgText(Dialog,IDC_FILE_PATH);
              if IsDlgButtonChecked(Dialog,IDC_FILE_APPEND)<>BST_UNCHECKED then
                flags:=flags or ACF_FAPPEND
              else if IsDlgButtonChecked(Dialog,IDC_FILE_WRITE)<>BST_UNCHECKED then
                flags:=flags or ACF_FWRITE;
            end;
          end;
        end;

        ACT_ADVANCE: begin
          condition:=ADV_COND_NOP;
          if      IsDlgButtonChecked(Dialog,IDC_FLAG_GT )=BST_CHECKED then
            condition:=ADV_COND_GT
          else if IsDlgButtonChecked(Dialog,IDC_FLAG_LT )=BST_CHECKED then
            condition:=ADV_COND_LT
          else if IsDlgButtonChecked(Dialog,IDC_FLAG_EQ )=BST_CHECKED then
            condition:=ADV_COND_EQ;
          value:=GetDlgItemInt(Dialog,IDC_ADV_VALUE,pbool(nil)^,false);

          if IsDlgButtonChecked(Dialog,IDC_FLAG_NOT)=BST_CHECKED then
            condition:=condition or ADV_COND_NOT;

          if      IsDlgButtonChecked(Dialog,IDC_FLAG_BREAK)=BST_CHECKED then
            action:=ADV_ACT_BREAK
          else if IsDlgButtonChecked(Dialog,IDC_FLAG_JUMP )=BST_CHECKED then
            action:=ADV_ACT_JUMP
          else
            action:=ADV_ACT_NOP;

          case action of
            ADV_ACT_JUMP: operval:=GetDlgText(Dialog,IDC_ADV_VAL2);
          end;

          if IsDlgButtonChecked(Dialog,IDC_FLAG_VARS)<>BST_UNCHECKED then
          begin
            varval:=GetDlgText(Dialog,IDC_ADV_VARS);
            action:=action or ADV_ACT_VARS;
            if IsDlgButtonChecked(Dialog,IDC_ADV_ASINT)<>BST_UNCHECKED then
              flags:=flags or ACF_VARASINT;
          end
;{//!!executively!!
          else }if IsDlgButtonChecked(Dialog,IDC_FLAG_MATH)=BST_CHECKED then
          begin
            mathval:=GetDlgItemInt(Dialog,IDC_ADV_VAL1,pbool(nil)^,true);
            action :=action or ADV_ACT_MATH;
            oper   :=CB_GetData(GetDlgItem(Dialog,IDC_ADV_OPER));
//            oper   :=SendDlgItemMessage(Dialog,IDC_ADV_OPER,CB_GETCURSEL,0,0);
          end;
        end;

        ACT_CHAIN: begin
           wnd:=GetDlgItem(Dialog,IDC_GROUP_LIST);
           i:=SendMessage(wnd,CB_GETCURSEL,0,0);
           if i>0 then
             id:=SendMessage(wnd,CB_GETITEMDATA,i,0)
           else
             id:=0;
        end;

        ACT_RW: begin
          if IsDlgButtonChecked(Dialog,IDC_RW_CURRENT)=BST_CHECKED then
            flags:=flags or ACF_CURRENT
          else if IsDlgButtonChecked(Dialog,IDC_RW_RESULT)=BST_CHECKED then
            flags:=flags or ACF_RESULT
          else if IsDlgButtonChecked(Dialog,IDC_RW_PARAM)=BST_CHECKED then
            flags:=flags or ACF_PARAM
          else
            dbcontact:=SendDlgItemMessage(Dialog,IDC_CONTACTLIST,CB_GETITEMDATA,
                SendDlgItemMessage(Dialog,IDC_CONTACTLIST,CB_GETCURSEL,0,0),0);
          dbmodule :=GetDlgText(Dialog,IDC_RW_MODULE ,true);
          dbsetting:=GetDlgText(Dialog,IDC_RW_SETTING,true);
          if IsDlgButtonChecked(Dialog,IDC_RW_MVAR)=BST_CHECKED then
            flags2:=flags2 or ACF2_RW_MVAR;
          if IsDlgButtonChecked(Dialog,IDC_RW_SVAR)=BST_CHECKED then
            flags2:=flags2 or ACF2_RW_SVAR;

          if IsDlgButtonChecked(Dialog,IDC_RW_WRITE)=BST_CHECKED then
            flags:=flags or ACF_DBWRITE
          else if IsDlgButtonChecked(Dialog,IDC_RW_DELETE)=BST_CHECKED then
            flags:=flags or ACF_DBDELETE;

          if IsDlgButtonChecked(Dialog,IDC_RW_LAST)=BST_CHECKED then
            flags:=flags or ACF_LAST;

          if IsDlgButtonChecked(Dialog,IDC_RW_TVAR)=BST_CHECKED then
            flags2:=flags2 or ACF2_RW_TVAR;

          i:=CB_GetData(GetDlgItem(Dialog,IDC_RW_DATATYPE));
          case i of
            0: flags:=flags or ACF_DBBYTE;
            1: flags:=flags or ACF_DBWORD;
            2: flags:=flags or 0;
            3: flags:=flags or ACF_DBANSI;
            4: flags:=flags or ACF_DBUTEXT;
          end;
          if i<3 then
          begin
            if (flags and ACF_LAST)=0 then
            begin
              if GetNumValue(GetDlgItem(Dialog,IDC_RW_VALUE),
                 (flags2 and ACF2_RW_TVAR)<>0,dbvalue) then
                flags2:=flags2 or ACF2_RW_HEX;
            end;
          end
          else
          begin
            if (flags and ACF_LAST)=0 then
              pWideChar(dbvalue):=GetDlgText(Dialog,IDC_RW_TEXT);
          end;

          if (IsDlgButtonChecked(Dialog,IDC_RW_LAST)=BST_CHECKED) or
             ((flags and ACF_LAST)<>0) then
            flags:=flags or ACF_LAST;
        end;

        ACT_MESSAGE: begin
          pWideChar(msgtitle):=GetDlgText(Dialog,IDC_MSG_TITLE);
          pWideChar(msgtext ):=GetDlgText(Dialog,IDC_MSG_TEXT);
          if IsDlgButtonChecked(Dialog,IDC_MSG_KEEP)=BST_CHECKED then
            flags:=flags or ACF_MSG_KEEP;
          if IsDlgButtonChecked(Dialog,IDC_MSG_TTL)=BST_CHECKED then
            flags2:=flags2 or ACF2_MSG_TTL;
          if IsDlgButtonChecked(Dialog,IDC_MSG_TXT)=BST_CHECKED then
            flags2:=flags2 or ACF2_MSG_TXT;

          if      IsDlgButtonChecked(Dialog,IDC_MSGB_OC )=BST_CHECKED then boxopts:=MB_OKCANCEL
          else if IsDlgButtonChecked(Dialog,IDC_MSGB_ARI)=BST_CHECKED then boxopts:=MB_ABORTRETRYIGNORE
          else if IsDlgButtonChecked(Dialog,IDC_MSGB_YNC)=BST_CHECKED then boxopts:=MB_YESNOCANCEL
          else if IsDlgButtonChecked(Dialog,IDC_MSGB_YN )=BST_CHECKED then boxopts:=MB_YESNO
          else if IsDlgButtonChecked(Dialog,IDC_MSGB_RC )=BST_CHECKED then boxopts:=MB_RETRYCANCEL
          else{if IsDlgButtonChecked(Dialog,IDC_MSGB_OK )=BST_CHECKED then}boxopts:=MB_OK;

          if      IsDlgButtonChecked(Dialog,IDC_MSGI_ERROR)=BST_CHECKED then boxopts:=boxopts or MB_ICONHAND
          else if IsDlgButtonChecked(Dialog,IDC_MSGI_QUEST)=BST_CHECKED then boxopts:=boxopts or MB_ICONQUESTION
          else if IsDlgButtonChecked(Dialog,IDC_MSGI_WARN )=BST_CHECKED then boxopts:=boxopts or MB_ICONWARNING
          else if IsDlgButtonChecked(Dialog,IDC_MSGI_INFO )=BST_CHECKED then boxopts:=boxopts or MB_ICONINFORMATION
          ;//else if IsDlgButtonChecked(Dialog,IDC_MSGI_NONE)=BST_CHECKED then ;
        end;

      end;
    end;
  end;

  procedure BuildActionChain(group:integer=-1);
  var
    i,j,item:integer;
    wnd:HWND;
    act:pHKAction;
    idx:integer;
  begin
    if (ChMask and ACTM_ACTS)=0 then exit;
    ChMask:=ChMask and not ACTM_ACTS;
    SaveAction(-1,-1);
    wnd:=GetDlgItem(Dialog,IDC_ACTION_LIST);
    i:=SendMessageW(wnd,LVM_GETITEMCOUNT,0,0);
    idx:=LV_GetLParam(GetDlgItem(Dialog,IDC_ACTION_GROUP),group);
    if i>0 then
    begin
      j:=LV_GetLParam(wnd,0);
      NewGroupList^[idx].firstAction:=j;
      act:=@NewActionList^[j];
      for item:=1 to i-1 do
      begin
        j:=LV_GetLParam(wnd,item);
        act^.next:=j;
        act:=@NewActionList^[j];
      end;
      act^.next:=0;
    end
    else
    begin
      if idx>=0 then
        NewGroupList^[idx].firstAction:=0;
    end;
  end;

  procedure CheckActionList(next:integer);
  var
    i:integer;
    wnd:HWND;
  begin
    wnd:=GetDlgItem(Dialog,IDC_ACTION_LIST);
    i:=SendMessage(wnd,LVM_GETITEMCOUNT,0,0);
    if i>0 then
    begin
      EnableWindow(GetDlgItem(Dialog,IDC_ACTION_HELP),true);
      if next=i then
        dec(next);
      ListView_SetItemState(wnd,next,
          LVIS_FOCUSED or LVIS_SELECTED,
          LVIS_FOCUSED or LVIS_SELECTED);
    end
    else
    begin
      SHWindows;
      SHActButtons(SW_HIDE);
      EnableWindow(wnd,false);
      EnableWindow(GetDlgItem(Dialog,IDC_ACTION_HELP  ),false);
      EnableWindow(GetDlgItem(Dialog,IDC_GROUP_TEST   ),false);
      EnableWindow(GetDlgItem(Dialog,IDC_ACTION_DELETE),false);
      next:=0;
    end;
    CheckActList(next);
  end;

  procedure CheckGroupList(next:integer);
  var
    i:integer;
    wnd:HWND;
    li:LV_ITEMW;
  begin
    wnd:=GetDlgItem(Dialog,IDC_ACTION_GROUP);
    i:=SendMessage(wnd,LVM_GETITEMCOUNT,0,0);
    if i>0 then
    begin
      if next=i then
        dec(next);
      ListView_SetItemState(wnd,next,LVIS_FOCUSED or LVIS_SELECTED,
        LVIS_FOCUSED or LVIS_SELECTED);
      li.iItem   :=next;
      li.iSubItem:=0;
      li.mask    :=LVIF_PARAM;
      SendMessage(wnd,LVM_GETITEM,0,tlparam(@li));
    end
    else
    begin
      EnableWindow(wnd,false);
      EnableWindow(GetDlgItem(Dialog,IDC_GROUP_DELETE),false);
      CheckActionList(0);
      EnableWindow(GetDlgItem(Dialog,IDC_ACTION_NEW),false);
    end;
    CheckGrpList(next);
  end;

  // Fill action group list and disable chain controls
  function FillGroupList{(Dialog:hwnd)}:integer;
  var
    CurGroup:pHKRecord;
    i:integer;
    list:HWND;
    lvi:TLVITEMW;
  begin
    SendDlgItemMessage(Dialog,IDC_ACTION_LIST,LVM_DELETEALLITEMS,0,0);
    CheckActionList(-1);
    list:=GetDlgItem(Dialog,IDC_ACTION_GROUP);

    SendMessage(list,LVM_DELETEALLITEMS,0,0);
    CurGroup:=@NewGroupList^;
    result:=-1;
    lvi.mask:=LVIF_TEXT+LVIF_PARAM;
    lvi.iSubItem:=0;
    for i:=0 to NewMaxGroups-1 do
    begin
      if (CurGroup^.flags and ACF_ASSIGNED)<>0 then
      begin
        lvi.iItem :=i;
        lvi.lParam:=i;
        if CurGroup^.descr=nil then
          lvi.pszText:=NoDescription
        else
          lvi.pszText:=CurGroup^.descr;
        SendMessageW(list,LVM_INSERTITEMW,0,tlparam(@lvi));
        inc(result);
      end;
      inc(CurGroup);
    end;

    EnableWindow(GetDlgItem(Dialog,IDC_ACTION_GROUP ),result>=0);
    EnableWindow(GetDlgItem(Dialog,IDC_ACTION_LIST  ),result>=0);
    EnableWindow(GetDlgItem(Dialog,IDC_ACTION_NEW   ),result>=0);
    EnableWindow(GetDlgItem(Dialog,IDC_GROUP_DELETE ),result>=0);
    if result<0 then
    begin
      EnableWindow(GetDlgItem(Dialog,IDC_GROUP_TEST   ),false);
      EnableWindow(GetDlgItem(Dialog,IDC_ACTION_HELP  ),false);
      EnableWindow(GetDlgItem(Dialog,IDC_ACTION_DELETE),false);
      EnableWindow(GetDlgItem(Dialog,IDC_ACTION_UP    ),false);
      EnableWindow(GetDlgItem(Dialog,IDC_ACTION_DOWN  ),false);
      EnableWindow(GetDlgItem(Dialog,IDC_STAT_GROUPS  ),false);
      EnableWindow(GetDlgItem(Dialog,IDC_ACTION_TYPE  ),false);
    end
    else
      result:=0;
    SendMessage(list,CB_SETCURSEL,0,0);
    SendMessage(list,LVM_SETCOLUMNWIDTH,0,LVSCW_AUTOSIZE_USEHEADER);

    ListView_SetItemState(list,0,
      LVIS_FOCUSED or LVIS_SELECTED,
      LVIS_FOCUSED or LVIS_SELECTED);
  end;

  procedure SHMath(show:boolean);
  var
    wnd:HWND;
  begin
    EnableWindow(GetDlgItem(Dialog,IDC_ADV_ASINT),not show);
    EnableWindow(GetDlgItem(Dialog,IDC_ADV_VARS ),not show);

    wnd:=GetDlgItem(Dialog,IDC_ADV_OPER);
    EnableWindow(wnd,show);
    EnableWindow(GetDlgItem(Dialog,IDC_ADV_VAL1),
       show and (CB_GetData(wnd)<>lresult(aeNot)));//(SendMessage(wnd,CB_GETCURSEL,0,0)<>0));
  end;

  procedure SetMBRadioIcon(h:THANDLE;id:dword;icon:uint_ptr);
  begin
    SendDlgItemMessage(Dialog,id,BM_SETIMAGE,IMAGE_ICON,
      LoadImage(h,MAKEINTRESOURCE(icon),IMAGE_ICON,16,16,0{LR_SHARED}));
  //  SendDlgItemMessage(Dialog,id,BM_SETIMAGE,IMAGE_ICON,LoadIcon(0,icon));
  end;

  procedure SetMBRadioIcons;
  var
    h:THANDLE;
  begin
    h:=LoadLibrary('user32.dll');
  //  SetMBRadioIcon(IDC_MSGI_NONE,IDI_); //?
    SetMBRadioIcon(h,IDC_MSGI_ERROR,103{IDI_HAND});
    SetMBRadioIcon(h,IDC_MSGI_QUEST,102{IDI_QUESTION});
    SetMBRadioIcon(h,IDC_MSGI_WARN ,101{IDI_EXCLAMATION});
    SetMBRadioIcon(h,IDC_MSGI_INFO ,104{IDI_ASTERISK});
    FreeLibrary(h);
  end;

  procedure FillFileName(idc:integer);
  var
    pw,ppw:pWideChar;
  begin
    mGetMem(pw,1024*SizeOf(WideChar));
    ppw:=GetDlgText(Dialog,idc);
    if ShowDlgW(pw,ppw) then
      SetDlgItemTextW(Dialog,idc,pw);
    mFreeMem(ppw);
    mFreeMem(pw);
  end;

var
  wnd,wnd1,wnd2:HWND;
  i,j:int_ptr;
  lvflag:integer;
  pc:pAnsiChar;
  li:LV_ITEMW;
  lv:LV_COLUMNW;
  b:boolean;
  ico:HICON;
begin
  result:=0;
  case hMessage of
    WM_DESTROY: begin
      ApiCard.Free;
      SetCancel;
      mFreeMem(wstruct);
      mFreeMem(lstruct);
    end;

    WM_INITDIALOG: begin
      ApiCard:=CreateServiceCard(Dialog);
      wstruct:=nil;
      lstruct:=nil;
      SetStart;
      DontReact :=true;
      SHWindows;
      TranslateDialogDefault(Dialog);
      SetButtonIcons2(Dialog);
      wnd:=GetDlgItem(Dialog,IDC_ACTION_LIST);
      SendMessage(wnd,LVM_SETEXTENDEDLISTVIEWSTYLE,LVS_EX_CHECKBOXES,LVS_EX_CHECKBOXES);
      SendMessage(wnd,LVM_SETUNICODEFORMAT,1,0);
      zeromemory(@lv,sizeof(lv));
      lv.mask:=LVCF_WIDTH;
      lv.cx  :=110;
      SendMessageW(wnd,LVM_INSERTCOLUMNW ,0,tlparam(@lv));
      SendMessageW(wnd,LVM_SETCOLUMNWIDTH,0,LVSCW_AUTOSIZE_USEHEADER);

      MakeResultTypeList(GetDlgItem(Dialog,IDC_SRV_RESULT));
      MakeParamTypeList (GetDlgItem(Dialog,IDC_FLAG_WPAR));
      MakeParamTypeList (GetDlgItem(Dialog,IDC_FLAG_LPAR));
      MakeMathOperList  (GetDlgItem(Dialog,IDC_ADV_OPER));
      MakeFileEncList   (GetDlgItem(Dialog,IDC_FILE_ENC));
      MakeDataTypeList  (GetDlgItem(Dialog,IDC_RW_DATATYPE));

      // service list for RunService
      ApiCard.FillList(GetDlgItem(Dialog,IDC_EDIT_SERVICE));
      // contact list for ContactMessage
      FillContactList(GetDlgItem(Dialog,IDC_CONTACTLIST),fCLfilter,fCLformat);
      // action type combobox
      FillActTypeList(GetDlgItem(Dialog,IDC_ACTION_TYPE));

      if isVarsInstalled then
      begin
        ico:=CallService(MS_VARS_GETSKINITEM,0,VSI_HELPICON);
        SendDlgItemMessage(Dialog,IDC_HLP_FVARS,BM_SETIMAGE,IMAGE_ICON,ico);
        SendDlgItemMessage(Dialog,IDC_HLP_VARS ,BM_SETIMAGE,IMAGE_ICON,ico);
        SendDlgItemMessage(Dialog,IDC_ADV_HVARS,BM_SETIMAGE,IMAGE_ICON,ico);
      end;

      if ServiceExists(MS_SYSTEM_GET_XI)=0 then
      begin
        EnableWindow(GetDlgItem(Dialog,IDC_GROUP_EXPORT),false);
        EnableWindow(GetDlgItem(Dialog,IDC_GROUP_IMPORT),false);
      end;

      OldActTableProc  :=pointer(SetWindowLongPtrW(wnd,GWL_WNDPROC,long_ptr(@NewActTableProc)));
      OldGroupTableProc:=pointer(SetWindowLongPtrW(GetDlgItem(Dialog,IDC_ACTION_GROUP),
            GWL_WNDPROC,long_ptr(@NewGroupTableProc)));

      // fill group list
      wnd:=GetDlgItem(Dialog,IDC_ACTION_GROUP);
      SendMessage(wnd,LVM_SETUNICODEFORMAT,1,0);
      lv.mask:=LVCF_WIDTH;
      lv.cx  :=110;
      SendMessageW(wnd,LVM_INSERTCOLUMNW,0,tlparam(@lv));
      FillGroupList{(Dialog)};
      FillChainList(Dialog);

      SetMBRadioIcons;

      // fill current group
      MakeActionList(@NewGroupList^);
      ChMask:=0;
      CheckGrpList(-1);
      DontReact:=false;
    end;

    WM_COMMAND: begin
      if DontReact then exit;
      case wParam shr 16 of
        CBN_EDITCHANGE: begin
          ChMask:=ChMask or ACTM_ACT or ACTM_ACTS;
          SetChanged(Dialog,etACT);
        end;
        EN_CHANGE: begin
// check for group renaming
          if loword(wParam)<>IDC_EDIT_FORMAT then
          begin
            ChMask:=ChMask or ACTM_ACT or ACTM_ACTS;
            SetChanged(Dialog,etACT);
          end;
        end;
        CBN_SELCHANGE:  begin
          ChMask:=ChMask or ACTM_ACT or ACTM_ACTS;
          SetChanged(Dialog,etACT);
          case loword(wParam) of
            IDC_SRV_RESULT: begin
              i:=CB_GetData(lParam);
              case i of
                sresHex,sresInt,sresStruct: begin
                  SHControl(IDC_RES_FREEMEM,SW_HIDE);
                  SHControl(IDC_RES_UNICODE,SW_HIDE);
                  if i=sresInt then
                    SHControl(IDC_RES_SIGNED,SW_SHOW)
                  else
                    SHControl(IDC_RES_SIGNED,SW_HIDE);
                end;
                sresString: begin
                  SHControl(IDC_RES_FREEMEM,SW_SHOW);
                  SHControl(IDC_RES_UNICODE,SW_SHOW);
                  SHControl(IDC_RES_SIGNED ,SW_HIDE);
                end;
              end;
            end;

            IDC_ADV_OPER: begin
              EnableWindow(GetDlgItem(Dialog,IDC_ADV_VAL1),
                (CB_GetData(lParam)<>lresult(aeNot)));
//                SendMessage(lParam,CB_GETCURSEL,0,0)<>0);
            end;

            IDC_RW_DATATYPE: begin
              if CB_GetData(GetDlgItem(Dialog,IDC_RW_DATATYPE))>2 then
              begin
                SHControl(IDC_RW_TEXT ,SW_SHOW);
                SHControl(IDC_RW_VALUE,SW_HIDE);
              end
              else
              begin
                SHControl(IDC_RW_TEXT ,SW_HIDE);
                SHControl(IDC_RW_VALUE,SW_SHOW);
              end;
            end;

            IDC_ACTION_TYPE: begin
              i:=SendMessage(lParam,CB_GETCURSEL,0,0);
              SHWindows(ActIds[i].code);
              ChangeActionName(-1,i+1);
              case ActIds[i].code of
                ACT_CONTACT: EnableWindow(GetDlgItem(Dialog,IDC_CONTACTLIST),true);
                ACT_RW: begin
                  EnableWindow(GetDlgItem(Dialog,IDC_CONTACTLIST),
                    (IsDlgButtonChecked(Dialog,IDC_RW_MANUAL)=BST_CHECKED));

                  if CB_GetData(GetDlgItem(Dialog,IDC_RW_DATATYPE))>2 then
                  begin
                    SHControl(IDC_RW_TEXT ,SW_SHOW);
                    SHControl(IDC_RW_VALUE,SW_HIDE);
                  end
                  else
                  begin
                    SHControl(IDC_RW_TEXT ,SW_HIDE);
                    SHControl(IDC_RW_VALUE,SW_SHOW);
                  end;

                end;
                ACT_ADVANCE: FillSubList(Dialog);
              end;
            end;
{
            IDC_EDIT_WPAR,IDC_EDIT_LPAR: begin
              SendMessage(lParam,CB_GETLBTEXT,
                 SendMessage(lParam,CB_GETCURSEL,0,0),
                 dword(@buf));
              if loword(wParam)=IDC_EDIT_WPAR then
                FixParam(buf,IDC_EDIT_WPAR,IDC_FLAG_WPAR)
              else
                FixParam(buf,IDC_EDIT_LPAR,IDC_FLAG_LPAR)
            end;
}
            IDC_FLAG_WPAR,IDC_FLAG_LPAR: begin
              if loword(wParam)=IDC_FLAG_WPAR then
              begin
                wnd :=GetDlgItem(Dialog,IDC_EDIT_WPAR);
                wnd1:=GetDlgItem(Dialog,IDC_WSTRUCT);
                wnd2:=GetDlgItem(Dialog,IDC_SRV_WPAR);
              end
              else
              begin
                wnd :=GetDlgItem(Dialog,IDC_EDIT_LPAR);
                wnd1:=GetDlgItem(Dialog,IDC_LSTRUCT);
                wnd2:=GetDlgItem(Dialog,IDC_SRV_LPAR);
              end;
              i:=CB_GetData(GetDlgItem(Dialog,loword(wParam)));

              if i=ptStruct then
              begin
                ShowWindow(wnd ,SW_HIDE);
                ShowWindow(wnd2,SW_HIDE);
                ShowWindow(wnd1,SW_SHOW);
              end
              else
              begin
                ShowWindow(wnd ,SW_SHOW);
                ShowWindow(wnd2,SW_SHOW);
                ShowWindow(wnd1,SW_HIDE);
                if i in [ptCurrent,ptResult,ptParam] then
                  EnableWindow(wnd,false)
                else
                begin
                  EnableWindow(wnd,true);
{
                flag:=GetWindowLongPtr(wnd,GWL_STYLE);
                if i=ptNumber then
                  flag:=flag or ES_NUMBER
                else
                  flag:=flag and not ES_NUMBER;
                SetWindowLongPtr(wnd,GWL_STYLE,flag);
}
                end;
              end;
            end;
            IDC_EDIT_SERVICE: ReloadService;
          end;
        end;
        BN_CLICKED: begin
          case loword(wParam) of
            IDC_GROUP_RELOAD, // don't affect to saved (DB) datas
            IDC_WSTRUCT,      // 'Changed' on process
            IDC_LSTRUCT,      // 'Changed' on process
            IDC_HLP_FVARS,
            IDC_HLP_VARS,
            IDC_ADV_HVARS,
            IDC_ACTION_HELP,
            IDC_GROUP_EXPORT,
            IDC_CNT_APPLY,
            IDC_CNT_FILTER,
            IDC_GROUP_TEST: ;

            IDC_GROUP_UP,
            IDC_GROUP_DOWN,
            IDC_GROUP_NEW : SetChanged(Dialog,etHK);

            IDC_GROUP_DELETE, // action deleting with subactions
            IDC_GROUP_IMPORT,
            IDC_ACTION_NEW,
            IDC_ACTION_DELETE,
            IDC_ACTION_UP,
            IDC_ACTION_DOWN: begin
              ChMask:=ChMask or ACTM_ACT or ACTM_ACTS;
              SetChanged(Dialog,etHK+etACT);
            end;
          else
            ChMask:=ChMask or ACTM_ACT or ACTM_ACTS;
            SetChanged(Dialog,etACT);
          end;

          case loword(wParam) of
            IDC_SRV_WPAR,
            IDC_SRV_LPAR,
            IDC_SRV_SRVC,
            IDC_PRG_PRG ,
            IDC_PRG_ARG ,
            IDC_TXT_FILE,
            IDC_TXT_TEXT,
            IDC_RW_MVAR ,
            IDC_RW_SVAR ,
            IDC_RW_TVAR ,
            IDC_MSG_TTL ,
            IDC_MSG_TXT : SetButtonIcon(lParam,checknames[IsDlgButtonChecked(Dialog,loword(wParam))]);
          end;

          case loword(wParam) of
            IDC_CNT_FILTER,
            IDC_CNT_APPLY: begin
              if loword(wParam)=IDC_CNT_APPLY then
              begin
                mFreeMem(fCLformat);
                fCLformat:=GetDlgText(Dialog,IDC_EDIT_FORMAT);
                DBWriteUnicode(0,DBBranch,'CLformat',fCLformat);
              end
              else
              begin
                fCLfilter:=IsDlgButtonChecked(Dialog,IDC_CNT_FILTER)<>BST_UNCHECKED;
                DBWriteByte(0,DBBranch,'CLfilter',ord(fCLfilter));
              end;
// Saving and restoring contact after list rebuild
              wnd:=GetDlgItem(Dialog,IDC_CONTACTLIST);
              i:=SendMessage(wnd,CB_GETITEMDATA,SendMessage(wnd,CB_GETCURSEL,0,0),0);

              FillContactList(wnd,fCLfilter,fCLformat);

              SendMessage(wnd,CB_SETCURSEL,FindContact(wnd,i),0);
            end;
            IDC_HLP_FVARS,
            IDC_HLP_VARS : ShowHelp(hlpVariables);
            IDC_ADV_HVARS: ShowHelp(hlpAdvVariables);

            IDC_GROUP_EXPORT: begin
              if ShowDlgW(xmlfilename,xmlfilename,inoutfilter,false) then
              begin
                wnd:=GetDlgItem(Dialog,IDC_ACTION_GROUP);
                for i:=0 to ListView_GetItemCount(wnd)-1 do
                begin
                  if ListView_GetItemState(wnd,i,LVIS_SELECTED)<>0 then
                  begin
                    with GroupList[LV_GetLParam(wnd,i)] do
                      if (flags and ACF_ASSIGNED)<>0 then // must be always true
                        flags:=flags or ACF_EXPORT;
                  end
                  else
                    with GroupList[i] do
                      if (flags and (ACF_EXPORT or ACF_ASSIGNED))=
                                    (ACF_EXPORT or ACF_ASSIGNED) then
                        flags:=flags and not ACF_EXPORT;
                end;
                i:=ACIO_EXPORT or ACIO_SELECTED;
                if GetFSize(xmlfilename)>0 then
                  if MessageBoxW(Dialog,TranslateW('Append data to file'),
                     PluginName,MB_YESNO+MB_ICONWARNING)=IDYES then
                    i:=i or ACIO_APPEND;
                CallService(MS_ACT_INOUT,i,TLPARAM(@xmlfilename));
//                Export({GetLParam(GetDlgItem(Dialog,IDC_ACTION_GROUP)),}xmlfilename,i);
                for i:=0 to MaxGroups-1 do
                  with GroupList[i] do
                    if (flags and (ACF_EXPORT or ACF_ASSIGNED))=
                                  (ACF_EXPORT or ACF_ASSIGNED) then
                      flags:=flags and not ACF_EXPORT;
              end;
            end;

            IDC_GROUP_IMPORT: begin
              if ShowDlgW(xmlfilename,xmlfilename,inoutfilter) then
              begin
//                if Import(xmlfilename) then
                if CallService(MS_ACT_INOUT,0,TLPARAM(@xmlfilename))<>0 then
                begin
                  ChMask:=ChMask or ACTM_NEW;
                  SendMessage(Dialog,WM_COMMAND,IDC_GROUP_RELOAD+(BN_CLICKED shl 16),
                    GetDlgItem(Dialog,IDC_GROUP_RELOAD));
//(in reload)       FillChainList(Dialog);
                end;
              end;
            end;

            IDC_WSTRUCT, IDC_LSTRUCT: begin
              if loword(wParam)=IDC_WSTRUCT then
                pc:=wstruct
              else
                pc:=lstruct;
//!!!!
              pAnsiChar(j):=EditStructure(pAnsiChar(pc),Dialog);
              if j<>0 then
              begin
                ChMask:=ChMask or ACTM_ACT or ACTM_ACTS;
                SetChanged(Dialog,etACT);
                mFreeMem(pAnsiChar(pc));
                pc:=pAnsiChar(j);

                if loword(wParam)=IDC_WSTRUCT then
                  wstruct:=pc
                else
                  lstruct:=pc;
              end;
            end;

            IDC_PROGRAM: begin
              FillFileName(IDC_EDIT_PRGPATH);
            end;
            IDC_FILE_FILEBTN: begin
              FillFileName(IDC_FILE_PATH);
            end;

            IDC_GROUP_TEST: begin
              wnd:=GetDlgItem(Dialog,IDC_ACTION_LIST);
              li.mask    :=LVIF_PARAM;
              li.iSubItem:=0;
              li.iItem   :=0;
              SendMessageW(wnd,LVM_GETITEMW,0,tlparam(@li));
              j:=SendMessage(wnd,LVM_GETNEXTITEM,-1,LVNI_FOCUSED);

              ActionStarterWait(li.lParam);
              // doubling from  "reload" button
              wnd:=GetDlgItem(Dialog,IDC_ACTION_GROUP);
              i:=SendMessage(wnd,LVM_GETNEXTITEM,-1,LVNI_FOCUSED);
              NewGroupList :=GroupList;
              NewMaxGroups :=MaxGroups;
              NewActionList:=ActionList;
              NewMaxActions:=MaxActions;
              FillGroupList{(Dialog)};
              FillChainList(Dialog);

              Listview_SetItemState(wnd,0,0,LVIS_FOCUSED or LVIS_SELECTED);
              Listview_SetItemState(wnd,i,
                   LVIS_FOCUSED or LVIS_SELECTED,
                   LVIS_FOCUSED or LVIS_SELECTED);
              SendMessage(wnd,LVM_ENSUREVISIBLE,i,0);

              wnd:=GetDlgItem(Dialog,IDC_ACTION_LIST);
              Listview_SetItemState(wnd,0,0,LVIS_FOCUSED or LVIS_SELECTED);
              Listview_SetItemState(wnd,j,
                   LVIS_FOCUSED or LVIS_SELECTED,
                   LVIS_FOCUSED or LVIS_SELECTED);
              SendMessage(wnd,LVM_ENSUREVISIBLE,j,0);

            end;
            IDC_GROUP_NEW: begin
              i:=AddGroup(Dialog,NewGroup(NewGroupList,NewMaxGroups));
              if i>=0 then
              begin
                ChMask:=ChMask or ACTM_NEW or ACTM_SORT;
                EnableWindow(GetDlgItem(Dialog,IDC_ACTION_GROUP),true);
                EnableWindow(GetDlgItem(Dialog,IDC_GROUP_DELETE),true);
                EnableWindow(GetDlgItem(Dialog,IDC_ACTION_NEW  ),true);
                FillChainList(Dialog);
                CheckGrpList(i);
              end;
            end;
            IDC_GROUP_DELETE: begin
              wnd:=GetDlgItem(Dialog,IDC_ACTION_GROUP);
              for i:=ListView_GetItemCount(wnd)-1 downto 0 do
              begin
                if ListView_GetItemState(wnd,i,LVIS_SELECTED)<>0 then
                begin
                  ChMask:=ChMask or ACTM_DELETE or ACTM_SORT;

                  with NewGroupList^[LV_GetLParam(wnd,i)] do
                  begin
                    flags:=0;
                    mFreeMem(descr);
                    FreeActions(NewActionList,firstAction);
                  end;

                  SendMessage(wnd,LVM_DELETEITEM,i,0);
                end;
              end;
              SendDlgItemMessage(Dialog,IDC_ACTION_LIST,LVM_DELETEALLITEMS,0,0);
              FillChainList(Dialog);
              Listview_SetItemState(wnd,0,LVIS_FOCUSED or LVIS_SELECTED,
                                          LVIS_FOCUSED or LVIS_SELECTED);
              CheckGroupList(-1);
{
              i:=SendMessageW(wnd,LVM_GETNEXTITEM,-1,LVNI_FOCUSED); //??
              if i>=0 then
              begin
                ChMask:=ChMask or ACTM_DELETE;
                j:=GetLParam(wnd,i);

                with NewGroupList^[j] do
                begin
                  flags:=0;
                  mFreeMem(descr);
                  FreeActions(NewActionList,firstAction);
                end;
                SendDlgItemMessage(Dialog,IDC_ACTION_LIST,LVM_DELETEALLITEMS,0,0);

//??                i:=ListView_GetNextItem(wnd,-1,LVNI_FOCUSED);
                SendMessage(wnd,LVM_DELETEITEM,i,0);
                FillChainList(Dialog);
                CheckGroupList(i);
              end;
}
            end;
            IDC_GROUP_RELOAD: begin
              ChMask:=ChMask or ACTM_RELOAD;
              SetCancel;
              NewGroupList :=GroupList;
              NewMaxGroups :=MaxGroups;
              NewActionList:=ActionList;
              NewMaxActions:=MaxActions;
              FillGroupList{(Dialog)};
              FillChainList(Dialog);
            end;

            IDC_ACTION_HELP: begin
              ShowHelp(SendDlgItemMessage(Dialog,IDC_ACTION_TYPE,CB_GETCURSEL,0,0));
            end;

            IDC_ACTION_NEW: begin
              wnd:=GetDlgItem(Dialog,IDC_ACTION_LIST);
              li.mask    :=LVIF_PARAM;
              i          :=SendMessage(wnd,LVM_GETNEXTITEM,-1,LVNI_FOCUSED);
              li.iItem   :=i+1;
              li.iSubItem:=0;
              li.lParam  :=NewAction(NewActionList,NewMaxActions);
              SendMessageW(wnd,LVM_INSERTITEMW,0,tlparam(@li));
              ListView_SetCheckState(wnd,li.iItem,true);
              if li.iItem=0 then
              begin
                ListView_SetItemState(wnd,0,LVIS_FOCUSED or LVIS_SELECTED,
                  LVIS_FOCUSED or LVIS_SELECTED);
                SHActButtons(SW_SHOW);
              end;
              ChangeActionName(li.iItem);
              EnableWindow(GetDlgItem(Dialog,IDC_ACTION_LIST  ),true);
              EnableWindow(GetDlgItem(Dialog,IDC_ACTION_HELP  ),true);
              EnableWindow(GetDlgItem(Dialog,IDC_GROUP_TEST   ),true);
              EnableWindow(GetDlgItem(Dialog,IDC_ACTION_DELETE),true);
              EnableWindow(GetDlgItem(Dialog,IDC_ACTION_TYPE  ),true);
              CheckActList(i);

              wnd:=GetDlgItem(Dialog,IDC_ADV_VAL2);
              i:=SendMessage(wnd,CB_GETCURSEL,0,0);
              FillSubList(Dialog);
              SendMessage(wnd,CB_SETCURSEL,i,0);
            end;
            IDC_ACTION_DELETE: begin
              wnd:=GetDlgItem(Dialog,IDC_ACTION_LIST);
              for i:=ListView_GetItemCount(wnd)-1 downto 0 do
              begin
                if ListView_GetItemState(wnd,i,LVIS_SELECTED)<>0 then
                begin
                  FreeAction(@NewActionList^[LV_GetLParam(wnd,i)]);
                  SendMessage(wnd,LVM_DELETEITEM,i,0);
                end;
              end;
              Listview_SetItemState(wnd,0,LVIS_FOCUSED or LVIS_SELECTED,
                                          LVIS_FOCUSED or LVIS_SELECTED);
              CheckActionList(0);
{
              wnd:=GetDlgItem(Dialog,IDC_ACTION_LIST);
              li.iItem:=SendMessage(wnd,LVM_GETNEXTITEM,-1,LVNI_FOCUSED); //??
              if li.iItem>=0 then
              begin
                li.mask    :=LVIF_PARAM;
                li.iSubItem:=0;
                SendMessageW(wnd,LVM_GETITEM,0,dword(@li));
                FreeAction(@NewActionList^[li.lParam]);

                SendMessage(wnd,LVM_DELETEITEM,li.iItem,0);
                CheckActionList(li.iItem);
              end;
}
            end;

            IDC_GROUP_UP: begin
              wnd:=GetDlgItem(Dialog,IDC_ACTION_GROUP);
//              i:=SendMessage(wnd,LVM_GETNEXTITEM,-1,LVNI_FOCUSED);
//              if i>0 then
              begin
                CheckGrpList(MoveGroup(wnd,-1,-1));
                ChMask:=ChMask or ACTM_SORT;
              end;
            end;
            IDC_GROUP_DOWN: begin
              wnd:=GetDlgItem(Dialog,IDC_ACTION_GROUP);
//              i:=SendMessage(wnd,LVM_GETNEXTITEM,-1,LVNI_FOCUSED);
//              if i<(SendMessage(wnd,LVM_GETITEMCOUNT,0,0)-1) then
              begin
                CheckGrpList(MoveGroup(wnd,-1,1));
                ChMask:=ChMask or ACTM_SORT;
              end;
            end;

            IDC_ACTION_UP: begin
              wnd:=GetDlgItem(Dialog,IDC_ACTION_LIST);
//              i:=SendMessage(wnd,LVM_GETNEXTITEM,-1,LVNI_FOCUSED);
//              if i>0 then
                CheckActList(MoveGroup(wnd,-1,-1));
            end;
            IDC_ACTION_DOWN: begin
              wnd:=GetDlgItem(Dialog,IDC_ACTION_LIST);
//              i:=SendMessage(wnd,LVM_GETNEXTITEM,-1,LVNI_FOCUSED);
//              if i<(SendMessage(wnd,LVM_GETITEMCOUNT,0,0)-1) then
                CheckActList(MoveGroup(wnd,-1,1));
            end;

            IDC_FILE_WRITE, IDC_FILE_READ, IDC_FILE_APPEND:
                EnableWindow(GetDlgItem(Dialog,IDC_EDIT_INSERT),
                             loword(wParam)<>IDC_FILE_APPEND);

            IDC_RW_DELETE,
            IDC_RW_READ,
            IDC_RW_WRITE: begin
              b:=loword(wParam)<>IDC_RW_DELETE;
              EnableWindow(GetDlgItem(Dialog,IDC_RW_DATATYPE),b);
              EnableWindow(GetDlgItem(Dialog,IDC_RW_LAST    ),b);
              EnableWindow(GetDlgItem(Dialog,IDC_RW_VALUE   ),b);
              EnableWindow(GetDlgItem(Dialog,IDC_RW_TEXT    ),b);
            end;

            IDC_FLAG_CLIP,IDC_FLAG_FILE,IDC_FLAG_MESSAGE: begin
              b:=loword(wParam)=IDC_FLAG_CLIP;
//!! +text read = disabled
              EnableWindow(GetDlgItem(Dialog,IDC_CLIP_COPYTO),b);
              EnableWindow(GetDlgItem(Dialog,IDC_CLIP_PASTE ),b);
              b:=b or ((loword(wParam)=IDC_FLAG_FILE) and
                 (IsDlgButtonChecked(Dialog,IDC_FILE_READ)<>BST_UNCHECKED));
              EnableWindow(GetDlgItem(Dialog,IDC_EDIT_INSERT),not b);

              b:=loword(wParam)=IDC_FLAG_FILE;
              EnableWindow(GetDlgItem(Dialog,IDC_FILE_ENC    ),b);
              EnableWindow(GetDlgItem(Dialog,IDC_FILE_PATH   ),b);
              EnableWindow(GetDlgItem(Dialog,IDC_FILE_FILEBTN),b);
              EnableWindow(GetDlgItem(Dialog,IDC_FILE_READ   ),b);
              EnableWindow(GetDlgItem(Dialog,IDC_FILE_WRITE  ),b);
              EnableWindow(GetDlgItem(Dialog,IDC_FILE_APPEND ),b);
            end;

            IDC_FLAG_JUMP: begin
              EnableWindow(GetDlgItem(Dialog,IDC_ADV_VAL2),true);
            end;

            IDC_FLAG_BREAK,IDC_FLAG_ANOP:
            begin
              EnableWindow(GetDlgItem(Dialog,IDC_ADV_VAL2),false);
            end;

            IDC_FLAG_VARS: begin
              if IsDlgButtonChecked(Dialog,IDC_FLAG_VARS)<>BST_UNCHECKED then
              begin
                SHMath(false);
                CheckDlgButton(Dialog,IDC_FLAG_MATH,BST_UNCHECKED);
              end
              else
              begin
                EnableWindow(GetDlgItem(Dialog,IDC_ADV_ASINT),false);
                EnableWindow(GetDlgItem(Dialog,IDC_ADV_VARS ),false);
              end;
            end;
            IDC_FLAG_MATH: begin
              if IsDlgButtonChecked(Dialog,IDC_FLAG_MATH)<>BST_UNCHECKED then
              begin
                SHMath(true);
                CheckDlgButton(Dialog,IDC_FLAG_VARS,BST_UNCHECKED);
              end
              else
              begin
                EnableWindow(GetDlgItem(Dialog,IDC_ADV_OPER),false);
                EnableWindow(GetDlgItem(Dialog,IDC_ADV_VAL1),false);
              end;
            end;

            IDC_RW_CURRENT, IDC_RW_RESULT, IDC_RW_PARAM: begin
              EnableWindow(GetDlgItem(Dialog,IDC_CONTACTLIST),false);
            end;
            IDC_RW_MANUAL: EnableWindow(GetDlgItem(Dialog,IDC_CONTACTLIST),true);

            IDC_RW_LAST: begin
              b :=IsDlgButtonChecked(Dialog,IDC_RW_LAST )=BST_UNCHECKED;
              EnableWindow(GetDlgItem(Dialog,IDC_RW_VALUE), b);
              EnableWindow(GetDlgItem(Dialog,IDC_RW_TEXT ), b);
            end;
          end;
        end;
      end;
    end;

    WM_HELP: begin
      if (PHELPINFO(lParam)^.iContextType=HELPINFO_WINDOW) then
        ShowHelp(SendDlgItemMessage(Dialog,IDC_ACTION_TYPE,CB_GETCURSEL,0,0));
    end;

    WM_NOTIFY: begin
      case integer(PNMHdr(lParam)^.code) of
        PSN_APPLY: begin
          BuildActionChain;
          SetSave(Dialog,LV_GetLParam(GetDlgItem(Dialog,IDC_ACTION_GROUP)));

          if ActionList<>NewActionList then
          begin
            DestroyActions(ActionList,MaxActions);
            ActionList:=NewActionList;
            MaxActions:=NewMaxActions;
          end;

          SaveGroups;

          if ChMask<>0 then //??
          begin
            NotifyEventHooks(hHookChanged,ChMask,0);
            ChMask:=0;
          end;

        end;

        NM_DBLCLK: begin
          if PNMListView(lParam)^.iItem>=0 then
            PostMessageW(PNMHdr(lParam)^.hWndFrom,LVM_EDITLABELW,
                        PNMListView(lParam)^.iItem,0);
        end;

        LVN_ITEMCHANGED: begin
          if DontReact then exit; // bug when group moved avoid

          if wParam=IDC_ACTION_GROUP then
          begin
            if PNMLISTVIEW(lParam)^.uChanged=LVIF_STATE then
            begin
              lvflag:=(PNMLISTVIEW(lParam)^.uOldState and LVNI_FOCUSED)-
                      (PNMLISTVIEW(lParam)^.uNewState and LVNI_FOCUSED);

              if lvflag>0 then // old focus
                BuildActionChain(PNMLISTVIEW(lParam)^.iItem)
              else if lvflag<0 then // new focus
              begin
                DontReact:=true;

                ClearDialogData;
                MakeActionList(@NewGroupList^[PNMLISTVIEW(lParam)^.lParam]);
                CheckGrpList(PNMLISTVIEW(lParam)^.iItem);

                DontReact:=false;
              end
              else
              begin
                lvflag:=(PNMLISTVIEW(lParam)^.uOldState and LVNI_SELECTED)-
                        (PNMLISTVIEW(lParam)^.uNewState and LVNI_SELECTED);
                if lvflag<>0 then
                  CheckGrpList(PNMLISTVIEW(lParam)^.iItem);
              end;
            end;
          end
          else if wParam=IDC_ACTION_LIST then
          begin
            lvflag:=(PNMLISTVIEW(lParam)^.uOldState and LVNI_FOCUSED)-
                    (PNMLISTVIEW(lParam)^.uNewState and LVNI_FOCUSED);
            if lvflag>0 then // old focus
              SaveAction(PNMLISTVIEW(lParam)^.iItem,
                         PNMLISTVIEW(lParam)^.lParam)
            else if lvflag<0 then // new focus
            begin
              DontReact:=true;

              ClearDialogData;
              j:=PNMLISTVIEW(lParam)^.lParam;
              FillAction(j);
              CheckActList(PNMLISTVIEW(lParam)^.iItem);

              DontReact:=false;
            end
            else
            begin // checkboxes
              lvflag:=(PNMLISTVIEW(lParam)^.uOldState and LVNI_SELECTED)-
                      (PNMLISTVIEW(lParam)^.uNewState and LVNI_SELECTED);
              if lvflag<>0 then
                CheckGrpList(PNMLISTVIEW(lParam)^.iItem);

              if (PNMLISTVIEW(lParam)^.uOldState or PNMLISTVIEW(lParam)^.uNewState)=$3000 then
              begin
                if PNMLISTVIEW(lParam)^.uOldState=$1000 then
                  i:=0
                else
                  i:=ACF_DISABLED;
                j:=PNMLISTVIEW(lParam)^.lParam;
                NewActionList^[j].flags:=(NewActionList^[j].flags and not ACF_DISABLED) or dword(i);
                ChMask:=ChMask or ACTM_ACT or ACTM_ACTS;
                SetChanged(Dialog,etACT);
              end;
            end;
          end;
        end;

        LVN_ENDLABELEDITW: begin
          if DontReact then exit;
          if wParam=IDC_ACTION_GROUP then
          begin
            with PLVDISPINFOW(lParam)^ do
            begin
              if item.pszText<>nil then
              begin
                ChMask:=ChMask or ACTM_RENAME;
                SetChanged(Dialog,etHK);
                item.mask:=LVIF_TEXT;
                if pWideChar(item.pszText)^=#0 then
                  pWideChar(item.pszText):=NoDescription;
                SendMessageW(hdr.hWndFrom,LVM_SETITEMW,0,tlparam(@item));

                with NewGroupList^[item.lParam] do
                begin
                  mFreeMem(descr);
                  StrDupW(descr,item.pszText);
                end;

                FillChainList(Dialog);
                result:=1;
              end;
            end;
          end
          else if wParam=IDC_ACTION_LIST then
          begin
            with PLVDISPINFOW(lParam)^ do
            begin
              if item.pszText<>nil then
              begin
                ChMask:=ChMask or ACTM_ACT or ACTM_ACTS;
                SetChanged(Dialog,etACT);
                ChangeActionName(item.iItem,0,pWideChar(item.pszText));
                result:=1;
              end;
//??
            end;
          end;
        end;

      end;
    end;
  else
//  {result:=}DefWindowProc(Dialog,hMessage,wParam,lParam);
  end;
//  {result:=}DefWindowProc(Dialog,hMessage,wParam,lParam);
end;