Microsoft KB Archive/174087: Difference between revisions

From BetaArchive Wiki
(importing KB archive)
 
m (Text replacement - "&" to "&")
 
(3 intermediate revisions by the same user not shown)
Line 58: Line 58:
* the Customize method of the Toolbar is invoked.
* the Customize method of the Toolbar is invoked.


By default, this dialog lists all of the buttons on the Toolbar in the "Toolbar Buttons" lists but lists only a Separator in the "Available Buttons" list. This article describes how you can display additional toolbar buttons in the "Available Buttons" list.
By default, this dialog lists all of the buttons on the Toolbar in the "Toolbar Buttons" lists but lists only a Separator in the "Available Buttons" list. This article describes how you can display additional toolbar buttons in the "Available Buttons" list.


</div>
</div>
Line 65: Line 65:
== MORE INFORMATION ==
== MORE INFORMATION ==


All of the buttons in the Buttons collection of a Toolbar control appear in the Customize Toolbar dialog. Buttons that are currently showing on the Toolbar appear in the &quot;Toolbar Buttons&quot; list and Buttons that have been removed from the Toolbar through customization appear in the &quot;Available Buttons&quot; list. To add additional buttons to the &quot;Available Buttons&quot; list, create your default toolbar, use the SaveToolbar method to save this setting, add the additional buttons at run-time, and then use RestoreToolbar to restore the &quot;default&quot; toolbar settings.<br />
All of the buttons in the Buttons collection of a Toolbar control appear in the Customize Toolbar dialog. Buttons that are currently showing on the Toolbar appear in the "Toolbar Buttons" list and Buttons that have been removed from the Toolbar through customization appear in the "Available Buttons" list. To add additional buttons to the "Available Buttons" list, create your default toolbar, use the SaveToolbar method to save this setting, add the additional buttons at run-time, and then use RestoreToolbar to restore the "default" toolbar settings.<br />


=== Step-by-Step Example ===
=== Step-by-Step Example ===
Line 85: Line 85:


                     </pre></li>
                     </pre></li>
<li>Set the ImageList property of Toolbar1 to &quot;ImageList1.&quot;</li>
<li>Set the ImageList property of Toolbar1 to "ImageList1."</li>
<li><p>Add three buttons to Toolbar1 with the following properties:</p>
<li><p>Add three buttons to Toolbar1 with the following properties:</p>
<pre class="fixed_text">  Index        Key            Image
<pre class="fixed_text">  Index        Key            Image
Line 95: Line 95:


                     </pre>
                     </pre>
<p>NOTE: The Toolbar contains only these three buttons because this is the layout of the &quot;default&quot; toolbar. The Copy, Paste, and Cut buttons will be added at run-time so that they will appear in the &quot;Additional Buttons&quot; list.<br />
<p>NOTE: The Toolbar contains only these three buttons because this is the layout of the "default" toolbar. The Copy, Paste, and Cut buttons will be added at run-time so that they will appear in the "Additional Buttons" list.<br />
<br />
<br />
</p></li>
</p></li>
<li><p>Add the following code to Form1:</p>
<li><p>Add the following code to Form1:</p>
<pre class="codesample">      Private Declare Function RegOpenKey Lib &quot;advapi32.dll&quot; Alias _
<pre class="codesample">      Private Declare Function RegOpenKey Lib "advapi32.dll" Alias _
         &quot;RegOpenKeyA&quot; (ByVal hKey As Long, ByVal lpSubKey As String, _
         "RegOpenKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, _
         phkResult As Long) As Long
         phkResult As Long) As Long


       Const HKEY_CURRENT_USER = &amp;H80000001
       Const HKEY_CURRENT_USER = &H80000001


       Private Sub Form_Load()
       Private Sub Form_Load()
Line 111: Line 111:
         'Check to see if the registry keys for the toolbar exists
         'Check to see if the registry keys for the toolbar exists
         'If not, then save the initial toolbar settings
         'If not, then save the initial toolbar settings
         Success = RegOpenKey(HKEY_CURRENT_USER, &quot;MyApp&quot;, hKey)
         Success = RegOpenKey(HKEY_CURRENT_USER, "MyApp", hKey)
         If Success &lt;&gt; 0 Then Toolbar1.SaveToolbar &quot;Test&quot;, &quot;MyApp&quot;, _
         If Success <> 0 Then Toolbar1.SaveToolbar "Test", "MyApp", _
             &quot;Toolbar1&quot;
             "Toolbar1"


         'Add the toolbars you wish to see in the &quot;Available Buttons&quot; list
         'Add the toolbars you wish to see in the "Available Buttons" list
         Toolbar1.Buttons.Add , &quot;Copy&quot;, , , &quot;Copy&quot;
         Toolbar1.Buttons.Add , "Copy", , , "Copy"
         Toolbar1.Buttons.Add , &quot;Paste&quot;, , , &quot;Paste&quot;
         Toolbar1.Buttons.Add , "Paste", , , "Paste"
         Toolbar1.Buttons.Add , &quot;Cut&quot;, , , &quot;Cut&quot;
         Toolbar1.Buttons.Add , "Cut", , , "Cut"


         'Restore the toolbar settings
         'Restore the toolbar settings
         DoEvents
         DoEvents
         Toolbar1.RestoreToolbar &quot;Test&quot;, &quot;MyApp&quot;, &quot;Toolbar1&quot;
         Toolbar1.RestoreToolbar "Test", "MyApp", "Toolbar1"
         DoEvents
         DoEvents


Line 131: Line 131:
         'When the form unloads, save the toolbar settings
         'When the form unloads, save the toolbar settings
         'to HKEY_CURRENT_USER\MyApp
         'to HKEY_CURRENT_USER\MyApp
         Toolbar1.SaveToolbar &quot;Test&quot;, &quot;MyApp&quot;, &quot;Toolbar1&quot;
         Toolbar1.SaveToolbar "Test", "MyApp", "Toolbar1"


       End Sub
       End Sub
Line 137: Line 137:
                     </pre>
                     </pre>
<p>NOTE: If you are using Visual Basic version 6.0, change the following line in the Form_GotFocus event:</p>
<p>NOTE: If you are using Visual Basic version 6.0, change the following line in the Form_GotFocus event:</p>
<pre class="codesample">  Success = RegOpenKey(HKEY_CURRENT_USER, &quot;MyApp&quot;, hKey)
<pre class="codesample">  Success = RegOpenKey(HKEY_CURRENT_USER, "MyApp", hKey)
                     </pre>
                     </pre>
<p>to:</p>
<p>to:</p>
<pre class="codesample">  Success = RegOpenKey(HKEY_CURRENT_USER, &quot;Test\MyApp&quot;, hKey)
<pre class="codesample">  Success = RegOpenKey(HKEY_CURRENT_USER, "Test\MyApp", hKey)
                     </pre></li>
                     </pre></li>
<li>Press the F5 key to run the application. Double-click Toolbar1 to display the Customize Toolbar dialog. Notice that the Cut, Copy, and Paste toolbars appear in the Additional Buttons list. NOTE: The SaveToolbar and RestoreToolbar methods used in this example write and read the registry entry HKEY_CURRENT_USER\MyApp\Toolbar1.</li></ol>
<li>Press the F5 key to run the application. Double-click Toolbar1 to display the Customize Toolbar dialog. Notice that the Cut, Copy, and Paste toolbars appear in the Additional Buttons list. NOTE: The SaveToolbar and RestoreToolbar methods used in this example write and read the registry entry HKEY_CURRENT_USER\MyApp\Toolbar1.</li></ol>
Line 153: Line 153:
<div class="indent">
<div class="indent">


'''[[../182943|182943]]''' : BUG: &quot;Key&quot; Argument of SaveToolBar &amp; RestoreToolBar Doesn't Work
'''[[../182943|182943]]''' : BUG: "Key" Argument of SaveToolBar & RestoreToolBar Doesn't Work





Latest revision as of 12:30, 21 July 2020

Knowledge Base


Article ID: 174087

Article Last Modified on 2/24/2005



APPLIES TO

  • Microsoft Visual Basic 5.0 Learning Edition
  • Microsoft Visual Basic 6.0 Learning Edition
  • Microsoft Visual Basic 5.0 Professional Edition
  • Microsoft Visual Basic 6.0 Professional Edition
  • Microsoft Visual Basic 5.0 Enterprise Edition
  • Microsoft Visual Basic 6.0 Enterprise Edition
  • Microsoft Visual Basic 4.0 Standard Edition
  • Microsoft Visual Basic 4.0 Professional Edition
  • Microsoft Visual Basic 4.0 32-Bit Enterprise Edition



This article was previously published under Q174087

SUMMARY

The Toolbar control that is provided with the Microsoft Windows Common Controls (COMCTL32.OCX) can be customized by users. The Customize Toolbar method is displayed if either:

  • the AllowCustomize property is set to True and the user double- clicks the Toolbar


-or-

  • the Customize method of the Toolbar is invoked.

By default, this dialog lists all of the buttons on the Toolbar in the "Toolbar Buttons" lists but lists only a Separator in the "Available Buttons" list. This article describes how you can display additional toolbar buttons in the "Available Buttons" list.

MORE INFORMATION

All of the buttons in the Buttons collection of a Toolbar control appear in the Customize Toolbar dialog. Buttons that are currently showing on the Toolbar appear in the "Toolbar Buttons" list and Buttons that have been removed from the Toolbar through customization appear in the "Available Buttons" list. To add additional buttons to the "Available Buttons" list, create your default toolbar, use the SaveToolbar method to save this setting, add the additional buttons at run-time, and then use RestoreToolbar to restore the "default" toolbar settings.

Step-by-Step Example

  1. Start a new project.
  2. Reference the Microsoft Windows Common Controls (COMCTL32.OCX).
  3. Add a Toolbar and an ImageList to Form1.
  4. Add six images to ImageList1 with the following properties:

       Index          Key          Picture
       -----          ---          -------
    
       1              Bold        ..\VB\Graphics\Bitmaps\Tlbr_w95\Bld.bmp
       2              Italic      ..\VB\Graphics\Bitmaps\Tlbr_w95\Itl.bmp
       3              Underline   ..\VB\Graphics\Bitmaps\Tlbr_w95\Undrln.bmp
       4              Copy        ..\VB\Graphics\Bitmaps\Tlbr_w95\Copy.bmp
       5              Paste       ..\VB\Graphics\Bitmaps\Tlbr_w95\Paste.bmp
       6              Cut         ..\VB\Graphics\Bitmaps\Tlbr_w95\Cut.bmp
    
                        
  5. Set the ImageList property of Toolbar1 to "ImageList1."
  6. Add three buttons to Toolbar1 with the following properties:

       Index        Key            Image
       -----        ---            -----
    
       1            Bold           Bold
       2            Italic         Italic
       3            Underline      Underline
    
                        

    NOTE: The Toolbar contains only these three buttons because this is the layout of the "default" toolbar. The Copy, Paste, and Cut buttons will be added at run-time so that they will appear in the "Additional Buttons" list.

  7. Add the following code to Form1:

          Private Declare Function RegOpenKey Lib "advapi32.dll" Alias _
            "RegOpenKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, _
            phkResult As Long) As Long
    
          Const HKEY_CURRENT_USER = &H80000001
    
          Private Sub Form_Load()
    
             Me.Show
    
             'Check to see if the registry keys for the toolbar exists
             'If not, then save the initial toolbar settings
             Success = RegOpenKey(HKEY_CURRENT_USER, "MyApp", hKey)
             If Success <> 0 Then Toolbar1.SaveToolbar "Test", "MyApp", _
                "Toolbar1"
    
             'Add the toolbars you wish to see in the "Available Buttons" list
             Toolbar1.Buttons.Add , "Copy", , , "Copy"
             Toolbar1.Buttons.Add , "Paste", , , "Paste"
             Toolbar1.Buttons.Add , "Cut", , , "Cut"
    
             'Restore the toolbar settings
             DoEvents
             Toolbar1.RestoreToolbar "Test", "MyApp", "Toolbar1"
             DoEvents
    
          End Sub
    
          Private Sub Form_Unload(Cancel As Integer)
    
             'When the form unloads, save the toolbar settings
             'to HKEY_CURRENT_USER\MyApp
             Toolbar1.SaveToolbar "Test", "MyApp", "Toolbar1"
    
          End Sub
    
                        

    NOTE: If you are using Visual Basic version 6.0, change the following line in the Form_GotFocus event:

       Success = RegOpenKey(HKEY_CURRENT_USER, "MyApp", hKey)
                        

    to:

       Success = RegOpenKey(HKEY_CURRENT_USER, "Test\MyApp", hKey)
                        
  8. Press the F5 key to run the application. Double-click Toolbar1 to display the Customize Toolbar dialog. Notice that the Cut, Copy, and Paste toolbars appear in the Additional Buttons list. NOTE: The SaveToolbar and RestoreToolbar methods used in this example write and read the registry entry HKEY_CURRENT_USER\MyApp\Toolbar1.


REFERENCES

For additional information, please see the following article in the Microsoft Knowledge Base:

182943 : BUG: "Key" Argument of SaveToolBar & RestoreToolBar Doesn't Work


Keywords: kbhowto kbcontrol KB174087