Solved

Hot toolbar buttons: general trouble

Posted on 2004-04-11
5
395 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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Login Script to Copy Folders 12 35
Host to IP 7 78
while loop over for loop 7 101
EvenOdd challenge 10 106
Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
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.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

786 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