October 28, 2016
Hot Topics:

Create a Status Bar using the API

  • November 19, 2002
  • By Sam Huggill
  • Send Email »
  • More Articles »

Anyway, lets get on. The constants prefixed by WM_ and WS_ are windows messages and windows styles. The constants prefixed by SB_ are, quite obviously for the status bar. And the constants prefixed by CCS_ relate to the common controls, in this case, the status bar.

We also use a couple of API calls. These include the CreateStatusWindow (already mentioned), SendMessage, DestroyWindow and MoveWindow. The SendMessage, like it sounds, is used for sending messages to our control. The DestroyWindow clears our control from memory and the MoveWindow is self-explanatory.

All of these API calls and constants can be found in the modAPI module, found below.

Option Explicit 
'// NOTE: Some of the constants in this module   
'// wereextracted from the ComCtrl.h header file  

'// API calls needed to create our status bar 
'// through the API  

'// Main API call used to create the window. 
'// Returns the  window handle of the new 
'// status bar  
Public Declare Function CreateStatusWindowA Lib _
   "ComCtl32.dll" _ 
   (ByVal style As Long, _ 
   ByVal lpszText As String, _ 
   ByVal hwndParent As Long, ByVal wID As Long) _
   As Long 
'// Used to change/modify styles in our status bar  
Public Declare Function SendMessage Lib _
   "user32" Alias 
  (ByVal hWnd As Long, _ 
  ByVal wMsg As Long, _ 
  ByVal wParam As Long, lParam As Any) _
  As Long 
'// Used to remove our status bar from memory  
Public Declare Function DestroyWindow Lib _
  "user32" _ 
  (ByVal hWnd As Long) As Long 
'// Move our status bar so we can see it  
Public 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 
'// WM_ Windows Messages and Styles  
Public Const WS_VISIBLE = &H10000000 _
  'Makes it visible  
Public Const WM_USER = &H400 
Public Const WS_CHILD = &H40000000 _
  'Makes it a child of our parent window  
Public Const WM_SIZE = &H5 _
  'Changes the size  
Public Const WM_GETFONT = &H31 _
  'Gets the font from a window  
Public Const WM_SETFONT = &H30 _
  'Sets the font of a window  
'// Status Bar Messages and Styles  
Public Const SB_SETTEXT = (WM_USER + 1) _
  'Sets text  
Public Const sbSimpleIdx = 255 
Public Const SBT_SUNKEN = &H0 _
  'Sunken styles  
Public Const SBT_POPOUT = &H200 _
  'Popped out style  
Public Const SB_GETTEXTLENGTH = (WM_USER + 3) _
  'Returns the text length  
Public Const SB_SETPARTS = (WM_USER + 4) _
  'Adds new panels  
Public Const SB_GETPARTS = (WM_USER + 6) _
  'Retreives panels  
Public Const SB_GETTEXT = (WM_USER + 2) _
  'Returns text  
'// Common Control Styles for alignment  
Public Const CCS_TOP = &H1&  'Top  
Public Const CCS_BOTTOM = &H3&  'Bottom   

Copy and paste that into a new module (or just use the one in the download).

Page 2 of 3

Comment and Contribute


(Maximum characters: 1200). You have characters left.



Enterprise Development Update

Don't miss an article. Subscribe to our newsletter below.

Sitemap | Contact Us

Thanks for your registration, follow us on our social networks to keep up-to-date
Rocket Fuel