| 网站首页 | 文章中心 | 电子书下载 | 矢量图库 | 视频教程 | 素材下载 | 程序代码下载 | JS代码 | 论坛 | 
常用软件类:
|杀毒安全 |联络聊天 |网络软件 |多媒体类 |系统工具 |图形图像 |系统工具 |应用软件 |行业软件
开发设计类:
|动画制作 |图像处理 |3D设计 |操作系统 |站长学院 |网络相关 |WEB设计 |数据库类 |程序开发
Visual Basic编程常见问题
作者:佚名    文章来源:网络    点击数:    更新时间:2006-11-24
 


  如何把小图片填满 Form 成为背景图?

  对于这个问题,我看过很多方法,有的方法很麻烦,要声明一大堆 Type,用一大堆的 API,但是有一个最笨但我认为最好的方法如下: (就好像拼磁砖一样,不用任何 API, 不必声明任何 Type)

  在 Form 中放一个 PictureBox,Picture 属性设定为某一张小图,AutoSize 属性性设定 True,完成的模组如下:

Sub PictureTile(Frm As Form, Pic As PictureBox)
 Dim i As Integer
 Dim t As Integer
 Frm.AutoRedraw = True
 Pic.BorderStyle = 0
 For t = 0 To Frm.Height Step Pic.ScaleHeight
  For i = 0 To Frm.Width Step Pic.ScaleWidth
   Frm.PaintPicture Pic.Picture, i, t
  Next i
 Next t
End Sub

  PictureTile 这个模组共有二个参数,第一个是表单名称,第二个则是 PictureBox 的名称。以下为一应用实例:

Private Sub Form_Load()
 PictureTile Me, Picture1
End Sub
如何把小图片填满 MDIForm 成为背景图?

  以下这个范例,要:

  1、一个 MDIForm:不必设定任何属性。

  2、一个 Form1:不一定是 MDIChild,最好 MDIChild 为 False,但是 AutoRedraw 设成 True。

  3、Form1 上面放一个隐藏的 PictureBox:名称为 Picture1,不必设定 Picture 属性。

  4、一张图片的完整路径。

’将以下模组放入 MDIForm 的声明区中:

Sub TileMDIBkgd(MDIForm As Form, bkgdtiler As Form, bkgdfile As String)
If bkgdfile = "" Then Exit Sub
Dim ScWidth%, ScHeight%
ScWidth% = Screen.Width / Screen.TwipsPerPixelX
ScHeight% = Screen.Height / Screen.TwipsPerPixelY
Load bkgdtiler
bkgdtiler.Height = Screen.Height
bkgdtiler.Width = Screen.Width
bkgdtiler.ScaleMode = 3
bkgdtiler!Picture1.Top = 0
bkgdtiler!Picture1.Left = 0
bkgdtiler!Picture1.Picture = LoadPicture(bkgdfile)
bkgdtiler!Picture1.ScaleMode = 3

For n% = 0 To ScHeight% Step bkgdtiler!Picture1.ScaleHeight
For o% = 0 To ScWidth% Step bkgdtiler!Picture1.ScaleWidth
bkgdtiler.PaintPicture bkgdtiler!Picture1.Picture, o%, n%
Next o%
Next n%

MDIForm.Picture = bkgdtiler.Image
Unload bkgdtiler
End Sub

  以下为一应用实例:

Private Sub MDIForm_Load()
TileMDIBkgd Me, Form1, "c:\windows\Tiles.bmp"
End Sub

  关闭指定的程序

  要做到像 Task Manager 一样,可以关闭指定的程序,方法如下:

  在声明区中放入以下声明:(16位 改成 win31 API)

Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long

Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long

Public Const WM_CLOSE = &H10

  以下之范例示范如何关闭一个视窗标题 (Caption) 为 【小算盘】的程序:

Dim winHwnd As Long
Dim RetVal As Long
winHwnd = FindWindow(vbNullString, "小算盘")
Debug.Print winHwnd
If winHwnd <> 0 Then
 RetVal = PostMessage(winHwnd, WM_CLOSE, 0&, 0&)
 If RetVal = 0 Then
  MsgBox "Error posting message."
 End If
Else
 MsgBox "并未开启小算盘程序."
End If

  如何隐藏及再显示鼠标

  很简单,只用到了一个 ShowCursor API,参数也很简单,只有一个 bShow,设定值如下:

True:显示鼠标 / False:隐藏鼠标

Declare Function ShowCursor Lib "user32" Alias "ShowCursor" (ByVal bShow As Long) As Long

  如何从您的应程序中结束 Windows 重开机?

  很多软件在 Setup 完之后都会自动关机重开机,以便让某些设定值可以生效,其实这个功能很简单,只要几行指令就可以做到了!

  关键就是要使用 ExitWindowsEx 这个 API,这个 API 只有二个参数,第一个参数是一个 Flag,目的是要告诉 Windows 要以什么方式关机,在下面的声明中会列出可用的 Flag 常数值,至于第二个参数则是一个保留值,只要设定成 0 就可以了。

  很重要的一点是:如果您想要让关机动作更顺利,记得要 Unload 您的程序!

’在声明区中 (Bas Module / Form Module) 加入以下声明:

Public Const EWX_LOGOFF = 0 ’这四个常数值可以并用
Public Const EWX_SHUTDOWN = 1
Public Const EWX_REBOOT = 2
Public Const EWX_FORCE = 4

Declare Function ExitWindowsEx Lib "user32" Alias "ExitWindowsEx" (ByVal uFlags As Long, ByVal dwReserved As Long) As Long

’实例:如果您想强迫关机重开机,程序码如下:

ret = ExitWindowsEx(EWX_FORCE OR EWX_REBOOT, 0)

 

上一页  [1] [2] [3] [4] [5] [6] [7] 下一页


  • 上一篇文章:

  • 下一篇文章: 没有了
  • 相关文章