TheCodeCracker Posted February 24, 2008 Posted February 24, 2008 Hi Guys...i am learnning masm...and have managed to learn howto skin windows, buttons as well as some other controls.I have even managed to design some small keygen templates. but guys i need some help regarding using custom fonts both open type as well as True TypesI'll be grateful for any helpgreetz,TCC/CiB
Ufo-Pu55y Posted February 24, 2008 Posted February 24, 2008 (edited) Quickly made a radasm bone:FontFromResources.rarIt won't save the font to hdd, but be aware, that 'AddFontMemResourceEx' doesn't work on Win98. Edited February 24, 2008 by Ufo-Pu55y
diablo2oo2 Posted February 24, 2008 Posted February 24, 2008 (edited) Quickly made a radasm bone:FontFromResources.rarIt won't save the font to hdd, but be aware, that 'AddFontMemResourceEx' doesn't work on Win98.nice. too bad that the AddFontMemResourceEx API is not supportet for win me/98... Maybe better use AddFontResource API ??? (After using the font it shoulde be removed with RemoveFontResource?)is there also a method for win 98/me systems? Maybe there is a method installing a font over commandline? Edited February 24, 2008 by diablo2oo2
TheCodeCracker Posted February 24, 2008 Author Posted February 24, 2008 Thank You UFO-Pussy....Atlast...i was expecting the answer from you and Ziggy only... Thanks Again greetz, TCC/CiB
Ufo-Pu55y Posted February 24, 2008 Posted February 24, 2008 nice. too bad that the AddFontMemResourceEx API is not supportet for win me/98... Maybe better use AddFontResource API ??? (After using the font it shoulde be removed with RemoveFontResource?)is there also a method for win 98/me systems? Maybe there is a method installing a font over commandline? Here's a code I've found on MASM board, which should work for 98 (AddFontResource):Instal_Font.zipBut you have to write it to system's font dir and register it Thank You UFO-Pussy....Atlast...i was expecting the answer from you and Ziggy only...Thanks Again Tho I got it, after Killboy found a c++ snippet about that ^^
Loki Posted February 25, 2008 Posted February 25, 2008 May be similar to what UFO posted (not checked) but I have used the following to register a new font (not removed afterwards though)ResExtractFile proc hInst:DWORD, Resource:DWORD, ResMarker:DWORD, Destination:DWORDLOCAL hRsrc:DWORDLOCAL hResource:DWORDLOCAL dwResSize:DWORDLOCAL hFile:DWORDLOCAL dwWritten:DWORDLOCAL lpfResource:DWORDLOCAL hkResult:DWORDLOCAL dwDisposition:DWORDLOCAL dwLength:DWORDinvoke FindResource,hInst,Resource,ResMarker.if eax == NULL not eax.else mov hRsrc,eax invoke LoadResource,hInst,hRsrc .if eax == NULL not eax .else mov hResource,eax invoke SizeofResource,hInst,hRsrc mov dwResSize,eax invoke LockResource,hResource mov lpfResource,eax invoke CreateFile, Destination, GENERIC_WRITE, 0, NULL, CREATE_NEW, FILE_ATTRIBUTE_NORMAL, NULL mov hFile, eax invoke WriteFile, hFile, lpfResource, dwResSize, ADDR dwWritten, NULL invoke CloseHandle, hFile invoke lstrlen, addr szFileName mov dwLength,eax invoke RegCreateKeyEx, HKEY_LOCAL_MACHINE, ADDR szSubKey, NULL, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, ADDR hkResult, ADDR dwDisposition .if eax == ERROR_SUCCESS invoke RegSetValueEx, hkResult, addr szValueName, NULL, REG_SZ, addr szFileName, dwLength invoke RegCloseKey, ADDR hkResult .endif invoke AddFontResource, addr szFileName invoke SendMessage, HWND_BROADCAST, WM_FONTCHANGE, NULL, NULL .endif .endifretResExtractFile endpThe font file is added to the resources with:FontFile BINFILE fonts\<font_name>.TTF
mudlord Posted February 25, 2008 Posted February 25, 2008 Tho I got it, after Killboy found a c++ snippet about that ^^ Any chance Killboy can repost this C++ code snippet?
Ufo-Pu55y Posted February 25, 2008 Posted February 25, 2008 That was the snippet I got: HINSTANCE h=AfxGetInstanceHandle(); ULONG nFont = 1; HRSRC hr=FindResource(h, "#4" , RT_FONT); HGLOBAL hg=LoadResource(h,hr); LPSTR lp=(LPSTR)LockResource(hg); DWORD dwSize = SizeofResource(h, hr); HANDLE handle = AddFontMemResourceEx(lp, dwSize, 0, &nFont); // TODO: Add extra initialization here LOGFONT lf; memset(&lf, 0, sizeof(LOGFONT)); // Clear out structure. lf.lfHeight = 20; // Request a 20-pixel-high font strcpy(lf.lfFaceName, "LadderKK"); // with face name "Arial". m_font.CreateFontIndirect(&lf); // Create the font. GetDlgItem(IDC_EDIT1)->SetFont(&m_font); Still find it easier to read compiled c++ stuff than its source
mudlord Posted February 25, 2008 Posted February 25, 2008 Hehehe, for me its the exact opposite. I really should learn ASM these days, as all I use is C/C++. Thanks for the snippet though, it will come in handy
TheCodeCracker Posted February 25, 2008 Author Posted February 25, 2008 @UFO-PU55Y bro i'm using your code snippet but itn not setting the font.... I'm not getting any errors or warnings and the font is being set to Arial. I'm using WinASM as IDE and Masm v6. on Windows Vista Ultimate ( DlgProc proc hWin:DWORD,uMsg:DWORD,wParam:DWORD,lParam:DWORD mov eax,uMsg .if eax == WM_INITDIALOG invoke LoadIcon,hInstance,200 invoke SendMessage, hWin, WM_SETICON, 1, eax invoke FindResource,NULL,300,RT_RCDATA mov fntinfo,eax invoke LoadResource,NULL,eax invoke LockResource,eax mov pfont,eax invoke SizeofResource,NULL,fntinfo invoke AddFontMemResourceEx,pfont,eax,0,offset nfont invoke CreateFontIndirect,offset lfFont mov hfont,eax invoke GetDlgItem,hWin,1002 invoke SendMessage,eax,WM_SETFONT,offset hfont,1 .elseif eax == WM_COMMAND mov eax,wParam .if eax == IDB_EXIT invoke SendMessage, hWin, WM_CLOSE, 0, 0 .endif .elseif eax == WM_CLOSE invoke EndDialog, hWin, 0 .endif xor eax,eax retDlgProc endp
TheCodeCracker Posted February 25, 2008 Author Posted February 25, 2008 Sorry i got my error Me silly Anywyas Thanks again...i've learnt alot here and hope to learn more.... greetz TCC/CiB
ragdog Posted February 25, 2008 Posted February 25, 2008 hii have a another example found on my drivei hope its help youEmbedded.TTF.Font.Example.rargreetsragdog
diablo2oo2 Posted February 26, 2008 Posted February 26, 2008 Another Problem:If you have a font file which is named not correctly. How to get the correct font name so that you can use "CreateFont..." Funktion? Because the fontname seems to be stored inside the fontfile...Any idea?
Ufo-Pu55y Posted February 26, 2008 Posted February 26, 2008 (edited) Another Problem:If you have a font file which is named not correctly. How to get the correct font name so that you can use "CreateFont..." Funktion? Because the fontname seems to be stored inside the fontfile...Any idea?You'll see the correct name by simply doubleclicking and opening with system's font viewer.I renamed a bunch of font files with their correct font name in order to simply create themlater on with their filename w/o extension as parameter.But if you're after a code to retrieve the correct names:http://www.codeguru.com/cpp/g-m/gdi/fontha...le.php/c3659__1But that would prolly mean a ****load of code, coz truetype and opentype fonts are toodifferent to handle :XEDIT/Tho I just read about an undocumented GDI API call: GetFontResourceInfo !But no further info about what parameters it needs. I only read the commentto fire up SoftIce to check this function out for yourself.. lol Edited February 26, 2008 by Ufo-Pu55y
diablo2oo2 Posted February 26, 2008 Posted February 26, 2008 (edited) thank you ufo! i think the sourcecode getfontnamefromfile.cpp is interesting. i want build in this function additionally. because ttf files are used often. maybe i will translate it to masm.But first i will take a look to this GDI API GetFontResourceInfo.... --> http://www.autoitscript.com/forum/index.php?showtopic=30552 ...very interesting... Edited February 26, 2008 by diablo2oo2
TheCodeCracker Posted February 26, 2008 Author Posted February 26, 2008 Thanks UFO-PU55y and Diablo for this informative discusiion is this thread Thanks Again greetz, TCC/CiB
diablo2oo2 Posted February 26, 2008 Posted February 26, 2008 I figured out how to use the GetFontResourceInfoW function. Here is the masm code, how to get the correct fontname from any fontfile...GetFontName proc uses edi esi ebx _fontfile:dword,_buffer:dword,_buffersize:dword LOCAL local_hlib :DWORD LOCAL local_fontfile_wide[1024] :BYTE LOCAL local_sizeof_buffer :DWORD LOCAL local_fontstruct[92] :BYTE;unknown structure;---set return value to 0--- xor ebx,ebx invoke LoadLibrary,chr$("gdi32.dll") mov local_hlib,eax invoke GetProcAddress,eax,chr$("GetFontResourceInfoW") .if eax!=NULL mov edi,eax ;---convert ansi to unicode--- invoke MultiByteToWideChar,0,MB_PRECOMPOSED,_fontfile,-1,addr local_fontfile_wide,sizeof local_fontfile_wide ;---add font to Windows font table--- invoke AddFontResource,_fontfile ;---call undocumented GetFontResourceInfoW--- mov local_sizeof_buffer,sizeof local_fontstruct lea ecx,local_sizeof_buffer lea eax,local_fontfile_wide lea esi,local_fontstruct push 2 ;1=get fontname (works not always good) / 2=get structure with fontname push esi ;structure push ecx ;size of recievebuffer push eax ;font filename call edi ;GetFontResourceInfoW .if eax==TRUE mov ebx,eax ;modify return value to 1 add esi,28 ;point to correct unicode fontname ;---convert unicode to ansi--- invoke WideCharToMultiByte,0,WC_COMPOSITECHECK,esi,-1,_buffer,_buffersize,0,0 .endif ;---remove font from Windows font table--- invoke RemoveFontResource,_fontfile ;---free loaded dll--- invoke FreeLibrary,local_hlib .endif mov eax,ebx retGetFontName endp
Ufo-Pu55y Posted February 26, 2008 Posted February 26, 2008 Great ! I also tried it, but missed the AddFontResource and only tried it with unregistered fonts.. dooh. Ofc I didn't get **** returned from that function all the time ^^Cool that you figured it out ! :cool:
diablo2oo2 Posted February 26, 2008 Posted February 26, 2008 but this function is only for XP systems where gdi32.dll contains "GetFontResourceInfoW"in win98`s gdi32.dll its just called "GetFontResourceInfo". So maybe there are no widechars. I dont have win98 system. so i cant figure it out...
Killboy Posted February 26, 2008 Posted February 26, 2008 Why dont you use the ascii version by default ? Is there no A-version on XP ?
Ufo-Pu55y Posted February 26, 2008 Posted February 26, 2008 (edited) Why dont you use the ascii version by default ? Is there no A-version on XP ?nop. at least I couldn't find it. M$ ftw. Edited February 26, 2008 by Ufo-Pu55y
mudlord Posted February 27, 2008 Posted February 27, 2008 (edited) Which means this particular function is WinNT specific, since Unicode (wide char) functions can't natively be used under Win9x. And from my test app, it crashed when using a "A" alternative. Plus I have read somewhere that it is a native WinNT function.. Edited February 27, 2008 by mudlord
diablo2oo2 Posted March 3, 2008 Posted March 3, 2008 i noticed that using:SendMessage(HWND_BROADCAST,WM_FONTCHANGE,0,0);is not good after installing a font, even microsofts says, that its better when you use it after installing a font.But it causes strange bugs.
DfDf Posted April 4, 2008 Posted April 4, 2008 i noticed that using:SendMessage(HWND_BROADCAST,WM_FONTCHANGE,0,0);is not good after installing a font, even microsofts says, that its better when you use it after installing a font.But it causes strange bugs.Much better to use PostMessage... ;-)
diablo2oo2 Posted April 5, 2008 Posted April 5, 2008 i noticed that using:SendMessage(HWND_BROADCAST,WM_FONTCHANGE,0,0);is not good after installing a font, even microsofts says, that its better when you use it after installing a font.But it causes strange bugs.Much better to use PostMessage... ;-)no, the problem is not only the SendMessage API.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now