Solved

Hot toolbar buttons: general trouble

Posted on 2004-04-11
5
390 Views
Last Modified: 2013-11-20
Hello !

I have been following a tutorial on the Internet about creating rollover buttons like those in IE, and have copied code exactly to my app yet it does not work.  All that happens is that the toolbar appears in grey form and never turns to colour when the mouse moves over it.  Here is my code:

int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{      
      if (CMDIFrameWnd::OnCreate(lpCreateStruct) == -1)
            return -1;
      
      if (!m_wndToolbar.Create(this) ||
            !m_wndToolbar.LoadToolBar(IDR_MAINFRAME))
      {
            TRACE0("Failed to create toolbar\n");
            return -1;      // fail to create
      }

      m_wndToolbar.ModifyStyle(0, TBSTYLE_FLAT);

      if (!m_hotToolbar.Create(this) ||
            !m_hotToolbar.LoadToolBar(IDR_HOTBAR))
      {
            TRACE0("Failed to create toolbar\n");
            return -1;      // fail to create
      }

      m_hotToolbar.ModifyStyle(0, TBSTYLE_FLAT);

      if (!m_wndStatusbar.Create(this) ||
            !m_wndStatusbar.SetIndicators(indicators,
              sizeof(indicators)/sizeof(UINT)))
      {
            TRACE0("Failed to create status bar\n");
            return -1;      // fail to create
      }

      // Set up hot bar image lists.
      CImageList      imageList;
      CBitmap            bitmap;

      bitmap.LoadBitmap(IDB_TOOLBAR_COLD);
      imageList.Create(21, 20, ILC_COLORDDB|ILC_MASK, 13, 1);
      imageList.Add(&bitmap, RGB(255,0,255));
      m_hotToolbar.SendMessage(TB_SETIMAGELIST, 0, (LPARAM)imageList.m_hImageList);
      imageList.Detach();
      bitmap.Detach();

      bitmap.LoadBitmap(IDB_TOOLBAR_HOT);
      imageList.Create(21, 20, ILC_COLORDDB|ILC_MASK, 13, 1);
      imageList.Add(&bitmap, RGB(255,0,255));
      m_hotToolbar.SendMessage(TB_SETHOTIMAGELIST, 0, (LPARAM)imageList.m_hImageList);
      imageList.Detach();
      bitmap.Detach();

      // TODO: Delete these three lines if you don't want the toolbar to
      //  be dockable
      m_wndToolbar.EnableDocking(CBRS_ALIGN_ANY);
      m_hotToolbar.EnableDocking(CBRS_ALIGN_ANY);
      EnableDocking(CBRS_ALIGN_ANY);
      DockControlBar(&m_wndToolbar);
      DockControlBar(&m_hotToolbar);

      SetClassLong(m_hWnd, GCL_STYLE, GetClassLong(m_hWnd, GCL_STYLE) & ~(CS_HREDRAW | CS_VREDRAW));
      
      return 0;
}

What is wrong with this ?  I have copied the code line for line and it is still not working.

TIA !
0
Comment
Question by:mrwad99
  • 3
  • 2
5 Comments
 
LVL 4

Accepted Solution

by:
caner_elci earned 75 total points
ID: 10801094
Add COMMAND handlers for your toolbar's buttons.. then they will be enabled..
0
 
LVL 19

Author Comment

by:mrwad99
ID: 10801140
Doh.   Of course.

Before I slink away in embarasment; could you tell me what the need for

SendMessage(TB_SETHOTIMAGELIST, 0, (LPARAM)imageList.m_hImageList);

is ?  I looked at the example MFCIE and this does not use it..

Thanks.
0
 
LVL 4

Expert Comment

by:caner_elci
ID: 10801152
When you hover on a toolbar button, it changes the image of that button with the one specified in hot image list, and this message tells the toolbar, what is that imagelist..
0
 
LVL 19

Author Comment

by:mrwad99
ID: 10801157
Thanks a lot for that :)
0
 
LVL 4

Expert Comment

by:caner_elci
ID: 10801160
you're welcome :)
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now