1、创建一个Form1窗体,设置2个Command按钮,将Command1和Command2的Caption属性分别设置为:“变暗”和“恢复”。
2、在窗体代码模块中声明API函数和相应的类型,代码如下:
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function ReleaseDC Lib "user32" (ByVal hwnd As Long, ByVal hdc As Long) As Long
Private Declare Function CreatePatternBrush Lib "gdi32" (ByVal hBitmap As Long) As Long
Private Declare Function PatBlt Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal dwRop As Long) As Long
Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
Private Declare Function CreateBitmap Lib "gdi32" (ByVal nWidth As Long, ByVal nHeight As Long, ByVal nPlanes As Long, ByVal nBitCount As Long, lpBits As Any) As Long
Private Declare Function SelectObject Lib "gdi32" (ByVal hdc As Long, ByVal hObject As Long) As Long
Private Declare Function InvalidateRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT, ByVal bErase As Long) As Long
3、编写代码实现程序功能,由于版面所限,具体代码将放到CCE网站(http://www.cce.com.cn)。
以上就是屏幕变暗的方法。如果要使窗体、图片框等对象变暗,只要使窗体或图片框等对象获取句柄即可,修改Command1_Click过程和Command2_Click过程中的以下语句即可实现窗体变暗。
hdc5=Form1.Hdc;
Width5=Form1.width;
height5=Form1.height;
ReleaseDC(Form1.hwnd,hdct)
aa=InvalidateRect (Form1.hwnd,bottom,1)。
以上程序在VB6.中文版,Windwos 98 环境中运行通过。有兴趣的朋友可以去试一试,看到这种效果是不是觉得很惊奇呢!作者: yuhuofei 时间: 2007-1-24 16:34 标题: 用VB实现屏幕阴暗操作