DestroyWindow(getHandle());
}
-bool ToolBar::create(int _tbID, HWND parentHwnd, DWORD dwStyle) {
+bool ToolBar::create(int _tbID, HWND _parentHwnd, DWORD dwStyle) {
+ parentHwnd = _parentHwnd;
dwStyle |= WS_CHILD;
// Create the ToolBar window
return SendMessage(getHandle(), TB_GETBUTTONINFO, idButton, (LPARAM)btnInfo);
}
+int ToolBar::getButtonsHeight() {
+ return HIWORD(SendMessage(getHandle(), TB_GETBUTTONSIZE, 0, 0));
+}
+
+int ToolBar::getButtonsWidth() {
+ return LOWORD(SendMessage(getHandle(), TB_GETBUTTONSIZE, 0, 0));
+}
+
bool ToolBar::setButtonInfo(int idButton, TBBUTTONINFO* btnInfo) {
assert(idButton >= 0);
assert(btnInfo > 0);
}
void ToolBar::autoSize() {
- SendMessage(getHandle(), TB_AUTOSIZE, 0, 0);
+ DWORD style = SendMessage(getHandle(), TB_GETSTYLE, 0, 0);
+ if (style & CCS_NORESIZE) {
+ RECT r, btnRect;
+ GetClientRect(parentHwnd, &r);
+ getButtonRect(0, &btnRect);
+ int height = getButtonsHeight() + btnRect.top * 2 + 1;
+ SetWindowPos(getHandle(), HWND_TOP, 0, 0, r.right - r.left, height,
+ SWP_NOMOVE);
+ } else {
+ SendMessage(getHandle(), TB_AUTOSIZE, 0, 0);
+ }
+}
+
+int ToolBar::getHeight() {
+ RECT r;
+ GetWindowRect(getHandle(), &r);
+ return r.bottom - r.top + 1;
}
// It returns index of the button if successful, or -1 otherwise.
int getButtonInfo(int idButton, TBBUTTONINFO *btnInfo);
+ // getButtonsHeight() retrieves the height of the toolbar buttons.
+ int getButtonsHeight();
+
+ // getButtonsWidth() retrieves the width of the toolbar buttons.
+ int getButtonsWidth();
+
// setButtonInfo() sets the information for an existing button in a toolbar.
bool setButtonInfo(int idButton, TBBUTTONINFO* ptbbi);
// getHandle() returns handle to a toolbar window.
HWND getHandle() { return hwndToolBar; }
+ // getHeight() returns the toolbar window height.
+ int getHeight();
+
protected:
HWND hwndToolBar;
+ HWND parentHwnd;
int tbID;
};