no-frills Progress/SplashText/ToolTip alternative

Get help with using AutoHotkey and its commands and hotkeys
User avatar
jeeswg
Posts: 6904
Joined: 19 Dec 2016, 01:58
Location: UK

no-frills Progress/SplashText/ToolTip alternative

09 Mar 2018, 00:07

For similar reasons to the script in the link, I'm trying to create a short easy-to-share large-font alternative to the Progress/SplashText/ToolTip commands.
no-frills SplashImage - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=5&t=45295

The script works, however, there is one flaw mentioned below, if anybody can find a fix for it.

Code: Select all

q:: ;no-frills Progress/SplashText/ToolTip alternative
;note: there is one flaw:
;the main GUI window (a Static control),
;is a different colour to the central Static control,
;one workaround is to use the AutoHotkey2 class
;as the main GUI window, however,
;it may not be available in AutoHotkey v2,
;I'm looking for alternative classes (perhaps a simple control)
;or other fixes

;note:
;default font for the Progress command (tested on Windows 7)
;MS Shell Dlg, size 0 (yes, 0)

vDHW := A_DetectHiddenWindows
DetectHiddenWindows, On
vText := "this is my text`r`n" "this is some more text`r`n" "abcdefghijklmnopqrstuvwxyz`r`n" "aaaa aaaa aaaa aaaa aaaa aaaa"
;vPosX := 300, vPosY := 300
vPosX := "", vPosY := ""
;vLimW := ""
;vLimW := 150
;vLimW := 300
vLimW := 280
;vFontName := "Arial"
vFontName := "MS Shell Dlg"
vFontSize := 18
vFontWeight := 400
vMgnX := 10, vMgnY := 5
;vMgnX := 14, vMgnY := 13

vHeight := -DllCall("kernel32\MulDiv", Int,vFontSize, Int,A_ScreenDPI, Int,72)
hFont := DllCall("gdi32\CreateFont", Int,vHeight, Int,vWidth:=0, Int,vEscapement:=0, Int,vOrientation:=0, Int,vWeight:=vFontWeight, UInt,vItalic:=0, UInt,vUnderline:=0, UInt,vStrikeOut:=0, UInt,vCharSet:=0, UInt,vOutPrecision:=3, UInt,vClipPrecision:=2, UInt,vQuality:=1, UInt,vPitchAndFamily:=34, Str,vFaceName:=vFontName, Ptr)
if (vLimW = "")
	vLimW := A_ScreenWidth
JEE_StrGetDim(vText, hFont, vTextW, vTextH, vDTFormat:=0x2410, vLimW, vLimH:="")
vPosW := vTextW+2*vMgnX, vPosH := vTextH+2*vMgnY
WinGetPos,,,, vTaskbarH, ahk_class Shell_TrayWnd
if (vPosX = "")
	vPosX := Round((A_ScreenWidth-vPosW)/2)
if (vPosY = "")
	vPosY := Round((A_ScreenHeight-vPosH-vTaskbarH)/2)

;SS_EDITCONTROL := 0x2000 ;allows word breaks (words can be split up)
hGuiSplash := DllCall("user32\CreateWindowEx", UInt,vWinExStyle:=0x8, Str,vWinClass:="Static", Str,vWinText:="", UInt,vWinStyle:=0x80800000, Int,vPosX, Int,vPosY, Int,vPosW, Int,vPosH, Ptr,hWndParent:=0, Ptr,hMenu:=0, Ptr,hInstance:=0, Ptr,vParam:=0, Ptr) ;WS_POPUP := 0x80000000 ;WS_BORDER := 0x800000 ;WS_EX_TOPMOST := 0x8
;hGuiSplash := DllCall("user32\CreateWindowEx", UInt,vWinExStyle:=0x8, Str,vWinClass:="AutoHotkey2", Str,vWinText:="", UInt,vWinStyle:=0x80800000, Int,vPosX, Int,vPosY, Int,vPosW, Int,vPosH, Ptr,hWndParent:=0, Ptr,hMenu:=0, Ptr,hInstance:=0, Ptr,vParam:=0, Ptr) ;WS_POPUP := 0x80000000 ;WS_BORDER := 0x800000 ;WS_EX_TOPMOST := 0x8
hStc := DllCall("user32\CreateWindowEx", UInt,vWinExStyle:=0, Str,vWinClass:="Static", Str,vWinText:=vText, UInt,vWinStyle:=0x50002000, Int,vMgnX, Int,vMgnY, Int,vTextW, Int,vTextH, Ptr,hWndParent:=hGuiSplash, Ptr,hMenu:=0, Ptr,hInstance:=0, Ptr,vParam:=0, Ptr) ;WS_CHILD := 0x40000000 ;WS_VISIBLE := 0x10000000 ;SS_EDITCONTROL := 0x2000
SendMessage, 0x30, % hFont, 0,, % "ahk_id " hStc ;WM_SETFONT := 0x30
WinShow, % "ahk_id " hGuiSplash
Sleep, 1000
DllCall("user32\DestroyWindow", Ptr,hGuiSplash)
DetectHiddenWindows, % vDHW

;for comparison:
;Progress, zh0 b1 c0 fs18, % vText,,, Arial
Progress, zh0 b1 c0 fs18, % vText
Sleep, 1000
Progress, Off
return

;==================================================

;vLimW and vLimH if present are used as limits
;JEE_DrawText
JEE_StrGetDim(vText, hFont, ByRef vTextW, ByRef vTextH, vDTFormat:=0x400, vLimW:="", vLimH:="")
{
	;DT_EDITCONTROL := 0x2000 ;DT_NOPREFIX := 0x800
	;DT_CALCRECT := 0x400 ;DT_NOCLIP := 0x100
	;DT_EXPANDTABS := 0x40 ;DT_SINGLELINE := 0x20
	;DT_WORDBREAK := 0x10

	;HWND_DESKTOP := 0
	hDC := DllCall("user32\GetDC", Ptr,0, Ptr)
	hFontOld := DllCall("gdi32\SelectObject", Ptr,hDC, Ptr,hFont, Ptr)
	VarSetCapacity(SIZE, 8, 0)
	vTabLengthText := "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
	DllCall("gdi32\GetTextExtentPoint32", Ptr,hDC, Str,vTabLengthText, Int,52, Ptr,&SIZE)
	vTabLength := NumGet(&SIZE, 0, "Int") ;cx ;logical units
	vTabLength := Floor((vTabLength/52)+0.5)
	vTabLength := Round(vTabLength*(72/A_ScreenDPI))
	vLen := StrLen(vText)

	VarSetCapacity(DRAWTEXTPARAMS, 20, 0)
	NumPut(20, &DRAWTEXTPARAMS, 0, "UInt") ;cbSize
	NumPut(vTabLength, &DRAWTEXTPARAMS, 4, "Int") ;iTabLength
	;NumPut(0, &DRAWTEXTPARAMS, 8, "Int") ;iLeftMargin
	;NumPut(0, &DRAWTEXTPARAMS, 12, "Int") ;iRightMargin
	NumPut(vLen, &DRAWTEXTPARAMS, 16, "UInt") ;uiLengthDrawn

	VarSetCapacity(RECT, 16, 0)
	if !(vLimW = "")
		NumPut(vLimW, &RECT, 8, "Int")
	if !(vLimH = "")
		NumPut(vLimH, &RECT, 12, "Int")
	DllCall("user32\DrawTextEx", Ptr,hDC, Str,vText, Int,vLen, Ptr,&RECT, UInt,vDTFormat, Ptr,&DRAWTEXTPARAMS)
	DllCall("gdi32\SelectObject", Ptr,hDC, Ptr,hFontOld, Ptr)
	DllCall("user32\ReleaseDC", Ptr,0, Ptr,hDC)

	vTextW := NumGet(&RECT, 8, "Int")
	vTextH := NumGet(&RECT, 12, "Int")
}
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
User avatar
jeeswg
Posts: 6904
Joined: 19 Dec 2016, 01:58
Location: UK

Re: no-frills Progress/SplashText/ToolTip alternative

30 Mar 2018, 02:13

- The active window was losing focus. This was fixed by using ShowWindow with SW_SHOWNA instead.

Code: Select all

;before:
WinShow, % "ahk_id " hGuiSplash
;after:
DllCall("user32\ShowWindow", Ptr,hGuiSplash, Int,8) ;SW_SHOWNA := 8
- I was surprised that WinShow didn't just show the window, that SW_SHOWNA was necessary.
- I suppose that aside from the Gui command, this functionality isn't built in to AutoHotkey.
- I suppose also that sometimes there are other situations, when dealing with third-party software, that using the ShowWindow function beats WinShow.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
just me
Posts: 6551
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: no-frills Progress/SplashText/ToolTip alternative

30 Mar 2018, 05:04

Brute force: Use an additional static control to fill the client area's background:

Code: Select all

hGuiSplash := DllCall("user32\CreateWindowEx", UInt,vWinExStyle:=0x8, Str,vWinClass:="Static", Str,vWinText:="", UInt,vWinStyle:=0x80800000, Int,vPosX, Int,vPosY, Int,vPosW, Int,vPosH, Ptr,hWndParent:=0, Ptr,hMenu:=0, Ptr,hInstance:=0, Ptr,vParam:=0, Ptr) ;WS_POPUP := 0x80000000 ;WS_BORDER := 0x800000 ;WS_EX_TOPMOST := 0x8
hBkg := DllCall("user32\CreateWindowEx", UInt,vWinExStyle:=0, Str,vWinClass:="Static", Str,vWinText:="", UInt,vWinStyle:=0x50000000, Int,0, Int,0, Int,vPosW, Int,vPosH, Ptr,hWndParent:=hGuiSplash, Ptr,hMenu:=0, Ptr,hInstance:=0, Ptr,vParam:=0, Ptr) ;WS_CHILD := 0x40000000 ;WS_VISIBLE := 0x10000000
hStc := DllCall("user32\CreateWindowEx", UInt,vWinExStyle:=0, Str,vWinClass:="Static", Str,vWinText:=vText, UInt,vWinStyle:=0x50002000, Int,vMgnX, Int,vMgnY, Int,vTextW, Int,vTextH, Ptr,hWndParent:=hGuiSplash, Ptr,hMenu:=0, Ptr,hInstance:=0, Ptr,vParam:=0, Ptr) ;WS_CHILD := 0x40000000 ;WS_VISIBLE := 0x10000000 ;SS_EDITCONTROL := 0x2000

Return to “Ask For Help”

Who is online

Users browsing this forum: Albireo, Bing [Bot], Odlanir, pn4265 and 253 guests