|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
|
Announcements
Want a new Job?
Chapters
Services
Feature Zones
|
Credits and AcknowlegementsThis module is based on the ATL DeskBand Wizard article that was created by Erik Thompson. My thanks goes to him for producing a great wizard that saves you the nity grity of creating DeskBands. Please note that this project does not use MFC, for all those MFC die hards that want to use MFC in their Tool Bands I suggest you down load the KKBar sample from microsofts MSDN site. The KBBar Sample can be downloaded from here Creating the ToolBand ModuleYou will need to install the ATL DeskBand Wizard in order to create ToolBands. Please follow the instruction in this article. The best way to kick start a Tool band project is to use the ATL COM App Wizard. The COM Object needs to be in-proc therefore choose 'DLL' as the Server Type. The rest of the options can be kept in there default state. (Note this project does not use MFC, as the project is based on ATL and WTL) Once you have a ATL COM Project, You can use the ATL DeskBand Wizard to create the Initial Tool Band. Adding Support for WTLYou will require the WTL Libraries, these can be downloaded from the microsoft site The following header files needs to be added to stdafx.h file atlapp.h atlwin.h atlctrls.h atlmisc.h Create the ToolBarYou can create your toolbar in the usual way via the resource editor, Once you have your toolbar you need to create the toolbar dynamically. The DWORD dStyle = WS_CHILD | WS_VISIBLE | WS_CLIPCHILDREN | WS_CLIPSIBLINGS |
CCS_NODIVIDER | CCS_NORESIZE | CCS_NOPARENTALIGN |
TBSTYLE_TOOLTIPS | TBSTYLE_FLAT;
HWND hWnd = m_wndToolBar.CreateSimpleToolBarCtrl(hWndChild, IDR_TOOLBAR_TEST,
FALSE, dStyle);
This is done in the RegisterAndCreateWindow function that is called from SetSite method. Message ReflectionThe best way to handle the messages of the toolbar is to let the control handle its own messages via "Message Reflection". The best way to reflect the messages is to create an invisible control that acts as the parent for the toolbar. The invisible control will reflect the toolbar messages back to itself. See The following code shows the parent child relationship that is used to achieve Message Reflection. BOOL CToolBandObj::RegisterAndCreateWindow()
{
RECT rectClientParent;
::GetClientRect(m_hWndParent, &rectClientParent);
// We need to create an Invisible Child Window using the Parent Window,
// this will also be used to reflect Command
// messages from the rebar
HWND hWndChild = m_wndInvisibleChildWnd.Create(m_hWndParent,
The following Macros are used to identify the reflected messages from the ordinary messages. e.g WM_COMMAND reflected comes back as OCM_COMMAND. #define OCM_COMMAND_CODE_HANDLER(code, func) \ if(uMsg == OCM_COMMAND && code == HIWORD(wParam)) \ { \ bHandled = TRUE; \ lResult = func(HIWORD(wParam), LOWORD(wParam), (HWND)lParam, bHandled); \ if(bHandled) \ return TRUE; \ } #define OCM_COMMAND_ID_HANDLER(id, func) \ if(uMsg == OCM_COMMAND && id == LOWORD(wParam)) \ { \ bHandled = TRUE; \ lResult = func(HIWORD(wParam), LOWORD(wParam), (HWND)lParam, bHandled); \ if(bHandled) \ return TRUE; \ } #define OCM_NOTIFY_CODE_HANDLER(cd, func) \ if(uMsg == OCM_NOTIFY && cd == ((LPNMHDR)lParam)->code) \ { \ bHandled = TRUE; \ lResult = func((int)wParam, (LPNMHDR)lParam, bHandled); \ if(bHandled) \ return TRUE; \ } Browser NavigationIn order to Navigate on the browser you need to instantiate the IWebBrowser2 COM Object. This is usually done on the SetSite Method e.g. IServiceProviderPtr pServiceProvider = pUnkSite; if (_Module.m_pWebBrowser) _Module.m_pWebBrowser = NULL; if(FAILED(pServiceProvider->QueryService(SID_SWebBrowserApp, IID_IWebBrowser, (void**)&_Module.m_pWebBrowser))) return E_FAIL; Once you have the COM Object Instantiated, you can move to your URL using the navigate method _variant_t varURL = _bstr_t("www.codeproject.com"); _variant_t varEmpty; _Module.m_pWebBrowser->Navigate2(&varURL, &varEmpty, &varEmpty, &varEmpty, &varEmpty); Drag and Drop Edit and ComboBox ControlThe CBandEditCtrl class is inherited from a WTL CEdit control that has drag and drop facility. i.e. you can drag text from the browser straight to the CEdit Control. The CBandComboBoxCtrl class is inherited from a WTL CComboBox control that has drag and drop facility. i.e. you can drag text from the browser straight to the CComboBox Control.
Configurable Toolbar Button StylesThe CBandToolBarCtrl class allows you to have the follwoing button styles on the toolbar
Pop-up Menu TrackingA pop up menu is used to get to the configuration options
ToolTipsThis has been taken from MSDN to explain why you need to handle the tooltips on the toolbar your self. Tool tips are automatically displayed for buttons and other controls contained in a parent window derived from CFrameWnd. This is because CFrameWnd has a default handler for the TTN_GETDISPINFO notification, which handles TTN_NEEDTEXT notifications from tool tip controls associated with controls. However, this default handler is not called when the TTN_NEEDTEXT notification is sent from a tool tip control associated with a control in a window that is not a CFrameWnd, such as a control on a dialog box or a form view. Therefore, it is necessary for you to provide a handler function for the TTN_NEEDTEXT notification message in order to display tool tips for child controls. This can be easily done in WTL by using the following Message Handler in the overriden ToolBar Control NOTIFY_CODE_HANDLER(TTN_NEEDTEXT, OnToolbarNeedText) The following is the code that loads the tool tips from the resources and sets the tool tip text. LRESULT CBandToolBarCtrl::OnToolbarNeedText(int /*idCtrl*/, LPNMHDR pnmh, BOOL& bHandled) { CString sToolTip; //-- make sure this 1is not a seperator if (idCtrl != 0) { if (!sToolTip.LoadString(idCtrl)) { bHandled = FALSE; return 0 } } LPNMTTDISPINFO pttdi = reinterpret_cast<LPNMTTDISPINFO> (pnmh);pttdi->lpszText = MAKEINTRESOURCE(idCtrl); pttdi->hinst = _Module.GetResourceInstance(); pttdi->uFlags = TTF_DI_SETITEM; //-- message processed return 0; } Update the Status BarYou can update the status bar using the browser method put_StatusText, this method can be used typically in the WM_MENUSELECT event The following is the code that loads up the menu text from the resources and displays it on the browser status bar. LRESULT CBandToolBarCtrl::OnMenuSelect(UINT /*uMsg*/, How to add a Chevron to your toolbandIn order to add a chevron to your toolband you need to add the DBIMF_USECHEVRON flags to your GetBandInfo method in the DBIM_MODEFLAGS mask. ... if(pdbi->dwMask == DBIM_MODEFLAGS) { //AddChevron pdbi->dwModeFlags = DBIMF_NORMAL | DBIMF_VARIABLEHEIGHT | DBIMF_USECHEVRON | DBIMF_BREAK; } ... This basically add the ability to show the chevron, if you want to see it appear on your toolband, then you must make sure the pdbi->ptMinSize.x value is less then your pdbi->ptActual.x value (Again this values can be set in the GetBandInfo method. In order to handle the events of the button in the chevron menu, you must subclass the rebar control which is hosting your toolbar. The following steps have been used to sublass the rebar control 1. Find the rebar control - This can be achieved by getting the browsers window handle and searching for all its child windows, until you find the rebar control. 2. Once you have found the rebar control you can simply subclass it using an ATL CContainedWindow. BOOL CBandToolBarCtrl::SetBandRebar()
{
HWND hWnd(NULL);
_Module.m_pWebBrowser->
get_HWND((long*)&hWnd);
if (hWnd == NULL)
return FALSE;
m_ctlRebar.m_hWnd = FindRebar(hWnd);
if (m_ctlRebar.m_hWnd == NULL)
return FALSE;
m_RebarContainer.SubclassWindow(m_ctlRebar);
return TRUE;
}
Once you have subclass the window, the events should reach the toolbar class.
|
||||||||||||||||||||||
|
PermaLink |
Privacy |
Terms
of Use
Last Updated: 5 Oct 2002 Editor: Chris Maunder |
Copyright 2001 by Rashid Thadha Everything else Copyright © CodeProject, 1999-2008 Web15 | Advertise on the Code Project |