BalloonTip

Post your working scripts, libraries and tools for AHK v1.1 and older
ninjspks
Posts: 8
Joined: 01 Nov 2020, 22:30
Contact:

BalloonTip

Post by ninjspks » 14 Nov 2022, 17:06

I thought I might share this with the community, as I threw it together. Also why traytips speech mark is usually truncated was revealed to me.

I have chosen to write it this way so the tip can be set to eminate from whichever location is desired, rather than being limited to "edit fields" it created an arbitrary gui at the target and disposes of it afterwards. "Can" also be called without specifying anything more than the text content for your lesiure .Please also note duration<1000 -> converted to seconds.

Would be good to make into a class imho too. I also plan to add custom icon support and ultimately animation support :superhappy: .

Cheers for the resources and to the almighty L :bravo:

Code: Select all

; use: BalloonTip("blablablah","Title:",2955,22,false,5)
;		|| BalloonTip("blablablah",2955,22) 
;		|| BalloonTip("blablablah")
; return,
 
BalloonTip(txt,title="",x="",y="",isGuiExist="",Dur="") {
	isint(title)? (Dur:=isGuiExist, isGuiExist:=Y
	, Y:=X, X:=title, title:="") : (), (Dur=""?Dur:=5)
	(isint(isGuiExist)?isint(isGuiExist)?Dur:=isGuiExist,isGuiExist:="")
	(!X?X:=a_screenwidth-400 :()),	(!Y?Y:=a_screenheight-80)
	if isGuiExist
		gui,add,edit,disabled x%X% y%Y% w1 h1 hwndhEdit
	else {
		gui,testt:new,-dpiscale
		gui,testt:add,edit,disabled x%X% y%Y% w1 h1 hwndhEdit
	}
	_ShowBalloonTip(hEdit,title,txt,"")
	(fn:= Func("BallClean").Bind(Dur,hEdit)).Call(Dur,hEdit)
	return,
}

_ShowBalloonTip(hEdit,p_Title,p_Text,p_Icon:=0) {
	static EM_SHOWBALLOONTIP:= 0x1503
	loop,parse,% "TTI_NONE,TTI_INFO,TTI_WARNING,TTI_ERROR
	,TTI_INFO_LARGE,TTI_WARNING_LARGE,TTI_ERROR_LARGE",`,
		static (%a_loopfield%):= A_index
	cbSize:= (A_PtrSize=8)? 32:16, wTitle:=p_Title, wText:=p_Text
	if !isUnicode() {
		(StrLen(p_Title)? VarSetCapacity(wTitle,StrLen(p_Title)*2,0)
		,StrPut(p_Title,&wTitle,"UTF-16"))
		(StrLen(p_Text)? VarSetCapacity(wText,StrLen(p_Text)*2,0)
		,StrPut(p_Text,&wText,"UTF-16"))
	}	
	VarSetCapacity(EDITBALLOONTIP,cbSize)
	NumPut(cbSize, EDITBALLOONTIP,0,"Int")
	NumPut(&wTitle,EDITBALLOONTIP,(A_PtrSize=8)? 8:4,"Ptr")
	NumPut(&wText, EDITBALLOONTIP,(A_PtrSize=8)? 16:8,"Ptr")
	NumPut(p_Icon, EDITBALLOONTIP,(A_PtrSize=8)? 24:12,"Int")
	SendMessage,EM_SHOWBALLOONTIP,0,&EDITBALLOONTIP,,ahk_id %hEdit%
	Return,ErrorLevel
}

HideBalloonTip(hEdit) {
	Static EM_HIDEBALLOONTIP:= 0x1504
	SendMessage,EM_HIDEBALLOONTIP,0,0,,ahk_id %hEdit%
	Return,ErrorLevel
}

BallClean(Dur,hWnd) {
	(Dur<1000?Dur*=1000)
	sleep,% Dur
	HideBalloonTip(hWnd)
	gui,testt:destroy
}

isint(V) {
	if V is integer
		 return,1
	else,return,0
}

isUnicode() {
	if A_IsUnicode
		 return,1
	else,return,0
}

ninjspks
Posts: 8
Joined: 01 Nov 2020, 22:30
Contact:

Re: BalloonTip

Post by ninjspks » 15 Nov 2022, 06:23

im not sure Im allowed to edit my posts yet. line 9 should read (isint(isGuiExist)?isGuiExist>1?Dur:=isGuiExist,isGuiExist:="")

murataygun
Posts: 104
Joined: 07 Aug 2015, 15:53

Re: BalloonTip

Post by murataygun » 05 Dec 2022, 17:23

Good. Thanks.

Post Reply

Return to “Scripts and Functions (v1)”