设为首页收藏本站Access中国

Office中国论坛/Access中国论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

返回列表 发新帖
查看: 5756|回复: 7
打印 上一主题 下一主题

[API] 如何在access中使用clipboard(剪切板)啊?

[复制链接]
跳转到指定楼层
1#
发表于 2004-8-24 16:29:00 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
如何在access中使用clipboard(剪切板)啊?比如清空剪切板,向其中添加内容等

For you exampleConst LR_LOADFROMFILE = &H10

Const IMAGE_BITMAP = 0

Const IMAGE_ICON = 1

Const IMAGE_CURSOR = 2

Const IMAGE_ENHMETAFILE = 3

Const CF_BITMAP = 2

Private Declare Function LoadImage Lib "user32" Alias "LoadImageA" (ByVal hInst As Long, ByVal lpsz As String, ByVal dwImageType As Long, ByVal dwDesiredWidth As Long, ByVal dwDesiredHeight As Long, ByVal dwFlags As Long) As Long

Private Declare Function CloseClipboard Lib "user32" () As Long

Private Declare Function OpenClipboard Lib "user32" (ByVal hwnd As Long) As Long

Private Declare Function EmptyClipboard Lib "user32" () As Long

Private Declare Function SetClipboardData Lib "user32" (ByVal wFormat As Long, ByVal hMem As Long) As Long

Private Declare Function IsClipboardFormatAvailable Lib "user32" (ByVal wFormat As Long) As Long

Private Sub Form_Load()

       hBitmap = LoadImage(App.hInstance, "c:\windows\logow.sys", IMAGE_BITMAP, 320, 200, LR_LOADFROMFILE)

    If hBitmap = 0 Then

        MsgBox "There was an error while loading the bitmap"

        Exit Sub

    End If

    'open the clipboard

    OpenClipboard Me.hwnd

    'Clear the clipboard

    EmptyClipboard

    'Put our bitmap onto the clipboard

    SetClipboardData CF_BITMAP, hBitmap

    'Check if there's a bitmap on the clipboard

    If IsClipboardFormatAvailable(CF_BITMAP) = 0 Then

        MsgBox "There was an error while pasting the bitmap to the clipboard!"

    End If

    'Close the clipboard

    CloseClipboard

    'Get the picture from the clipboard

    Me.Picture = Clipboard.GetData(vbCFBitmap)

End Sub


给你一个fan0217写的函数:
Function SendToScrap(strSendText As String) As Boolean
'===============================================================================
'-函数名称:         SendToScrap
'-功能描述:         发送文本到剪贴板
'-输入参数说明:     必选:strSendText As String 发送的文本
'-返回参数说明:     发送成功:True  发送失败:False
'-使用语法示例:     SendToScrap("你好!")
'-参考:
'-使用注意:         需要引用Microsoft Forms2.0 Object Library (%system32%\FM20.DLL)
'-兼容性:
'-作者:             fan0217 fan0217@163.com
'-更新日期:        2006-02-24
'===============================================================================
On Error GoTo Err_SendToScrap
Dim tmpData As New DataObject
    tmpData.SetText strSendText
    tmpData.PutInClipboard
   
    SendToScrap = True

Exit_SendToScrap:
    Exit Function

Err_SendToScrap:
    SendToScrap = False
    MsgBox Err.Description
    Resume Exit_SendToScrap
      
End Function

在文本框双击事件中调用:
    DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70  '此句是保存代码,如果是新输入的内容,不加这句将复制不到内容……
    SendToScrap (Me.Text1)
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享分享 分享淘帖 订阅订阅
2#
发表于 2004-8-24 16:37:00 | 只看该作者
直接用复制粘贴的命令,不够吗?
3#
 楼主| 发表于 2004-8-24 18:18:00 | 只看该作者
不行啊,我要把一个字符串放到剪切板上去!!![em03]
4#
发表于 2004-8-24 18:34:00 | 只看该作者
1。建议你用其他方法2。一定要用剪贴板的话,用API使用WINDOWS 的剪贴板OpenClipboardEmptyClipboardSetClipboardDataGetClipboardDataCloseClipboard非常繁
5#
 楼主| 发表于 2004-8-24 18:54:00 | 只看该作者
对对对了,就是要用到 SetClipboardData 要用哪个api 啊??我有点菜,写的具体点啊!![em02]
6#
发表于 2004-8-24 19:31:00 | 只看该作者
For you exampleConst LR_LOADFROMFILE = &H10

Const IMAGE_BITMAP = 0

Const IMAGE_ICON = 1

Const IMAGE_CURSOR = 2

Const IMAGE_ENHMETAFILE = 3

Const CF_BITMAP = 2

Private Declare Function LoadImage Lib "user32" Alias "LoadImageA" (ByVal hInst As Long, ByVal lpsz As String, ByVal dwImageType As Long, ByVal dwDesiredWidth As Long, ByVal dwDesiredHeight As Long, ByVal dwFlags As Long) As Long

Private Declare Function CloseClipboard Lib "user32" () As Long

Private Declare Function OpenClipboard Lib "user32" (ByVal hwnd As Long) As Long

Private Declare Function EmptyClipboard Lib "user32" () As Long

Private Declare Function SetClipboardData Lib "user32" (ByVal wFormat As Long, ByVal hMem As Long) As Long

Private Declare Function IsClipboardFormatAvailable Lib "user32" (ByVal wFormat As Long) As Long

Private Sub Form_Load()

       hBitmap = LoadImage(App.hInstance, "c:\windows\logow.sys", IMAGE_BITMAP, 320, 200, LR_LOADFROMFILE)

    If hBitmap = 0 Then

        MsgBox "There was an error while loading the bitmap"

        Exit Sub

    End If

    'open the clipboard

    OpenClipboard Me.hwnd

    'Clear the clipboard

    EmptyClipboard

    'Put our bitmap onto the clipboard

    SetClipboardData CF_BITMAP, hBitmap

    'Check if there's a bitmap on the clipboard

    If IsClipboardFormatAvailable(CF_BITMAP) = 0 Then

        MsgBox "There was an error while pasting the bitmap to the clipboard!"

    End If

    'Close the clipboard

    CloseClipboard

    'Get the picture from the clipboard

    Me.Picture = Clipboard.GetData(vbCFBitmap)

End Sub

7#
 楼主| 发表于 2004-8-24 19:36:00 | 只看该作者
谢谢!!!![em02][em02][em02][em02]
8#
发表于 2007-8-8 09:57:15 | 只看该作者
给你一个fan0217写的函数:
Function SendToScrap(strSendText As String) As Boolean
'===============================================================================
'-函数名称:         SendToScrap
'-功能描述:         发送文本到剪贴板
'-输入参数说明:     必选:strSendText As String 发送的文本
'-返回参数说明:     发送成功:True  发送失败:False
'-使用语法示例:     SendToScrap("你好!")
'-参考:
'-使用注意:         需要引用Microsoft Forms2.0 Object Library (%system32%\FM20.DLL)
'-兼容性:
'-作者:             fan0217 fan0217@163.com
'-更新日期:        2006-02-24
'===============================================================================
On Error GoTo Err_SendToScrap
Dim tmpData As New DataObject
    tmpData.SetText strSendText
    tmpData.PutInClipboard
   
    SendToScrap = True

Exit_SendToScrap:
    Exit Function

Err_SendToScrap:
    SendToScrap = False
    MsgBox Err.Description
    Resume Exit_SendToScrap
      
End Function

在文本框双击事件中调用:
    DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70  '此句是保存代码,如果是新输入的内容,不加这句将复制不到内容……
    SendToScrap (Me.Text1)
您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|站长邮箱|小黑屋|手机版|Office中国/Access中国 ( 粤ICP备10043721号-1 )  

GMT+8, 2024-11-26 04:28 , Processed in 0.106621 second(s), 31 queries .

Powered by Discuz! X3.3

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表