Do you want to create a simple status bar in VB? Is there a few MB of OCX? Is there a way to create a status bar in an API, and VB makes the beginner friends very convenient, but for you When VB has something to find, it is found that VB is originally a chicken rib ...
Create a form first, add two Button in the form, then write the following code:
'---------------------------------------------' ' Create Status bar demo '' Code by loveboom [dfcg] [fcg] [US] 'email: loveboom # 163.com' http://blog.9cbs.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 rett = true kilobox "Create a status bar success!" Else Msgbox "created status bar failed :-(!", 48nd if
End Sub
Private submmand2_click () setbartext hwndbar, 1, "create statusbar demo :-)!" End Sub
'Mobile Status Bar Private Sub Form_Resize () MovestatWindow Hwndbarend Sub
Then add a module, write the code in the module:
Private Const WS_CHILD As Long = & H40000000 'WS_CHILD and WS_VISIBLE essential function Private Const WS_VISIBLE As Long = & H10000000Private Const WM_USER As Long = & H400Private Const SB_SETPARTS As Long = (WM_USER 4)' two constants in VB, api interrogator there is no need to manually add 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 hwndParent As Long, ByVal wID As Long) As LongPrivate 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 LongPrivate Declare Function MoveWindow Lib "user32.dll" (ByVal hwnd As Long , Byval x ask, BYVAL NWIDTH AS long, BYVAL NHEIGHT AS long, BYVAL BREPAINT AS Long AS Long '-------------------- ----------------------------- 'creation status bar' function description: 'PARENTHWND status bar belonging to the handle' IDC_STATBAR status bar ID number, used to click on the status bar "HBarwin" HBARWIN Function Returns the handle of the status bar 'sztext to display the letter interest''----------------------------------------------- ---- Function Createstatbar (PARENTHWND As Long, Idc_statbar As Long, HBarwin As String = "DEMO") AS Boolean Dim Ret As long 'return value DIM BAR (0 to 1) as long' column Number of DIM SZBAR AS Long '------------------------------------------------------------------- ------------------ 'Define array BAR (0) = 235' The first column width is 245 bar (1) = -1 '-1 indicates that the following divided into one Bar '---------------------------------------------- -------
ret = CreateStatusWindow (WS_CHILD Or WS_VISIBLE, ByVal szText, ParenthWnd, IDC_STATBAR) 'create a status bar szbar = 2 If ret = 0 Then' If the creation fails exit process CreateStatBar = False Exit Function End If hBarWin = ret 'returns a handle to the status bar If SZBAR> 1 THEN 'Because the default is a column, it is judged that it is greater than 1 is a column sendMessage Hbarwin, SB_SETPARTS, SZBAR, BAR (0)' Ben End if createstatbar = true 'Create a successful return true Value end function' ---------------------------- 'Move Status Bar' ----------------- ----------- Sub movestatwindow (HBAR As Long) If the status bar handle is not 0 mobile call movewindow (hbar, 0, 0, 0, 0, true) end ifend sub
'---------------------------- "Display information on the specified column' hbar is the handle of the status bar 'szbar specified Which column shows information, starting from 0, that is, if we want to display information in the second column, SZBAR is set to 1'sztext to display the information to display '-------------- ----------------------- Sub setbartext (HBAR As stay) SendMessage HBar, SB_SETTEXTA, SZBAR, BYVAL STRTEXTEND SUB The column is basically viable, of course, you can also use setWindowlong to handle status bar information. Programs are tested under Win 2003 VB6 SP6