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