Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Get OSD (on-screen display) width/height without actually rendering
Is it possible to get the OSD width/height without actually rendering it?
I want to use the retrieved widht/height to adjust the X/Y position in the actual code that renders the OSD.

I can imagine you might need to modify the original "OnScreenDisplay" function, this might take a lot of time.
So this is not an urgent request, but maybe there is another way around or something?
Not too much work.

Function OsdCalcSize
Select All      Help
function'SIZE $text [x] [y] [$fname] [fsize] [flags] [wrapwidth] [RECT&rect] ;;flags: 1 nontransparent, 4 click to hide, 16 use raw x y, 32 place by the mouse, 0x100 bold, 0x200 italic

;Calculates width and height of OnScreenDisplay window if you would call it with these parameters.

;Parameters are the same as of <help>OnScreenDisplay</help>. Uses only flags listed above. Does not have pictfile parameter. Also uses <help>_monitor</help>. If need rectangle in screen, use the rect parameter.

fsize=iif(fsize fsize 24)
if(flags&1=0) if(flags&4 or ScreenColors<8) flags|1
__Font hfont.Create(fname fsize flags>>8&3)

int ww retry monf monitor
if(flags&32) flags|16; monitor=-1; x+xm; y+ym; else if(flags&16=0) monitor=_monitor
GetWorkArea 0 0 ww
int hdc=GetDC(0)
int oldfont=SelectObject(hdc hfont)
rt.right=iif(wrapwidth>0 wrapwidth ww)
if(flags&0x200) rt.right+fsize/4 ;;avoid clipping part of last char when italic
SelectObject hdc oldfont; ReleaseDC 0 hdc
if(flags&1) rt.right+8; rt.bottom+3;

OffsetRect &rt x y
AdjustWindowPos 0 &rt iif(flags&16 1|4|8 1)|monf monitor

if(!retry and wrapwidth<=0) ;;maybe nonprimary monitor, different width
,monitor=MonitorFromRect(&rt 2); monf=32
,if(monitor!=MonitorFromWindow(0 1))
,,MonitorFromIndex monitor 33 &rt
,,RECT r0; rt=r0
,,retry=1; goto g2

if(&rect) rect=rt
ret z
Thank you for this!!!
Sorry another final question about this:
Could you provide a function that does the exact same but now for the tooltip?
Standard tooltips? No, don't know how.
Yes the standard tooltips.
Below is the code for the function I use (I adjusted it slightly).
Don't remember where I got it from (Archive, Forum, QM itself...?)

It is no problem if not possible. Thank you anyway!

Function ToolTip
Select All      Help
function $text timeS x y [maxTipWidth] [flags] [$title] [$titleIcon] [color] ;;flags: 1 balloon (XP+), 2 asynchronous (don't wait).  titleIcon: "info" "warning" "error"

;Shows tooltip that is not attached to a control.

;color - [0]: none  OR =>  HEX values, examples  red: 0x0000ff , green: 0x00ff00 , blue: 0xff0000
;text - text.
;timeS - time to show, s.
;x, y - position in screen.
;maxTipWidth - max width. If nonzero, text can be multiline.
;;;1 - balloon. Unavailable on Windows 2000.
;;;2 - don't wait until disappears. The function creates other thread to show the tooltip.
;title - title text. Max 99 characters.
;titleIcon - one of standard icons (see above). On Windows XP SP2 and later can be icon file.

;ToolTip "tooltip" 2 100 100

;str s="Asynchronous balloon tooltip[]with title and icon."
;ToolTip s 10 xm ym 300 3 "title" "$qm$\info.ico"

if flags&2
,mac "ToolTip" "" text timeS x y maxTipWidth flags~2 title titleIcon

if(flags&1) st|TTS_BALLOON
int hwndTT = CreateWindowEx(WS_EX_TOPMOST TOOLTIPS_CLASS 0 st 0 0 0 0 0 0 0 0)

if(maxTipWidth) SendMessage(hwndTT, TTM_SETMAXTIPWIDTH, 0, maxTipWidth)

if !empty(title)
,int ic; if(!empty(titleIcon)) ic=SelStr(0 titleIcon "info" "warning" "error"); if(!ic) __Hicon _ic=GetFileIcon(titleIcon); ic=_ic
,SendMessage(hwndTT TTM_SETTITLEW ic @title)

TOOLINFOW ti.cbSize=44
ti.uFlags = TTF_TRACK
SendMessage(hwndTT, TTM_ADDTOOLW, 0, &ti)
SendMessage(hwndTT, TTM_TRACKPOSITION, 0, MakeInt(x, y))
SendMessage(hwndTT, TTM_TRACKACTIVATE, 1, &ti)

;; ---- SET BORDERCOLOR ---------

,int w1=win("" "tooltips_class32")
,RECT rr
,GetWindowRect w1 &rr
,__OnScreenRect osr.SetStyle(color)
,osr.Show(1 rr)
;; ---- /SET BORDERCOLOR ---------

opt waitmsg 1
wait timeS -WV hwndTT; err

;; ---- HIDE BORDER ---------
;; ---- /HIDE BORDER ---------

DestroyWindow hwndTT

Forum Jump:

Users browsing this thread: 1 Guest(s)