Author |
Topic: Font selection dialogue (Read 2111 times) |
|
admin
Administrator
member is offline


Posts: 1145
|
 |
Re: Font selection dialogue
« Reply #5 on: Sep 4th, 2011, 11:19am » |
|
on Sep 4th, 2011, 10:37am, Nick wrote:| Is there something different about variables and system calls between authoring mode and runtime |
|
Not really, in fact the environments are virtually identical.
Unfortunately you don't show the code in which you initialise MS_logfont, which seems likely to be the source of the problem.
Quote:| I can send you the modified TEXTEDIT.BBC file if you like |
|
Please do.
Richard.
|
|
Logged
|
|
|
|
Nick
New Member
member is offline


Gender: 
Posts: 33
|
 |
Re: Font selection dialogue
« Reply #6 on: Sep 4th, 2011, 1:26pm » |
|
on Sep 4th, 2011, 11:19am, Richard Russell wrote:Not really, in fact the environments are virtually identical.
Unfortunately you don't show the code in which you initialise MS_logfont, which seems likely to be the source of the problem. |
|
Almost certainly! But if that is the case, I would be grateful to know why the 'incorrectness' does not manifest itself in the SAME way in authoring and runtime...?
Anyway, the code for the modified TEXTEDIT.BBC is below..
Thanks!
Nick
REM. A simple text editor in BBC BASIC for Windows IF HIMEM <= PAGE+12288 THEN HIMEM = PAGE+10000 INSTALL @lib$+"WINLIB5" EM_GETMODIFY = &B8 EM_SETMODIFY = &B9 EM_SETSEL = &B1 EM_UNDO = &C7 ES_AUTOHSCROLL = &80 ES_MULTILINE = &4 WM_CLEAR = &303 WM_COPY = &301 WM_CUT = &300 WM_GETFONT = &31 WM_GETTEXT = &D WM_GETTEXTLENGTH = &E WM_PASTE = &302 WM_SETFONT = &30 WM_SETTEXT = &C WS_VSCROLL = &200000 REM. Set up menus: AM$ = "AppendMenu" SYS "CreatePopupMenu" TO H% SYS AM$, H%, 0, 20, "&New"+CHR$9+"Ctrl+N" SYS AM$, H%, 0, 21, "&Open"+CHR$9+"Ctrl+O" SYS AM$, H%, 0, 22, "&Save"+CHR$9+"Ctrl+S" SYS AM$, H%, 0, 23, "Save &As" SYS AM$, H%, &800, 0, 0 SYS AM$, H%, 0, 24, "E&xit" SYS "CreatePopupMenu" TO E% SYS AM$, E%, 0, 30, "&Undo"+CHR$9+"Ctrl+Z" SYS AM$, E%, &800, 0, 0 SYS AM$, E%, 0, 31, "Cu&t"+CHR$9+"Ctrl+X" SYS AM$, E%, 0, 32, "&Copy"+CHR$9+"Ctrl+C" SYS AM$, E%, 0, 33, "&Paste"+CHR$9+"Ctrl+V" SYS AM$, E%, 0, 34, "De&lete" SYS AM$, E%, &800, 0, 0 SYS AM$, E%, 0, 35, "Select &All"+CHR$9+"Ctrl+A" SYS "CreatePopupMenu" TO O% SYS AM$, O%, 0, 40, "Set &Font" SYS "CreateMenu" TO M% SYS "SetMenu", @hwnd%, M% SYS AM$, M%, 16, H%, "&File" SYS AM$, M%, 16, E%, "&Edit" SYS AM$, M%, 16, O%, "&Options" SYS "DrawMenuBar", @hwnd% REM. Create edit window: Hedit% = FN_createwindow("EDIT", "", 0, 0, @vdu.tr%, @vdu.tb%, 0, \ \ WS_VSCROLL + ES_AUTOHSCROLL + ES_MULTILINE, 0) SYS "SetWindowText", Hedit%, "This is some initial text" REM. Create keyboard shortcuts: nsc% = 4 DIM accel{(nsc%-1) fVirt&, pad&, key{l&,h&}, cmd{l&,h&}} accel{(0)}.key.l& = 14 : accel{(0)}.cmd.l& = 20 : REM Ctrl+N = New accel{(1)}.key.l& = 15 : accel{(1)}.cmd.l& = 21 : REM Ctrl+O = Open accel{(2)}.key.l& = 19 : accel{(2)}.cmd.l& = 22 : REM Ctrl+S = Save accel{(3)}.key.l& = 1 : accel{(3)}.cmd.l& = 35 : REM Ctrl+A = Select All SYS "CreateAcceleratorTable", accel{(0)}, nsc% TO haccel% @haccel% = haccel% @hwacc% = @hwnd% REM. Create and initialise data structures for dialogue boxes: DIM Fn% 255, Lf% 59 DIM fs{lStructSize%, hwndOwner%, hInstance%, lpstrFilter%, \ \ lpstrCustomFilter%, nMaxCustFilter%, nFilterIndex%, \ \ lpstrFile%, nMaxFile%, lpstrFileTitle%, \ \ nMaxFileTitle%, lpstrInitialDir%, lpstrTitle%, \ \ flags%, nFileOffset{l&, h&}, nFileExtension{l&, h&}, \ \ lpstrDefExt%, lCustData%, lpfnHook%, lpTemplateName%} ff$ = "TXT files"+CHR$0+"*.TXT"+CHR$0+"All files"+CHR$0+"*.*"+CHR$0+CHR$0 ex$ = "txt" fs.lStructSize% = DIM(fs{}) fs.hwndOwner% = @hwnd% fs.lpstrFilter% = !^ff$ fs.lpstrDefExt% = !^ex$ fs.lpstrFile% = Fn% fs.nMaxFile% = 256 fs.flags% = 6 DIM cf{lStructSize%, hwndOwner%, hdc%, lpLogFont%, \ \ iPointSize%, flags%, rgbColors%, lCustData%, \ \ lpfnHook%, lpTemplateName%, hInstance%, lpszStyle%, \ \ nFontType{l&, h&}, pad{l&, h&}, nSizeMin%, nSizeMax%} cf.lStructSize% = DIM(cf{}) cf.hwndOwner% = @hwnd% cf.lpLogFont% = Lf% cf.flags% = 1 PROCmakelogfontdefault REM. Set up 'interrupts': Menu% = 0 ON CLOSE IF FNchanged PROCexit ELSE RETURN ON MOVE PROCmove(@msg%, @wparam%, @lparam%) : RETURN ON SYS Menu% = @wparam% : RETURN ON ERROR SYS "MessageBox", @hwnd%, REPORT$, 0, 48 REM. Main loop: REPEAT K% = 0 : SWAP K%, Menu% CASE K% AND &FFFF OF WHEN 20: IF FNchanged PROCnew WHEN 21: IF FNchanged PROCload WHEN 22: IF FNsave PROCunchanged WHEN 23: IF FNsaveas PROCunchanged WHEN 24: IF FNchanged PROCexit WHEN 30: SYS "SendMessage", Hedit%, EM_UNDO, 0, 0 WHEN 31: SYS "SendMessage", Hedit%, WM_CUT, 0, 0 WHEN 32: SYS "SendMessage", Hedit%, WM_COPY, 0, 0 WHEN 33: SYS "SendMessage", Hedit%, WM_PASTE, 0, 0 WHEN 34: SYS "SendMessage", Hedit%, WM_CLEAR, 0, 0 WHEN 35: SYS "SendMessage", Hedit%, EM_SETSEL, 0, -1 WHEN 40: PROCfont ENDCASE PROC_setfocus(Hedit%) WAIT 1 UNTIL FALSE END DEF PROCexit PROC_closewindow(Hedit%) QUIT DEF PROCmove(M%, W%, L%) : PRIVATE S% : IF S% ENDPROC S% = TRUE IF M%=5 SYS "MoveWindow", Hedit%, 0, 0, L% AND &FFFF, L% >> 16, 1 S% = FALSE ENDPROC DEF PROCfont : LOCAL F%, R% SYS "ChooseFont", cf{} TO R% IF R% THEN SYS "SendMessage", Hedit%, WM_GETFONT, 0, 0 TO F% IF F% SYS "DeleteObject", F% SYS "CreateFontIndirect", cf.lpLogFont% TO F% SYS "SendMessage", Hedit%, WM_SETFONT, F%, 1 ENDIF ENDPROC DEF PROCnew : LOCAL F% ?Fn% = 0 : PROCtitle SYS "SendMessage", Hedit%, WM_SETTEXT, 0, ^F% ENDPROC DEF PROCload : LOCAL F%, L% SYS "GetOpenFileName", fs{} TO F% IF F% PROCtitle ELSE ENDPROC F% = OPENIN$$Fn% IF F% THEN L% = EXT#F% : CLOSE #F% SYS "GlobalAlloc", 0, L%+1 TO F% OSCLI "LOAD """+$$Fn%+""" "+STR$~F%+"+"+STR$~L% F%?L% = 0 SYS "SendMessage", Hedit%, WM_SETTEXT, 0, F% TO L% SYS "GlobalFree", F% IF L% = 0 ERROR 100, "File "+$$Fn%+" too big" ELSE ERROR 101, "Can't open file "+$$Fn% ENDIF ENDPROC DEF FNsaveas : LOCAL F%, L% SYS "GetSaveFileName", fs{} TO F% IF F% PROCtitle ELSE = FALSE DEF FNsave : LOCAL F%, L% : IF ?Fn% = 0 THEN = FNsaveas SYS "SendMessage", Hedit%, WM_GETTEXTLENGTH, 0, 0 TO L% SYS "GlobalAlloc", 0, L%+1 TO F% SYS "SendMessage", Hedit%, WM_GETTEXT, L%+1, F% OSCLI "SAVE """+$$Fn%+""" "+STR$~F%+"+"+STR$~L% SYS "GlobalFree", F% = TRUE DEF FNchanged : LOCAL R% SYS "SendMessage", Hedit%, EM_GETMODIFY, 0, 0 TO R% IF R% = 0 THEN = TRUE SYS "MessageBox", @hwnd%, "Save changes?", "TEXTEDIT", 35 TO R% IF R% = 6 IF FNs PROCunchanged : = TRUE IF R% = 7 PROCunchanged : = TRUE = FALSE DEF PROCtitle SYS "SetWindowText", @hwnd%, "TEXTEDIT - "+$$Fn% ENDPROC DEF PROCunchanged SYS "SendMessage", Hedit%, EM_SETMODIFY, 0, 0 ENDPROC DEF PROCmakelogfontdefault REM ************************* UPGRADE - include Font name, style etc as initialisable parameters REM from the main application later... REM Creates a LOGFONT structure in MS_logfont for initialising the dialog box REM At the end, MS_logfont is a pointer to the start of the memory block for MS_logfont REM This is a really dumb way to do it, but time is pressing... REM DATA for Microsoft Sans Serif 22 regular REM This data came from a WM_GETFONT call when the control is configured for MSSF regular 22... DIM MS_logfont 59 LOCAL v%,ptr% DATA &E3,&FF,&FF,&FF,0,0,0,0,0,0,0,0,0,0,0,0,&90,&1,0,0,0,0,0,0,&3,&2,\ \&1,&22,&4D,&69,&63,&72,&6F,&73,&6F,&66,&74,&20,&53,&61,&6E,&73,&20,&53,&65, \ \&72,&69,&66,0,0,0,0,0,0,0,0,0,0,0,0,0,0 ptr%=MS_logfont FOR x=0 TO 59: READ v%: ptr%?x=v% : NEXT SYS "SendMessage",Hedit%, WM_GETFONT, 0, 0 TO F% IF F% SYS "DeleteObject", F% cf.lpLogFont%=MS_logfont SYS "CreateFontIndirect", cf.lpLogFont% TO F% PRINT TAB(0,5)" CreateFontIndirect result: "F% WAIT 100 SYS "SendMessage", Hedit%, WM_SETFONT, F%, 1 SYS "SetWindowText", Hedit%, "This is some initial text at the end of PROCmakelogfontdefault" ENDPROC
|
|
Logged
|
|
|
|
admin
Administrator
member is offline


Posts: 1145
|
 |
Re: Font selection dialogue
« Reply #7 on: Sep 4th, 2011, 2:46pm » |
|
on Sep 4th, 2011, 1:26pm, Nick wrote:| Almost certainly! But if that is the case, I would be grateful to know why the 'incorrectness' does not manifest itself in the SAME way in authoring and runtime...? |
|
You are not permitted to split a DATA statement between multiple lines using the line continuation character '\'. This is explicitly stated in the documentation:
Quote:You can use the line continuation character almost anywhere that a space would be allowed, but not:
within a quoted (constant) string in a star command (use OSCLI instead) in a REM statement in a DATA statement immediately after the initial keyword of a statement |
|
I am surprised that you didn't receive an error message, but it is absolutely not compatible with compiling/crunching.
Anyway, I can hardly think of a more horrible thing than initialising a LOGFONT structure from a load of constants in a DATA statement! This is how I would do it:
Code: DIM logfont{lfHeight%, lfWidth%, lfEscapement%, lfOrientation%, lfWeight%, \
\ lfItalic&, lfUnderline&, lfStrikeOut&, lfCharSet&, lfOutPrecision&, \
\ lfClipPrecision&, lfQuality&, lfPitchAndFamily&, lfFaceName&(31)}
logfont.lfHeight% = -29
logfont.lfWeight% = FW_NORMAL
logfont.lfOutPrecision& = OUT_STROKE_PRECIS
logfont.lfClipPrecision& = CLIP_STROKE_PRECIS
logfont.lfQuality& = DRAFT_QUALITY
logfont.lfPitchAndFamily& = FF_SWISS OR VARIABLE_PITCH
logfont.lfFaceName&() = "Microsoft Sans Serif" That actually conveys some meaning!
Richard.
|
|
Logged
|
|
|
|
Nick
New Member
member is offline


Gender: 
Posts: 33
|
 |
Re: Font selection dialogue
« Reply #8 on: Sep 4th, 2011, 5:53pm » |
|
on Sep 4th, 2011, 2:46pm, Richard Russell wrote:| You are not permitted to split a DATA statement between multiple lines using the line continuation character '\'. This is explicitly stated in the documentation: |
|
Yet again, "RTFM!"....thanks.
Quote:| Anyway, I can hardly think of a more horrible thing than initialising a LOGFONT structure from a load of constants in a DATA statement! |
|
Also very much agreed!
(I did REM to myself; "This is a really dumb way to do it, but time is pressing..."). But it was part of my learning curve - I intended to come back and do redo that bit - at least for now, I could be sure of the values being passed.
Remember, I am not used to this level of access to variables - it is truly amazing. (The last time I got deeply involved using BBC Basic was 25 years ago!)
I am still gtting my head (back) around the different indirection operators. I wanted to get the functionality (vaguely) right before coming back to make things more orthodox!
This now works perfectly - thank you so much.
Nick
|
|
Logged
|
|
|
|
|