Sponsoring website: Emergency Boot CD

Windows Power-User Series


Hacking Windows™ 95/98/NT
NOTEPAD: Changing the Display Font
( Try something new in Notepad ...
Use the old DOS characters again!
The alternate Fonts are displayed below.)




Have you ever looked at some old DOS documents with graphics or special characters and wished you could see them as intended in a Windows program rather than having to open it in an old DOS Editor using a DOS-window? You could use the OEM font set which comes close to the view you'd see in a full-size DOS window. But Notepad is stuck with ONLY ONE font, and many other Windows programs don't allow you to use the OEM font either!
Well, by changing the value of one byte in Notepad, you can display a file in one of five new fonts; including the OEM font shown here:


( Note: The free editor, PFE32, has an optional setting for using the OEM font.)

Eventually, I will not only create a fully reversible patch program, but hope to make one which will allow you to choose any of the available fonts from a menu inside of NOTEPAD. Until then, I'll show you how to change Notepad so you can also use one of these fonts too:





This last one certainly doesn't look very appealing. From the choices available, I'd imagine that apart from using the OEM font (byte = 0Ah) to view old DOS documents, most of you might like to try the ANSI_FIXED_FONT (byte = 0Bh).



What Needs to be Changed in Notepad


Program Operation

Notepad actually uses some code from a Windows system program called GDI32.DLL to set up how it will display the contents of any file it opens. The particular API (Application Program Interface) instruction we need to identify in the code is called GetStockObject. When Notepad calls upon GDI32 to run this specific instruction, it must also send a parameter (or argument) which tells it what font to use. Notepad passes the data to GDI32 by first placing it in a specific location of an area of memory known to the program as The Stack; we say it pushes the data onto the stack. And, logically enough, we'll be looking for a PUSH instruction just before the CALL to the GDI32 code. Unless you want to try your hand at using whatever sophisticated Windows debugging program you might have, then don't worry about these details!! It makes sense (and turns out to be true) that there'd be only one reference to GDI32.GetStockObject in the Notepad code, and for a Windows 95 'B' machine, it will look like this once the code is loaded into memory:

004027BE   6A10           push 00000010
004027C0   FF1594724000   Call dword ptr [00407294]


Here are some notes (only the details pertaining to fonts shown here) from a reference work on Windows API code [My own comments in brackets]:


 The GetStockObject function retrieves a handle to one of the predefined
                             stock pens, brushes, fonts, or palettes.
 HGDIOBJ GetStockObject(
         int  fnObject       // type of stock object
         );

 Parameters
 fnObject -- Specifies the type of stock object. This parameter can be
             any one of the following values [only the fonts shown above
             will be listed here]:

    Value             Meaning

 SYSTEM_FIXED_FONT    Fixed-pitch (monospace) system font already used
  [ 16 = 10h ]        in Windows versions earlier than 3.0 [This is the 
                      font used by NOTEPAD. Note the hex byte 10 that's
                      pushed onto the stack just before the call.]

 OEM_FIXED_FONT       Original equipment manufacturer (OEM) dependent
  [ 10 = 0Ah ]        fixed-pitch (monospace) font. [This gives us an
                      acceptable approximation in Windows programs to
                      the old DOS font characters on most systems.]

 ANSI_FIXED_FONT      Windows fixed-pitch (monospace) system font.
  [ 11 = 0Bh ]        [Might be a nice alternative to the original font.]

 ANSI_VAR_FONT        Windows variable-pitch (proportional space) system
  [ 12 = 0Ch ]        font. [Sure looks tiny; although this might be very
                      useful if you had huge text files to search!]

 DEVICE_DEFAULT_FONT  "Windows NT only: Device-dependent font." [I'm not
  [ 14 = 0Eh ]        exactly sure what this means, but from the pictures
                      above you might conclude that using the 0Eh byte in
                      Windows 95 simply displays the ANSI_FIXED_FONT with
                      a larger size.]

 SYSTEM_FONT          System font. By default, Windows uses the system
  [ 13 = 0Dh ]        font to draw menus, dialog box controls, and text.
                      In Windows versions 3.0 and later, the system font
                      is a proportionally spaced font; earlier versions
                      of Windows used a monospace system font. [ NOTE:
                      By trying many different byte values, I came to the
                      conclusion that using any value not defined on this
                      list produces the same effect as using this font.]



Actually making the change to Notepad

After searching for the string of hex digits which makes up the two instructions shown above (6A 10 FF 15 94 72 40 00) and verifying that they occur only once in the file, I identified what I've been calling the font byte (10h in the PUSH instruction) as offset location 001BBF for my copy of NOTEPAD.EXE (08-24-96 11:11a 34,304 bytes).

If you have Windows 95 B and know how to use a hex editor (see the section titled, Making the changes to Notepad Yourself on my page about Removing the 'Nag Screen' if you need a free hex editor and some help using it), then you've already got all the info you need... Just load a COPY of NOTEPAD.EXE into your hex editor and go for it.

For those of you with Win 98, 98SE or NT I'd like to verify my findings before releasing them publicly; but feel free to ask for the information if you want to try it out! (Use:
this online form to contact me.) I still need to search through a copy of Win NT's NOTEPAD.

NOTE: Since Notepad isn't very large (roughly 30kb) you might want to make a couple different versions saved under different names for whenever you might need them: NOTEANSI.exe or NOTEPOEM.exe (at least until I can make a menu program for choosing these fonts from within Notepad). Also: Notepad appears to run OK from any folder, even a different drive, at least on my Win 95 B machine, so you could place these patched copies in separate folders.

More information will be added upon verification !

Posted: Tuesday August 22, 2000


DISCLAIMER

Microsoft is a registered trademark, and the Microsoft Windows logos and screens are trademarks of Microsoft. The phrases "Windows 95," "Windows 98," "Windows NT," etc. may also be trademarks of Microsoft. All other logos or trademarks are owned or are property of their respective owner or owners.

Although I do try to help those in need when time permits, I am not responsible for any damage which may be caused by any software or information that you view or download from this web site, nor for any information obtained from or regarding the personal descriptions or opinions of others on pages that may be accessible from this page.


The Starman's Windows
Power-User Series
Page

The Starman's Free Tools
for Windows™ Page