Author |
Topic: Changing fonts (Read 442 times) |
|
g3nrw
Junior Member
member is offline


Posts: 74
|
 |
Changing fonts
« Thread started on: Oct 12th, 2014, 08:13am » |
|
I want to change the font in a program, by following an example in:
http://bb4w.wikispaces.com/Changing+the+font+of+a+control
As a test, I inserted the following code into DLGDEMO.bas, immediately after dlg%=FN_newdialog: Code:
dlg%=FN_newdialog("Dialogue box", 20, 20, 160, 128, 8, 560)
SYS "CreateFont",60,0,0,0,700,1,1,0,0,0,0,0,0,"Arial" TO hfont%
SYS "SendMessage", dlg%, WM_SETFONT, hfont%, 0
hoping that all text in the window would be displayed in 60pt Arial Bold Italic Underline.
But the font remained as the default (Fixedsys?).
What am I missing?
-- Ian
|
|
Logged
|
|
|
|
rtr2
Guest
|
 |
Re: Changing fonts
« Reply #1 on: Oct 12th, 2014, 09:34am » |
|
on Oct 12th, 2014, 08:13am, g3nrw wrote: Multiple errors there, I'm afraid:
The first parameter of SendMessage should be !dlg% rather than dlg% (just a typo I expect).
You are trying to change the font of a dialogue box which does not yet exist! Any code which uses the dialogue's handle must go after the PROC_showdialog() (!dlg% is zero beforehand).
Nothing ever gets 'printed' in the parent dialogue box (only in its child controls) so even if you succeeded in changing the associated font the effect would be 'invisible'. Quote:But the font remained as the default (Fixedsys?). |
|
The default dialogue box font is MS Sans Serif (strictly speaking the font should be discovered at run-time because it varies between different versions of Windows, themes etc., but WINLIB2 doesn't bother).
Richard.
|
|
Logged
|
|
|
|
g3nrw
Junior Member
member is offline


Posts: 74
|
 |
Re: Changing fonts
« Reply #2 on: Oct 12th, 2014, 3:12pm » |
|
Hmmm
In fact I tried creating the font before and after showdialog, with the same unexpected non-result.
Just to be certain I have not made a mistake in CreateFont, I have copied your "CreateFont" command example exactly, previously setting up values for h% etc. Also, for fun, I have included a MessageBox to show the value of the font handle: Code:
PROC_showdialog(dlg%)
REM New code in DLGDEMO.bas
WM_SETFONT = 48
h% = 20
w% = 900
i% = 1
u% = 1
SYS "CreateFont",h%,0,0,0,w%,i%,u%,0,0,0,0,0,0,"Courier New" TO hfont%
SYS "SendMessage", !dlg%, WM_SETFONT, hfont%, 0
SYS "MessageBox", @hwnd%, "hfont%= " + STR$(hfont%), "", 0
REM End of new code
I have tried many variations of the variables h% etc, but there is no change to the displayed default font -- even when using "TRUE" for i% and u%.
I was a little suprised (I think) to see the font handle value vary widely from run to run, from very large negative numbers to very large positive numbers (e.g.1234567E9). Are those values real?
Finally, just to make sure I am not totally misunderstanding all of this, I was hoping to change the font of all the text in the "Dialog Box" that appears in DLGDEMO.bas. Or am I really setting up the font for an as yet non-existent *child* of "Dialog Box"?
-- Ian
|
|
Logged
|
|
|
|
rtr2
Guest
|
 |
Re: Changing fonts
« Reply #3 on: Oct 12th, 2014, 5:34pm » |
|
on Oct 12th, 2014, 3:12pm, g3nrw wrote:In fact I tried creating the font before and after showdialog, with the same unexpected non-result. |
|
Indeed, as my reply explained (item 3):
"even if you succeeded in changing the associated font the effect would be 'invisible'".
Quote:I was hoping to change the font of all the text in the "Dialog Box" that appears in DLGDEMO.bas. |
|
There is no straightforward way to do that. In any case you should not (normally) be attempting to use a non-standard font. Windows is all about presenting a uniform user interface, so that the dialogue boxes in your program look the same (or nearly so) as the dialogue boxes in every other program.
Richard.
|
« Last Edit: Oct 12th, 2014, 5:39pm by rtr2 » |
Logged
|
|
|
|
sveinioslo
Developer
member is offline


Posts: 64
|
 |
Re: Changing fonts
« Reply #4 on: Oct 12th, 2014, 10:55pm » |
|
Quote: I was hoping to change the font of all the text in the "Dialog Box" that appears in DLGDEMO.bas |
|
This can be done by: 1. copy content of WINLIB2 to your program. 2. locate near the end of WINLIB2, this line: Code:SYS "MultiByteToWideChar", 0, 0, "MS Sans Serif", -1, dlg%+2*L%+40, 16 TO F% 3. as you probably can see already, change the 'MS Sans Serif' to the desired font. The fontsize you change by the next last value (8) of this line: Code:dlg%=FN_newdialog("Dialogue box", 20, 20, 160, 128, 8, 560)
One side effect of doing it this way, is that the dialoguebox size varies with different font sizes.
Svein
|
|
Logged
|
|
|
|
rtr2
Guest
|
 |
Re: Changing fonts
« Reply #5 on: Oct 13th, 2014, 08:05am » |
|
on Oct 12th, 2014, 10:55pm, sveinioslo wrote:This can be done by: 1. copy content of WINLIB2 to your program. 3. change the 'MS Sans Serif' to the desired font. |
|
This is undesirable in so many ways!
Richard.
|
|
Logged
|
|
|
|
Matt
Developer
member is offline


Gender: 
Posts: 210
|
 |
Re: Changing fonts
« Reply #6 on: Oct 13th, 2014, 8:44pm » |
|
on Oct 13th, 2014, 08:05am, g4bau wrote:This is undesirable in so many ways! |
|
Can you explain why?
A couple of years ago, I adjusted a WINLIB2 version that included DEF FN_newdialogf(title$,x%,y%,cx%,cy%,font%,size%,typeface$) and SYS "MultiByteToWideChar", 0, 0, typeface$, -1, dlg%+2*L%+40, 16 TO F%
This seemed to work fine, although I only ever used it once. (For some reason, I don't seem to have a copy of it now.) Is there a real potential for error with ajusting your code in this way?
Matt
|
|
Logged
|
|
|
|
rtr2
Guest
|
 |
Re: Changing fonts
« Reply #7 on: Oct 13th, 2014, 9:37pm » |
|
on Oct 13th, 2014, 8:44pm, Matt wrote: I thought these points were very well known:
Copying a library into a program 'freezes' it, so that subsequent changes to the library do not automatically get incorporated when the program is next compiled. This practice has in the past resulted in users reporting an incompatibility with a new version of Windows, when in fact the library has already been updated to address the issue.
Creating a 'custom' library, based on one of the supplied libraries, has much the same consequences. If the library on which it was based is updated, to fix a bug or improve compatibility, the user must remember to incorporate the changes into his customised version. Even if he remembers to do so, it can be quite difficult to transfer the modifications reliably, especially if it's not obvious what they are for or how they work (the supplied libraries are notoriously badly structured and commented, for reasons of brevity and speed).
Changing the 'default' dialogue box font, which then 'propagates' to all the child controls, is contrary to the fundamental principle of Windows of presenting a uniform user interface whatever application is being used. Imagine what would happen if the font size were increased significantly and the user has also selected extra large fonts because of (say) an eyesight problem. The combination of the two could result in a dialogue box which doesn't fit on the screen or is otherwise impossible to use.
If you must modify the functionality of a library (and I would need to be convinced) remember that you need only copy an individual FN/PROC into your program - which will then automatically take precedence over the one with the same name in the library. That reduces the possibility of future problems if the library is updated. I cannot think of any circumstances when it makes sense to copy an entire library into a user's program as Svein advocates. Richard.
|
« Last Edit: Oct 13th, 2014, 10:43pm by rtr2 » |
Logged
|
|
|
|
|