Using the API to create a status bar in VB

Source: Internet
Author: User
Tags exit
Create
VB you want to create a simple status bar also used that a few MB OCX? There is no way to use it, the following is the API to create
A status bar, VB to learn from a novice friend is very convenient, but you have some understanding of VB, but found that VB is the original chicken ribs ...
First create a form, add two button to the form, and write the following code:
’-----------------------------------------------
’
Create Status Bar Demo
’
Code by Loveboom[dfcg][fcg][us]
Email:loveboom#163.com
Http://blog.csdn.net/bmd2chen
’
’-------------------------------------------------
Dim Hwndbar as Long; status bar handle
Private Const Idc_statbar as Long = &h2005 status bar ID
Private Sub Command1_Click ()
DIM ret as Boolean
ret = Createstatbar (Me.hwnd, Idc_statbar, Hwndbar)
IF ret = True Then
MsgBox "Create status bar success!"
Else
MsgBox "Create status bar failed:-(!", 48
End If
End Sub

Private Sub Command2_Click ()
Setbartext Hwndbar, 1, "Create StatusBar Demo:-)!"
End Sub
Move the status bar
Private Sub form_resize ()
Movestatwindow Hwndbar
End Sub

Then add a module that writes the code in the module:
Private Const ws_child as Long = &h40000000 ws_child and ws_visible are required functions
Private Const ws_visible as Long = &h10000000
Private Const wm_user as Long = &h400
Private Const sb_setparts as Long = (Wm_user + 4) These two constants are not in VB's own API query and need to be added manually
Private Const sb_settexta as Long = (Wm_user + 1)
Private Declare Function createstatuswindow Lib "Comctl32.dll" (ByVal style as Long, ByVal lpsztext as String, ByVal HWNDP Arent as long, ByVal WID as Long
Private Declare Function sendmessage Lib "user32.dll" Alias "SendMessageA" (ByVal hwnd as Long, ByVal wmsg as Long, ByVal WParam as Long, ByRef LParam as any) as long
Private Declare Function movewindow Lib "user32.dll" (ByVal hwnd as Long, ByVal x as Long, ByVal y as Long, ByVal nwidth A s long, ByVal nheight as Long, ByVal Brepaint as long) as long
’--------------------------------------------------
’
Create a status bar
Function Description:
Parenthwnd the handle to which the status bar belongs
The ID number of the Idc_statbar status bar, for actions such as clicks on the status bar
Hbarwin function returns a handle to the status bar
Sztext the information to display
’
’---------------------------------------------------
Function Createstatbar (Parenthwnd as Long, idc_statbar as long, hbarwin as Long, Optional sztext as String = "Demo") as Bo Olean
DIM ret as Long return value
Location of Dim Bar (0 to 1) as Long columns
Number of Dim Szbar as Long columns

’-------------------------------------------------------
Defining arrays
Bar (0) = 235 The first column width is 245
Bar (1) =-1-1 means the following is divided into one column

’-------------------------------------------------------
ret = Createstatuswindow (ws_child Or ws_visible, ByVal sztext, Parenthwnd, idc_statbar) Create status bar
Szbar = 2
If ret = 0 Then Exit procedure if creation fails
Createstatbar = False
Exit Function
End If
Hbarwin = RET Returns the handle of the status bar
If Szbar > 1 Then because the default is divided into one column so, here is judged to be greater than 1 is the column
SendMessage Hbarwin, Sb_setparts, Szbar, bar (0) columns
End If
Createstatbar = True to create a successful return truth value
End Function
’----------------------------
Move the status bar
’----------------------------
Sub Movestatwindow (Hbar as Long)
If Hbar Then move if the status bar handle is not 0
Call MoveWindow (hbar, 0, 0, 0, 0, True)
End If
End Sub
’------------------------------
Display information on a specified bar
Hbar as a handle to the status bar
SZBAR specifies in which column to display the information, starting from 0, that is to say, if two columns, we want to display the information in the second column, Szbar is set to 1
Sztext the information to display
’-------------------------------
Sub Setbartext (Hbar as Long, szbar as Long, strText as String)
SendMessage Hbar, Sb_settexta, Szbar, ByVal StrText
End Sub

This status bar is basically feasible, of course, you can also use SetWindowLong to process the status bar information.
The program is tested through the win 2003 VB6 SP6

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.