Jump to content


CreateFont function only making underlined font


  • Please log in to reply
5 replies to this topic

#1 ahkrocks

ahkrocks
  • Guests

Posted 19 July 2012 - 11:14 AM

I am using the CreateFont function written by majkinetor to modify the font in a tooltip. Everything works great except the font is underlined. Here is the relevant peices of code:

...
SetTooltipFont(tooltipID, "s24 , Arial")                         ; set the tooltip text font   
...
SetTooltipFont(pTooltipID, pFont="") {
   local height, weight, italic, underline, strikeout , nCharSet
   local hFont
   static WM_SETFONT := 0x30


 ;parse font
   italic      := InStr(pFont, "italic")    ?  1    :  0
   underline   := InStr(pFont, "underline") ?  1    :  0
   strikeout   := InStr(pFont, "strikeout") ?  1    :  0
   weight      := InStr(pFont, "bold")      ? 700   : 400

 ;height
   RegExMatch(pFont, "(?<=[S|s])(\d{1,2})(?=[ ,])", height)
   if (height = "")
      height := 10
   RegRead, LogPixels, HKEY_LOCAL_MACHINE, SOFTWARE\Microsoft\Windows NT\CurrentVersion\FontDPI, LogPixels
   height := -DllCall("MulDiv", "int", Height, "int", LogPixels, "int", 72)

 ;face
   RegExMatch(pFont, "(?<=,).+", fontFace)   
   if (fontFace != "")
       fontFace := RegExReplace( fontFace, "(^\s*)|(\s*$)")      ;trim
   else fontFace := "MS Sans Serif"


 ;create font
   hFont   := DllCall("CreateFont", "int",  height, "int",  0, "int",  0, "int", 0
                      ,"int",  weight,   "Uint", italic,   "Uint", underline
                      ,"Uint", strikeOut, "Uint", nCharSet, "Uint", 0, "Uint", 0, "Uint", 0, "Uint", 0, "str", fontFace)

   SendMessage,WM_SETFONT,hFont,TRUE, , ahk_id %pTooltipID%
   return ErrorLevel
}

Any advice is much appreciated!

#2 HotKeyIt

HotKeyIt
  • Fellows
  • 6190 posts

Posted 19 July 2012 - 09:26 PM

TT_Font() from TT() libraryworks fine for me, compare the code and see the difference.
Here is a modified version to work with hwnd
ToolTip Hello World!
TT_Font(WinExist("ahk_class tooltips_class32"),"s20 italic bold, Arial")
MsgBox end
TT_Font("")
TT_Font(hwnd, pFont="") { ;Taken from HE_SetFont, thanks majkinetor. http://www.autohotkey.com/forum/viewtopic.php?p=124450#124450
   static WM_SETFONT := 0x30,hFont
  if (hwnd="")
    Return DllCall("DeleteObject","PTR",hfont)
 ;parse font 
   italic      := InStr(pFont, "italic")    ?  1    :  0 
   underline   := InStr(pFont, "underline") ?  1    :  0 
   strikeout   := InStr(pFont, "strikeout") ?  1    :  0 
   weight      := InStr(pFont, "bold")      ? 700   : 400 

 ;height 
   RegExMatch(pFont, "(?<=[S|s])(\d{1,2})(?=[ ,])", height) 
   if (height = "") 
      height := 10 
   RegRead, LogPixels, HKEY_LOCAL_MACHINE, SOFTWARE\Microsoft\Windows NT\CurrentVersion\FontDPI, LogPixels 
   height := -DllCall("MulDiv", "int", Height, "int", LogPixels, "int", 72) 

 ;face 
   RegExMatch(pFont, "(?<=,).+", fontFace)    
   if (fontFace != "") 
       fontFace := RegExReplace( fontFace, "(^\s*)|(\s*$)")      ;trim 
   else fontFace := "MS Sans Serif" 
  If (pFont && !InStr(pFont,",") && (italic+underline+strikeout+weight)=400)
    fontFace:=pFont
  
 ;create font 
  If hFont
      DllCall("DeleteObject","PTR",hfont)
  hFont   := DllCall("CreateFont", "int",  height, "int",  0, "int",  0, "int", 0 
                      ,"int",  weight,   "Uint", italic,   "Uint", underline 
                      ,"uint", strikeOut, "Uint", nCharSet, "Uint", 0, "Uint", 0, "Uint", 0, "Uint", 0, "str", fontFace,"PTR") 
  Return DllCall("SendMessage","PTR",hwnd,"UInt",WM_SETFONT,"PTR",hFont,"PTR",TRUE,"PTR")
}


#3 ahkrocks

ahkrocks
  • Guests

Posted 19 July 2012 - 11:20 PM

Tooltips created by an ahk script seem to change their font just fine. But external application tooltips have the font underlined :?

Try this script to change the font of external application tooltips and the "Hello World" tooltip (I have of course left out the code for TT_font() in this snippet):

#Persistent

ToolTip Hello World!

SetTimer TooltipFinder, 50

TooltipFinder:
  IfWInExist ahk_class tooltips_class32
  { 
    WinGet, tooltipID, ID

    TT_font(tooltipID, "s20 italic bold, Arial")
  }

When I run this script and open a Windows explorer window and hover over a file name to get its tooltip to pop up, I see the "Hello World" tooltip in the intended font and the Windows explorer tooltip in the underlined font :?

#4 HotKeyIt

HotKeyIt
  • Fellows
  • 6190 posts

Posted 20 July 2012 - 06:21 AM

It does not work on a different process, I think this is because your font is created in memory where explorer has no access to. Also when you try to modify a ToolTip of another AHK process it does not work.
For example try to change the size, it does not work for me.

#5 ahkrocks

ahkrocks
  • Guests

Posted 20 July 2012 - 06:31 AM

It does not work on a different process, I think this is because your font is created in memory where explorer has no access to.


For me it works, but only partially. The script I posted changes the size, fontface, bold, and italic of the Windows explorer tooltip font. I can also change its max width and set its delay time to up to 30 seconds or so. The only problem is when I send the Windows explorer tooltip a WM_SETFONT message the font is always underlined :?

Have you run the script with the timed function? I am running Vista if that makes a difference.

#6 ahkrocks

ahkrocks
  • Guests

Posted 20 July 2012 - 06:46 AM

This is what I see when I run the script I posted and hover over an Explorer file to bring up its tooltip:

Posted Image