Changing the Toolbar Button State

Start with the project you created in Changing the Toolbar State

1.

Add the following popup menu to the main menu created in Changing the Toolbar State:

&Check Button
               &Brush with ID = IDM_CHECKBUTTON_BRUSH
               &Shape Polygon with ID = IDM_CHECKBUTTON_SHAPE_POLYGON
               &Fill Color with ID = IDM_CHECKBUTTON_FILL_COLORREPLACE
               &Mover with ID = IDM_CHECKBUTTON_MOVER

&Disable Button
               &Brush with ID = IDM_DISABLEBUTTON_BRUSH
               &Shape Polygon with ID = IDM_DISABLEBUTTON_SHAPE_POLYGON
               &Fill Color with ID = IDM_DISABLEBUTTON_FILL_COLORREPLACE
               &Mover with ID = IDM_DISABLEBUTTON_MOVER

&Hide Button
               &Brush with ID = IDM_HIDEBUTTON_BRUSH
               &Shape Polygon with ID = IDM_HIDEBUTTON_SHAPE_POLYGON
               &Fill Color with ID = IDM_HIDEBUTTON_FILL_COLORREPLACE
               &Mover with ID = IDM_HIDEBUTTON_MOVER

2.

Add the following code to the WndProc after "return 0L;" statement of the case IDM_SETPOSITION_TEST4 in the WM_COMMAND message:

    case IDM_CHECKBUTTON_BRUSH:
       L_TBSetButtonChecked ( pToolbar, ID_TOOL_PAINT_BRUSH ) ;
       break ;
   
    case IDM_CHECKBUTTON_SHAPE_POLYGON:
       L_TBSetButtonChecked ( pToolbar, ID_TOOL_PAINT_SHAPE_POLYGON ) ;
       break ;

    case IDM_CHECKBUTTON_FILL_COLORREPLACE:
       L_TBSetButtonChecked ( pToolbar, ID_TOOL_PAINT_FILL_COLORREPLACE ) ;
       break ;

    case IDM_CHECKBUTTON_MOVER:
       L_TBSetButtonChecked ( pToolbar, ID_TOOL_PAINT_MOVER ) ;
       break ;

    case IDM_DISABLEBUTTON_BRUSH:
       L_TBIsButtonEnabled ( pToolbar, ID_TOOL_PAINT_BRUSH, &fState ) ;

       L_TBSetButtonEnabled ( pToolbar, ID_TOOL_PAINT_BRUSH, ! fState ) ;

       CheckMenuItem ( GetMenu ( hWnd ),
          IDM_DISABLEBUTTON_BRUSH,
          MF_BYCOMMAND | ( fState ? MF_CHECKED : MF_UNCHECKED ) ) ;
       break ;

    case IDM_DISABLEBUTTON_SHAPE_POLYGON:
       L_TBIsButtonEnabled ( pToolbar, ID_TOOL_PAINT_SHAPE_POLYGON, &fState ) ;

       L_TBSetButtonEnabled ( pToolbar, ID_TOOL_PAINT_SHAPE_POLYGON, ! fState ) ;

       CheckMenuItem ( GetMenu ( hWnd ),
          IDM_DISABLEBUTTON_SHAPE_POLYGON,
          MF_BYCOMMAND | ( fState ? MF_CHECKED : MF_UNCHECKED ) ) ;

       break ;

    case IDM_DISABLEBUTTON_FILL_COLORREPLACE:
       L_TBIsButtonEnabled ( pToolbar, ID_TOOL_PAINT_FILL_COLORREPLACE, &fState ) ;

       L_TBSetButtonEnabled ( pToolbar, ID_TOOL_PAINT_FILL_COLORREPLACE, ! fState ) ;

       CheckMenuItem ( GetMenu ( hWnd ),
          IDM_DISABLEBUTTON_FILL_COLORREPLACE,
          MF_BYCOMMAND | ( fState ? MF_CHECKED : MF_UNCHECKED ) ) ;
       break ;

    case IDM_DISABLEBUTTON_MOVER:
       L_TBIsButtonEnabled ( pToolbar, ID_TOOL_PAINT_MOVER, &fState ) ;

       L_TBSetButtonEnabled ( pToolbar, ID_TOOL_PAINT_MOVER, ! fState ) ;

       CheckMenuItem ( GetMenu ( hWnd ),
          IDM_DISABLEBUTTON_MOVER,
          MF_BYCOMMAND | ( fState ? MF_CHECKED : MF_UNCHECKED ) ) ;
       break ;

    case IDM_HIDEBUTTON_BRUSH:
       L_TBIsButtonVisible ( pToolbar, ID_TOOL_PAINT_BRUSH, &fState ) ;

       L_TBSetButtonVisible ( pToolbar, ID_TOOL_PAINT_BRUSH, ! fState ) ;

       CheckMenuItem ( GetMenu ( hWnd ),
          IDM_HIDEBUTTON_BRUSH,
          MF_BYCOMMAND | ( fState ? MF_CHECKED : MF_UNCHECKED ) ) ;

       EnableMenuItem ( GetMenu ( hWnd ),
          IDM_DISABLEBUTTON_BRUSH,
          MF_BYCOMMAND | ( fState ? MF_GRAYED : MF_ENABLED ) ) ;
       break ;

    case IDM_HIDEBUTTON_SHAPE_POLYGON:
       L_TBIsButtonVisible ( pToolbar, ID_TOOL_PAINT_SHAPE_POLYGON, &fState ) ;

       L_TBSetButtonVisible ( pToolbar, ID_TOOL_PAINT_SHAPE_POLYGON, ! fState ) ;

       CheckMenuItem ( GetMenu ( hWnd ),
          IDM_HIDEBUTTON_SHAPE_POLYGON,
          MF_BYCOMMAND | ( fState ? MF_CHECKED : MF_UNCHECKED ) ) ;

       EnableMenuItem ( GetMenu ( hWnd ),
          IDM_DISABLEBUTTON_SHAPE_POLYGON,
          MF_BYCOMMAND | ( fState ? MF_GRAYED : MF_ENABLED ) ) ;
       break ;

    case IDM_HIDEBUTTON_FILL_COLORREPLACE:
       L_TBIsButtonVisible ( pToolbar, ID_TOOL_PAINT_FILL_COLORREPLACE, &fState ) ;

       L_TBSetButtonVisible ( pToolbar, ID_TOOL_PAINT_FILL_COLORREPLACE, ! fState ) ;

       CheckMenuItem ( GetMenu ( hWnd ),
          IDM_HIDEBUTTON_FILL_COLORREPLACE,
          MF_BYCOMMAND | ( fState ? MF_CHECKED : MF_UNCHECKED ) ) ;

       EnableMenuItem ( GetMenu ( hWnd ),
          IDM_DISABLEBUTTON_FILL_COLORREPLACE,
          MF_BYCOMMAND | ( fState ? MF_GRAYED : MF_ENABLED ) ) ;

       break ;

    case IDM_HIDEBUTTON_MOVER:
       L_TBIsButtonVisible ( pToolbar, ID_TOOL_PAINT_MOVER, &fState ) ;

       L_TBSetButtonVisible ( pToolbar, ID_TOOL_PAINT_MOVER, ! fState ) ;

       CheckMenuItem ( GetMenu ( hWnd ),
          IDM_HIDEBUTTON_MOVER,
          MF_BYCOMMAND | ( fState ? MF_CHECKED : MF_UNCHECKED ) ) ;

       EnableMenuItem ( GetMenu ( hWnd ),
          IDM_DISABLEBUTTON_MOVER,
          MF_BYCOMMAND | ( fState ? MF_GRAYED : MF_ENABLED ) ) ;
       break ;

3.

Compile and run the project by selecting Build->Execute tutorial.exe from the menu.

See Also:

Getting and Setting Toolbar Button Information

Programming with LEADTOOLS Toolbars

Toolbar Tutorials