-
Notifications
You must be signed in to change notification settings - Fork 0
/
TabControl.cpp
58 lines (48 loc) · 1.29 KB
/
TabControl.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
#include "TabControl.h"
TabControl::TabControl()
{
}
TabControl::TabControl(HWND _hwnd): _hwnd(_hwnd)
{
}
TabControl::~TabControl()
{
}
TabControl::operator HWND() const
{
return _hwnd;
}
void TabControl::AddItem(const char* itemText)
{
char buffer[50];
strcpy(buffer, itemText);
TCITEM tabControlItem;
tabControlItem.mask = TCIF_TEXT;
tabControlItem.pszText = buffer;
auto newTabIndex = TabCtrl_GetItemCount(_hwnd);
TabCtrl_InsertItem(_hwnd, newTabIndex, &tabControlItem);
}
BOOL TabControl::TryProcessMessage(UINT message, WPARAM wParam, LPARAM lParam)
{
auto notificationMessageHandler = (NMHDR*)lParam;
if (notificationMessageHandler->hwndFrom != _hwnd) return FALSE;
switch (notificationMessageHandler->code)
{
case TCN_SELCHANGE:
{
auto tabIndex = TabCtrl_GetCurSel(_hwnd);
UpdateTabLayout(tabIndex);
return TRUE;
}
}
return FALSE;
}
void TabControl::UpdateTabLayout(int idx)
{
for(auto it = controls.begin(); it != controls.end(); it++)
ShowWindow(it->second, (it->first == idx)? SW_SHOW : SW_HIDE);
}
void TabControl::Register(int tabIndex, HWND control)
{
controls.push_back(std::make_pair(tabIndex, control));
}