VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



ComboBox on Toolbar

by Andrew Mitchell Barfield (1 Submission)
Category: Custom Controls/Forms/Menus
Compatability: Visual Basic 3.0
Difficulty: Unknown Difficulty
Date Added: Wed 3rd February 2021
Rating: (39 Votes)

This subroutine shows how to Really put a ComboBox (or any control with a hWnd) onto a ToolBar
(or any other control/window with a hWnd).

Inputs
There are no input paramaters
Assumes
Add a ComboBox, CheckBox and Toolbar to Form1. Keep the default names of the above mentioned controls. Don't worry about control placement or size. Click the form after you run the app.
Code Returns
There are no function returns
Side Effects
No side effects, completely safe.
API Declarations

Rate ComboBox on Toolbar

Option Explicit
Private Declare Function SetParent Lib "user32" (ByVal hWndChild As Long, ByVal hWndNewParent As Long) As Long
Private Declare Function MoveWindow Lib "user32" (ByVal hwnd As Long, ByVal X As Long, ByVal Y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal bRepaint As Long) As Long

Private Sub Form_Load()
'Set Toolbar1 as Combo1's parent, then move Combo1 where we want it. 
   SetParent Combo1.hwnd, Toolbar1.hwnd
   MoveWindow Combo1.hwnd, 100, 1, 50, 50, True 'Note: units are pixels
'Set Toolbar1 as Check1's parent, then move Check1 where we want it. 
   SetParent Check1.hwnd, Toolbar1.hwnd
   MoveWindow Check1.hwnd, 175, 5, 150, 15, True
End Sub

Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
'Demonstrate that Combo1 and Check1 are really "on" Toolbar1 by moving Toolbar1 when
'the form is clicked.
   Toolbar1.Move X, Y
End Sub

Download this snippet    Add to My Saved Code

ComboBox on Toolbar Comments

No comments have been posted about ComboBox on Toolbar. Why not be the first to post a comment about ComboBox on Toolbar.

Post your comment

Subject:
Message:
0/1000 characters