News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Iczelion's Tutorial 35

Started by Robert Collins, December 27, 2004, 06:09:28 AM

Previous topic - Next topic

pbrennick

Robert,
There are 3 structures that are important for font setting.  Giving you a portion of my code is causing real problems because SetFormat is relying on some of those structures being initialized at the start of the program based on initial settings if it is a first run or data from the registry if not a first run.

What I am going to do is attach my complete project to this posting so you can see how I initialized the structures.  If the font looks too bold something is wrong in one of the structures.

If you play with the part of my editor that is used to build projects, remember that it expects the .rc and .asm files to have the same names, such as test.asm and test.rc

Also, I have not written the code for console builds yet, that will be in the next few days ahead and then the project will be complete except for updating the docs.

Once you have got the info from my project that you need, feel free to continue to ask questions.  It sounds like you are determined to learn, that attitude will get you far.  Keep it up.

Paul


[attachment deleted by admin]

raymond

#16
Paul,

Thanks for your code on WYSIWYG printing. That may be what I was looking for. I'm going to experiment with it to fit my specific needs. (I had previously attempted that route, but failed because I couldn't understand some of the requirements.)

Raymond
When you assume something, you risk being wrong half the time
http://www.ray.masmcode.com

pbrennick

Raymond,
Have you written a procedure that does the page setup?  Sets margins, orientation, etc.
Paul

raymond

Paul,

That was several months ago. At that time, I didn't really understand what was required in the two DC parameters, nor how to fill the two RC parameters, nor how to use the EM_FORMATRANGE message. Your code should now help me in setting things up properly.

Thanks

Raymond
When you assume something, you risk being wrong half the time
http://www.ray.masmcode.com

Robert Collins

Hi Paul,

OK, I d/l your source and have been going over it briefly. My first impression was that this is one great looking and functional editor and the code is laid out real professional like. Your style of coding is nicely organized, extremely (and well done) commented, and easy to follow. I wish the other programmers where I work would follow your style.

Well, before I start to get into it I have encountered something that I am not sure what is going on. It appears that the font selection from the drop down font dialog box doesn't seem to work as I would expect it to. As I select different fonts it doesn't change the font in the text window. Now, sometimes it will but in most cases it wont. I toggled back and forth with several different font names and style (bold, italic, regular, etc) but the text remains the same in the text editor window. Also, I selected Wingdings but the font remained the same as it was but later when I changed from Wingding to some other font the Wingding font appeared. At one time I had selected MS Sans Serif and the font did change but it wasn't MS Sans Serif, I don't know what font it was but I know it wasn't MS San Serif. Now, whatever it was, I then went back and changed it from Regular to Bold and then the Wingding font appeared. Are you aware of any problems with this feature of the program.

One thing that I noticed in all font selections was that none of them ever appeared as bold when I selected the bold style.

Robert Collins

Ok, I went into the code and commented out the below two lines in WndProc @ WM_INITDIALOG


       inv  GtFrmRegistry            ; Load settings from Registry
       inv  LoadMRUFiles             ; Load MRU from Registry


Now when I play around with the fonts from the dialog box they do change to the fonts I select, but still I am unable to change the style. It appears that the Regular, Italic, Bold, Bold Italic styles are ignored. 

Robert Collins

Hi Paul,

Me again. Here is something that is somewhat confusing me.

In the Registry I found the following:

HKEY_LOCAL_MACHINE\Software\Editor+

Background Color                             0x00ffffff (16777215)
Character Font                               "Courier"
Font Height                                  0xfffffff3 (4294967283)
Font Weight                                  0x00000190 (400)
MRU_File1                                    "C:\Assembly32\GeneSys\GeneSys.asm"
MRU_FIle2                                    ""
MRU_FIle3                                    ""
MRU_FIle4                                    ""
MRU_FIle5                                    ""
Point Size                                   0x00000064 (100)
Text Color                                   0x00000000 (0)


Which is what your program retrieves at WndProc WM_INITDIALOG

    .
    .
    inv  GtFrmRegistry            ; Load settings from Registry
    '
    ''


So, it should load the font stated in the registry, 'Courier', but it doesn't. It loads a font called 'Lucida Handwriting' which is one if the fonts I was playing around with earlier. As it turns out I put that name in the below variable:

FontName        DB  'Lucida Handwriting', 32-18 Dup (0)   ; 32 bytes max (including ASCIIZ terminator)

My question is wouldn't the information in the registry superceed any hard coded names in the program? Otherwise, what is the point of saving the font name in the registry if the program ignores it and uses the font name in the variable? I haven't studied the code so maybe there is something that I am overlooking.

pbrennick

Robert,
I am going to repair the registry and stausbar update problem that you discovered and then repost the project.  If you save your data as an rtf file it will then preserve the formatting you placed on the data.  But there is definitely a problem as I just stated.
Paul

Robert Collins

Quote from: pbrennick on December 29, 2004, 09:32:17 PM
Robert,
I am going to repair the registry and stausbar update problem that you discovered and then repost the project.  If you save your data as an rtf file it will then preserve the formatting you placed on the data.  But there is definitely a problem as I just stated.
Paul


You know, that never entered my mind. So, you are saying that a saved file as an RTF will preserve the formatting (incl. font, font size, etc). OK, I agree but during my playing around with the editor I never saved anything.

Here is what I find:

In the below snippit FontName = 'Ludica Handwriting' and is copied to lfnt.lfFontName. This is the first occurance of using FontName.


WndProc proc
   '
   '
   inv  lstrcpy, Offset lfnt.lfFaceName, Offset FontName ; Get fontname
   '
   '


In the below snippit FontName = 'Ludica Handwriting'. This is the 2nd occurance of FontName used.


ShowFont proc
   .
   .
   inv  lstrcpy, Addr Stuffing, Addr FontName  ; Build the message
   '
   '


In the below snippit FontName and szFontName = 'Ludica Handwriting' on the first time into this proc.
On the second time into this proc FontName and szFontName = 'Courier'.
This is the 3rd and 4th time FontName is used.


GtFrmRegistrt proc
   .
   .
   inv  lstrcpy, Addr FontName, Addr szFontName    ; Store FontName
   '
   '
/code]

So, the only other variable is lfnt.lfFontName which contained 'Ludica Handwriting'

Robert Collins

In the below line lfnt.lfFaceName is 'Ludica Handwriting'. This is why it doesn't put the font from the registry into the cf structure.
Either you need to use FontName or somewhere else in the code you need to initialize lfnt.lfFaceName with the name of the font
from the registry.



SetFormat proc
   .
   .
   inv  lstrcpyn, Addr cf.szFaceName, Offset lfnt.lfFaceName, LF_FACESIZE
   '
   '

pbrennick

There is a problem and I am working on it.  I may not be able to get a solution for several days because of a personal problem.  As it is the version I have on my machine loads and saves to the registry correcly and the statusbar correctly shows the current font.  The only problem I have left is initializing the font at the beginning of the run.  I can get it to load something but something is still wrong.
Be patient, Rome wasn't built overnight,
Paul

donkey

#26
Hi Paul,

If you are loading and saving a font to the registry why not use raw data and just save the structure directly. Yes even in MASM syntax :)

FontSubKey DB "Software\SomeCompany\SomeApp\Preferences",0
userfontvalue DB "UserFont",0
; If no font entry is found Tahoma 10pt will be the default
FontStruct LOGFONT <-13,0,0,0,900,FALSE,FALSE,0,0,0,0,0,0,"Tahoma">


SaveFontToReg proc
LOCAL hFontKey :DWORD
LOCAL Disposition :DWORD

invoke RegCreateKeyEx,HKEY_CURRENT_USER,OFFSET FontSubKey,0,0, \
REG_OPTION_NON_VOLATILE,KEY_ALL_ACCESS,0, \
ADDR hFontKey,ADDR Disposition

invoke RegSetValueEx,[hFontKey], OFFSET userfontvalue, 0, REG_BINARY, \
OFFSET FontStruct, SIZEOF LOGFONT

invoke RegCloseKey,[hFontKey]
ret
SaveFontToReg endp


LoadFontFromReg proc
LOCAL hFontKey :DWORD
LOCAL uDataCode :DWORD
LOCAL nBytes :DWORD

mov [nBytes],SIZEOF LOGFONT
invoke RegOpenKeyEx,HKEY_CURRENT_USER,OFFSET FontSubKey, \
0,KEY_READ,ADDR hFontKey
or eax,eax
jnz @F
invoke RegQueryValueEx,[hFontKey],OFFSET userfontvalue,0, \
ADDR uDataCode,OFFSET FontStruct,ADDR nBytes

invoke RegCloseKey,[hFontKey]
@@:
ret

LoadFontFromReg endp
"Ahhh, what an awful dream. Ones and zeroes everywhere...[shudder] and I thought I saw a two." -- Bender
"It was just a dream, Bender. There's no such thing as two". -- Fry
-- Futurama

Donkey's Stable

Robert Collins

I wouldn't do it that way because you wind up with the following registry entry:


UserFont                           F3 FF FF FF 00 00 00 00 00 00 00 00 00 00 00 00 84 03 00 00 00 00 00 00 00 00 00 00 54 61 68 6F 6D 61 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00


.....and it makes it too difficult to know what it is by looking at the entry in the registry. I like to see each key and it's value so if I wanted to modify the registry I
would know how to do it.

pbrennick

Donkey,
Thamks for the information, I will play with it even though the registry load/save is now correct in the nwest version that has not been posted yet.  I am going crazy trying to find out ehat is wrong with the initial font creation which uses the data from the registry.  I am using a MessageBox to debug and the fourth quadrant of the statusbar shows basic information about the default font.  What is driving me crazy is that if I load the font dialog and then close it without any changes all is fixed and the font displays correctly.  Please note that although I am using the RichEdit control I only am using it for the ability to load huge files like the Bible text.  The fact that opening the dialog and then closing it is leading me to believe that maybe I should initialize the CHOOSEFONT structure.
Paul

Paul

pbrennick

#29
Robert,
The font problem is solved.  Ramon gently reminded me that lfnt.lfCharset needs to be set correctly.  Stupid oversight on my part and Ramon rocks!  I have a small issue with text color not being set correctly after the font dialog runs and I am not recreating the font after the window is destroyed by clicking on New in the menu.  As you probably know, this is why clicking on New causes the font to switch to Tahoma which is the default font for that control.  These are simple fixes and when I have completed them, I will repost the code in Manos' subforum called Windows Projects, probably tomorrow or Saturday at the latest because of my personal problem.  Your critique of my code has caused it to become a better program and I thank you very much for your guidance and wish you good fortune in your future programming endeavors.  In the future let's continue this discussion in Manos' subforum, okay?  I would encourage you to post your efforts in Manos' subforum, as well, when you are ready.  That way we can continue to help you along.

Paul

EDIT:  TextColor is repaired, one to go!