| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 860 人关注过本帖
标题:[求助]VB6.0的一个看似极为简单的问题,请高手帮我做出!
取消只看楼主 加入收藏
潇潇儿
Rank: 1
等 级:新手上路
帖 子:18
专家分:0
注 册:2005-9-28
收藏
 问题点数:0 回复次数:2 
[求助]VB6.0的一个看似极为简单的问题,请高手帮我做出!
编制一个程序,在窗体上放一个Text1,text2,text3;
要求:
在这个程序运行时,把它最小化到后台,当别的程序在前台运行时,按键盘的“F2”,能使程序的Text1里的内容直接粘贴到当前程序的文本框里;按键盘的“F3”,能使程序的Text2里的内容直接粘贴到当前程序的文本框里;按键盘的“F4”,能使程序的Text3里的内容直接粘贴到当前程序的文本框里.



比如在文本框里输入111111
运行记事本,按“F2”直接粘贴出111111






搜索更多相关主题的帖子: 键盘 记事本 文本框 Text1 Text2 
2005-11-26 23:32
潇潇儿
Rank: 1
等 级:新手上路
帖 子:18
专家分:0
注 册:2005-9-28
收藏
得分:0 

以下代码,只可以在窗口里有一个text时,可以实现这个功能,可是现在需要有三个text,对应三个热键F2 F3 F4都可以使用,如何更改啊,大家帮我看看!

窗体的代码:
Option Explicit

Private Sub Form_Load()
Dim ret As Long

'记录原来的window程序地址
preWinProc = GetWindowLong(Me.hwnd, GWL_WNDPROC)
'用自定义程序代替原来的window程序
ret = SetWindowLong(Me.hwnd, GWL_WNDPROC, AddressOf Wndproc)

idHotKey = 1
uVirtKey = vbKeyF2
ret = RegisterHotKey(Me.hwnd, idHotKey, Modifiers, uVirtKey)
End Sub

Private Sub Form_Unload(Cancel As Integer)
Dim ret As Long
'取消Message的截取,使之送往原来的windows程序
ret = SetWindowLong(Me.hwnd, GWL_WNDPROC, preWinProc)
Call UnregisterHotKey(Me.hwnd, uVirtKey)
End Sub

Private Sub Text1_Change()

End Sub

模块1的代码:
Option Explicit

Declare Function SetWindowLong Lib "User32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Declare Function GetWindowLong Lib "User32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Declare Function CallWindowProc Lib "User32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hwnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Declare Function RegisterHotKey Lib "User32" (ByVal hwnd As Long, ByVal id As Long, ByVal fsModifiers As Long, ByVal vk As Long) As Long
Declare Function UnregisterHotKey Lib "User32" (ByVal hwnd As Long, ByVal id As Long) As Long

Public Const WM_HOTKEY = &H312
Public Const MOD_ALT = &H1
Public Const MOD_CONTROL = &H2
Public Const MOD_SHIFT = &H4
Public Const GWL_WNDPROC = (-4)

Public preWinProc As Long
Public Modifiers As Long, uVirtKey As Long, uVirtKey1 As Long, idHotKey As Long
Private Type taLong
ll As Long
End Type

Private Type t2Int
lWord As Integer
hWord As Integer
End Type

Public Function Wndproc(ByVal hwnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Dim KeyStr As String
KeyStr = frmMain.Text1.Text
If Msg = WM_HOTKEY Then
If wParam = idHotKey Then
Dim lp As taLong, i2 As t2Int
lp.ll = lParam
LSet i2 = lp
If (i2.lWord = Modifiers) And i2.hWord = uVirtKey Then
SendKeys KeyStr
End If
End If
End If
'如果不是热键信息则调用原来的程序
Wndproc = CallWindowProc(preWinProc, hwnd, Msg, wParam, lParam)

End Function


[此贴子已经被作者于2005-11-26 23:42:22编辑过]


My LiFE FOR NeTW0RK
2005-11-26 23:38
潇潇儿
Rank: 1
等 级:新手上路
帖 子:18
专家分:0
注 册:2005-9-28
收藏
得分:0 
请版主说明白点好吗?急啊~~谢谢了~你说的我没看懂啊?

My LiFE FOR NeTW0RK
2005-11-27 21:04
快速回复:[求助]VB6.0的一个看似极为简单的问题,请高手帮我做出!
数据加载中...
 
   



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

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