Adding Buttons to an Internet Explorer Toolbar (Deskband)

evildogeye
evildogeye used Ask the Experts™
on
I am trying to add buttons to an internet explorer toolbar.  I have tried using the following code, to no avail.  I have seen similar code working in another program, so I'm not quite sure what I am doing wrong.  Thanks for any help or insight.

BOOL Cbar::RegisterAndCreateWindow(void)
{
//If the window doesn't exist yet, create it now.
if(!m_hWnd)
{
  WNDCLASS wc;
  if(!GetClassInfo(g_hInst, DB_CLASS_NAME, &wc))
  {
    ZeroMemory(&wc, sizeof(wc));
    wc.style= CS_HREDRAW | CS_VREDRAW | CS_GLOBALCLASS;
     wc.lpfnWndProc    = (WNDPROC)WndProc;
    wc.cbClsExtra     = 0;
    wc.cbWndExtra     = 0;
    wc.hInstance      = g_hInst;
    wc.hIcon          = 0;
    wc.hCursor        = LoadCursor(NULL, IDC_CROSS);
    wc.hbrBackground  = (HBRUSH)CreateSolidBrush(RGB(255, 250, 250));
    wc.lpszMenuName   = 0; // MAKEINTRESOURCE(IDR_MENU1);
    wc.lpszClassName  = DB_CLASS_NAME;
         
    RECT  rc;
    GetClientRect(m_hwndParent, &rc);

         
DWORD DEFAULT_TOOLBAR_STYLE = ( WS_VISIBLE | WS_CHILD | WS_CLIPCHILDREN | WS_CLIPSIBLINGS | CCS_NORESIZE | CCS_NODIVIDER | CCS_NOPARENTALIGN | CCS_TOP |
TBSTYLE_TOOLTIPS | TBSTYLE_FLAT | TBSTYLE_LIST |TBSTYLE_TRANSPARENT );

InitCommonControls();

HWND test;

test = CreateWindowEx(   0, DB_CLASS_NAME, NULL,
                     DEFAULT_TOOLBAR_STYLE, 0,
                     0, 10, 10, m_hwndParent,
                     NULL, g_hInst, (LPVOID)this);

SendMessage(test, TB_BUTTONSTRUCTSIZE, sizeof( TBBUTTON ), 0 );
int iIndex = SendMessage(test, TB_ADDSTRING, 0,(LPARAM)"PLEASEWORK");

TBBUTTON Button;
ZeroMemory((void*)&Button, sizeof(TBBUTTON));
Button.idCommand = 119;
Button.fsState = TBSTATE_ENABLED;
Button.fsStyle = BTNS_BUTTON|BTNS_AUTOSIZE|BTNS_SHOWTEXT;
Button.dwData = 0;
Button.iString = iIndex;
Button.iBitmap = 0;
SendMessage(test, TB_INSERTBUTTON, 0, (LPARAM)&Button);
}
return (NULL != m_hWnd);
}
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Author

Commented:
I guess I should say, the toolbar displays as it is supposed to, however no buttons appear on the toolbar.

Commented:
I think you should first send TB_ADDBITMAP to it to initialize the bitmap the bar used. Then send TB_ADDBUTTONS msg to it.
or try to use SendMessage(test, TB_INSERTBUTTON, 1, (LPARAM)&Button);
PAQed - no points refunded (of 500)

ee_ai_construct
Community Support Moderator

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial