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
|
#include "common.h"
#pragma hdrstop
extern HINSTANCE hInst;
#define MAXLBUTS 32
LBUTOPT LBUTS[MAXLBUTS];
static int LButCnt = 0;
extern char *AS(char *str, const char *setting, char *addstr);
//wparam -id
INT_PTR LaunchService(WPARAM wParam, LPARAM lParam)
{
PROCESS_INFORMATION pi;
STARTUPINFO si = {0};
si.cb = sizeof(si);
if ( lParam < 0 || lParam >= MAXLBUTS )
return -1;
if ( CreateProcess(NULL, LBUTS[lParam].lpath, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi)) {
CloseHandle(pi.hProcess);
CloseHandle(pi.hThread);
}
Sleep(20);
CallService(MS_TTB_SETBUTTONSTATE, LBUTS[lParam].hframe, TTBST_RELEASED);
return 0;
}
//wparam -id
//lparam &LBTOPT
INT_PTR GetLButton(WPARAM wParam, LPARAM lParam)
{
if ( wParam < 0 || wParam >= MAXLBUTS )
return -1;
LBUTOPT *lbo = ( LBUTOPT* )lParam;
if (lbo == NULL)
return -1;
if (LBUTS[wParam].hframe == 0)
return -1;
*lbo = LBUTS[wParam];
return 0;
}
//wparam -id
//lparam &LBTOPT
INT_PTR ModifyLButton(WPARAM wParam, LPARAM lParam)
{
if ( wParam < 0 || wParam >= LButCnt )
return -1;
LBUTOPT *lbo = ( LBUTOPT* )lParam;
if (lbo == NULL)
return -1;
if (LBUTS[wParam].hframe == 0)
return -1;
DeleteLBut(wParam, 0);
if (LBUTS[wParam].lpath != NULL){free(LBUTS[wParam].lpath);}
if (LBUTS[wParam].name != NULL){free(LBUTS[wParam].name);}
LBUTS[wParam].name = NULL;
LBUTS[wParam].lpath = NULL;
if (lbo->name != NULL)
LBUTS[wParam].name = _strdup(lbo->name);
if (lbo->lpath != NULL)
LBUTS[wParam].lpath = _tcsdup(lbo->lpath);
LBUTS[wParam].hframe = InsertLBut(wParam);
SaveAllLButs();
return 0;
}
INT_PTR InsertLBut(int id)
{
HBITMAP DefLUp = LoadBitmap(hInst, MAKEINTRESOURCE(IDB_LAUNCHDN));
HBITMAP DefLDn = LoadBitmap(hInst, MAKEINTRESOURCE(IDB_LAUNCHUP));
TTBButton ttb = { 0 };
ttb.cbSize = sizeof(ttb);
ttb.hbBitmapDown = DefLDn;
ttb.hbBitmapUp = DefLUp;
ttb.dwFlags = TTBBF_VISIBLE|TTBBF_ISLBUTTON;
ttb.pszServiceDown = TTB_LAUNCHSERVICE;
ttb.lParamDown = id;
ttb.name = LBUTS[id].name;
LButCnt++;
return TTBAddButton(( WPARAM )&ttb, 0);
}
INT_PTR DeleteLBut(WPARAM id, LPARAM lParam)
{
if (LBUTS[id].hframe != 0)
{
TTBRemoveButton(LBUTS[id].hframe, 0);
LBUTS[id].hframe = 0;
if (LBUTS[id].name != NULL){free(LBUTS[id].name);}
if (LBUTS[id].lpath != NULL){free(LBUTS[id].lpath);}
LBUTS[id].name = NULL;
LBUTS[id].lpath = NULL;
LButCnt--;
}
return 0;
}
int LoadAllLButs()
{
char buf[255];
char buf1[10];
char fixname[255];
int id;
//must be locked
memset(buf, 0, SIZEOF(buf));
memset(LBUTS, 0, sizeof(LBUTS));
for (int i = 0; i < MAXLBUTS; i++) {
memset(buf1, 0, SIZEOF(buf1));
itoa(i, buf1, 10);
AS(fixname, "LBUT", buf1);
id = DBGetContactSettingWord(0, TTB_OPTDIR, AS(buf, fixname, ""), -1);
if (id != -1) {
LBUTS[i].name = DBGetString(0, TTB_OPTDIR, AS(buf, fixname, "_name"));
LBUTS[i].lpath = DBGetStringT(0, TTB_OPTDIR, AS(buf, fixname, "_lpath"));
if (LBUTS[i].lpath == NULL)
LBUTS[i].lpath = _tcsdup( _T("Execute Path"));
LBUTS[i].hframe = 0;
LBUTS[i].hframe = InsertLBut(i);
}
}
return 0;
}
int SaveAllLButs()
{
char buf[255];
char buf1[10];
char fixname[255];
//must be locked
memset(buf, 0, SIZEOF(buf));
for (int i = 0;i<MAXLBUTS;i++) {
itoa(i, buf1, 10);
if (LBUTS[i].hframe != 0) {
AS(fixname, "LBUT", buf1);
DBWriteContactSettingWord(0, TTB_OPTDIR, AS(buf, fixname, ""), i);
DBWriteContactSettingString(0, TTB_OPTDIR, AS(buf, fixname, "_name"), LBUTS[i].name);
DBWriteContactSettingTString(0, TTB_OPTDIR, AS(buf, fixname, "_lpath"), LBUTS[i].lpath);
}
else {
AS(fixname, "LBUT", buf1);
DBWriteContactSettingWord(0, TTB_OPTDIR, AS(buf, fixname, ""), -1);
DBDeleteContactSetting(0, TTB_OPTDIR, AS(buf, fixname, ""));
DBDeleteContactSetting(0, TTB_OPTDIR, AS(buf, fixname, "_lpath"));
DBDeleteContactSetting(0, TTB_OPTDIR, AS(buf, fixname, "_name"));
}
}
return 0;
}
//return 0 on success, -1 on error
INT_PTR InsertNewFreeLBut(WPARAM wParam, LPARAM lParam)
{
char buf[256];
if (LButCnt < MAXLBUTS) {
for (int i = 0;i<MAXLBUTS;i++) {
if (LBUTS[i].hframe == 0)
{
wsprintfA(buf, "%s %d", Translate("Default"), i);
LBUTS[i].name = _strdup(buf);
LBUTS[i].lpath = _tcsdup( _T("Execute Path"));
LBUTS[i].hframe = InsertLBut(i);
SaveAllLButs();
return 0;
}
}
}
return -1;
}
int InitLBut()
{
CreateServiceFunction(TTB_LAUNCHSERVICE, LaunchService);
CreateServiceFunction(TTB_ADDLBUTTON, InsertNewFreeLBut);
CreateServiceFunction(TTB_REMOVELBUTTON, DeleteLBut);
CreateServiceFunction(TTB_MODIFYLBUTTON, ModifyLButton);
CreateServiceFunction(TTB_GETLBUTTON, GetLButton);
LoadAllLButs();
return 0;
}
int UnInitLBut()
{
SaveAllLButs();
return 0;
}
|