tooltip 在数据窗口中的用法
Long ii_dwID
inv_Tooltip.of_SetMaxWidth( 1500 )
inv_Tooltip.of_SetTipTitle( inv_Tooltip.TTI_INFO, ls_Roomno )
ii_dwID = inv_ToolTip.of_AddTool(dw_4, "" , 0 )
inv_Tooltip.of_SettipText( This, ii_dwID, '测试aaa' )
我在Clicked 或者 自定义 pbm_mousemove 事件.当我点一下的时候不会弹出信息.总是要再移动一下鼠标才能弹出信息出来
[解决办法]
看一下你的of_setiptext是怎么写的?
或者单步跟踪一下
如果你用的是pb11以上的版本,数据窗口的列有tip属性,设置即可
[解决办法]
有数据窗口tip示例,如果需要可发至邮箱
[解决办法]
forward
global type n_cst_dwsrv_autohint from nonvisualobject
end type
type logfont from structure within n_cst_dwsrv_autohint
end type
type textsize from structure within n_cst_dwsrv_autohint
end type
end forward
type logfont from structure
longlfHeight
longlfWidth
longlfEscapement
longlfOrientation
longlfWeight
characterlfItalic
characterlfUnderline
characterlfStrikeOut
characterlfCharSet
characterlfOutPrecision
characterlfClipPrecision
characterlfQuality
characterlfPitchAndFamily
stringlfFaceName
end type
type textsize from structure
longl_cx
longl_cy
end type
global type n_cst_dwsrv_autohint from nonvisualobject
event type long ue_mousemove ( unsignedlong flags, integer xpos, integer ypos )
event type long resize ( unsignedlong sizetype, integer newwidth, integer newheight )
end type
global n_cst_dwsrv_autohint n_cst_dwsrv_autohint
type prototypes
FUNCTION ulong GetDC(ulong hwnd) LIBRARY "user32.dll"
FUNCTION ulong ReleaseDC(ulong hwnd,ulong hdc) LIBRARY "user32.dll"
FUNCTION ulong SelectObject(ulong hdc,ulong hObject) LIBRARY "gdi32.dll"
FUNCTION ulong DeleteObject(ulong hObject) LIBRARY "gdi32.dll"
FUNCTION ulong CreateFontIndirect(ref LOGFONT lpLogFont) LIBRARY "gdi32.dll" ALIAS FOR "CreateFontIndirectA"
FUNCTION ulong GetTextExtentExPoint(ulong hdc,ref string lpszStr,ulong cchString,ulong nMaxExtent,ref ulong lpnFit,ref ulong alpDx,ref textSIZE lpSize) LIBRARY "gdi32.dll" ALIAS FOR "GetTextExtentExPointA"
FUNCTION ulong GetTextExtentPoint32(ulong hdc,ref string lpsz,ulong cbString,ref textSIZE lpSize) LIBRARY "gdi32.dll" ALIAS FOR "GetTextExtentPoint32A"
Function long MulDiv (long nNumber, long nNumerator, long nDenominator) Library "KERNEL32.DLL"
FUNCTION ulong GetDeviceCaps(ulong hdc,ulong nIndex) LIBRARY "gdi32.dll"
end prototypes
type variables
Private:
DataWindow idw_requestor
nvo_tooltips ToolTip
String is_prior_dwo
end variables
forward prototypes
public function long of_gettextwidth (string as_colname, string as_text)
public subroutine of_replacestring (ref string as_src, string as_oldstr, string as_newstr)
public function integer of_setrequestor (datawindow adw_requestor)
end prototypes
event type long ue_mousemove(unsignedlong flags, integer xpos, integer ypos);String ls_dwo,ls_col,ls_text
Long ll_row
Int li_pos
ls_dwo = idw_requestor.GetObjectAtPointer()
If is_prior_dwo = ls_dwo Then
Return 0
Else
is_prior_dwo = ls_dwo
End If
If Tooltip.tipvisible() or flags <> 0 Then
Tooltip.hidetip(idw_requestor)
end if
li_pos = Pos(ls_dwo, "~t")
If li_pos <= 0 Then Return 0
ls_col = Left (ls_dwo, li_pos - 1 )
ll_row = Long(Mid(ls_dwo,li_pos + 1 ))
If idw_requestor.Describe(ls_col+".Type") <> "column" Then Return 0 //不是列对象
Long ll_width,ll_needWidth,ll_x
String ls_editSty
ll_width = Long(idw_requestor.Describe(ls_col+".Width"))
ll_x = Long(idw_requestor.Describe(ls_col+".x"))
ls_editSty = idw_requestor.Describe(ls_col+".Edit.Style")
If ls_editSty = "editmask" Then //有掩码
Int li_colNum
String ls_mask
li_colNum = Integer(idw_requestor.Describe(ls_col+".ID"))
ls_mask = idw_requestor.Describe(ls_col+".EditMask.Mask")
If Left(idw_requestor.Describe(ls_col+".Coltype"),4) = "char" Then //字符型掩码
//字符可以转化为数字(直接用string(s,"##")得不到)
of_replaceString(ls_mask,"#","@")
ls_text = String(idw_requestor.Object.Data[ll_row,li_colNum],ls_mask)
Else //其它类型掩码
////messagebox("",ls_mask)
ls_text = String(idw_requestor.Object.Data[ll_row,li_colNum],ls_mask)
End If
Else
//当前行列值(便于dddw,ddlb得到显示值)
ls_text = idw_requestor.Describe("Evaluate('LookUpDisplay("+ls_col+")',"+String(ll_row)+")")
End If
//需要宽度
ll_needWidth = of_getTextWidth(ls_col,ls_text)
If ls_editSty = "checkbox" Or ls_editSty = "radiobuttons" Then
//这两种类型需要加个额外值
ll_needWidth+= 86
End If
//列的宽度不够 或者 位于显示的最右列,只能显示一部分
If ll_width < ll_needWidth Or &
ll_x+ll_width >= idw_requestor.Width +Long(idw_requestor.Object.DataWindow.HorizontalScrollPosition) Then
//修改Tip
Tooltip.SetTipText( idw_requestor, Tooltip.ToolID - 1,ls_text)
Tooltip.relaymsg(idw_requestor)
Return 0
End If
Return 0
end event
event type long resize(unsignedlong sizetype, integer newwidth, integer newheight);If sizetype <> 1 Then
Tooltip.updatetiprect(idw_requestor,Tooltip.ToolID - 1 ,0,0,&
UnitsToPixels(idw_requestor.Width, XUnitsToPixels!),UnitsToPixels(idw_requestor.Height, YUnitsToPixels!) )
End If
Return 0
end event
public function long of_gettextwidth (string as_colname, string as_text);//根据列名和文本,得到文本的显示宽度
//得到字体相关信息
Int li_charset
li_charset = Integer(idw_requestor.Describe(as_colName+".Font.CharSet"))
Int li_Escapement
li_Escapement = Integer(idw_requestor.Describe(as_colName+".Font.Escapement"))
String ls_Face
ls_Face = idw_requestor.Describe(as_colName+".Font.Face")
Int li_Family
li_Family = Integer(idw_requestor.Describe(as_colName+".Font.Family"))
Int li_height
li_height = Integer(idw_requestor.Describe(as_colName+".Font.Height"))
Int li_Italic
li_Italic = Integer(idw_requestor.Describe(as_colName+".Font.Italic"))
Int li_Pitch
li_Pitch = Integer(idw_requestor.Describe(as_colName+".Font.Pitch"))
Int li_Strikethrough
li_Strikethrough = Integer(idw_requestor.Describe(as_colName+".Font.Strikethrough"))
Int li_Underline
li_Underline = Integer(idw_requestor.Describe(as_colName+".Font.Underline"))
Int li_Weight
li_Weight = Integer(idw_requestor.Describe(as_colName+".Font.Weight"))
Int li_Width
li_Width = Integer(idw_requestor.Describe(as_colName+".Font.Width"))
Longll_newFont,ll_oldFont,ll_hdc
LOGFONT lst_Font
lst_Font.lfWeight = li_Weight
lst_Font.lfWidth = li_Width
If li_Italic = 1 Then
lst_Font.lfItalic = Char(255)
Else
lst_Font.lfItalic = Char(0)
End If
If li_Underline = 1 Then
lst_Font.lfUnderline = Char(1)
Else
lst_Font.lfUnderline = Char(0)
End If
If li_Strikethrough = 1 Then
lst_Font.lfStrikeOut = Char(1)
Else
lst_Font.lfStrikeOut = Char(0)
End If
//DEFAULT_CHARSET
lst_Font.lfCharSet = Char(li_charset)
lst_Font.lfOutPrecision = Char(0)
lst_Font.lfClipPrecision = Char(0)
lst_Font.lfQuality = Char(0)
lst_Font.lfPitchAndFamily = Char(0)
lst_Font.lfFaceName = ls_Face
ll_hdc = getdc(Handle(idw_requestor))
//以点为大小单位的字体转变成设备所需要的恰当的逻辑大小
//LOGPIXELSY=90
//muldiv : abs(li_Height)*getdevicecaps(ll_hdc,90)/72
lst_Font.lfHeight = - muldiv(Abs(li_height),getdevicecaps(ll_hdc,90),72)
//用指定的属性创建逻辑字体
ll_newFont = CreateFontIndirect(lst_Font)
//选入
ll_oldFont = SelectObject(ll_hdc,ll_newFont)
TextSize lstr_Size
//判断字串的大小
GetTextExtentpoint32(ll_hdc, as_text, Len(as_text), lstr_Size )
//恢复
SelectObject(ll_hdc,ll_oldFont)
//释放资源
DeleteObject(ll_newFont)
ReleaseDC(Handle(idw_requestor),ll_hdc)
//返回宽度(unit单位)
Return PixelsToUnits(lstr_Size.l_cx,XPixelsToUnits!)
end function
public subroutine of_replacestring (ref string as_src, string as_oldstr, string as_newstr);Int start_pos = 0
// Find the first occurrence of old_str.
start_pos = Pos(as_src, as_oldstr)
// Only enter the loop if you find old_str.
Do While start_pos > 0
// Replace old_str with new_str.
as_src = Replace(as_src, start_pos, &
Len(as_oldstr), as_newstr)
// Find the next occurrence of old_str.
start_pos = Pos(as_src, as_oldstr, &
start_pos+Len(as_newstr))
Loop
end subroutine
public function integer of_setrequestor (datawindow adw_requestor);If IsNull(adw_requestor) Or Not IsValid(adw_requestor) Then
Return -1
End If
idw_Requestor = adw_requestor
toolTip.addtool(adw_requestor,"",0)
Return 1
end function
on n_cst_dwsrv_autohint.create
call super::create
TriggerEvent( this, "constructor" )
end on
on n_cst_dwsrv_autohint.destroy
TriggerEvent( this, "destructor" )
call super::destroy
end on
[解决办法]
forward
global type nvo_tooltips from nonvisualobject
end type
type point from structure within nvo_tooltips
end type
type msg from structure within nvo_tooltips
end type
type rect from structure within nvo_tooltips
end type
type toolinfo from structure within nvo_tooltips
end type
end forward
type point from structure
longx
longy
end type
type msg from structure
longhwnd
longmessage
longwparam
longlparam
longtime
pointpt
end type
type rect from structure
longleft
longtop
longright
longbottom
end type
type toolinfo from structure
longcbsize
longuflags
longhwnd
longuid
rectrect
longhinstance
stringlpsztext
end type
global type nvo_tooltips from nonvisualobject autoinstantiate
end type
type prototypes
// ToolTips函数
SubRoutine InitCommonControls() library "comctl32.dll"
Function long CreateWindowExA(ulong dwExStyle, string ClassName, &
long WindowName, ulong dwStyle, ulong X, ulong Y, ulong nWidth, &
ulong nHeight, ulong hWndParent, ulong hMenu, ulong hInstance, &
ulong lpParam) library "user32.dll"
Function integer DestroyWindow(long hWnd) library "user32.dll"
Function integer ToolTipMsg(long hWnd, long uMsg, long wParam, &
REF TOOLINFO ToolInfo) library "user32.dll" Alias For "SendMessageA"
Function integer RelayMsg(long hWnd, long uMsg, long wParam, &
REF MSG Msg) library "user32.dll" Alias For "SendMessageA"
Function uLong SendMessageString( uLong hwnd, uLong Msg, uLong wParam, Ref String lpzString ) Library "user32.dll" Alias For "SendMessageA"
FUNCTION ulong ShowWindow(ulong hwnd,ulong nCmdShow) LIBRARY "user32.dll"
//内存管理函数
//Function long LocalAlloc(long Flags, long Bytes) library "kernel32.dll"
//Function long LocalFree(long MemHandle) library "kernel32.dll"
//Function long lstrcpy(long Destination, string Source) library "kernel32.dll"
FUNCTION ulong IsWindowVisible(ulong hwnd) LIBRARY "user32.dll"
end prototypes
type variables
//私有常量
Private:
//杂项常量
CONSTANT stringTOOLTIPS_CLASS = 'tooltips_class32'
CONSTANT ulongCW_USEDEFAULT = 2147483648
CONSTANT longWM_USER = 1024
CONSTANT longWS_EX_TOPMOST = 8
CONSTANT longWM_SETFONT = 48
// ToolTip Messages
Constant long TTM_ADDTOOL = WM_USER + 4
Constant long TTM_DELTOOL = WM_USER + 5
Constant long TTM_NEWTOOLRECT= WM_USER + 6
Constant long TTM_RELAYEVENT = WM_USER + 7
Constant long TTM_POPUP =WM_USER + 34
Constant long TTM_UPDATE= WM_USER + 29
Constant long TTM_UPDATETIPTEXT= WM_USER + 12
Constant long TTM_TRACKACTIVATE= WM_USER + 17
Constant long TTM_TRACKPOSITION= WM_USER + 18
Constant long TTM_SETMAXTIPWIDTH= 1048
Constant long TTM_GETMAXTIPWIDTH= WM_USER + 25
Constant long TTM_SETTIPBKCOLOR= WM_USER + 19
Constant long TTM_SETTIPTEXTCOLOR= WM_USER + 20
Constant long TTM_SETTITLEA = WM_USER + 32
// Tooltip flags
Constant integer TTF_CENTERTIP = 2
Constant integer TTF_RTLREADING= 4
Constant integer TTF_SUBCLASS= 16
Constant integer TTF_TRACK= 32
Constant integer TTF_ABSOLUTE= 128
Constant integer TTF_TRANSPARENT= 256
Constant integer TTF_DI_SETITEM= 32768
Constant integer TTS_BALLOON = 64
//Title Constants
Constant integer TTI_NONE = 0
Constant integer TTI_INFO = 1
Constant integer TTI_WARNING = 2
Constant integer TTI_ERROR = 3
//公共变量和常量
Public:
long hWndTT=0// Tooltip control window handle
long ToolID = 1// Tooltip internal ID
CONSTANT integer STYLE_NORMAL = 0
CONSTANT integer STYLE_BALLOONTIP = 1
integer TIPSTYLE
end variables
forward prototypes
public subroutine setfont (long hfont)
public subroutine settipposition (integer x, integer y)
public subroutine settrack (dragobject object, integer uid, boolean status)
public subroutine updatetiprect (dragobject object, long uid, long left, long top, long right, long bottom)
public function integer addtool (dragobject object, string tiptext, integer flags)
public subroutine hidetip (dragobject controlobject)
public subroutine settiptext (dragobject object, long uid, string tiptext)
public subroutine setmaxwidth (long al_maxwidth)
public function integer removetool (dragobject ado_object, integer ai_toolid)
public subroutine settiptitle (integer ai_icon, string as_title)
public subroutine settipbkcolor (long aul_color)
public subroutine relaymsg (dragobject object)
public function boolean tipvisible ()
public subroutine relaymsg (dragobject object, long wordparm, integer longparm)
end prototypes
public subroutine setfont (long hfont);//此函数用于设置ToolTips窗口的字体,代码如下:
Send(hWndTT,WM_SETFONT,hFont,1)
end subroutine
public subroutine settipposition (integer x, integer y);//此函数用于设置ToolTips的位置,代码如下:
Send(hWndTT,TTM_TRACKPOSITION,0,Long(X,Y))
end subroutine
public subroutine settrack (dragobject object, integer uid, boolean status);//此函数用于激活或取消ToolTips窗口设置新文本,代码如下:
//参数Status为True时激活,为False时取消
TOOLINFO ToolInfo
ToolInfo.cbSize = 40
ToolInfo.hWnd = Handle(Object)
ToolInfo.uID = uID
If Status Then
ToolTipMsg(hWndTT,TTM_TRACKACTIVATE,1,ToolInfo)
Else
ToolTipMsg(hWndTT,TTM_TRACKACTIVATE,0,ToolInfo)
End If
end subroutine
public subroutine updatetiprect (dragobject object, long uid, long left, long top, long right, long bottom);//此函数用于更新ToolTips的矩形框,代码如下:
TOOLINFO TOOLINFO
TOOLINFO.hWnd = Handle(Object)
TOOLINFO.uID = uID
TOOLINFO.Rect.Left = Left
TOOLINFO.Rect.Top = Top
TOOLINFO.Rect.Right = Right
TOOLINFO.Rect.Bottom = Bottom
ToolTipMsg(hWndTT,TTM_NEWTOOLRECT,0,TOOLINFO)
end subroutine
public function integer addtool (dragobject object, string tiptext, integer flags);//此函数用于注册要显示ToolTips的控制,代码如下:
If hWndTT <= 0 Then
If TIPSTYLE = STYLE_BALLOONTIP Then
hWndTT = CreateWindowExA(WS_EX_TOPMOST,TOOLTIPS_CLASS,0, TTF_CENTERTIP+ TTS_BALLOON, &
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, &
0, 0, Handle(GetApplication()),0)
Else
hWndTT = CreateWindowExA(WS_EX_TOPMOST, TOOLTIPS_CLASS,0,TTF_CENTERTIP, &
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, &
0, 0, Handle(GetApplication()),0)
End If
End If
TOOLINFO TOOLINFO
TOOLINFO.cbSize = 40
TOOLINFO.uFlags = Flags
TOOLINFO.hWnd = Handle(Object)
TOOLINFO.hInstance = 0
TOOLINFO.uID = ToolID
ToolID++
TOOLINFO.lpszText = tiptext
//LStrCpy(ToolInfo.lpszText,Left(tiptext,80))
TOOLINFO.Rect.Left = 0
TOOLINFO.Rect.Top = 0
TOOLINFO.Rect.Right = UnitsToPixels(Object.Width,XUnitsToPixels!)
TOOLINFO.Rect.Bottom = UnitsToPixels(Object.Height,YUnitsToPixels!)
If ToolTipMsg(hWndTT,TTM_ADDTOOL, 0, TOOLINFO) = 0 Then
//MessageBox("错误","不能注册控件!",StopSign!,Ok!)
// LocalFree(ToolInfo.lpszText) //释放分配的内存
Return(-1)
End If
//LocalFree(ToolInfo.lpszText) //释放分配的内存
Return(ToolID - 1)
end function
public subroutine hidetip (dragobject controlobject);MSG MSG
MSG.hWnd = Handle(ControlObject)
MSG.Message = 513 // WM_LBUTTONDOWN
MSG.WParam = Message.WordParm
MSG.Lparam = Message.LongParm
RelayMsg(hWndTT,TTM_RELAYEVENT,0,MSG)
end subroutine
public subroutine settiptext (dragobject object, long uid, string tiptext);//此函数用于为ToolTips窗口设置新文本,代码如下:
TOOLINFO ToolInfo
ToolInfo.hWnd = Handle(Object)
ToolInfo.uID = uID
ToolInfo.lpszText = TipText
ToolTipMsg(hWndTT,TTM_UPDATETIPTEXT,0,ToolInfo)
end subroutine
public subroutine setmaxwidth (long al_maxwidth);
Send( hWndTT, TTM_SETMAXTIPWIDTH, 0, UnitsToPixels( al_MaxWidth, xUnitsToPixels! ) )
Return
end subroutine
public function integer removetool (dragobject ado_object, integer ai_toolid);
TOOLINFO TOOLINFO
Integerli_Width, li_Height
TOOLINFO.cbSize = 40
TOOLINFO.uFlags = 16 //Flags
TOOLINFO.hWnd = Handle( ado_Object )
TOOLINFO.hInstance = 0 // Not used
TOOLINFO.uID = ai_ToolID
ToolTipMsg( hWndTT, TTM_DELTOOL, 0, TOOLINFO )
Return 1
end function
public subroutine settiptitle (integer ai_icon, string as_title);
SendMessageString( hWndTT, TTM_SETTITLEA, ai_Icon, as_Title )
end subroutine
public subroutine settipbkcolor (long aul_color);
Send( hWndTT, TTM_SETTIPBKCOLOR,aul_color, 0 )
end subroutine
public subroutine relaymsg (dragobject object);//此函数用于向显示ToolTips窗口发送控制消息,代码如下:
MSG MSG
MSG.hWnd = Handle(Object) // WM_MOUSEMOVE
MSG.Message = 512
MSG.WParam = Message.WordParm
MSG.LParam = Message.LongParm
RelayMsg(hWndTT,TTM_RELAYEVENT,0,MSG)
end subroutine
public function boolean tipvisible ();If IsWindowVisible(HwndTT) > 0 Then Return True
Return False
end function
public subroutine relaymsg (dragobject object, long wordparm, integer longparm);//此函数用于向显示ToolTips窗口发送控制消息,代码如下:
MSG MSG
MSG.hWnd = Handle(Object) // WM_MOUSEMOVE
MSG.Message = 512
MSG.WParam = WordParm
MSG.LParam = LongParm
RelayMsg(hWndTT,TTM_RELAYEVENT,0,MSG)
end subroutine
on nvo_tooltips.create
call super::create
TriggerEvent( this, "constructor" )
end on
on nvo_tooltips.destroy
TriggerEvent( this, "destructor" )
call super::destroy
end on
event constructor;//结构point用于传送坐标
//结构msg用于传送消息
//结构rect用于传送矩形框的位置
//结构toolinfo用于传送与tooltips相关的消息
//用法/////////////////////////////////////////////////////////////
//定义实例变量:
//nca_ToolTips invo_ToolTip
//window open事件:
//注册要显示ToolTips的控制
//invo_tooltip.AddTool(sle_userid,"请输入登录用户名",0)
//invo_tooltip.AddTool(sle_password,"请输入登录口令",0)
//需要提示的控件,在自定义ue_mousemove事件(pbm_mousemove):
//invo_tooltip.RelayMsg(This)
//////////////////////////////////////////////////////////////////
InitCommonControls()
end event
event destructor;if hWndTT>0 then DestroyWindow(hWndTT)
end event
[解决办法]
好久以前写的,使用方法:
forward
global type uo_autohint_dw from datawindow
end type
end forward
global type uo_autohint_dw from datawindow
integer width = 699
integer height = 416
string title = "none"
boolean livescroll = true
borderstyle borderstyle = stylelowered!
event ue_mousemove pbm_mousemove
end type
global uo_autohint_dw uo_autohint_dw
type prototypes
end prototypes
type variables
Private:
n_cst_dwsrv_autoHint inv_antohint
end variables
event ue_mousemove;IF IsValid(inv_antohint) THEN
RETURN inv_antohint.Event ue_MouseMove(flags,xpos,ypos)
END IF
end event
on uo_autohint_dw.create
end on
on uo_autohint_dw.destroy
end on
event constructor;inv_antohint = create n_cst_dwsrv_autoHint
inv_antohint.of_SetRequestor(this)
end event
event resize;
IF IsValid(inv_antohint) THEN
RETURN inv_antohint.Event resize(sizetype,newwidth,newheight)
END IF
end event
event destructor;if isvalid(inv_antohint) then
Destroy inv_antohint
end if
end event
[解决办法]
我给大家找了一个更方便、简单的示例,发至下列邮箱,还有需要的朋友,可以到http://download.csdn.net/source/1736927下载
ming030826 <ming030826@163.com>, qdgkyy <qdgkyy@163.com>, xueying0000 <xueying0000@163.com>, wenxing_zhong <wenxing_zhong@163.com>, suiyuan-2007 <suiyuan-2007@163.com>, bibidbzfish <bibidbzfish@163.com>, fm20027 <fm20027@163.com>[