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
|
#include "common.h"
#pragma hdrstop
extern HINSTANCE hInst;
#define MAXSEPS 32
int Separators[MAXSEPS];
static int SeparatorCnt = 0;
int InsertSeparator(int id)
{
char buf[255];
wsprintfA(buf, "%s %d", Translate("Separator"), id);
TTBButton ttb = { 0 };
ttb.cbSize = sizeof(ttb);
ttb.dwFlags = TTBBF_VISIBLE | TTBBF_ISSEPARATOR;
ttb.pszServiceDown = "";
ttb.pszServiceUp = "";
ttb.lParamDown = id;
ttb.name = buf;
SeparatorCnt++;
return ( int )TTBAddButton((WPARAM)&ttb, 0);
}
INT_PTR DeleteSeparator(WPARAM id, LPARAM lParam)
{
if ((id<0) || (id >= MAXSEPS)) {
MessageBoxA(0, "Wrong id", "Error", 0);
return 0;
}
if (Separators[id] != 0) {
TTBRemoveButton(Separators[id], 0);
Separators[id] = 0;
SeparatorCnt--;
}
SaveAllSeparators();
return 1;
}
int LoadAllSeparators()
{
//must be locked
char buf[255];
memset(buf, 0, sizeof(buf));
memset(Separators, 0, sizeof(Separators));
for (int i = 0; i < MAXSEPS; i++) {
char buf1[10];
_itoa(i, buf1, 10);
int id = DBGetContactSettingWord(0, TTB_OPTDIR, AS(buf, "Sep", buf1), -1);
if (id == i)
Separators[i] = InsertSeparator(i);
}
return 0;
}
int SaveAllSeparators()
{
char buf[255];
char buf1[10];
for (int i = 0; i < MAXSEPS; i++) {
memset(buf1, 0, sizeof(buf1));
_itoa(i, buf1, 10);
if (Separators[i] != 0)
DBWriteContactSettingWord(0, TTB_OPTDIR, AS(buf, "Sep", buf1), i);
else {
DBWriteContactSettingWord(0, TTB_OPTDIR, AS(buf, "Sep", buf1), -1);
DBDeleteContactSetting(0, TTB_OPTDIR, AS(buf, "Sep", buf1));
}
}
return 0;
}
//return 0 on success, -1 on error
INT_PTR InsertNewFreeSeparator(WPARAM wParam, LPARAM lParam)
{
if (SeparatorCnt < MAXSEPS) {
for (int i = 0; i < MAXSEPS; i++) {
if (Separators[i] == 0) {
Separators[i] = InsertSeparator(i);
SaveAllSeparators();
return 0;
}
}
}
return -1;
}
|