Solved

Hot toolbar buttons: general trouble

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Replacement selected text 2 65
iSeries DB2 Query 2 98
either24  challenge 19 105
Making an alias 7 110
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…
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
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.
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

713 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