API在VB中应用之技巧集锦[3]

[入库:2005年8月18日] [更新:2007年3月24日]

本文简介:选择自 icemanpro 的 blog

     call disablectrlaltdelete(true)
     恢复ctrl-alt-delete :
     call disablectrlaltdelete(false)
    
    
     16、如何移动没有标题栏的窗口?
    
     我们一般是用鼠标按住窗口的标题栏,然后移动窗口,当窗口没有标题栏时,我们可以用下面的方法来移动窗口:
    
     *api函数声明:
     declare function releasecapture lib "user32" () as long declare function sendmessage lib "user32" alias "sendmessagea" (byval hwnd as long, byval wmsg as long, byval wparam as long, lparam as any) as long
     public const htcaption = 2
     public const wm_nclbuttondown = &ha1
     在 form_mousedown 事件中:
     private sub form_mousedown(button as integer, shift as integer, x as single, y as single)
     releasecapture sendmessage hwnd, wm_nclbuttondown, htcaption,0&
     end sub
    
    
     17、vb中如何使用延时函数?
    
     *api函数声明:
     declare sub sleep lib "kernel32" (byval dwmilliseconds as long)
     调用:
     注释:延时1秒
     call sleep(1000)
    
    
     18、调用修改屏幕保护口令的窗口:
    
     private declare function pwdchangepassword lib "mpr" alias "pwdchangepassworda" (byval lpcregkeyname as string, byval hwnd as long, byval uireserved1 as long, byval uireserved2 as long) as long
     调用:
     call pwdchangepassword("scrsave", me.hwnd, 0, 0)
    
     19、使windows开始屏幕保护:
     *api函数声明
     private declare function sendmessage lib "user32"
     alias "sendmessagea" (byval hwnd as long, byval wmsg
     as long, byval wparam as long, byval lparam as long)
     as long
     const wm_syscommand = &h112&
     const sc_screensave = &hf140&
     注释:调用
     dim result as long
     result = sendmessage(form1.hwnd, wm_syscommand, sc_screensave, 0&)
    
    
     20、如何改变windows桌面背景?
     *api函数声明
     const spi_setdeskwallpaper = 20
     const spif_updateinifile = &h1
     declare function systemparametersinfo lib "user32" alias "systemparametersinfoa" (byval uaction as long, byval uparam as long, byval lpvparam as any, byval fuwinini as long) as long
     注释:调用
     call systemparametersinfo(spi_setdeskwallpaper, 0, "c:windowsclouds.bmp", spif_updateinifile)
    
    
     21、怎样确定系统是否安装了声卡?
    
     *api函数声明:
     declare function waveoutgetnumdevs lib "winmm.dll" alias "waveoutgetnumdevs" () as long
     代码如下:
     dim i as integer
     i = waveoutgetnumdevs()
     if i > 0 then msgbox "你的系统可以播放声音。", vbinformation, "声卡检测"
     else
     msgbox "你的系统不能播放声音。", vbinformation, "声卡检测"
     end if
    
    
     22、如何找到cd-rom驱动器的盘号?
     下面的函数将检查你计算机所有的驱动器看是否是 cd-rom,如果是就返回驱动器号,如果没有就返回空字符
     public function getcdromdrive() as string
      dim ltype as long,i as integer,tmpdrive as string,found as boolean
      on error goto errl
      for i = 0 to 25
       tmpdrive = chr(65 + i) & ":"
       ltype = getdrivetype(tmpdrive) 注释:win32 api 函数
       if (ltype = drive_cdrom) then 注释:win32 api 常数
        found = true
        exit for
       end if
      next
      if not found then tmpdrive = ""
      bi_getcdromdrive = tmpdrive
      exit function
      errl: msgbox error$

本文关键:API在VB中应用之技巧集锦
  相关方案
Google
 

本站最佳浏览方式为 分辨率 1024x768 IE 6.0(或更高版本的 IE浏览器)

go top