vbCoders Guest



Don't have an account yet? Register
 


Forgot Password?



32-bit Floating Toolbar (NT & 95)

by Mike Jones (1 Submission)
Category: Windows API Call/Explanation
Compatability: Visual Basic 3.0
Difficulty: Unknown Difficulty
Date Added: Wed 3rd February 2021
Rating: (41 Votes)

This code gives you the ability to create a 'floating toolbar' within your application. The old SetWindowWord function is only good for 16-bit applications, so it won't run under a 32-bit OS (like NT4). The API call you should use if you are programming a 32-bit application is SetWindowLong. It works the same way as SetWindowWord, only uses DWORD(Long) values instead of WORD values for the 32-bit OS.

Inputs
You will need to create 2 forms (Form1 & Form2). On Form1, place a Command button (Command1) On Form2, set the Window Style to 4-FixedToolWindow (not nessesary)
Assumes
This function will make a form a 'child window' of any form you specify.
Code Returns
Sets Form2 to be a child of Form1 (giving it a 'floating toolbar' effect)
Side Effects
Won't work with 16-bit OS's. Use SetWindowWord for 16-bit.
API Declarations
' Place this code into a module
Public Const GWL_HWNDPARENT = (-8)
Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long

Rate 32-bit Floating Toolbar (NT & 95)

' Place this code in the General Declarations section of Form1.
Private Sub Command1_Click()
  'Open the toolbar window
  Form2.Show
  'Move the toolbar to the right
  'of Form1.
  '(gives it a docking effect)
  Form2.Height = Form1.Height - 330
  'Subtract the titlebar height -^
  Form2.Left = Form1.Left + Form1.Width - Form2.Width
  Form2.Top = Form1.Top + Form1.Height - Form2.Height
End Sub
Private Sub Form_Load()
  'Set the button properties
  Command1.Caption = "Show Toolbar"
  Command1.Width = 2055
  Command1.Height = 375
End Sub
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
  'If Form2 is opened when you close
  'Form1, it will not end your app, so
  'you have to manually unload Form2.
  Unload Form2
End Sub
' Place this code in the Form_Load event of Form2
Private Sub Form_Load()
SetWindowLong Me.hwnd, GWL_HWNDPARENT, Form1.hwnd
End Sub

Download Snippet Download this snippet   Add to My Save List Add to My Saved Code

32-bit Floating Toolbar (NT & 95) Comments

No comments have been posted about 32-bit Floating Toolbar (NT & 95). Why not be the first to post a comment about 32-bit Floating Toolbar (NT & 95).

Post your comment

Subject:
Message:
0/1000 characters