步 驟
1、創(chuàng)建一個(gè)Form1窗體,設(shè)置2個(gè)Command按鈕,將Command1和Command2的Caption屬性分別設(shè)置為:“變暗”和“恢復(fù)”。
2、在窗體代碼模塊中聲明API函數(shù)和相應(yīng)的類型,代碼如下:
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、編寫代碼實(shí)現(xiàn)程序功能,由于版面所限,具體代碼將放到CCE網(wǎng)站(http://www.cce.com.cn)。
以上就是屏幕變暗的方法。如果要使窗體、圖片框等對象變暗,只要使窗體或圖片框等對象獲取句柄即可,修改Command1_Click過程和Command2_Click過程中的以下語句即可實(shí)現(xiàn)窗體變暗。
hdc5=Form1.Hdc;
Width5=Form1.width;
height5=Form1.height;
ReleaseDC(Form1.hwnd,hdct)
aa=InvalidateRect (Form1.hwnd,bottom,1)。
以上程序在VB6.中文版,Windwos 98 環(huán)境中運(yùn)行通過。有興趣的朋友可以去試一試,看到這種效果是不是覺得很驚奇呢!
相關(guān)推薦:2010年9月計(jì)算機(jī)等級考試成績查詢時(shí)間匯總
2011計(jì)算機(jī)等級考試二級VB考點(diǎn)及習(xí)題匯總
北京 | 天津 | 上海 | 江蘇 | 山東 |
安徽 | 浙江 | 江西 | 福建 | 深圳 |
廣東 | 河北 | 湖南 | 廣西 | 河南 |
海南 | 湖北 | 四川 | 重慶 | 云南 |
貴州 | 西藏 | 新疆 | 陜西 | 山西 |
寧夏 | 甘肅 | 青海 | 遼寧 | 吉林 |
黑龍江 | 內(nèi)蒙古 |