-
Notifications
You must be signed in to change notification settings - Fork 74
/
mdiclient.c
119 lines (107 loc) · 2.48 KB
/
mdiclient.c
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
#include "mdiclient.h"
#include "sisw.h"
#include "tabctl.h"
#include "const.h"
extern HWND hwnd_mdi_client;
static WNDPROC old_mdi_client_proc = NULL;
static WINDOWPOS last_windowpos;
//获取窗口句柄
HWND GetMdiClientHwnd(HWND parent)
{
HWND find = NULL;
find = FindWindowEx(parent,NULL,SI_CLASSNAME_MDI,NULL);
return find;
}
static LRESULT CALLBACK MdiClientSubClass(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch(uMsg)
{
case WM_WINDOWPOSCHANGING:
{
WINDOWPOS* pos = (WINDOWPOS*)lParam;
SiTabCtl_OnPosChanging(pos);
if(!(pos->flags & SWP_NOMOVE))
{
last_windowpos.x = pos->x;
last_windowpos.y = pos->y;
}
if(!(pos->flags & SWP_NOSIZE))
{
last_windowpos.cx = pos->cx;
last_windowpos.cy = pos->cy;
pos->y += SiTabCtl_GetHeight();
pos->cy -= SiTabCtl_GetHeight();
lParam = (LPARAM)pos;
}
}
break;
default:
break;
}
LRESULT lr = CallWindowProc(old_mdi_client_proc, hWnd, uMsg, wParam, lParam);
switch(uMsg)
{
case WM_MDICREATE:
{
MDICREATESTRUCT* mdi = (MDICREATESTRUCT*)lParam;
HWND hwnd = FindWindowEx(hwnd_mdi_client,NULL,mdi->szClass,mdi->szTitle);
if(hwnd == NULL)
{
OutputDebugString("find si_Sw HWND failed");
break;
}
HookSiSw(hwnd);
char title[SI_BUF_SIZE];
GetSiSwTitle(mdi->szTitle,title);
SiTabCtl_AddItem(title,hwnd);
SiTabCtl_SetCurItem(hwnd);
//resize
BOOL resize = SiTabCtl_IsRowChanged();
if(resize == TRUE)
{
ResizeMdiClient();
}
}
break;
case WM_MDIDESTROY:
{
HWND hwnd = (HWND)wParam;
SiTabCtl_DelItem(hwnd);
UnhookSiSw(hwnd);
//find new
HWND curhwnd = (HWND)SendMessage(hwnd_mdi_client,WM_MDIGETACTIVE,0,0);
if(curhwnd != NULL && IsWindow(curhwnd))
{
SiTabCtl_SetCurItem(curhwnd);
}
//resize
BOOL resize = SiTabCtl_IsRowChanged();
if(resize == TRUE)
{
ResizeMdiClient();
}
}
break;
case WM_MDIACTIVATE:
{
HWND hwnd = (HWND)wParam;
SiTabCtl_SetCurItem(hwnd);
}
break;
default:
break;
}
return lr;
}
//重新调整窗口大小
void ResizeMdiClient(void)
{
//调用MoveWindow立即重绘窗口
MoveWindow(hwnd_mdi_client,last_windowpos.x,last_windowpos.y,last_windowpos.cx,last_windowpos.cy,TRUE);
}
//替换窗口消息
void HookMdiClient(void)
{
old_mdi_client_proc = (WNDPROC)GetWindowLong(hwnd_mdi_client,GWL_WNDPROC);
SetWindowLong(hwnd_mdi_client,GWL_WNDPROC,(DWORD)MdiClientSubClass);
}