我们在所有的可编辑控件中可以看到的一闪一闪的光标在系统中是什么玩意儿? 我们在所有的可编辑控件中可以看到的一闪一闪的光标在系统中是什么玩意儿?字与字间有它的容身之处?越想越不明白了。有谁知道? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 那么高深的问题我怎么没想到。。这玩意儿从DOS时代就有了,听说教光标吧 输入一下东西到记事本保存为一个frm文件用vb打开VERSION 5.00Begin VB.Form Form1 Caption = "Lesson4_4" ClientHeight = 4185 ClientLeft = 60 ClientTop = 345 ClientWidth = 6690 LinkTopic = "Form1" ScaleHeight = 4185 ScaleWidth = 6690 StartUpPosition = 3 'Windows Default Begin VB.TextBox Text1 Height = 1350 Left = 1560 TabIndex = 1 Text = "Text1" Top = 2760 Width = 4935 End Begin VB.PictureBox Picture1 BackColor = &H00FFFFFF& Height = 2475 Left = 1560 ScaleHeight = 2415 ScaleWidth = 4875 TabIndex = 0 Top = 60 Width = 4935 End Begin VB.Label Label1 Caption = "Text控件" Height = 315 Left = 660 TabIndex = 3 Top = 2880 Width = 1335 End Begin VB.Label P Caption = "PictureBox控件" Height = 255 Left = 180 TabIndex = 2 Top = 240 Width = 1515 EndEndAttribute VB_Name = "Form1"Attribute VB_GlobalNameSpace = FalseAttribute VB_Creatable = FalseAttribute VB_PredeclaredId = TrueAttribute VB_Exposed = FalseOption ExplicitPrivate Declare Function CreateCaret& Lib "user32" (ByVal hwnd As Long, ByVal hBitmap As Long, ByVal nWidth As Long, ByVal nHeight As Long)Private Declare Function ShowCaret& Lib "user32" (ByVal hwnd As Long)Private Declare Function SetCaretPos& Lib "user32" (ByVal x As Long, ByVal y As Long)Private Declare Function HideCaret& Lib "user32" (ByVal hwnd As Long)Private Declare Function DestroyCaret& Lib "user32" ()Private Sub Form_Load() Form1.ScaleMode = vbPixels Picture1.ScaleMode = vbPixels Picture1.FontSize = 14End SubPrivate Sub Picture1_Click() ' Picture1_GotFocusEnd SubPrivate Sub Picture1_GotFocus() Dim dl& Dim CreateHeight As Integer CreateHeight = Picture1.TextHeight("I") dl& = CreateCaret(Picture1.hwnd, 0, 2, CreateHeight) dl& = SetCaretPos(Picture1.CurrentX, Picture1.CurrentY) dl& = ShowCaret(Picture1.hwnd)End SubPrivate Sub Picture1_KeyPress(KeyAscii As Integer) Dim dl& dl& = HideCaret(Picture1.hwnd) Picture1.Print Chr(KeyAscii); If Picture1.CurrentX >= (Picture1.Width - Picture1.TextWidth("W")) Then '换行 Picture1.CurrentX = 0 Picture1.CurrentY = Picture1.CurrentY + Picture1.TextHeight("I") End If dl& = SetCaretPos(Picture1.CurrentX, Picture1.CurrentY) dl& = ShowCaret(Picture1.hwnd)End SubPrivate Sub Picture1_LostFocus() Dim dl& ' dl& = DestroyCaretEnd Sub可以输入中文,但是输入法的那个小条不会出现 TO:tonylk(=www.tonixsoft.com=) 这个叫光标,地球人都知道。:)那关于这个叫Caret的东东,有详细介绍吗 根据Caret,先找到了些资料当窗口拥有键盘焦点或者处于激活状态时,可以创建一个Caret,失去焦点之前必须销毁该Caret。CreateCaret()函数用来创建Caret,系统将该函数指定的位置Pixel取反得到Caret。Caret建立后用ShowCaret()显示Caret并使其闪烁。获得闪烁速度(Flash Time)用GetBlinkTime()*2,设置闪烁时间用SetBlinkTime()/2,Flash Time是Caret从复原到反色再到复原的周期,而Get/SetBlinkTime()得到和设置的是Caret从复原到反色或者从反色到复原的时间,因此要乘/除2。获得Caret用GetCaretPos(),参数为一个POINT结构,存放Caret在当前窗口中的位置,SetCaretPos()在Caret不可见的情况下仍然起作用。暂时隐藏Caret使用HideCaret(),再显示用ShowCaret(),彻底销毁Caret用DestroyCaret。 一、 创建并显示Caret 改变或显示一个窗口的Caret,应捕获其WM_SETFOCUS消息 1、 CreateCaret()函数 CreateCaret(hWnd,(HBITMAP)NULL,30,60) hWnd:拥有Caret的窗口句柄 NULL:如果使用位图Caret,此参数为一个HBITMAP,该HBITMAP可以通过LoadBitmap、CreateBitmap和CreateDIBitmap获得,如果为NULL,将建立一个实心矩形光标。 30,60:光标的大小单位为逻辑单位,如果非NULL的位图句柄,这两个参数被忽略。 使用位图光标HBITMAP hbm;hbm=LoadBitmap((HINSTANCE)GetWindowLong(hWnd,GWL_HINSTANCE),MAKEINTRESOURCE(IDB_BITMAP1));CreateCaret(hWnd,(HBITMAP)hbm,0,0); 2、 为了精确确定Caret的大小,可以传递SM_CXBORDER和SM_CYBORDER给GetSystemMetics()函数获得以Pixel为计量单位的窗口的边框的宽和高,据此计算Caret的大小。 二、 使Caret随鼠标的移动而移动 1、 捕获WM_MOUSEMOVE消息: int x: int y; x=LOWORD(lParam); y=HIWORD(lParam); 获得事件发生时鼠标的位置 2、 将Caret移至光标处:SetCaretPos(x,y) 3、 在随鼠标移动的过程中Caret的闪烁效果不明显,鼠标停留片刻后,Caret恢复正常闪烁。 使用代码 ADODC控件 连接数据库 本人有2套知名企业的ERP源代码+全套文档资料开卖!能出得起钱的和我联系 如何检测inputbox中输入的字符串?在线等。急!!!!! 模块与窗体之间传递的问题 我有一个很棘手的问题,请大家帮忙。是关于vb控制word文件的。 vb怎样结束当前工程。 win98没法安装 如何对中文和英文混合字符串进行加密和解密(最好给我源程序)? VB下数据类型转换的问题 大家好!假期过完了!都说一说自己的趣事! datagrid 有没有响应 行首的click事件呢 如何实现这种权限管理
这玩意儿从DOS时代就有了,听说教光标吧
VERSION 5.00
Begin VB.Form Form1
Caption = "Lesson4_4"
ClientHeight = 4185
ClientLeft = 60
ClientTop = 345
ClientWidth = 6690
LinkTopic = "Form1"
ScaleHeight = 4185
ScaleWidth = 6690
StartUpPosition = 3 'Windows Default
Begin VB.TextBox Text1
Height = 1350
Left = 1560
TabIndex = 1
Text = "Text1"
Top = 2760
Width = 4935
End
Begin VB.PictureBox Picture1
BackColor = &H00FFFFFF&
Height = 2475
Left = 1560
ScaleHeight = 2415
ScaleWidth = 4875
TabIndex = 0
Top = 60
Width = 4935
End
Begin VB.Label Label1
Caption = "Text控件"
Height = 315
Left = 660
TabIndex = 3
Top = 2880
Width = 1335
End
Begin VB.Label P
Caption = "PictureBox控件"
Height = 255
Left = 180
TabIndex = 2
Top = 240
Width = 1515
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Private Declare Function CreateCaret& Lib "user32" (ByVal hwnd As Long, ByVal hBitmap As Long, ByVal nWidth As Long, ByVal nHeight As Long)
Private Declare Function ShowCaret& Lib "user32" (ByVal hwnd As Long)
Private Declare Function SetCaretPos& Lib "user32" (ByVal x As Long, ByVal y As Long)
Private Declare Function HideCaret& Lib "user32" (ByVal hwnd As Long)Private Declare Function DestroyCaret& Lib "user32" ()
Private Sub Form_Load()
Form1.ScaleMode = vbPixels
Picture1.ScaleMode = vbPixels
Picture1.FontSize = 14
End SubPrivate Sub Picture1_Click()
' Picture1_GotFocus
End SubPrivate Sub Picture1_GotFocus()
Dim dl&
Dim CreateHeight As Integer
CreateHeight = Picture1.TextHeight("I")
dl& = CreateCaret(Picture1.hwnd, 0, 2, CreateHeight)
dl& = SetCaretPos(Picture1.CurrentX, Picture1.CurrentY)
dl& = ShowCaret(Picture1.hwnd)
End SubPrivate Sub Picture1_KeyPress(KeyAscii As Integer)
Dim dl& dl& = HideCaret(Picture1.hwnd)
Picture1.Print Chr(KeyAscii);
If Picture1.CurrentX >= (Picture1.Width - Picture1.TextWidth("W")) Then '换行
Picture1.CurrentX = 0
Picture1.CurrentY = Picture1.CurrentY + Picture1.TextHeight("I")
End If
dl& = SetCaretPos(Picture1.CurrentX, Picture1.CurrentY)
dl& = ShowCaret(Picture1.hwnd)
End SubPrivate Sub Picture1_LostFocus()
Dim dl&
' dl& = DestroyCaret
End Sub可以输入中文,但是输入法的那个小条不会出现
那关于这个叫Caret的东东,有详细介绍吗
CreateCaret(hWnd,(HBITMAP)NULL,30,60) hWnd:拥有Caret的窗口句柄 NULL:如果使用位图Caret,此参数为一个HBITMAP,该HBITMAP可以通过LoadBitmap、CreateBitmap和CreateDIBitmap获得,如果为NULL,将建立一个实心矩形光标。 30,60:光标的大小单位为逻辑单位,如果非NULL的位图句柄,这两个参数被忽略。 使用位图光标HBITMAP hbm;
hbm=LoadBitmap((HINSTANCE)GetWindowLong(hWnd,GWL_HINSTANCE),MAKEINTRESOURCE(IDB_BITMAP1));
CreateCaret(hWnd,(HBITMAP)hbm,0,0); 2、 为了精确确定Caret的大小,可以传递SM_CXBORDER和SM_CYBORDER给GetSystemMetics()函数获得以Pixel为计量单位的窗口的边框的宽和高,据此计算Caret的大小。 二、 使Caret随鼠标的移动而移动 1、 捕获WM_MOUSEMOVE消息: int x:
int y;
x=LOWORD(lParam);
y=HIWORD(lParam); 获得事件发生时鼠标的位置 2、 将Caret移至光标处:SetCaretPos(x,y) 3、 在随鼠标移动的过程中Caret的闪烁效果不明显,鼠标停留片刻后,Caret恢复正常闪烁。