| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1444 人关注过本帖
标题:请教:用VB6打开网页,然后全选、复制,打开记事本,再粘贴
只看楼主 加入收藏
dingzhenrong
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2018-11-22
收藏
 问题点数:0 回复次数:2 
请教:用VB6打开网页,然后全选、复制,打开记事本,再粘贴
新手向老师请教,想用VB6完成这几个动作:1、用系统浏览器打开网页。2、在网页上右键--全选(也就是Ctrl+A)。3、Ctrl+C。4、Ctrl+V到记事本上。(不用WebBrowser或其他方法打开网页,只用浏览器打开)
第一步用下面的代码打开网页,后面3步就不会来了。请老师不吝赐教,在这先谢了!!!
Private Sub Command1_Click()
 OpenUrl "https://www.baidu.com/"
End Sub
Private Sub OpenUrl(tUrl As String)
 ShellExecute Me.hwnd, "Open", tUrl, 0, 0, 0
End Sub
搜索更多相关主题的帖子: VB6 打开 网页 全选 记事本 
2020-03-31 16:23
dingzhenrong
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2018-11-22
收藏
得分:0 
有请老师帮忙!!!
2020-04-01 11:39
时光流逝
Rank: 4
来 自:北京
等 级:业余侠客
威 望:8
帖 子:94
专家分:297
注 册:2019-11-16
收藏
得分:0 
程序代码:
Private Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal Scan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
Private Declare Function MapVirtualKey Lib "user32" Alias "MapVirtualKeyA" (ByVal wCode As Long, ByVal wMapType As Long) As Long
Private Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" ( _
ByVal hwnd As Long, _
ByVal lpOperation As String, _
ByVal lpFile As String, _
ByVal lpParameters As String, _
ByVal lpDirectory As String, _
ByVal nShowCmd As Long) _
As Long
Const KEYEVENTF_KEYUP = &H2 '释放按键
Const vbKeyControl = &H11 '释放按键
Const vbKeyA = &H65 '释放按键
Const vbKeyC = &H67 '释放按键
Const vbKeyV = &H86 '释放按键
Private Function Shell_Ex(ExeName As String) As Boolean '异步执行外部程序
 Dim Id As Long, Name As String

 Name = Mid(ExeName, InStrRev(ExeName, "\") + 1)

 Id = Shell(ExeName, vbNormalFocus)

 

 On Error Resume Next

 Dim objWMIService, colProcessList, objProcess

 Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")

 Do

 Shell_Ex = True

 Set colProcessList = objWMIService.ExecQuery _

 ("Select * from Win32_Process Where Name='" & Name & "' and handle='" & Id & "'")

 For Each objProcess In colProcessList

 Shell_Ex = False

 Exit For

 Next

 DoEvents

 Loop Until Shell_Ex = True

 Set objProcess = Nothing

 Set colProcessList = Nothing

 Set objWMIService = Nothing
End Function
Private Sub OpenUrl(Url As String)
    ShellExecute Me.hwnd, "Open", Url, 0, 0, 0
End Sub
Private Sub OpenNotePad()
    Shell_Ex "c:\windows\notepad.exe"
End Sub
Private Sub AllSelect()
    keybd_event vbKeyControl, 0, 0, 0 '按下Ctrl键
    keybd_event vbKeyA, 0, 0, 0 '按下A键
    keybd_event vbKeyA, 0, KEYEVENTF_KEYUP, 0 '释放A键
    keybd_event vbKeyControl, 0, KEYEVENTF_KEYUP, 0 '释放Ctrl键
End Sub
Private Sub AllCopy()
    keybd_event vbKeyControl, 0, 0, 0 '按下Ctrl键
    keybd_event vbKeyC, 0, 0, 0 '按下C键
    keybd_event vbKeyC, 0, KEYEVENTF_KEYUP, 0 '释放C键
    keybd_event vbKeyControl, 0, KEYEVENTF_KEYUP, 0 '释放Ctrl键
End Sub
Private Function GetHandle(Title As String) As Long
    Dim hWindow: hWindow = FindWindow(vbNullString, Title)
    If hWindow Then '如果获取句柄成功
        GetHandle = FindWindowEx(hWindow, 0, "Edit", vbNullString)
    End If
End Function
Private Sub AllPaste(hwnd As Long)
    PostMessage Me.hwnd, WM_KEYDOWN, vbKeyControl, MapVirtualKey(vbKeyControl, 0) ' 模拟按下 Ctrl 键
    PostMessage Me.hwnd, WM_KEYDOWN, vbKeyV, MapVirtualKey(vbKeyV, 0) ' 模拟按下 V 键
    PostMessage Me.hwnd, WM_KEYUP, vbKeyV, MapVirtualKey(vbKeyV, 0) ' 模拟抬起 V 键
    PostMessage Me.hwnd, WM_KEYUP, vbKeyControl, MapVirtualKey(vbKeyControl, 0) ' 模拟抬起 Ctrl 键
End Sub
Private Sub Form_Load()
    'Dim Url:Url=InputBox("请输入URL:")
    Dim Url As String '这里一定要定义为String类型,否则IDE会崩溃
    Url = InputBox("请输入URL:")
    OpenUrl Url
    AllSelect
    AllCopy
    OpenNotePad
    AllPaste GetHandle("无标题 - 记事本")
End Sub

这段代码理论上能运行,我没测试过
2020-04-08 08:53
快速回复:请教:用VB6打开网页,然后全选、复制,打开记事本,再粘贴
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.024884 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved