怎样才能获得当前具有输入焦点的句柄?

bernard 2002-07-10 02:58:38
我想作一个类似软键盘的东西,用sendkeys 把字符传到其他程序中。
...全文
35 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
bernard 2002-07-11
  • 打赏
  • 举报
回复
已用如下方法实现,谢谢二位
Public Declare Function SetForegroundWindow Lib "user32" Alias "SetForegroundWindow" (ByVal hwnd As Integer) As Integer
Public Declare Function GetForegroundWindow Lib "user32" Alias "GetForegroundWindow" () As Integer
Public WinHld As Integer

Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
'Get the windows' handlle if it's not Me, the send the french word.
Dim hldtmp As Integer
hldtmp = GetForegroundWindow
If hldtmp <> Me.Handle.ToInt32 Then
WinHld = hldtmp
End If
End Sub

Private Sub Button1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Button1.MouseUp
SetForegroundWindow(WinHld)

Windows.Forms.SendKeys.Send("œ")
End Sub
kill2003 2002-07-10
  • 打赏
  • 举报
回复
'This Project needs
'- two timers, interval=100
'- a button

'in general section
Private Type POINTAPI
x As Long
y As Long
End Type

Private Declare Function GetActiveWindow Lib "user32" () As Long
Private Declare Function GetWindowDC Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function Ellipse Lib "gdi32" (ByVal hdc As Long, ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long

Private Declare Function TextOut Lib "gdi32" Alias "TextOutA" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal lpString As String, ByVal nCount As Long) As Long
Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Private Sub Form_Load()
Timer1.Interval = 100
Timer1.Enabled = True
Timer2.Interval = 100
Timer2.Enabled = True
Command1.Caption = "Draw Text"
End Sub
'This will draw an Ellipse on the active window
Sub Timer1_Timer()
Dim Position As POINTAPI
'Get the cursor position
GetCursorPos Position
'Draw the Ellipse on the Screen's DC
Ellipse GetWindowDC(0), Position.x - 5, Position.y - 5, Position.x + 5, Position.y + 5
End Sub
Sub Command1_Click()
'KPD-Team 1998
'URL: http://www.allapi.net/
'E-Mail: KPDTeam@Allapi.net

Dim intCount As Integer, strString As String
strString = "Cool, text on screen !"
For intCount = 0 To 30
'Draw the text on the screen
TextOut GetWindowDC(0), intCount * 20, intCount * 20, strString, Len(strString)
Next intCount
End Sub
Private Sub Timer2_Timer()
'Draw the text to the active window
TextOut GetWindowDC(GetActiveWindow), 50, 50, "This is a form", 14
End Sub
kill2003 2002-07-10
  • 打赏
  • 举报
回复
【VB声明】
Private Declare Function GetActiveWindow Lib "user32" Alias "GetActiveWindow" () As Long

【说明】
获得活动窗口的句柄

【返回值】
Long,活动窗口的句柄,如没有窗口处于活动状态,则返回零值
kill2003 2002-07-10
  • 打赏
  • 举报
回复
【VB声明】
Private Declare Function GetActiveWindow Lib "user32" Alias "GetActiveWindow" () As Long

【说明】
获得活动窗口的句柄

【返回值】
Long,活动窗口的句柄,如没有窗口处于活动状态,则返回零值

7,763

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧