用VB取得桌面窗口圖象
發(fā)表時間:2023-07-30 來源:明輝站整理相關(guān)軟件相關(guān)文章人氣:
[摘要]Windows提供了一個API函數(shù)GetDesktopWindow,該函數(shù)返回桌面窗口的設(shè)備描述。 因此利用它就可以輕松獲取桌面窗口的圖象。參見下例:>>步驟1----建立新工程。>...
Windows提供了一個API函數(shù)GetDesktopWindow,該函數(shù)返回桌面窗口的設(shè)備描述。 因此利用它就可以輕松獲取桌面窗口的圖象。
參見下例:
>>步驟1----建立新工程。
>>步驟2----編寫如下代碼:
Private Declare Function GetDesktopWindow Lib "user32" () As Long
Private Declare Function GetDC Lib "user32" (ByVal hwnd As Long) _
As Long
Private Declare Function BitBlt Lib "gdi32" _
(ByVal hDestDC As Long, ByVal x As Long, _
ByVal y As Long, ByVal nWidth As Long, _
ByVal nHeight As Long, ByVal hSrcDC As Long, _
ByVal xSrc As Long, ByVal ySrc As Long, _
ByVal dwRop As Long) As Long
Private Sub Form_Load()
Dim lDesktop As Long
Dim lDC As Long
Form1.AutoRedraw = True
Form1.ScaleMode = 1
lDesktop = GetDesktopWindow()
lDC = GetDC(lDesktop)
BitBlt Me.hDC, 0, 0, Screen.Width, Screen.Height, lDC, _
0, 0, vbSrcCopy
End Sub
>>步驟3----編譯運行,看看大功告成了吧!