我如何在下边弹出的txt文本中获取焦点?
我现在无法在弹出的窗体的获取焦点。'Option ExplicitPrivate Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long) As Long
'该函数获得有关指定窗口的信息,函数也获得在额外窗口内存中指定偏移位地址的32位度整型值。
Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
'该函数改变指定窗口的属性.函数也将指定的一个32位值设置在窗口的额外存储空间的指定偏移位置。
Private Declare Function GetWindowRect Lib "user32" (ByVal hWnd As Long, lpRect As RECT) As Long
'该函数返回指定窗口的边框矩形的尺寸。该尺寸以相对于屏幕坐标左上角的屏幕坐标给出。
Private Declare Function GetClientRect Lib "user32" (ByVal hWnd As Long, lpRect As RECT) As Long
'该函数获取窗口客户区的坐标。客户区坐标指定客户区的左上角和右下角。由于客户区坐标是相对子窗口客户区的左上角而言的,因此左上角坐标为(0,0)
Private Declare Function SetWindowPos Lib "user32" (ByVal hWnd As Long, ByVal hWndInsertAfter As Long, ByVal X As Long, ByVal Y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
'该函数改变一个子窗口,弹出式窗口式顶层窗口的尺寸,位置和Z序。子窗口,弹出式窗口,及顶层窗口根据它们在屏幕上出现的顺序排序、顶层窗口设置的级别最高,并且被设置为Z序的第一个窗口。
Private Declare Function ShowWindow Lib "user32" (ByVal hWnd As Long, ByVal nCmdShow As Long) As Long
'该函数设置指定窗口的显示状态。
'Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
'该函数检取光标的位置,以屏幕坐标表示。
Private Declare Function GetParent Lib "user32" (ByVal hWnd As Long) As Long
'该函数获得一个指定子窗口的父窗口句柄。
Private Declare Function SetParent Lib "user32" (ByVal hWndChild As Long, ByVal hWndNewParent As Long) As Long
'该函数改变某个子窗口的父窗口。
Private Declare Function GetFocus Lib "user32" () As Long
'确定当前焦点位于哪个控件上。
Private Declare Function GetCapture Lib "user32" () As Long
'该函数取得捕获了鼠标的窗口(如果存在)的句柄。在同一时刻,只有一个窗口能捕获鼠标;此时,该窗口接收鼠标的输入,无论光标是否在其范围内。
Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
'判断函数调用时指定虚拟键的状态
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
'该函数将指定的消息发送到一个或多个窗口。此函数为指定的窗口调用窗口程序,直到窗口程序处理完消息再返回。而函数PostMessage不同,将一个消息寄送到一个线程的消息队列后立即返回。
'Private Type POINTAPI
' X As Long
' Y As Long
'End Type
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
'----------------lbj
Enum GridListKind
Data = 1 '直接绑定数据库
AddItem = 2 '用listGrid.additem增加
End Enum
'
Enum SBorderKind
Line = 1 '下划线
Box = 2 '方框
End Enum
''----------------lbj
Private Const GWL_EXSTYLE As Long = (-20)
Private Const HWND_TOPMOST As Long = -1
Private Const SW_HIDE As Long = 0
Private Const SW_SHOW As Long = 5
Private Const SWP_NOSIZE As Long = &H1
Private Const WS_EX_TOOLWINDOW As Long = &H80
Private Const WM_KILLFOCUS As Long = &H8
Private Const WM_KEYDOWN As Long = &H100
Private Const WM_MOUSEWHEEL As Long = &H20A ' 鼠标滚轮消息
Private Const VK_LBUTTON As Long = &H1
Private Const VK_RBUTTON As Long = &H2
Private m_bDropDown As Boolean ' 是否显示 Grid
Private m_bSubclass As Boolean ' 是否已经子类处理
Private TextVisible As Boolean
'Implements ISubclass
'-----------------------lbj
Public ListGrid As TextBox
Public ReturnCol As Integer '返回列
'-----------------------lbj
'事件声明:
Event KeyDown(KeyCode As Integer, Shift As Integer) 'MappingInfo=txtEdit,txtEdit,-1,KeyDown
Event ListAddItem()
Event Change() 'MappingInfo=txtEdit,txtEdit,-1,Change
'
''------Kind属性lbj
'缺省属性值:
Const m_def_InRemark = False
Const m_def_TextWidth = 5000
Const m_def_HiddeCol = ""
Const m_def_CaptionInBox = False
Const m_def_Tag2 = ""
Const m_def_CaptionYN = True
'Const m_def_TextWidth = 5000
Const m_def_TextHeight = 2500
Const m_def_IsKey = False
Const m_def_IsNull = False
'Const m_def_TextWidth = 0
'Const m_def_TextHeight = 50
Const m_def_BorderKind = 1
Const m_def_DataKind = 1
Const m_def_DataField = ""
''属性变量:
Dim m_InRemark As Boolean
Dim m_TextWidth As Integer
Dim m_HiddeCol As String
Dim m_CaptionInBox As Boolean
Dim m_Tag2 As String
Dim m_CaptionYN As Boolean
Dim m_TextHeight As Variant
Dim m_IsKey As Boolean
Dim m_IsNull As Boolean
'Dim m_TextWidth As Variant
'Dim m_TextHeight As Variant
Dim m_BorderKind As SBorderKind
Dim m_DataField As String
Public TextBox As TextBox
Dim lScrWidth As Long
Dim lScrHeight As Long
Dim tR1 As RECT
Dim tR2 As RECT
Private Sub btnDropDown_Click()
If TextVisible = False Then
showdropdown2
Else
TextVisible = False
ShowWindow DictGrid.hWnd, SW_HIDE
End If
End Sub
Private Sub UserControl_Resize()
On Error Resume Next
UserControl.Height = 375
' If m_CaptionYN = True Then '有标题
Label1.Move 180, 90
Label1.Height = UserControl.Height - 30
Label1.Visible = True
txtEdit.Left = Label1.Left + Label1.Width + 150
txtEdit.Top = 80
txtEdit.Height = UserControl.ScaleHeight - txtEdit.Top - 30
If m_InRemark = True Then
If m_TextWidth = 0 Then m_TextWidth = Format(UserControl.ScaleWidth / 2, "####0")
txtEdit.Width = m_TextWidth
LabRemark.Visible = True
btnDropDown.Move txtEdit.Left + txtEdit.Width + 30, txtEdit.Top - 20, 255, btnDropDown.Height
LabRemark.Left = btnDropDown.Left + btnDropDown.Width + 50
LabRemark.Move LabRemark.Left, 90
Else
txtEdit.Width = UserControl.ScaleWidth - txtEdit.Left - btnDropDown.Width - 60
LabRemark.Visible = False
btnDropDown.Move ScaleWidth - 255 - 60 + 30, txtEdit.Top - 20, 255, btnDropDown.Height
End If
If m_CaptionInBox = True Then
Shape2.Left = 0
Else
Shape2.Left = txtEdit.Left - 30
End If
Shape1.Left = Shape2.Left
Shape1.Top = 0
Shape1.Width = UserControl.ScaleWidth - Shape1.Left
Shape1.Height = UserControl.ScaleHeight
Shape2.Left = Shape1.Left
Shape2.Top = UserControl.ScaleHeight - 10
Shape2.Width = Shape1.Width
Shape2.Height = 15
End Sub
Private Sub showdropdown2()
'If Not m_bDropDown Then
' 调整 Grid 的大小
' ...
SetWindowLong DictGrid.hWnd, GWL_EXSTYLE, GetWindowLong(DictGrid.hWnd, GWL_EXSTYLE) Or WS_EX_TOOLWINDOW
SetParent DictGrid.hWnd, 0
lScrWidth = Screen.Width / Screen.TwipsPerPixelX
lScrHeight = Screen.Height / Screen.TwipsPerPixelY
GetWindowRect txtEdit.hWnd, tR1 ' 获取 Text 的位置
GetClientRect DictGrid.hWnd, tR2 ' 获取 Grid 的大小
'DictGrid.Text = "showdropdown2"
' 计算显示位置,显示位置不能超出屏幕范围
If tR1.Left < 0 Then
tR1.Left = 0
End If
If tR1.Left + tR2.Right > lScrWidth Then
tR1.Left = lScrWidth - tR2.Right
End If
If tR1.Bottom < 0 Then
tR1.Bottom = 0
End If
If tR1.Bottom + tR2.Bottom > lScrHeight Then
' 从上方显示
tR1.Bottom = tR1.Top - tR2.Bottom - UserControl.Height / Screen.TwipsPerPixelY + 60 / Screen.TwipsPerPixelY
End If
If tR2.Right < tR1.Right - tR1.Left Then
tR2.Right = tR1.Right - tR1.Left
End If
' 设置 Grid 的位置
SetWindowPos DictGrid.hWnd, HWND_TOPMOST, tR1.Left - 2, tR1.Bottom + 2, 0, 0, SWP_NOSIZE
TextVisible = True
DictGrid.Enabled = True
DictGrid.SetFocus
End Sub
' 关闭 DropDown
Private Sub CloseDropDown()
' If m_bDropDown Then
ShowWindow DictGrid.hWnd, SW_HIDE
m_bDropDown = False
' End If
End Sub
直接描述你碰到的问题,贴一堆代码谁有那闲工夫给你慢慢看啊 你的代码中控件的名字都不是默认的,看起来够费劲的 +1
补充:VB , 控件