Create a status bar in VB using the API

xiaoxiao2021-03-05  23

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 ... first create a form, 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 field handle private const idc_statbar as long = & h2005 'status bar ID Private SUB Command1_click () DIM RET AS BooleanRet = Createstatbar (Me.hWnd, Idc_statbar, HWndbar) IF RET = TRUE THEN MSGBOX "Created Status Bar Success!" Else Msgbox "Created Status Bar Failed :-(!", 48nd IFEND Subprivate Sub Command2_click ) SetBarText hWndBar, 1, "! Create StatusBar Demo :-)" End Sub 'movement status bar Private Sub Form_Resize () MoveStatWindow hWndBarEnd Sub then add a module, the module to write the code: Private Const WS_CHILD As Long = & H40000000' WS_CHILD and WS_Visible is a required function private const ws_visible as ring = & h10000000private const wm_user as long = & h400Private const SB_SETPARTS AS L ONG = (WM_USER 4) 'These two constants are not in the API querier comes with VB, 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 Y As Long, Byval NWIDTH AS Long, Byval NHEIGHT As Long, Byval Brepaint As Long) ---------------------------------------------------------------------------------------------------- --------------------------------- '' Create a status bar 'function description:' ParenThwnd status bar belongs to the handle The ID number of the 'IDC_STATBAR status bar, the action on the click of the status bar' HBarwin function returns the handle of the status bar 'sztext to display the information to display ""------------ ------------------------------------- Function Createstatbar (PARENTHWND As Long, Idc_Statbar As Long, HBarwin AS Long, Optional Sztext As String = "Demo") AS Boolean Dim Ret As Long 'Return Value DIM BAR (0 to 1) AS Long' Bar Number of Dim Szbar As Long '------- -------------------------------------------------- - 'Definition array bar (0) = 235' The first column width is 245 bar (1) = -1 '-1 indicates that the rear is divided into column' --------------- ---------------------------------------- Ret = CreateStatusWindow (WS_CHILD or WS_VISIBLE, BYVAL SZTEXT , PARENTHWND, IDC_STATBAR) 'Creation Status Bar SZBAR = 2 if Ret = 0 Then' If the creation fails, exit the process of createstatbar = false exit function end if hbarwin = RET 'Return status bar handle if Szbar> 1 THEN' , bar (0) 'Bar End if createstatbar = true' creation success return true End function '------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ 'Mobile Status Bar' ---------------------------- Sub MovestatWindow (HBAR As Long) If HBar Then '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 '

转载请注明原文地址:https://www.9cbs.com/read-35249.html

New Post(0)