-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtoolbar.cpp
133 lines (119 loc) · 3.53 KB
/
toolbar.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
#include "toolbar.h"
HWND ToolBar::CreateToolbarInBand(UINT toolbarid)
{
INITCOMMONCONTROLSEX icex;
icex.dwSize = sizeof(INITCOMMONCONTROLSEX);
icex.dwICC = ICC_BAR_CLASSES;
InitCommonControlsEx(&icex);
HINSTANCE hinstance = (HINSTANCE)GetWindowLong(_hPrtWin,GWL_HINSTANCE);
_hToolBar = CreateWindowEx( NULL,
TOOLBARCLASSNAME,
(LPSTR)NULL,
WS_CHILD|TBSTYLE_LIST|TBSTYLE_FLAT|CCS_NODIVIDER|CCS_NORESIZE,
0,0,0,0,
_hPrtWin,
(HMENU)toolbarid,hinstance,NULL);
SendMessage(_hToolBar,TB_SETEXTENDEDSTYLE,NULL,TBSTYLE_EX_MIXEDBUTTONS);
SendMessage(_hToolBar,TB_BUTTONSTRUCTSIZE,(WPARAM)sizeof(TBBUTTON),0);
_idToolBar = toolbarid;
return _hToolBar;
};
HWND ToolBar::CreateToolbar(UINT toolbarid)
{
INITCOMMONCONTROLSEX icex;
icex.dwSize = sizeof(INITCOMMONCONTROLSEX);
icex.dwICC = ICC_BAR_CLASSES;
InitCommonControlsEx(&icex);
HINSTANCE hinstance = (HINSTANCE)GetWindowLong(_hPrtWin,GWL_HINSTANCE);
// Create a toolbar.
_hToolBar = CreateWindowEx(
WS_EX_LEFT|WS_EX_LTRREADING|WS_EX_RIGHTSCROLLBAR,
TOOLBARCLASSNAME,(LPSTR)NULL,
WS_CHILD|CCS_ADJUSTABLE,
0,0,200,20,_hPrtWin,
(HMENU)NULL,hinstance,NULL);
SendMessage(_hToolBar,TB_BUTTONSTRUCTSIZE,(WPARAM)sizeof(TBBUTTON),0);
_idToolBar = toolbarid;
return _hToolBar;
}
bool ToolBar::AddToolBarButtons(UINT uNumButtons,LPTBBUTTON lpButtons)
{
HRESULT ret = 0;
if (_hToolBar)
{
ret = SendMessage(_hToolBar,TB_ADDBUTTONS,(WPARAM)uNumButtons,(LPARAM)lpButtons);
}
return ret?true:false;
};
bool ToolBar::InsertToolBarButtons(UINT iButton,LPTBBUTTON lpButton)
{
HRESULT ret = 0;
if(_hToolBar)
{
ret = SendMessage(_hToolBar,TB_INSERTBUTTON,(WPARAM)iButton,(LPARAM)lpButton);
}
return ret?true:false;
};
void ToolBar::AutoSizeToolBar()
{
SendMessage(_hToolBar,TB_AUTOSIZE,0,0);
ShowWindow (_hToolBar, SW_SHOW);
};
/************************************
// Function name: ToolBar::AddString
// Description :
// Return type : bool
// Argument : LPSTR str:points to a character array with one or more null-terminated strings.
// The last string in the array must be terminated with two null characters.
************************************/
int ToolBar::AddStrings(LPSTR str)
{
UINT ret = -1;
if(_hToolBar)
{
ret = SendMessage(_hToolBar,TB_ADDSTRING,NULL,(LPARAM)str);
}
return ret;
};
bool ToolBar::CreateImgList(UINT imgcount,int x,int y)
{
_himglist = ImageList_Create(x,y,ILC_COLORDDB|ILC_MASK,imgcount,1);
SendMessage(_hToolBar,TB_SETIMAGELIST,0,(LPARAM)_himglist);
return _himglist?true:false;
}
bool ToolBar::AppendIconToImgList(HICON hicon)
{
int ret = -1;
ret = ImageList_AddIcon(_himglist,hicon);
return ret>=0?true:false;
}
void ToolBar::SetButtonState(int id,int state)
{
SendMessage(_hToolBar,TB_SETSTATE,id, MAKELONG(state,0) );
}
int ToolBar::GetCount()
{
return SendMessage(_hToolBar,TB_BUTTONCOUNT,NULL,NULL);
}
BOOL ToolBar::GetButtonRect(int item,RECT *pRect)
{
return SendMessage(_hToolBar,TB_GETITEMRECT,item,(long)pRect);
}
// long ToolBar::SetButtonData(int item,long data)
// {
// int item;
// TBBUTTONINFO tbBtInfo;
// ZeroMemory(&tbBtInfo,sizeof(TBBUTTONINFO));
// tbBtInfo.cbSize = sizeof(TBBUTTONINFO);
// tbBtInfo.dwMask = TBIF_LPARAM;
// SendMessage(_hToolBar,TB_SETBUTTONINFO,item,&tbBtInfo);
// }
//
// long ToolBar::GetButtonData(int item)
// {
// int item;
// TBBUTTON tbBt;
// ZeroMemory(&tbBt,sizeof(TBBUTTON));
// SendMessage(_hToolBar,TB_GETBUTTON,item,&tbBt);
// return tbBt.dwData;
// }