'本程序在Windows 2000 + VB6.0下通过Option ExplicitPrivate Declare Function RegOpenKeyEx Lib "advapi32" _
    Alias "RegOpenKeyExA" _
   (ByVal hKey As Long, _
    ByVal lpSubKey As String, _
    ByVal ulOptions As Long, _
    ByVal samDesired As Long, _
    ByRef phkResult As Long) As Long
     
Private Declare Function RegQueryValueEx Lib "advapi32" _
    Alias "RegQueryValueExA" _
   (ByVal hKey As Long, _
    ByVal lpValueName As String, _
    ByVal lpReserved As Long, _
    ByRef lpType As Long, _
    ByVal lpData As String, _
    ByRef lpcbData As Long) As Long
     
Private Declare Function RegCloseKey Lib "advapi32" _
   (ByVal hKey As Long) As LongPrivate Declare Function GetWindowsDirectory Lib "kernel32" _
    Alias "GetWindowsDirectoryA" _
   (ByVal lpBuffer As String, _
    ByVal nSize As Long) As LongConst READ_CONTROL = &H20000
Const KEY_QUERY_VALUE = &H1
Const KEY_SET_VALUE = &H2
Const KEY_CREATE_SUB_KEY = &H4
Const KEY_ENUMERATE_SUB_KEYS = &H8
Const KEY_NOTIFY = &H10
Const KEY_CREATE_LINK = &H20
Const KEY_ALL_ACCESS = KEY_QUERY_VALUE + _
                       KEY_SET_VALUE + _
                       KEY_CREATE_SUB_KEY + _
                       KEY_ENUMERATE_SUB_KEYS + _
                       KEY_NOTIFY + _
                       KEY_CREATE_LINK + _
                       READ_CONTROL
Const HKEY_CURRENT_USER = &H80000001
Const ERROR_SUCCESS = 0
Const REG_SZ = 1
Const REG_EXPAND_SZ = 2
Const REG_DWORD = 4
Private Sub MDIForm_Load()
    Set Me.Picture = LoadPicture(GetWallpaperPath())
End Sub
'取得桌面墙纸的文件路径
Private Function GetWallpaperPath() As String
    Dim strWallpaperPath As String
    Dim strSystemRoot As String
    Dim hKey As Long
    
    On Error GoTo ErrorHandler
   
    If GetKeyValue(HKEY_CURRENT_USER, _
                   "Software\Microsoft\Internet Explorer\Desktop\General", _
                   "Wallpaper", _
                   strWallpaperPath) Then
        
        '取得Windows目录
        strSystemRoot = Space(256)
        GetWindowsDirectory strSystemRoot, 256
        strSystemRoot = Left(strSystemRoot, InStr(1, strSystemRoot, Chr(0)) - 1)
        
        '把%SystemRoot%替换成Windows目录
        GetWallpaperPath = Replace(strWallpaperPath, "%SystemRoot%", strSystemRoot)
    Else
        GetWallpaperPath = ""
    End If
    
    Exit Function
ErrorHandler:
    MsgBox Err.Description, vbExclamation
End Function
'此函数来自About对话框模板,用于取得注册表中的键值
Private Function GetKeyValue(KeyRoot As Long, _
                            KeyName As String, _
                            SubKeyRef As String, _
                            ByRef KeyVal As String) As Boolean
    Dim i As Long
    Dim rc As Long
    Dim hKey As Long
    Dim hDepth As Long
    Dim KeyValType As Long
    Dim tmpVal As String
    Dim KeyValSize As Long
    
    rc = RegOpenKeyEx(KeyRoot, KeyName, 0, KEY_ALL_ACCESS, hKey)
    
    If (rc <> ERROR_SUCCESS) Then GoTo GetKeyError
    
    tmpVal = String$(1024, 0)
    KeyValSize = 1024
    
    rc = RegQueryValueEx(hKey, SubKeyRef, 0, _
                         KeyValType, tmpVal, KeyValSize)
                        
    If (rc <> ERROR_SUCCESS) Then GoTo GetKeyError
    
    If (Asc(Mid(tmpVal, KeyValSize, 1)) = 0) Then
        tmpVal = Left(tmpVal, KeyValSize - 1)
    Else
        tmpVal = Left(tmpVal, KeyValSize)
    End If
    
    Select Case KeyValType
    Case REG_SZ, REG_EXPAND_SZ
        KeyVal = tmpVal
    Case REG_DWORD
        For i = Len(tmpVal) To 1 Step -1
            KeyVal = KeyVal + Hex(Asc(Mid(tmpVal, i, 1)))
        Next
        KeyVal = Format$("&h" + KeyVal)
    End Select
    
    GetKeyValue = True
    rc = RegCloseKey(hKey)
    Exit Function
    
GetKeyError:
    KeyVal = ""
    GetKeyValue = False
    rc = RegCloseKey(hKey)
End Function

解决方案 »

  1.   

    楼上的说的不错
    补充:
    PaintDesktop VB声明 
    Declare Function PaintDesktop Lib "user32" Alias "PaintDesktop" (ByVal hdc As Long) As Long 
    说明 
    在指定的设备场景中描绘桌面墙纸图案 
    返回值 
    Long,TRUE(非零)表示成功,否则返回零 
    参数表 
    参数 类型及说明 
    hdc Long,要在其中填充的设备场景 http://www.mvps.org/vbvision/_samples/MDI_Background_Demo.zip
    MDI Background Demo.zip (25KB)
       This project shows how you can use memory device contexts to create pictures that can be assigned to the picture property of a VB MDI parent form.  The project contains routines to stretch a bitmap across the background of the form and center a bitmap on top of a background as well as a routine for tiling a bitmap onto the background.  It also contains code to draw transparent bitmaps that is used when overlaying a foreground bitmap onto the background.  This project replaces a previous demo that used subclassing to attain a similar result.  The routines in this project are generic enough that they can be used with any VB form or control that has a picture property.VB操作注册表:
    http://www.sqreg.com/file/vb/reg_01.htm
    http://www.sqreg.com/file/vb/reg_02.htm
    http://www.sqreg.com/file/vb/reg_03.htm
    http://www.sqreg.com/file/vb/reg_04.htm
    http://www.sqreg.com/file/vb/reg_05.htm
    http://www.sqreg.com/file/vb/reg_06.htm
    http://www.sqreg.com/file/vb/reg_07.htm
      

  2.   

    两个api
    一个是 getdc
    一个是 stretchblt
    具体的自己搞吧`!
    我只会这些了`!:)