-
Notifications
You must be signed in to change notification settings - Fork 4
/
ContainerWnd.h
92 lines (78 loc) · 2.16 KB
/
ContainerWnd.h
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
#ifndef CONTAINERWND_H
#define CONTAINERWND_H
#if _MSC_VER >= 1000
#pragma once
#endif // _MSC_VER >= 1000
typedef CWinTraits<WS_CHILD|WS_VISIBLE|WS_CLIPCHILDREN|WS_CLIPSIBLINGS,WS_EX_CLIENTEDGE>
CContainerWndTraits;
class CContainerWnd : public CWindowImpl<CContainerWnd,CWindow,CContainerWndTraits>
{
public:
DECLARE_WND_CLASS_EX(NULL, CS_DBLCLKS, COLOR_WINDOW)
typedef CWindowImpl<CContainerWnd,CWindow,CContainerWndTraits> baseClass;
BEGIN_MSG_MAP(CContainerWnd)
MESSAGE_HANDLER(WM_ERASEBKGND, OnErase)
MESSAGE_HANDLER(WM_SIZE,OnSize)
MESSAGE_HANDLER(WM_SETFOCUS,OnFocus)
{
bHandled = TRUE;
lResult = ForwardNotifications(uMsg, wParam, lParam, bHandled);
}
REFLECT_NOTIFICATIONS()
END_MSG_MAP()
static BOOL CALLBACK SizeProc(HWND hWnd,LPARAM lParam) {
RECT *rc=(RECT*)lParam;
::MoveWindow(hWnd,0,0,rc->right-rc->left,rc->bottom-rc->top,
TRUE);
return TRUE;
}
LRESULT OnSize(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL&) {
RECT rc;
GetClientRect(&rc);
::EnumChildWindows(*this,SizeProc,(LPARAM)&rc);
return 0;
}
LRESULT OnFocus(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL&) {
HWND hWnd=GetActiveWnd();
if (hWnd!=NULL)
::SetFocus(hWnd);
return 0;
}
LRESULT OnErase(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL&) {
return 1;
}
static BOOL CALLBACK FindProc(HWND hWnd,LPARAM lParam) {
if (::IsWindowVisible(hWnd)) {
*(HWND*)lParam=hWnd;
return FALSE;
}
return TRUE;
}
HWND GetActiveWnd() {
HWND hWnd=NULL;
::EnumChildWindows(*this,FindProc,(LPARAM)&hWnd);
if (hWnd==NULL)
hWnd=GetWindow(GW_CHILD);
return hWnd;
}
void HideActiveWnd() {
HWND hWnd=GetActiveWnd();
if (hWnd!=NULL)
::ShowWindow(hWnd,SW_HIDE);
}
void ActivateWnd(HWND hWnd) {
HWND hActive=GetActiveWnd();
if (hActive!=hWnd && hActive!=NULL)
::ShowWindow(hActive,SW_HIDE);
::ShowWindow(hWnd,SW_SHOW);
}
void AttachWnd(HWND hWnd) {
::ShowWindow(hWnd,SW_HIDE);
RECT rc;
GetClientRect(&rc);
::MoveWindow(hWnd,rc.left,rc.top,
rc.right-rc.left,rc.bottom-rc.top,
TRUE);
}
};
#endif