/
SecondModuleManagerWndProc.cpp
449 lines (355 loc) · 15 KB
/
SecondModuleManagerWndProc.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
/******************************************************************
文件名:SecondModuleManagerWndProc.cpp
文件描述:第二个模块管理器的三个消息处理函数
*********************************************************************/
#include <windows.h>
#include "MyDefine.h"
//使用全局变量 ModuleManager2 (在GlobleManager.h中定义,在Entry.cpp中初始化)
extern MODULEMANAGER ModuleManager2;
//用于在 【第二个模块管理器】 中指明当前 按钮选择了那个子模块
static idOfCurrentSubModule;
//【第二个模块】 “收藏”中的 的所有句柄
static HWND hStaticCurrentFloder,hFloderListBox, hLinkListBox,
hAddFloderButton, hDeleteFloderButton,
hAddLinkButton, hDeleteLinkButton;
static HWND hStaticCurrentFloder2,hFloderListBox2, hLinkListBox2,
hAddFloderButton2, hDeleteFloderButton2,
hAddLinkButton2, hDeleteLinkButton2;
static HWND hDlgAddNetLink, hDlgAddLocalLink,
hStaticName, hStaticLink, hNameEdit1, hLinkEdit1, hConformButton1 , hCancelbutton1,
hStaticName2, hStaticLink2, hNameEdit2, hLinkEdit2, hConformButton2 , hCancelbutton2;
/*****************************************************************
* 第二个模块下的子模块管理器的消息处理函数,包括:
*
* ModuleManagerProc2 管理器 “底层”静态 static Board 控件的消息处理函数
* ModuleButtonWindowProc2 管理器 “按钮”静态 static button board 控件的消息处理函数
* ModuleContentWindowProc2 管理器 “内容”静态 static content boead 控件(们)的消息处理函数
******************************************************************/
/*****************************************************************
* 模块管理器 的 底层静态“静态窗口” 使用的消息处理函数 (第二个模块管理器)
******************************************************************/
LRESULT CALLBACK ModuleManagerProc2 (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam){
PMODULEMANAGER pMM = GetPModuleManagerByStaticHWND(hwnd);
CheckNullErrorAndQuit(pMM,14,TEXT("Can't Get ModuleManager By HWND in ModuleManagerProc2()!"));
// RECT rect;
int cxWindow,cyWindow,cyChar,i;
switch(message)
{
case WM_SIZE:
//获得系统默认字体的高度
cyChar = HIWORD (GetDialogBaseUnits ()) ;
cxWindow = LOWORD(lParam);
cyWindow = HIWORD(lParam);
//设置hStaticBoard(第二个模块)的子窗口hButtonBoard 和hContentBoard的位置
MoveWindow(ModuleManager2.hButtonBoard,3,3,cxWindow-2*3,cyChar*2,TRUE);
for(i=0 ; i<ModuleManager2.countOfModule ; i++)
MoveWindow(ModuleManager2.pToolModule[i].hContentBoard,3,3+cyChar*2+3,cxWindow-2*3,cyWindow-3*2-3-cyChar*2,TRUE);
//显示当前所选定的“内容窗口”
for(i=0; i<ModuleManager2.countOfModule ;i++){
if(i==idOfCurrentSubModule){
ShowWindow(ModuleManager2.pToolModule[i].hContentBoard,SW_SHOW);
}
else
ShowWindow(ModuleManager2.pToolModule[i].hContentBoard,SW_HIDE);
}
break;
}
return CallWindowProc (pMM->OldModuleManager, hwnd, message, wParam,lParam) ;
}
/*****************************************************************
* 模块管理器 的 静态“按钮窗口”使用的消息处理函数 (第二个模块管理器)
******************************************************************/
LRESULT CALLBACK ModuleButtonWindowProc2 (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam){
HDC hdc ;
PAINTSTRUCT ps ;
RECT rect;
PMODULEMANAGER pMM = GetPModuleManagerByButtonHWND(hwnd);
CheckNullErrorAndQuit(pMM,15,TEXT("Can't Get ModuleManager By HWND in ModuleButtonWindowProc2()!"));
static int i , totalWidth,idGot;
static int cxWindow,cyWindow,cxChar;
static int* intList=NULL;
int lengthToLeft,buttonShift;
static int blockLeft,blockRight,newLeft,newRight,oldLeft,oldRight; //用于绘制高亮区域
static int firstTimeFlag = 1;
static bool toRight = true;
static int currentId = 0;
//"按钮窗口"的两个左右方向按钮
static HWND hLeftButton,hRightButton;
//记录“按钮窗口”中按钮的开始与结束位置
static int xButtonBegin,xButtonEnd;
switch(message)
{
case WM_CREATE:
/** 注意:在子窗口类别化时,次新的回调函数的WM_CREATE 不会被调用,进入该函数的该消息是在
CreateStaticModuleManergerBoard()中使用 SendMessage(pMM.hButtonBoard,WM_CREATE,0,0); 发送的 */
//设置定时器,用于绘画可以移动的高亮区域
SetTimer (hwnd, 2, 10, NULL) ;
blockLeft = blockRight = 0;
xButtonBegin = 5;
hLeftButton = CreateWindow(TEXT("button"),TEXT("<<"),WS_CHILD|BS_PUSHBUTTON,
0,0,0,0, // 使用 MAX_COUNT_OF_MODULE+1 作为向左移动按钮的ID
hwnd, (HMENU)(MAX_COUNT_OF_MODULE+1), (HINSTANCE)GetWindowLong(hwnd,GWL_HINSTANCE),NULL);
hRightButton = CreateWindow(TEXT("button"),TEXT(">>"),WS_CHILD|BS_PUSHBUTTON,
0,0,0,0, // 使用 MAX_COUNT_OF_MODULE+2 作为向右移动按钮的ID
hwnd, (HMENU)(MAX_COUNT_OF_MODULE+2), (HINSTANCE)GetWindowLong(hwnd,GWL_HINSTANCE),NULL);
break;
case WM_SIZE:
//获得“按钮窗口”的大小消息,和设备字体宽度
cxWindow = LOWORD(lParam);
cyWindow = HIWORD(lParam);
cxChar = LOWORD (GetDialogBaseUnits ()) ;
//仅调用一次
if(firstTimeFlag)
{
//将每个按钮的字体宽度信息保存在列表中
intList = (int*)malloc(sizeof(int)*ModuleManager2.countOfModule);
CheckNullErrorAndQuit(intList,19,TEXT("Memory for [intList] alloc failed in ModuleButtonWindowProc2()!"));
for(i=0 ; i< ModuleManager2.countOfModule ; i++)
{
intList[i] = GetWindowTextLength (ModuleManager2.pToolModule[i].hButton) ;
}
//第一次调用时将高亮的区域指定为第一个按钮
newLeft = xButtonBegin;
newRight = xButtonBegin + intList[0]*cxChar*2+30;
firstTimeFlag = 0;
}
//根据xButtonBegin和字体宽度等设置按钮的 位置和大小
lengthToLeft =0;
for(i=0 ; i< ModuleManager2.countOfModule ; i++)
{
MoveWindow(ModuleManager2.pToolModule[i].hButton,
xButtonBegin+lengthToLeft*cxChar*2+i*30,10, intList[i]*cxChar*2+30,cyWindow-10-2,TRUE);
lengthToLeft += intList[i];
}
//根据xButtonBegin 和 按钮总宽度获得 xButtonEnd
totalWidth = lengthToLeft*cxChar*2 + i*30;
xButtonEnd = xButtonBegin + totalWidth;
//由 xButtonBegin 、xButtonEnd 与 windows size 的关系决定“左右移动”按钮是否出现
if(xButtonBegin >= 5 && xButtonEnd <= cxWindow-5)
{
ShowWindow(hLeftButton,SW_HIDE);
ShowWindow(hRightButton,SW_HIDE);
}
else
{
MoveWindow(hLeftButton,cxWindow-5-60,1,30,9,TRUE);
MoveWindow(hRightButton,cxWindow-5-30,1, 30,9,TRUE);
ShowWindow(hLeftButton,SW_SHOW);
ShowWindow(hRightButton,SW_SHOW);
}
//改变大小变宽时,若左侧部分隐藏,右侧又有空余,则全部按钮拉着右边框跟着移动
if(xButtonBegin < 5 && xButtonEnd < cxWindow-5)
{
xButtonBegin += cxWindow- 5 - xButtonEnd;
newLeft += cxWindow- 5 - xButtonEnd;
newRight += cxWindow - 5-xButtonEnd;
toRight = true;
}
break;
case WM_COMMAND:
//由按钮的句柄获得其Id 即得到所在模块pToolModle[]的下标
idGot = GetWindowLong ((HWND)lParam, GWL_ID) ;
idOfCurrentSubModule = idGot < MAX_COUNT_OF_MODULE ? idGot : idOfCurrentSubModule;
if(idGot < MAX_COUNT_OF_MODULE) //为模块按钮的消息
{
for(i=0; i<pMM->countOfModule ;i++){
if(i==idOfCurrentSubModule)
ShowWindow(pMM->pToolModule[i].hContentBoard,SW_SHOW);
else
ShowWindow(pMM->pToolModule[i].hContentBoard,SW_HIDE);
}
//计算点击按钮的位置,储存在newLeft 和 newRight中
lengthToLeft =0;
for(i=0 ; i< ModuleManager2.countOfModule ; i++)
{
if(i==idOfCurrentSubModule){
newLeft= xButtonBegin+lengthToLeft*cxChar*2+i*30;
newRight= newLeft + intList[i]*cxChar*2+30;
break;
}
lengthToLeft += intList[i];
}
//确定高亮移动方向
if(idOfCurrentSubModule > currentId) toRight =true;
else
if(idOfCurrentSubModule < currentId) toRight = false;
currentId = idOfCurrentSubModule;
}
else //为“左右移动”按钮的消息
{
if(idGot == MAX_COUNT_OF_MODULE + 1) //为“向左”按钮
{
if(xButtonEnd > cxWindow-5){
buttonShift=xButtonEnd;
//改变Button位置
xButtonEnd = max( cxWindow-5, xButtonEnd-30);
xButtonBegin = xButtonEnd - totalWidth;
//改变高亮位置
buttonShift = xButtonEnd -buttonShift;
newLeft += buttonShift;
newRight += buttonShift;
toRight = false;
}
}
else //为“向右”按钮
{
if(xButtonBegin < 5){
buttonShift=xButtonBegin;
//改变Button位置
xButtonBegin = min( 5, xButtonBegin + 30);
xButtonEnd = xButtonBegin + totalWidth;
//改变高亮位置
buttonShift = xButtonBegin - buttonShift;
newLeft += buttonShift;
newRight += buttonShift;
toRight = true;
}
}
SendMessage(hwnd,WM_SIZE,0, (cyWindow<<16)|cxWindow);
InvalidateRect(hwnd,NULL,TRUE);
}
break;
case WM_TIMER:
//更新绘画高亮区域的范围
if(blockLeft != newLeft || blockRight != newRight)
{
oldLeft = blockLeft;
oldRight = blockRight;
blockLeft = blockLeft + (toRight ? 45:60)*(toRight ? 1:-1);
blockRight = blockRight + (toRight ? 60:45)*(toRight ? 1:-1);
blockLeft = toRight? min(blockLeft,newLeft):max(blockLeft,newLeft);
blockRight = toRight? min(blockRight,newRight):max(blockRight,newRight);
oldLeft = toRight? oldLeft:blockRight;
oldRight = toRight? blockLeft:oldRight;
InvalidateRect(hwnd,NULL,TRUE);
}
break;
case WM_PAINT:
hdc = BeginPaint (hwnd, &ps) ;
//FillRect(hdc,&ps.rcPaint,(HBRUSH)GetStockObject(WHITE_BRUSH));
//绘制高亮区域
//擦除旧的区域
SetRect(&rect,oldLeft,1,oldRight,8);
FillRect(hdc,&rect,(HBRUSH)GetStockObject(WHITE_BRUSH));
//绘制性的区域
SetRect(&rect,blockLeft,1,blockRight,8);
FillRect(hdc,&rect,(HBRUSH)GetStockObject(BLACK_BRUSH));
EndPaint (hwnd, &ps) ;
break;
}
return CallWindowProc (pMM->OldModuleButton, hwnd, message, wParam,lParam);
}
/*****************************************************************
* 每个新模块的 静态“内容窗口”使用的消息处理函数 (第二个模块管理器)
******************************************************************/
LRESULT CALLBACK ModuleContentWindowProc2 (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam){
//得到原来的消息函数
WNDPROC oldModuleContent = GetOldContentWndProcByContentHWND(hwnd);
CheckNullErrorAndQuit(oldModuleContent,16,TEXT("Can't Get oldModuleContent By HWND in ModuleButtonWindowProc()!"));
//得到模块的ID
int id = GetIdInModuleManagerByContentHWND(hwnd);
if(id == -1){
MessageBox(hwnd,TEXT("ErrorCode: 0X 0017\nCant't Get [idModule] in ModuleContentWindowProc2()"),TEXT("ERROR"),MB_ICONERROR);
PostQuitMessage (0) ;
}
//得到模块管理器指针
PMODULEMANAGER pMM = GetPModuleManagerByContentHWND(hwnd);
CheckNullErrorAndQuit(pMM,18,TEXT("Can't Get ModuleManager By ContentHWND in ModuleContentWindowProc2()!"));
static int cxWindow,cyWindow,cxChar,cyChar,i;
switch(message)
{
case WM_CREATE:
/** 注意:在子窗口类别化时,次新的回调函数的WM_CREATE 不会被调用,进入该函数的该消息是在
AddNewModule()中使用 SendMessage(hContentBoard,WM_CREATE,0,0); 发送的 */
//初始化第一个子模块的控件
if(id==0)
{
//显示当前文件夹的静态标签
hStaticCurrentFloder = CreateWindow(TEXT("static"),TEXT("当前文件夹"),WS_CHILD|WS_VISIBLE|SS_CENTER,
0,0,0,0,
hwnd, (HMENU)1, (HINSTANCE)GetWindowLong(hwnd,GWL_HINSTANCE),NULL);
//两个显示当前文件夹和链接的ListBox
hFloderListBox = CreateWindow(TEXT("listbox"),NULL,WS_CHILD|WS_VISIBLE|LBS_STANDARD,
0,0,0,0,
hwnd, (HMENU)2,(HINSTANCE)GetWindowLong(hwnd,GWL_HINSTANCE),NULL);
hLinkListBox = CreateWindow(TEXT("listbox"),NULL,WS_CHILD|WS_VISIBLE|LBS_STANDARD,
0,0,0,0,
hwnd, (HMENU)3,(HINSTANCE)GetWindowLong(hwnd,GWL_HINSTANCE),NULL);
//四个添加或删除按钮
hAddFloderButton = CreateWindow(TEXT("button"),TEXT("新增文件夹"),WS_CHILD|WS_VISIBLE|BS_DEFPUSHBUTTON,
0,0,0,0,
hwnd, (HMENU)4, (HINSTANCE)GetWindowLong(hwnd,GWL_HINSTANCE),NULL);
hDeleteFloderButton = CreateWindow(TEXT("button"),TEXT("删除文件夹"),WS_CHILD|WS_VISIBLE|BS_DEFPUSHBUTTON,
0,0,0,0,
hwnd, (HMENU)5, (HINSTANCE)GetWindowLong(hwnd,GWL_HINSTANCE),NULL);
hAddLinkButton = CreateWindow(TEXT("button"),TEXT("添加链接"),WS_CHILD|WS_VISIBLE|BS_DEFPUSHBUTTON,
0,0,0,0,
hwnd, (HMENU)6, (HINSTANCE)GetWindowLong(hwnd,GWL_HINSTANCE),NULL);
hDeleteLinkButton = CreateWindow(TEXT("button"),TEXT("删除链接"),WS_CHILD|WS_VISIBLE|BS_DEFPUSHBUTTON,
0,0,0,0,
hwnd, (HMENU)7, (HINSTANCE)GetWindowLong(hwnd,GWL_HINSTANCE),NULL);
}
else if(id==1)//初始化第二个子模块的控件
{
//显示当前文件夹的静态标签
hStaticCurrentFloder2 = CreateWindow(TEXT("static"),TEXT("当前文件夹"),WS_CHILD|WS_VISIBLE|SS_CENTER,
0,0,0,0,
hwnd, (HMENU)8, (HINSTANCE)GetWindowLong(hwnd,GWL_HINSTANCE),NULL);
//两个显示当前文件夹和链接的ListBox
hFloderListBox2 = CreateWindow(TEXT("listbox"),NULL,WS_CHILD|WS_VISIBLE|LBS_STANDARD,
0,0,0,0,
hwnd, (HMENU)9,(HINSTANCE)GetWindowLong(hwnd,GWL_HINSTANCE),NULL);
hLinkListBox2 = CreateWindow(TEXT("listbox"),NULL,WS_CHILD|WS_VISIBLE|LBS_STANDARD,
0,0,0,0,
hwnd, (HMENU)10,(HINSTANCE)GetWindowLong(hwnd,GWL_HINSTANCE),NULL);
//四个添加或删除按钮
hAddFloderButton2 = CreateWindow(TEXT("button"),TEXT("新增文件夹"),WS_CHILD|WS_VISIBLE|BS_DEFPUSHBUTTON,
0,0,0,0,
hwnd, (HMENU)11, (HINSTANCE)GetWindowLong(hwnd,GWL_HINSTANCE),NULL);
hDeleteFloderButton2 = CreateWindow(TEXT("button"),TEXT("删除文件夹"),WS_CHILD|WS_VISIBLE|BS_DEFPUSHBUTTON,
0,0,0,0,
hwnd, (HMENU)12, (HINSTANCE)GetWindowLong(hwnd,GWL_HINSTANCE),NULL);
hAddLinkButton2 = CreateWindow(TEXT("button"),TEXT("添加链接"),WS_CHILD|WS_VISIBLE|BS_DEFPUSHBUTTON,
0,0,0,0,
hwnd, (HMENU)13, (HINSTANCE)GetWindowLong(hwnd,GWL_HINSTANCE),NULL);
hDeleteLinkButton2 = CreateWindow(TEXT("button"),TEXT("删除链接"),WS_CHILD|WS_VISIBLE|BS_DEFPUSHBUTTON,
0,0,0,0,
hwnd, (HMENU)14, (HINSTANCE)GetWindowLong(hwnd,GWL_HINSTANCE),NULL);
}
else
{
}
break;
case WM_SIZE:
//获得“内容窗口”的大小消息,和设备字体宽度
cxWindow = LOWORD(lParam);
cyWindow = HIWORD(lParam);
cyChar = LOWORD (GetDialogBaseUnits ()) ;
//调整第一个子模块的控件的位置和大小
if(id==0)
{
MoveWindow(hStaticCurrentFloder,30,10,240,2*cyChar,TRUE);
MoveWindow(hFloderListBox,30,10+3*cyChar,240,cyWindow-10*cyChar-10,TRUE);
MoveWindow(hAddFloderButton,30,cyWindow-6*cyChar,110,4*cyChar,TRUE);
MoveWindow(hDeleteFloderButton,30+130,cyWindow-6*cyChar,110,4*cyChar,TRUE);
MoveWindow(hLinkListBox,30+300,15,300,cyWindow-10*cyChar-10+2*cyChar,TRUE);
MoveWindow(hAddLinkButton,30+300,cyWindow-6*cyChar,110,4*cyChar,TRUE);
MoveWindow(hDeleteLinkButton,30+300+190,cyWindow-6*cyChar,110,4*cyChar,TRUE);
}
else if(id==1)//调整第二个子模块的控件的位置和大小
{
MoveWindow(hStaticCurrentFloder2,30,10,240,2*cyChar,TRUE);
MoveWindow(hFloderListBox2,30,10+3*cyChar,240,cyWindow-10*cyChar-10,TRUE);
MoveWindow(hAddFloderButton2,30,cyWindow-6*cyChar,110,4*cyChar,TRUE);
MoveWindow(hDeleteFloderButton2,30+130,cyWindow-6*cyChar,110,4*cyChar,TRUE);
MoveWindow(hLinkListBox2,30+300,15,300,cyWindow-10*cyChar-10+2*cyChar,TRUE);
MoveWindow(hAddLinkButton2,30+300,cyWindow-6*cyChar,110,4*cyChar,TRUE);
MoveWindow(hDeleteLinkButton2,30+300+190,cyWindow-6*cyChar,110,4*cyChar,TRUE);
}
else
{
}
break;
}
return CallWindowProc (oldModuleContent, hwnd, message, wParam,lParam);
}