Changing the Toolbar State

Start with the project you created in Implementing Toolbars - Initializing, Creating and Freeing.

1.

Create the following Menus in ToolbarTutorial.rc :

 &View   
      &Toolbar with ID = IDM_VIEW_TOOLBAR   
   &Rows   
      &1 with ID = IDM_ROWS_1   
      &2 with ID = IDM_ROWS_2   
      &3 with ID = IDM_ROWS_3   
      &4 with ID = IDM_ROWS_4   
      &5 with ID = IDM_ROWS_5   
      &6 with ID = IDM_ROWS_6   
      &8 with ID = IDM_ROWS_8   
   &Set Position   
      Test &1 with ID = IDM_SETPOSITION_TEST1   
      Test &2 with ID = IDM_SETPOSITION_TEST2   
      Test &3 with ID = IDM_SETPOSITION_TEST3   
      Test &4 with ID = IDM_SETPOSITION_TEST4   
  

2.

Add the following function calls to the WndProc function definition, after the L_TBSetVisible function call in the WM_CREATE message:

CheckMenuItem ( GetMenu ( hWnd ),   
    IDM_VIEW_TOOLBAR,   
    MF_BYCOMMAND | MF_CHECKED ) ;   
CheckMenuRadioItem ( GetMenu ( hWnd ),   
    IDM_ROWS_1,   
    IDM_ROWS_8,   
    IDM_ROWS_1,   
    MF_BYCOMMAND ) ;   
CheckMenuRadioItem ( GetMenu ( hWnd ),   
    IDM_SETPOSITION_TEST1,   
    IDM_SETPOSITION_TEST4,   
    IDM_SETPOSITION_TEST1,   
    MF_BYCOMMAND ) ; 

3.

Add the following functions before the WndProc function definition:

static L_VOID OnViewToolbar ( pTOOLBARHANDLE pToolbar ) 
{ 
   L_BOOL bVisible ; 
   L_TBIsVisible ( pToolbar, &bVisible ) ; 
   L_TBSetVisible ( pToolbar, ! bVisible ) ; 
} 
static L_VOID OnRows ( pTOOLBARHANDLE pToolbar, L_INT nRows ) 
{ 
   L_TBSetRows ( pToolbar, nRows ) ; 
} 
static L_VOID OnSetPoistionTest ( HWND hWnd, pTOOLBARHANDLE pToolbar, L_INT nTest ) 
{ 
   RECT rcClient ; 
   POINT pt ; 
    
   GetClientRect ( hWnd, &rcClient ) ; 
   switch ( nTest ) 
   { 
      case 1: 
      pt.x = rcClient.left ; 
      pt.y = rcClient.top ; 
      ClientToScreen ( hWnd, &pt ) ; 
      L_TBSetPosition ( pToolbar, &pt, TOOLBAR_POSITION_TOP | TOOLBAR_POSITION_LEFT ) ; 
      break ; 
      case 2: 
      pt.x = rcClient.right ; 
      pt.y = rcClient.top ; 
      ClientToScreen ( hWnd, &pt ) ; 
      L_TBSetPosition ( pToolbar, &pt, TOOLBAR_POSITION_TOP | TOOLBAR_POSITION_RIGHT ) ; 
      break ; 
      case 3: 
      pt.x = rcClient.right ; 
      pt.y = rcClient.bottom ; 
       
      ClientToScreen ( hWnd, &pt ) ; 
      L_TBSetPosition ( pToolbar, &pt, TOOLBAR_POSITION_BOTTOM | TOOLBAR_POSITION_RIGHT ) ; 
      break ; 
      case 4: 
      pt.x = rcClient.left ; 
      pt.y = rcClient.bottom ; 
       
      ClientToScreen ( hWnd, &pt ) ; 
      L_TBSetPosition (pToolbar, &pt, TOOLBAR_POSITION_BOTTOM | TOOLBAR_POSITION_LEFT); 
      break ; 
   } 
} 

4.

Add the following variable declaration in the WndProc function after "static pTOOLBARHANDLE pToolbar ;" declaration:

L_BOOL fState ; 

5.

Add the following code to the WndProc function definition after the "return 0L ;" statement in the case WM_DESTROY message:

case WM_COMMAND: 
{ 
   switch ( LOWORD ( wParam ) ) 
   { 
      case IDM_VIEW_TOOLBAR: 
      OnViewToolbar ( pToolbar ) ; 
      L_TBIsVisible ( pToolbar, &fState ) ; 
      CheckMenuItem ( GetMenu ( hWnd ), 
      IDM_VIEW_TOOLBAR, 
      MF_BYCOMMAND | ( fState ? MF_CHECKED : MF_UNCHECKED ) ) ; 
      return 0L ; 
      case IDM_ROWS_1: 
      OnRows ( pToolbar, 1 ) ; 
      CheckMenuRadioItem ( GetMenu ( hWnd ), 
      IDM_ROWS_1, 
      IDM_ROWS_8, 
      IDM_ROWS_1, 
      MF_BYCOMMAND ) ; 
      return 0L ; 
      case IDM_ROWS_2: 
      OnRows ( pToolbar, 2 ) ; 
      CheckMenuRadioItem ( GetMenu ( hWnd ), 
      IDM_ROWS_1, 
      IDM_ROWS_8, 
      IDM_ROWS_2, 
      MF_BYCOMMAND ) ; 
      return 0L ; 
      case IDM_ROWS_3: 
      OnRows ( pToolbar, 3 ) ; 
      CheckMenuRadioItem ( GetMenu ( hWnd ), 
      IDM_ROWS_1, 
      IDM_ROWS_8, 
      IDM_ROWS_3, 
      MF_BYCOMMAND ) ; 
      return 0L ; 
      case IDM_ROWS_4: 
      OnRows ( pToolbar, 4 ) ; 
       
      CheckMenuRadioItem ( GetMenu ( hWnd ), 
      IDM_ROWS_1, 
      IDM_ROWS_8, 
      IDM_ROWS_4, 
      MF_BYCOMMAND ) ; 
      return 0L ; 
      case IDM_ROWS_5: 
      OnRows ( pToolbar, 5 ) ; 
      CheckMenuRadioItem ( GetMenu ( hWnd ), 
      IDM_ROWS_1, 
      IDM_ROWS_8, 
      IDM_ROWS_5, 
      MF_BYCOMMAND ) ; 
      return 0L ; 
      case IDM_ROWS_6: 
      OnRows ( pToolbar, 6 ) ; 
      CheckMenuRadioItem ( GetMenu ( hWnd ), 
      IDM_ROWS_1, 
      IDM_ROWS_8, 
      IDM_ROWS_6, 
      MF_BYCOMMAND ) ; 
      return 0L ; 
      case IDM_ROWS_8: 
      OnRows ( pToolbar, 7 ) ; 
      CheckMenuRadioItem ( GetMenu ( hWnd ), 
      IDM_ROWS_1, 
      IDM_ROWS_8, 
      IDM_ROWS_8, 
      MF_BYCOMMAND ) ; 
      return 0L ; 
      case IDM_SETPOSITION_TEST1: 
      OnSetPoistionTest ( hWnd, pToolbar, 1 ) ; 
      CheckMenuRadioItem ( GetMenu ( hWnd ), 
      IDM_SETPOSITION_TEST1, 
      IDM_SETPOSITION_TEST4, 
      IDM_SETPOSITION_TEST1, 
      MF_BYCOMMAND ) ; 
      return 0L ; 
      case IDM_SETPOSITION_TEST2: 
      OnSetPoistionTest ( hWnd, pToolbar, 2 ) ; 
      CheckMenuRadioItem ( GetMenu ( hWnd ), 
      IDM_SETPOSITION_TEST1, 
      IDM_SETPOSITION_TEST4, 
      IDM_SETPOSITION_TEST2, 
      MF_BYCOMMAND ) ; 
      return 0L ; 
      case IDM_SETPOSITION_TEST3: 
       
      OnSetPoistionTest ( hWnd, pToolbar, 3 ) ; 
      CheckMenuRadioItem ( GetMenu ( hWnd ), 
      IDM_SETPOSITION_TEST1, 
      IDM_SETPOSITION_TEST4, 
      IDM_SETPOSITION_TEST3, 
      MF_BYCOMMAND ) ; 
      return 0L ; 
      case IDM_SETPOSITION_TEST4: 
      OnSetPoistionTest ( hWnd, pToolbar, 4 ) ; 
      CheckMenuRadioItem ( GetMenu ( hWnd ), 
      IDM_SETPOSITION_TEST1, 
      IDM_SETPOSITION_TEST4, 
      IDM_SETPOSITION_TEST4, 
      MF_BYCOMMAND ) ; 
      return 0L ; 
   } 
} 
break ; 

6.

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

See Also

Getting and Setting Toolbar Information

Programming with LEADTOOLS Toolbars

Toolbar Tutorials

Help Version 19.0.2017.10.27
Products | Support | Contact Us | Copyright Notices
© 1991-2017 LEAD Technologies, Inc. All Rights Reserved.
LEADTOOLS Toolbar C API Help