1. getFontDialog
- Posted by Judith Evans <camping at cce?b.net> Nov 22, 2007
- 654 views
- Last edited Nov 23, 2007
Using CChris last win32lib, 70.2a, I've got a little test program in which I use getFontDialog to assign font to a button control. I then use getFontDialog again and the font size is not what I selected in the prior use of getFontDialog. I sent the program to CChris and he says he gets the font size he selected the first time. He suggested I post here so more people could test and report back if their test worked or not and what version of Windows they use. To make sure we are all testing the same way, the first time you click the button, enter into Font Dialog "Arial", "Bold" and 14. Click OK. Now click the button again and see if the font size is 14 or 11 or some other number. But CChris also stated "using larger sizes like 24, I'm getting 1 more" so you might want to test that value also. When I run the test entering initially 14, I get back 11. When I click the button again and enter 24 font size and then click the button again I get 20 font size. Using XP PRO. Here is the code for the test program:
include Win32Lib.ew without warning constant Window1 = createEx( Window, "Window1", 0, Default, Default, 400, 300, 0, 0 ) constant PushButton2 = createEx( PushButton, "Click to change font", Window1, 88, 108, 184, 28, 0, 0 ) procedure PushButton2_onClick (integer self, integer event, sequence params)--params is () object fontdata fontdata=getFontDialog(PushButton2) if sequence(fontdata) then setFont(PushButton2, fontdata[1],fontdata[2],fontdata[3]) end if end procedure setHandler( PushButton2, w32HClick, routine_id("PushButton2_onClick")) WinMain( Window1,Normal )
judith evans
2. Re: getFontDialog
- Posted by Dan Moyer <danielmoyer at prodigy?net> Nov 23, 2007
- 630 views
Windows XP Home Edition, Version 5.1.2600 Service Pack 2 : For what it might be worth, these are the results I get using Win32Lib ModVersion: 0.60.6 11/July/2005 (at least, I *think* that's the version I'm using; I wonder if there is a good way to PROGRAMMATICALLY interrogate the included Win32Lib for its version #, being as there isn't a VARIABLE named: "version" in it?) "Arial", "Bold" and 14 yields: Arial, button:bold, dialog report:REGULAR, and 14; (note: the BUTTON actually BECOMES BOLD, but the dialog SAYS it's "Regular") "Arial", "Bold" and 15 yields: Arial, button:bold, dialog report:REGULAR, and 15; (same note as above) SUMMARY: up to *15* SIZE is implemented correctly on button and reported same in dialog, and STYLE is implemented correctly on button but NOT reported correctly in dialog after clicking button again. ------------------------------------------ "Arial", "Bold" and 16 yields: Arial, button:bold, dialog report:REGULAR, and 17; (same note as above) "Arial", "Bold" and 24 yields Arial, button:bold, dialog report:REGULAR, and 25; (same note as above) SUMMARY: at and at least for some above 16, SIZE is wrongfully INCREMENTED by one for both implementation on button and report in dialog, and STYLE is again implemented correctly on button, but NOT reported correctly in dialog. Note about button/dialog variance: when I SELECT "bold", the dialog initially INDICATES "bold"; on "ok", the button now SHOWS in BOLD, but when CLICKED on again, the dialog NOW SAYS "regular", and if "ok" clicked, the button will display in regular. Dan Moyer
3. Re: getFontDialog
- Posted by CChris <christian.cuvier at a?riculture?gouv.fr> Nov 23, 2007
- 616 views
Dan Moyer wrote: > > Windows XP Home Edition, > Version 5.1.2600 Service Pack 2 : > > For what it might be worth, these are the results I get using > Win32Lib ModVersion: 0.60.6 11/July/2005 > > (at least, I *think* that's the version I'm using; I wonder if there is a good > way to PROGRAMMATICALLY interrogate the included Win32Lib for its version #, > being as there isn't a VARIABLE named: "version" in it?) > Eh? Quote from win32lib.ew: --/const Win32LibVersion --/desc Contains the current version of win32lib library. -- This is a sequence containing four elements. /n --/li Major version number (integer) --/li Minor version number (integer) --/li Patch or /i Revision number (integer) --/li Date of the version in DD-Mmm-YYYY format (string) -- --Example --/code -- setText(SB, sprintf("Win32Lib version %d.%d Patch#%d, %s", -- Win32LibVersion)) --/endcode I won't swear that all intermediate steps have this variable properly set though... If only because a minor patch loke 0.70.2b cannot be specified - I'll probably change that, thanks for mentioning it. It is defined as early as v0.55.5. I don't have earlier versions of the library. > "Arial", "Bold" and 14 yields: > Arial, button:bold, dialog report:REGULAR, and 14; > (note: the BUTTON actually BECOMES BOLD, but the dialog SAYS it's "Regular") > > "Arial", "Bold" and 15 yields: > Arial, button:bold, dialog report:REGULAR, and 15; > (same note as above) > > SUMMARY: up to *15* SIZE is implemented correctly on button and reported same > in dialog, and STYLE is implemented correctly on button but NOT reported > correctly > in dialog after clicking button again. > > ------------------------------------------ > > "Arial", "Bold" and 16 yields: > Arial, button:bold, dialog report:REGULAR, and 17; > (same note as above) > > "Arial", "Bold" and 24 yields > Arial, button:bold, dialog report:REGULAR, and 25; > (same note as above) > > SUMMARY: at and at least for some above 16, SIZE is wrongfully INCREMENTED by > one for both implementation on button and report in dialog, and STYLE is again > implemented correctly on button, but NOT reported correctly in dialog. > > Note about button/dialog variance: > when I SELECT "bold", the dialog initially INDICATES "bold"; on "ok", the > button now SHOWS in BOLD, but when CLICKED on again, the dialog NOW SAYS > "regular", > and if "ok" clicked, the button will display in regular. > > Dan Moyer I never noticed that "regukar" was substituted. See my post from a few hours ago. The corrected version is probably up for download now. CChris
4. Re: getFontDialog
- Posted by Dan Moyer <danielmoyer at prodi?y.net> Nov 27, 2007
- 670 views
CChris wrote: > > Dan Moyer wrote: > > > > Windows XP Home Edition, > > Version 5.1.2600 Service Pack 2 : > > > > For what it might be worth, these are the results I get using > > Win32Lib ModVersion: 0.60.6 11/July/2005 > > > > (at least, I *think* that's the version I'm using; I wonder if there is a > > good > > way to PROGRAMMATICALLY interrogate the included Win32Lib for its version #, > > being as there isn't a VARIABLE named: "version" in it?) > > > > Eh? > Quote from win32lib.ew: > --/const Win32LibVersion > --/desc Contains the current version of win32lib library. > -- This is a sequence containing four elements. /n > --/li Major version number (integer) > --/li Minor version number (integer) > --/li Patch or /i Revision number (integer) > --/li Date of the version in DD-Mmm-YYYY format (string) > -- > --Example > --/code > -- setText(SB, sprintf("Win32Lib version %d.%d Patch#%d, %s", > -- Win32LibVersion)) > --/endcode > > I won't swear that all intermediate steps have this variable properly set > though... > If only because a minor patch loke 0.70.2b cannot be specified - I'll probably > change that, thanks for mentioning it. > And thank you for info that I should have found myself :) > It is defined as early as v0.55.5. I don't have earlier versions of the > library. > <<snip>> > > Note about button/dialog variance: > > when I SELECT "bold", the dialog initially INDICATES "bold"; on "ok", the > > button now SHOWS in BOLD, but when CLICKED on again, the dialog NOW SAYS > > "regular", > > and if "ok" clicked, the button will display in regular. > > > > Dan Moyer > > I never noticed that "regukar" was substituted. > See my post from a few hours ago. The corrected version is probably up for > download > now. > > CChris
5. getFontDialog
- Posted by Pete Lomax <petelomax at blueyonder.co.uk> Aug 17, 2003
- 597 views
Derek, In getFontDialog, I found if I changed the line: store( hLogFont, lfHeight, -(100 * window_font[id][FontSize])/72) to store( hLogFont, lfHeight, window_font[id][FontSize]*5/3) then it seems to work much better. I see the 100/72 trick on msdn, not that I really understand it. Anyway, just after that, it is also missing the following lines: attrib=3Dwindow_font[id][FontAttrib] if and_bits(attrib,Bold) then store( hLogFont, lfWeight, vFontWeight) end if store ( hLogFont, lfItalic, and_bits(attrib,Italic) ) store ( hLogFont, lfUnderline, and_bits(attrib,Underline) ) store ( hLogFont, lfStrikeOut, and_bits(attrib,Strikeout) ) store( hChooseFont, CF_rgbColors, window_font[id][FontColor] ) Regards, Pete
6. getFontDialog
- Posted by Tom Irwin <tomirwin506 at hot?ail.co?> Oct 02, 2007
- 629 views
I use w32Lib's getFontDialog to change selected text in richedit controls. However, endusers often want to change only one item of fontname, style, size, or color and report finding it awkward to have to set all four each time the dialog is called. In fact they make mistakes by changing just what they want changed, not realizing that they just reset the other attributes to default. It works differently for them than their other common Windows programs. It would be extremely useful if the dialog could be made to show the font of the original selected text (as in text editors like Wordpad). Can anyone help as to how this might be accomplished?
7. Re: getFontDialog
- Posted by CChris <christian.cuvier at agric?ltur?.gouv.fr> Oct 02, 2007
- 624 views
Tom Irwin wrote: > > I use w32Lib's getFontDialog to change selected text in richedit controls. > > However, endusers often want to change only one item of fontname, style, size, > > or color and report finding it awkward to have to set all four each time the > dialog > is called. In fact they make mistakes by changing just what they want > changed, > > not realizing that they just reset the other attributes to default. It works > differently > for them than their other common Windows programs. > > It would be extremely useful if the dialog could be made to show the font of > the > original selected text (as in text editors like Wordpad). > > Can anyone help as to how this might be accomplished? It can be done by copying the text of the getFontDialog() function and deriving a variant from it. It initialises a structure for the font chooser to display its initial values; the variant needs to set these values to those relevant to the selection, while the original uses values relevant for the control as a whole. To get these values, send the RichEdit control an EM_GETCHARFORMAT message with wParam = SCF_SELECTION (which is 1), and lParam being the address of a valid CHARFORMAT structure. This structure must be initialised so that, on return from sendMessage(), the fields which you need initialised are indeed set up. Use w32fetch() to retrieve the values to w32store() in the font chooser init structure. The newer win32lib can create the structure and get its address by calling w32to_memory(ID_CHARFORMAT,{field values}). The field values will be as needed by the needs of the clone of getFontDialog(). With older versions, there is a struct_CHARFORMAT() function to do this - not sure it was documented -. CChris
8. Re: getFontDialog
- Posted by Tom Irwin <tomirwin506 at ?otmail?com> Oct 09, 2007
- 676 views
CChris wrote: > > Tom Irwin wrote: > > > > I use w32Lib's getFontDialog to change selected text in richedit controls. > > > > However, endusers often want to change only one item of fontname, style, > > size, > > > > or color and report finding it awkward to have to set all four each time the > > dialog > > is called. In fact they make mistakes by changing just what they want > > changed, > > > > not realizing that they just reset the other attributes to default. It > > works > > differently > > for them than their other common Windows programs. > > > > It would be extremely useful if the dialog could be made to show the font of > > the > > original selected text (as in text editors like Wordpad). > > > > Can anyone help as to how this might be accomplished? > > It can be done by copying the text of the getFontDialog() function and > deriving > a variant from it. It initialises a structure for the font chooser to display > its initial values; the variant needs to set these values to those relevant > to the selection, while the original uses values relevant for the control as > a whole. > > To get these values, send the RichEdit control an EM_GETCHARFORMAT message > with > wParam = SCF_SELECTION (which is 1), and lParam being the address of a valid > CHARFORMAT structure. This structure must be initialised so that, on return > from sendMessage(), the fields which you need initialised are indeed set up. > Use w32fetch() to retrieve the values to w32store() in the font chooser init > structure. > > The newer win32lib can create the structure and get its address by calling > w32to_memory(ID_CHARFORMAT,{field > values}). The field values will be as needed by the needs of the clone of > getFontDialog(). > With older versions, there is a struct_CHARFORMAT() function to do this - not > sure it was documented -. > > CChris Thanks Christian for your help. In case it saves someone else some time, here is the code I came up with to have the font dialog select the existing font characteristics rather than the control default font: (Sorry, this is for w32Lib 60.6 that I was working with, but later version can use similar) Add this function just following existing getFontDialog function:
global function getFontDialogSelTxt( integer id, atom sentmask,atom senteffects,atom sentheight,atom sentoffset, atom senttxtcolor,atom sentcharset,atom sentpitchnfam, sequence sentfacename) integer points, attrib sequence font atom hChooseFont, hLogFont, color, mset, cf object result,colort integer owner -- assume failure result = -1 owner = findParentWindow(id) -- create structures mset = w32new_memset() hChooseFont = w32acquire_mem(mset, SIZEOF_CHOOSEFONT) hLogFont = w32acquire_mem(mset, SIZEOF_LOGFONT) -- populate the choose font structure w32store( hLogFont, lfFaceName, sentfacename) if sequence(ctrl_Font[id][FontSize]) then w32store( hLogFont, lfHeight, ctrl_Font[id][FontSize][1] ) else w32store( hLogFont, lfHeight, -(5 * sentheight)/74 ) -- don't know proper method so adjusted nums to --give produce correct point size end if w32store( hLogFont, lfWeight, ((and_bits( senteffects, Bold) ) != 0) * vFontWeight ) w32store( hLogFont, lfItalic, (and_bits( senteffects, Italic)) != 0 ) w32store( hLogFont, lfUnderline, (and_bits( senteffects, Underline)) != 0 ) w32store( hLogFont, lfStrikeOut, (and_bits( senteffects, Strikeout)) != 0 ) w32store( hChooseFont, CF_lStructSize, SIZEOF_CHOOSEFONT ) w32store( hChooseFont, CF_hwndOwner, getHandle( owner ) ) w32store( hChooseFont, CF_Flags, CF_INITTOLOGFONTSTRUCT+CF_SCRIPTSONLY+CF_SCREENFONTS+CF_EFFECTS) w32store( hChooseFont, CF_hLogFont, hLogFont ) w32store(hChooseFont, CF_rgbColors, senttxtcolor) -- call the dialog if w32Func( xChooseFont,{ hChooseFont } ) then -- pointer to structure good? if w32fetch( hChooseFont, CF_hLogFont ) then -- got pointer successfully font = w32peek_string( w32address( hLogFont, lfFaceName ) ) --font = "Arial Black" points = floor( w32fetch( hChooseFont, CF_iPointSize ) / 10 ) -- clear attributes attrib = 0 -- NEW! 0.45o check correct flag -- bold? if w32fetch( hLogFont, lfWeight ) >= vFontWeight then attrib += Bold end if -- italic? if w32fetch( hLogFont, lfItalic ) then attrib += Italic end if -- underline? if w32fetch( hLogFont, lfUnderline ) then attrib += Underline end if -- strikeout? if w32fetch( hLogFont, lfStrikeOut ) then attrib += Strikeout end if --get font color color = w32fetch( hChooseFont, CF_rgbColors ) -- save result result = { font, points, attrib, color } end if end if -- Free the structures w32release_mem(mset) return result end function
Then this code in the main program:
cf = struct_CHARFORMAT ( 0,0,0,0,0,0,0,"") VOID = sendMessage(lyricriched2, EM_GETCHARFORMAT, SCF_SELECTION, cf) fname = w32fetch( cf, CHARFORMAT_szFaceName ) fcolor = w32fetch( cf, CHARFORMAT_crTextColor ) fheight = w32fetch( cf, CHARFORMAT_yHeight ) feffects = w32fetch( cf, CHARFORMAT_dwEffects) font = getFontDialogSelTxt( Win1,0,feffects,fheight,0,fcolor,0,0,fname )