Function Reference


Adds the font resource from a memory image to the system

#include <WinAPIGdi.au3>
_WinAPI_AddFontMemResourceEx ( $pData, $iSize )


$pData The pointer to a font resource.
$iSize The number of bytes in the font resource.

Return Value

Success: The handle uniquely identifies the fonts that were installed on the system,
@extended flag will contain a number of fonts added to the system as a result of this call.
Failure: 0.


This function allows an application to get a font that is embedded in a document or a Web page.
A font that is added by this is always private to the process that made the call and is not enumerable.

When the function succeeds, the caller of this function can free the memory pointed to by $pData because the system has made its own copy of the memory.
To remove the fonts that were installed, call _WinAPI_RemoveFontMemResourceEx().
However, when the process goes away, the system will unload the fonts.



See Also

Search AddFontMemResourceEx in MSDN Library.


#include <APIMiscConstants.au3>
#include <APIResConstants.au3>
#include <GUIConstantsEx.au3>
#include <Memory.au3>
#include <MsgBoxConstants.au3>
#include <StaticConstants.au3>
#include <WinAPIGdi.au3>
#include <WinAPIMisc.au3>
#include <WinAPIRes.au3>

Local Const $sJpg = @TempDir & '\~Tech.jpg'

; Load Resources.dll to memory
Local $hInstance = _WinAPI_LoadLibraryEx(@ScriptDir & '\Extras\Resources.dll', $LOAD_LIBRARY_AS_DATAFILE)
If Not $hInstance Then
        MsgBox(($MB_ICONERROR + $MB_SYSTEMMODAL), 'Error', @ScriptDir & '\Extras\Resources.dll not found.')

; Load JPEG resource from Resources.dll library
Local $hResource = _WinAPI_FindResource($hInstance, 'JPEG', 1)
Local $iSize = _WinAPI_SizeOfResource($hInstance, $hResource)
Local $hData = _WinAPI_LoadResource($hInstance, $hResource)
Local $pData = _WinAPI_LockResource($hData)

; Save resource to .jpg file
Local $hFile = FileOpen($sJpg, 2 + 16)
Local $tData = DllStructCreate('byte[' & $iSize & ']', $pData)
FileWrite($hFile, DllStructGetData($tData, 1))

; Load FONT resource from Resources.dll library
$hResource = _WinAPI_FindResource($hInstance, $RT_FONT, 'TECHNOVIA_CAPS')
$iSize = _WinAPI_SizeOfResource($hInstance, $hResource)
$hData = _WinAPI_LoadResource($hInstance, $hResource)
$pData = _WinAPI_LockResource($hData)

; Add font from a memory to the system
Local $hFont = _WinAPI_AddFontMemResourceEx($pData, $iSize)

; Load SOUND resource from Resources.dll library
$hResource = _WinAPI_FindResource($hInstance, 'SOUND', 1)
$iSize = _WinAPI_SizeOfResource($hInstance, $hResource)
$hData = _WinAPI_LoadResource($hInstance, $hResource)
$pData = _WinAPI_LockResource($hData)

; Copy WAV to memory for use later
Local $hWave = _MemGlobalAlloc($iSize, $GMEM_MOVEABLE)
Local $pWave = _MemGlobalLock($hWave)
_MemMoveMemory($pData, $pWave, $iSize)
; _MemGlobalUnlock($hWave)

; Load STRING resource from Resources.dll library
Local $sText = _WinAPI_LoadString($hInstance, 1)

; Unload Resources.dll from memory

; Create GUI
GUICreate('Test ' & StringReplace(@ScriptName, '.au3', '()'), 350, 350)
GUICtrlCreatePic($sJpg, 0, 0, 350, 350)
GUICtrlSetState(-1, $GUI_DISABLE)
GUICtrlCreateLabel($sText, 10, 18, 330, 36, $SS_CENTER)
GUICtrlSetFont(-1, 30, -1, -1, 'Technovia Caps')
GUICtrlSetColor(-1, 0xF06000)
Local $idButton = GUICtrlCreateButton('Play Sound', 125, 316, 100, 23)

While 1
        Switch GUIGetMsg()
                Case $GUI_EVENT_CLOSE
                Case $idButton
                        _WinAPI_PlaySound($pWave, BitOR($SND_ASYNC, $SND_MEMORY, $SND_NOWAIT))

; Free resources