顺便问一下,这个hmem到底是个什么玩意儿

解决方案 »

  1.   

    dim str as string 
    dim hMem as long 
    dim lngResult as longlngResult=SetClipboardData (整形值,hMem)MsgBox hMem
      

  2.   

    Declare Function GetFocus Lib "user32" () As Long
    Declare Function OpenClipboard Lib "user32" (hwnd As Long) As Long
    Declare Function CloseClipboard Lib "user32" () As Long
    Declare Function EmptyClipboard Lib "user32" () As Long
    Declare Function SetClipBoardData Lib "user32" Alias "SetClipboardData" (wFormat As Long, hData As Long) As Long
    Declare Function CopyStrtoLp Lib "Kernel32" Alias "lstrcpy" (lpDest As Long, lpScr As String) As Long
    Declare Function GlobalAlloc Lib "Kernel32" (wFlags As Long, dwBytes As Long) As Long
    Declare Function GlobalLock Lib "Kernel32" (hL As Long) As Long
    Declare Sub GlobalUnlock Lib "Kernel32" (hU As Long)
    Declare Function GlobalFree Lib "Kernel32" (hF As Long) As LongSub MAIN() SetClipBoard ("This is a test of the national broadcasting system.")
    End Sub
    Function SetClipBoard(szText$)
    '* Get the handle to the active Window.hwnd = GetFocus'* Add some NULL terminating characters to the String.szText$ = szText$ + Chr$(0) + Chr$(0)'* Allocate some global memory and copy the string to this memory.nSize = Len(szText$)
    hData = GlobalAlloc(2, nSize)
    hMem = GlobalLock(hData)
    hMem = CopyStrtoLp(hMem, szText$)'* Unlock the memory handle, the clipboard must receive an unlockedGlobalUnlock (hData)'* Open the clipboardIf (OpenClipboard(hwnd) <> 0) Then
            '* Clear current contents, add hData, Close Clipboard.
         n = EmptyClipboard
         n = SetClipBoardData(1, hData)
            '* the clipboard must be closed before any one else can access it.
         n = CloseClipboardElse
         n = 0
            '* Clipboard failed, free memory
            n2 = GlobalFree(hData)End If
    SetClipBoard = n
    End Function