AutoHotkey Community

It is currently May 27th, 2012, 7:51 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 24 posts ]  Go to page Previous  1, 2
Author Message
 Post subject:
PostPosted: October 18th, 2006, 4:40 pm 
Offline

Joined: October 18th, 2006, 3:58 am
Posts: 14
Thanks PhiLho

I've been busy getting confused with DllCall etc. For testing I'm using CTRL-Shift-Y to call the function:

^+y::
SendMessage, 0x1D,,,, ahk_id 0xFFFF
return

[where 0x1D is WM_FONTCHANGE; 0xFFF is HWND_BROADCAST (required)]

Font is added to the registry via a batch file. Doesn't work so far, but the screen flickers when the hotkey is pressed, so there's hope. Let's see what PostMessage does...


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 18th, 2006, 4:48 pm 
Offline

Joined: May 24th, 2006, 2:49 pm
Posts: 4511
Location: Belgrade
There might be a bug with broadcast message in AHK.
Every atempt I tried failed, I monitored messages via Spy and applications didn't receive Broadcast message.

You can find about that problem in bugs forum

_________________
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 18th, 2006, 5:19 pm 
Offline

Joined: October 18th, 2006, 3:58 am
Posts: 14
Bug or no bug, I doubt that explains why I'm getting nowhere - I've a lot to learn about AHK syntax.

Either of the following WM_FONTCHANGE broadcasts do seem to work, at least in so far as they flicker the screen:
PostMessage, 0x1D,,,, ahk_id 0xFFFF
SendMessage, 0x1D,,,, ahk_id 0xFFFF

Okay, I'll call it a day for now - need to get on with some work. Will log in again tomorrow morning. Many thanks everyone for the help so far.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 18th, 2006, 5:37 pm 
Offline

Joined: December 27th, 2005, 1:46 pm
Posts: 6837
Location: France (near Paris)
Note that AFAIK, you don't need to broadcast this message if you install a font just for an application that you run after the install, it will see the changes on startup. The other apps won't see the fonts, but that's not a problem if I understood correctly.

_________________
Image vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2")


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 18th, 2006, 5:42 pm 
Offline

Joined: October 18th, 2006, 3:58 am
Posts: 14
I think I've got it!

The following routines seem to work, and instantly too (they update a word processor's font menu even when its running). For testing, CTRL-SHIFT-Y (install) and CTRL-SHIFT-U (uninstall) are used:

^+y::
DllCall("AddFontResource", Str, "c:\fontname.ttf")
PostMessage, 0x1D,,,, ahk_id 0xFFFF
return

^+u::
DllCall("RemoveFontResource", Str, "c:\fontname.ttf")
PostMessage, 0x1D,,,, ahk_id 0xFFFF
return

Hopefully I'm not missing something, and it really is as simple as that...


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 18th, 2006, 6:45 pm 
Offline

Joined: May 24th, 2006, 2:49 pm
Posts: 4511
Location: Belgrade
that is good news...
I never managed to isue Broadcast message before, but it might be due to the fact i used another mechanism that you can see here


I just checked and it seems to work your way.

Thank you for this discovery.

_________________
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 18th, 2006, 7:05 pm 
Offline

Joined: October 18th, 2006, 3:58 am
Posts: 14
It's time to wrap up this thread, then. I've got the trick down a tee for loading and unloading fonts on the fly (instantly, too - no delay) without rebooting, or mucking about with the windows font folder or system registry, so here's the rundown in case anyone else needs it. My ignorance has the advantage of keeping the coding simple:

THE PROBLEM
Some programs, such as multilingual dictionaries, require special fonts to work. These are normally installed along with the program. However, those additional fonts also appear in the font menu of word processors, which can become very cluttered. The solution, as described below, is only to load special "one program only" fonts when those programs start, and to unload the fonts when the program closes. The following method works on Windows XP SP2 Home edition, and should work on most other flavours of Windows too. The idea could easily be applied to other OS.

THE SOLUTION
The program is loaded via a batch file rather than via the program's icon/shortcut. Before triggering the program (the second line, below), the batch file sends a script to autohotkey to load the required fonts using the AddFontResource function, and broadcast the change system-wide using WM_FONTCHANGE. The program then loads and runs. Upon the program closing, the batch file continues by sending an unload script to autohotkey.

I didn't try the alternative approach of letting autohotkey detect the program launch - I'm much happier with a one-off, user-triggered solution than have autohotkey poll constantly for programs that I might not use for weeks.

Files required:

[BATCH FILE]
c:\programs\autohotkey\autohotkey.exe c:\fonts\fonts_load.ahk"
c:\programs\fonthungryprogram\whatever.exe
c:\programs\autohotkey\autohotkey.exe c:\fonts\fonts_unload.ahk"

[FONTS_LOAD.AHK]
DllCall("AddFontResource", Str, "c:\fonts\fontone.ttf")
DllCall("AddFontResource", Str, "c:\fonts\fonttwo.ttf")
DllCall("AddFontResource", Str, "c:\fonts\fontthree.ttf")
DllCall("AddFontResource", Str, "c:\fonts\fontfour.ttf")
DllCall("AddFontResource", Str, "c:\fonts\fontfive.ttf")
PostMessage, 0x1D,,,, ahk_id 0xFFFF
return

[FONTS_UNLOAD.AHK]
DllCall("RemoveFontResource", Str, "c:\fonts\fontone.ttf")
DllCall("RemoveFontResource", Str, "c:\fonts\fonttwo.ttf")
DllCall("RemoveFontResource", Str, "c:\fonts\fontthree.ttf")
DllCall("RemoveFontResource", Str, "c:\fonts\fontfour.ttf")
DllCall("RemoveFontResource", Str, "c:\fonts\fontfive.ttf")
PostMessage, 0x1D,,,, ahk_id 0xFFFF
return

Barring any major oversight, I think that's all there is to it. I'm not sure whether sending the scripts to autohotkey when it's already running is recommended, but it works, and scripts contained in autohotkey.ini don't appear to be affected (they continue to work during and after the font loading and unloading).

Thanks once again to everyone who helped out on this thread, and of course to the developers of autohotkey (thankyouthankyouthankyou!) - a really sweet piece of programming that I'm well chuffed to have come across.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 19th, 2006, 12:26 am 
Script undoubtfully nominated to be moved to the Scripts&Functions section! 8)


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: October 19th, 2006, 8:58 am 
Offline

Joined: December 27th, 2005, 1:46 pm
Posts: 6837
Location: France (near Paris)
Good, I indeed thought it was so simple, but I had no time to test this. And you learnt some bits while doing this.
Another thing you can learn: no need for three files, even less for a batch one, AutoHotkey is able to run your program:

Code:
DllCall("AddFontResource", Str, "c:\fonts\fontone.ttf")
DllCall("AddFontResource", Str, "c:\fonts\fonttwo.ttf")
DllCall("AddFontResource", Str, "c:\fonts\fontthree.ttf")
DllCall("AddFontResource", Str, "c:\fonts\fontfour.ttf")
DllCall("AddFontResource", Str, "c:\fonts\fontfive.ttf")
PostMessage, 0x1D,,,, ahk_id 0xFFFF

RunWait c:\programs\fonthungryprogram\whatever.exe

DllCall("RemoveFontResource", Str, "c:\fonts\fontone.ttf")
DllCall("RemoveFontResource", Str, "c:\fonts\fonttwo.ttf")
DllCall("RemoveFontResource", Str, "c:\fonts\fontthree.ttf")
DllCall("RemoveFontResource", Str, "c:\fonts\fontfour.ttf")
DllCall("RemoveFontResource", Str, "c:\fonts\fontfive.ttf")
PostMessage, 0x1D,,,, ahk_id 0xFFFF

As I wrote earlier, perhaps you can even get rid of the PostMessages, because the newly ran program will see them (theoritically) and the already running programs won't, which is more or less what you wanted. To test, of course.

_________________
Image vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2")


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 24 posts ]  Go to page Previous  1, 2

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 1 guest


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group