vb中你想創建一個簡單的狀態欄也用上那個幾mb的ocx嗎?有沒有方法可以不用呢,下面就是以api來創建 一個狀態欄,vb讓初學朋友學得很方便,但對你對vb有所了解的時候,卻發現vb原來就是雞肋...... 先創建一個窗體,在窗體里添加兩個button,然后寫下以下代碼: ----------------------------------------------- create status bar demo code by loveboom[dfcg][fcg][us] email:loveboom#163.com http://blog.csdn.net/bmd2chen ------------------------------------------------- dim hwndbar as long ;狀態欄句柄 private const idc_statbar as long = &h2005 狀態欄id private sub command1_click() dim ret as boolean ret = createstatbar(me.hwnd, idc_statbar, hwndbar) if ret = true then msgbox "創建狀態欄成功!" else msgbox "創建狀態欄失敗:-(!", 48 end if end sub
private sub command2_click() setbartext hwndbar, 1, "create statusbar demo:-)!" end sub 移動狀態欄 private sub form_resize() movestatwindow hwndbar end sub
然后添加一個模塊,模塊里寫上代碼: private const ws_child as long = &h40000000 ws_child 和ws_visible是必需函數 private const ws_visible as long = &h10000000 private const wm_user as long = &h400 private const sb_setparts as long = (wm_user + 4) 這兩個常數在vb自帶的api查詢器里沒有,需要手工添加 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 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 as long, byval nheight as long, byval brepaint as long) as long -------------------------------------------------- 創建狀態欄 函數說明: parenthwnd 狀態欄所屬的句柄 idc_statbar 狀態欄的id號,用于對狀態欄的單擊之類的操作 hbarwin 函數返回狀態欄的句柄 sztext 要顯示的信息 --------------------------------------------------- function createstatbar(parenthwnd as long, idc_statbar as long, hbarwin as long, optional sztext as string = "demo") as boolean dim ret as long 返回值 dim bar(0 to 1) as long 分欄的各項位置 dim szbar as long 分欄的數目
------------------------------------------------------- ret = createstatuswindow(ws_child or ws_visible, byval sztext, parenthwnd, idc_statbar) 創建狀態欄 szbar = 2 if ret = 0 then 如果創建失敗則退出過程 createstatbar = false exit function end if hbarwin = ret 返回狀態欄的句柄 if szbar > 1 then 因為默認就是分一欄所以,這里判斷為大于1就是分欄 sendmessage hbarwin, sb_setparts, szbar, bar(0) 分欄 end if createstatbar = true 創建成功返回真值 end function ---------------------------- 移動狀態欄 ---------------------------- sub movestatwindow(hbar as long) if hbar then 如果狀態欄句柄不為0則移動 call movewindow(hbar, 0, 0, 0, 0, true) end if end sub ------------------------------ 在指定欄上顯示信息 hbar 為狀態欄的句柄 szbar 指定要在哪一欄顯示信息,從0開始計,也就是說,如果分兩欄,我們要在第二欄里顯示信息,szbar就設置為1 sztext 要顯示的信息 ------------------------------- sub setbartext(hbar as long, szbar as long, strtext as string) sendmessage hbar, sb_settexta, szbar, byval strtext end sub