[H2] tp() - new tooltip

许多实用脚本和封装函数, 可以让您编写脚本更加便捷高效

Moderators: tmplinshi, arcticir

arcticir
Posts: 694
Joined: 17 Nov 2013, 11:32

[H2] tp() - new tooltip

12 Jul 2016, 02:44

修改自HotKeyIt的脚本.

Code: Select all

f:=[]
f.x:=100
f.y:=100
f.id:=3
f.Text:="0123456789abcdefg"	;内容
f.width:=100		;最大宽度
f.Time:=2000		;计时关闭
f.font:="Comic Sans MS"	;字体
f.Size:=20		;字体大小
f.cr:=0x008000		;字体颜色
f.bd:=0xFFFFFF		;背景颜色
f.Italic:=1		; 斜体
f.Line:=1		; 下划线
f.StrikeOut:=1		;删除线
MsgBox % tp(f)
ExitApp

Code: Select all

tp(aText:="", aX:="", aY:="", aID:=1, width:="", Time:=""){
  static MAX_TOOLTIPS:=20,g_hWndToolTip:={1:0,2:0,3:0,4:0,5:0,6:0,7:0,8:0,9:0,10:0,11:0,12:0,13:0,14:0,15:0,16:0,17:0,18:0,19:0,20:0,base:{__Delete:"tp"}}
        ,SM_CXVIRTUALSCREEN:=78,SM_XVIRTUALSCREEN:=76,SM_YVIRTUALSCREEN:=77,SM_CYVIRTUALSCREEN:=79
        ,TTF_TRACK:=32,WS_EX_TOPMOST:=8, TOOLTIPS_CLASS:="tooltips_class32", TTS_NOPREFIX:=2,TTS_ALWAYSTIP:=1
        ,CW_USEDEFAULT:=2147483648,TTM_ADDTOOL:=1074,TTM_SETMAXTIPWIDTH:=1048,SM_CXSCREEN:=0,TTM_TRACKPOSITION:=1042,TTM_TRACKACTIVATE:=1041
        ,COORD_MODE_CLIENT:=0,COORD_MODE_WINDOW:=1,COORD_MODE_SCREEN:=2,RECT:="left,top,right,bottom",POINT:="x,y"
        ,TOOLINFO:="UINT cbSize;UINT uFlags;HWND hwnd;UINT_PTR uId;tp(RECT) rect;HINSTANCE hinst;LPTSTR lpszText;LPARAM lParam;void *lpReserved"
        ,dtw:=Struct(RECT),pt:=Struct(POINT),pt_cursor:=Struct(POINT),origin:=Struct(POINT),ttw:=Struct(RECT),ti:=Struct(TOOLINFO)
        ,rc:=Struct(RECT),ptx:=Struct(POINT),pg_hWndToolTip:=&g_hWndToolTip

	if IsObject(aText) and aText.Text
	this:=aText,ax:=aText.x,ay:=aText.y,aid:=aText.id?aText.id:1,width:=aText.width,Time:=aText.Time,aText:=aText.Text

	if IsObject(aText) and &aText=pg_hWndToolTip
	{
		for k,v in aText
			(v?DestroyWindow(v):"")
	} 
	else 
	{
		window_index := aID ;-1
		if (window_index < 0 || window_index >= MAX_TOOLTIPS)
			return "Max window number is %MAX_TOOLTIPS%"
		tip_hwnd := g_hWndToolTip[window_index]
		if (aText="")
			return (tip_hwnd && IsWindow(tip_hwnd))?DestroyWindow(tip_hwnd):"",g_hWndToolTip[window_index] := 0
		dtw.right := GetSystemMetrics(SM_CXVIRTUALSCREEN)
		if (dtw.right)
		{
			dtw.left := GetSystemMetrics(SM_XVIRTUALSCREEN)
			dtw.right += dtw.left
			dtw.top := GetSystemMetrics(SM_YVIRTUALSCREEN) 
			dtw.bottom := dtw.top + GetSystemMetrics(SM_CYVIRTUALSCREEN)
		}
		else GetWindowRect(GetDesktopWindow(), dtw[])

		(one_or_both_coords_unspecified := aX="" || aY="")
			?(GetCursorPos(pt_cursor[]),pt.x := pt_cursor.x + 16,pt.y := pt_cursor.y + 16):""
		,origin.Fill()
		,((aX!="" || aY!="") and (A_CoordMode%aWhichMode% != COORD_MODE_SCREEN)
			and (active_window && !IsIconic(active_window:= GetForegroundWindow())))
				?((A_CoordMode%aWhichMode% = COORD_MODE_WINDOW)
		  			?	GetWindowRect(active_window,rc[])?(origin.x += rc.left,origin.y += rc.top):""
		  			:	 ClientToScreen(active_window,ptx[])?(origin.x += ptx.x,origin.y += ptx.y):"")
				:""
		,(aX!="")?pt.x := aX + origin.x:"",(aY!="")?pt.y := aY + origin.y:""
		,ti.Fill(),ti.cbSize := sizeof(ti) - A_PtrSize,ti.uFlags := TTF_TRACK,ti.lpszText := aText

		if (!tip_hwnd || !IsWindow(tip_hwnd))
		{
			tip_hwnd := g_hWndToolTip[window_index] := CreateWindowExW(WS_EX_TOPMOST,TOOLTIPS_CLASS,0,TTS_NOPREFIX|TTS_ALWAYSTIP,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT)
			if this.bd or this.cr
				VarSetCapacity(empty, 2, 0),DllCall("UxTheme.dll\SetWindowTheme", "ptr", tip_hwnd, "ptr", 0, "ptr", &empty)
				,SendMessage_(tip_hwnd,1044,tp_BGR(this.cr?this.cr:0x000000) ,0) ;字体颜色
				,SendMessage_(tip_hwnd,1043,tp_BGR(this.bd?this.bd:0xFFFFFF) ,0) ;背景颜色,
			if this.font or this.Size or this.Italic or this.Line
				hDC:=CreateDC("DISPLAY",0,0,0)
				,SendMessage_(tip_hwnd,0x30,DllCall("CreateFont"
					,"Int",Round((this.Size?this.Size:10)*GetDeviceCaps(hDC,90)/72)*-1                                 ;-- nHeight
					,"Int",0                                        ;-- nWidth
					,"Int",0                                        ;-- nEscapement (0=normal horizontal)
					,"Int",0                                        ;-- nOrientation
					,"Int",400                                 ;-- 重量
					,"UInt",(this.Italic?this.Italic:0)   ; 斜体
					,"UInt",(this.Line?this.Line:0)                              	; 下划线
					,"UInt",(this.StrikeOut?this.StrikeOut:0)                   ; 删除线
					,"UInt",1                         ;-- 字符集
					,"UInt",4                         ;-- 输出精度
					,"UInt",0                   ;-- 剪辑精度
					,"UInt",2                         ;-- 质量
					,"UInt",0                         ;-- fdwPitchAndFamily
					,"Str",this.font) ,0),DeleteDC(hDC)
			SendMessage_(tip_hwnd,TTM_ADDTOOL,0,ti[])
			,SendMessage_(tip_hwnd,TTM_SETMAXTIPWIDTH,0,width?width:GetSystemMetrics(SM_CXSCREEN))
			,SendMessage_(tip_hwnd,TTM_TRACKPOSITION,0,(pt.x&0xffff)|(pt.y&0xffff)<<16)
			,SendMessage_(tip_hwnd,TTM_TRACKACTIVATE,1,ti[])
		}

		SendMessage_(tip_hwnd,TTM_UPDATETIPTEXT,0,ti[])
		,ttw.Fill(),GetWindowRect(tip_hwnd,ttw[])
		,tt_width := ttw.right - ttw.left,tt_height := ttw.bottom - ttw.top
		,(pt.x + tt_width >= dtw.right)
			?pt.x := dtw.right - tt_width - 1:""
		,(pt.y + tt_height >= dtw.bottom)
			?pt.y := dtw.bottom - tt_height - 1:""

		if (one_or_both_coords_unspecified)
		{
			ttw.left := pt.x,ttw.top := pt.y,ttw.right := ttw.left + tt_width
			,ttw.bottom := ttw.top + tt_height
			,(pt_cursor.x >= ttw.left && pt_cursor.x <= ttw.right && pt_cursor.y >= ttw.top && pt_cursor.y <= ttw.bottom)
				?(pt.x := pt_cursor.x - tt_width - 3,pt.y := pt_cursor.y - tt_height - 3):""
		}
		SendMessage_(tip_hwnd,TTM_TRACKPOSITION,0,(pt.x&0xffff)|(pt.y&0xffff)<<16)
		SendMessage_(tip_hwnd,TTM_TRACKACTIVATE,1,ti[])
		if Time
			SetTimer, __ToolTip_%aID%, % -Abs(Time)
	}
	Return
	__ToolTip_1:
	__ToolTip_2:
	__ToolTip_3:
	__ToolTip_4:
	__ToolTip_5:
	__ToolTip_6:
	__ToolTip_7:
	__ToolTip_8:
	__ToolTip_9:
	__ToolTip_10:
	__ToolTip_11:
	__ToolTip_12:
	__ToolTip_13:
	__ToolTip_14:
	__ToolTip_15:
	__ToolTip_16:
	__ToolTip_17:
	__ToolTip_18:
	__ToolTip_19:
	__ToolTip_20:
	tp(,,,SubStr(A_ThisLabel,11))
	Return
}

tp_BGR(BGR){
   return (((((((BGR & 0xFF) << 16) | (((BGR >> 8) & 0xFF) << 8)) | ((BGR >> 16) & 0xFF)) | ((0xAA & 0xFF) << 24))) & 0xFFFFFFFF)
}
guest3456
Posts: 3477
Joined: 09 Oct 2013, 10:31

Re: [H2] tp() - new tooltip

01 Nov 2016, 13:05

how/why is this better than the original TT() library?

https://autohotkey.com/board/topic/6060 ... p-library/

it certainly looks smaller

arcticir
Posts: 694
Joined: 17 Nov 2013, 11:32

Re: [H2] tp() - new tooltip

07 Nov 2016, 07:38

Tt () contains more functionality.
Tp () is simply an enhancement to the "tooltip" base functionality.
Guest

Re: [H2] tp() - new tooltip

09 Dec 2016, 22:55

函数不能直接用吗 ?
提示没有Struct函数, 去原贴补了一个
又提示没有destroy函数

这个是h版专用的吗 ?
arcticir
Posts: 694
Joined: 17 Nov 2013, 11:32

Re: [H2] tp() - new tooltip

10 Dec 2016, 06:21

HV2才能用的函数.
pk23
Posts: 110
Joined: 24 Apr 2015, 00:49

Re: [H2] tp() - new tooltip

26 Feb 2017, 21:55

V2对比V1,有哪些切身感受最明显的进步吗?
年龄大了,要没啥秒杀级的进步,就懒得再学新语法了
arcticir
Posts: 694
Joined: 17 Nov 2013, 11:32

Re: [H2] tp() - new tooltip

28 Feb 2017, 22:53

就是语法规范了

Return to “脚本函数”

Who is online

Users browsing this forum: No registered users and 11 guests