Windows提供了一個API函數GetDesktopWindow,該函數返回桌面窗口的設備描述。因此利用它就可以輕松獲取桌面窗口的圖象。
參見下例:
>>步驟1----建立新工程。
>>步驟2----編寫如下代碼:
PrivateDeclareFunctionGetDesktopWindowLib"user32"()AsLong
PrivateDeclareFunctionGetDCLib"user32"(ByValhwndAsLong)_
AsLong
PrivateDeclareFunctionBitBltLib"gdi32"_
(ByValhDestDCAsLong,ByValxAsLong,_
ByValyAsLong,ByValnWidthAsLong,_
ByValnHeightAsLong,ByValhSrcDCAsLong,_
ByValxSrcAsLong,ByValySrcAsLong,_
ByValdwRopAsLong)AsLong
PrivateSubForm_Load()
DimlDesktopAsLong
DimlDCAsLong
Form1.AutoRedraw=True
Form1.ScaleMode=1
lDesktop=GetDesktopWindow()
lDC=GetDC(lDesktop)
BitBltMe.hDC,0,0,Screen.Width,Screen.Height,lDC,_
0,0,vbSrcCopy
EndSub
>>步驟3----編譯運行,看看大功告成了吧!->