* key 1 "è" in textedit.bbc
Post by Danny72 on Nov 11th, 2009, 3:30pm
Hello
I would like to use the textedit.bbc as a simple wordprocessor in other languages.
I have tried putting in the code * key 1 "è"
as an easy way to input foreign accents but it doesn't seem to recognise it in the program.
Is there an easy solution to this?
Also, would the author of textedit.bbc mind if I distribute this text editor to other people.
Many thanks
Danny
Re: * key 1 "è" in textedit.bbc
Post by admin on Nov 11th, 2009, 5:17pm
Quote:I have tried putting in the code *key 1 "è" as an easy way to input foreign accents but it doesn't seem to recognise it in the program. |
|
TEXTEDIT.BBC spawns a Windows Edit Control, and doesn't use BBC BASIC for its keyboard input. As a result things like *KEY and *EXEC can't work (they are part of BASIC). Effectively, it works exactly as NOTEPAD does (which also uses a standard Edit Control).
However, for the same reason, the 'official' Windows shortcuts for accented characters etc. do work. For example if you have enabled the US-International Keyboard or the UK Extended Keyboard you can generate è by typing `e. If you have a French keyboard there's a key for it (the '7' key). Failing any of those, you can type Alt-0232 (Hold down Alt, type 0232 on the numeric keypad, release Alt).
For more information:
http://support.microsoft.com/default.aspx?scid=kb;en-us;306560&sd=tech#2
http://french.about.com/od/writing/ss/typeaccents.htm
If you're really determined you could probably make F1 work by re-engineering TEXTEDIT.BBC to use a docked dialogue box, using the WINLIB2B library (which includes a special function FN_newdialogaccel() that takes an additional parameter) and creating an Accelerator Table which performs the necessary translation. An interesting challenge!
Richard.
Re: * key 1 "è" in textedit.bbc
Post by Danny72 on Nov 11th, 2009, 7:31pm
Is it possible to have an extra pop-up menu on
textedit.bbc which would then display the accented character, when clicked?
thanks
Danny
Re: * key 1 "è" in textedit.bbc
Post by admin on Nov 11th, 2009, 10:14pm
Quote:Is it possible to have an extra pop-up menu on textedit.bbc which would then display the accented character, when clicked? |
|
Yes, that's straightforward. You could go further and have a toolbar (maybe a floating toolbar) with the accented characters all 'continuously' available with a single click of the mouse. When you want to insert the character, just send an appropriate WM_CHAR message to the edit control.
Richard.
Re: * key 1 "è" in textedit.bbc
Post by Danny72 on Nov 12th, 2009, 08:05am
Thanks for the WM_CHAR tip, though I can't seem to find any more info on this in the manual etc.
Could you let me know where it might go in the textedit.bbc please.
To get the character "è", would it be something like WM_CHAR 0232 somewhere?
Danny
rem. A simple text editor in BBC BASIC for Windows, 01-Dec-2006
install @lib$+"WINLIB5"
rem. Set up menus:
AM$ = "AppendMenu"
sys "CreatePopupMenu" to H%
sys AM$, H%, 0, 20, "&New"
sys AM$, H%, 0, 21, "&Open"
sys AM$, H%, 0, 22, "&Save"
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"
sys AM$, E%, &800, 0, 0
sys AM$, E%, 0, 31, "Cu&t"
sys AM$, E%, 0, 32, "&Copy"
sys AM$, E%, 0, 33, "&Paste"
sys AM$, E%, 0, 34, "De&lete"
sys AM$, E%, &800, 0, 0
sys AM$, E%, 0, 35, "Select &All"
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%!208, @vdu%!212, 0, &200044, 0)
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% = !!^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% = !!^cf{}
cf.hwndOwner% = @hwnd%
cf.lpLogFont% = Lf%
cf.flags% = 1
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%
F% = true
case K% 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%, &C7, 0, 0
when 31: sys "SendMessage", Hedit%, &300, 0, 0
when 32: sys "SendMessage", Hedit%, &301, 0, 0
when 33: sys "SendMessage", Hedit%, &302, 0, 0
when 34: sys "SendMessage", Hedit%, &303, 0, 0
when 35: sys "SendMessage", Hedit%, &B1, 0, -1
when 40: procfont
otherwise: F% = false
endcase
if F% sys "SetForegroundWindow", Hedit%
wait 1
until false
end
def procexit
proc_closewindow(Hedit%)
quit
def procmove(M%, W%, L%)
if M%=5 sys "MoveWindow", Hedit%, 0, 0, L% and &FFFF, L% >> 16, 1
endproc
def procfont : local F%, R%
sys "ChooseFont", cf{} to R%
if R% then
sys "SendMessage", Hedit%, &31, 0, 0 to F%
if F% sys "DeleteObject", F%
sys "CreateFontIndirect", cf.lpLogFont% to F%
sys "SendMessage", Hedit%, &30, F%, 1
endif
endproc
def procnew : local F%
?Fn% = 0 : proctitle
sys "SendMessage", Hedit%, &C, 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%, &C, 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%, &E, 0, 0 to L%
sys "GlobalAlloc", 0, L%+1 to F%
sys "SendMessage", Hedit%, &D, L%+1, F%
oscli "SAVE """+$$Fn%+""" "+str$~F%+"+"+str$~L%
sys "GlobalFree", F%
= true
def fnchanged : local R%
sys "SendMessage", Hedit%, &B8, 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%, &B9, 0, 0
endproc
Re: * key 1 "è" in textedit.bbc
Post by admin on Nov 12th, 2009, 08:38am
Quote:Could you let me know where it might go in the textedit.bbc please. |
|
The simplest solution is to add a new menu:
Code: SYS "CreatePopupMenu" TO char%
SYS "AppendMenu", char%, 0, 232, "è"
SYS "AppendMenu", char%, 0, 233, "é"
which you then need to add to the menu bar:
Code: SYS "AppendMenu", M%, 16, char%, "&Characters"
and then, in the main loop, process the messages:
Code: WHEN 232,233: SYS "SendMessage", Hedit%, WM_CHAR, K%, 0
(WM_CHAR is &102).
I still think a toolbar might be nicer, so you can get the accented characters with one mouse click rather then two.
Richard.
Re: * key 1 "è" in textedit.bbc
Post by Michael Hutton on Nov 12th, 2009, 08:55am
You could also use a Rich Edit Control which will allow you to use UNICODE. This code is a shell to expand on...
Code:
MODE 8
:\
\\ Install libraries
\
INSTALL @lib$+"WINLIB"
INSTALL @lib$+"WINLIB2"
INSTALL @lib$+"WINLIB5A"
REM!WC
WM_COMMAND = &111
CFM_BOLD = &1
CFM_COLOR = &40000000
CFM_FACE = &20000000
CFM_ITALIC = &2
CFM_SIZE = &80000000
CFM_STRIKEOUT = &8
CFM_UNDERLINE = &4
EM_EXLIMITTEXT = &435
EM_SETBKGNDCOLOR = &443
EM_SETCHARFORMAT = &444
EM_SETEVENTMASK = &445
EM_SHOWSCROLLBAR = &460
ENM_CHANGE = &1
ENM_KEYEVENTS = &10000
ENM_MOUSEEVENTS = &20000
ES_AUTOHSCROLL = &80
ES_AUTOVSCROLL = &40
ES_MULTILINE = &4
ES_NOHIDESEL = &100
SB_HORZ = 0
SB_VERT = 1
SCF_ALL = &4
WS_BORDER = &800000
_TRUE = 1
REM. Set up menus:
AM$ = "AppendMenu"
SYS "CreatePopupMenu" TO H%
SYS AM$, H%, 0, 20, "&New"
SYS AM$, H%, 0, 21, "&Open"
SYS AM$, H%, 0, 22, "&Save"
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"
SYS AM$, E%, &800, 0, 0
SYS AM$, E%, 0, 31, "Cu&t"
SYS AM$, E%, 0, 32, "&Copy"
SYS AM$, E%, 0, 33, "&Paste"
SYS AM$, E%, 0, 34, "De&lete"
SYS AM$, E%, &800, 0, 0
SYS AM$, E%, 0, 35, "Select &All"
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 Set up RichEdit Control
DIM CHARFORMAT{cbSize%, \
\ dwMask%, \
\ dwEffects%, \
\ yHeight%, \
\ yOffset%, \
\ crTextColor%, \
\ bCharSet&, \
\ bPitchAndFamily&, \
\ szFaceName&(31), \
\ padding&(1) }
fontsize% = 12
fontname$ = "Times"
bckgrdcolour% = &204030 : REM Horrible Greeny colour
textcolour% = &FFFFFF : REM White
SYS "LoadLibrary", "RICHED20.DLL" TO hRichEditDLL%
IF hRichEditDLL%=0 THEN ERROR 100,"Failed to load MSFTEDIT.DLL"
id_richedit% = 100
hRichEdit% = FN_createwindow(@hwnd%, \
\ "RichEdit20A", \
\ "", \
\ @vdu%!208/2, \
\ 0, \
\ @vdu%!208-@vdu%!208/2, \
\ @vdu%!212-20, \
\ id_richedit%, \
\ WS_BORDER OR ES_MULTILINE OR ES_AUTOHSCROLL OR ES_AUTOVSCROLL OR ES_NOHIDESEL, \
\ 0 )
:\
\\ Set Richedit FONT
\
CHARFORMAT.cbSize% = DIM(CHARFORMAT{})
CHARFORMAT.dwMask% = CFM_BOLD OR CFM_ITALIC OR CFM_UNDERLINE OR \
\ CFM_STRIKEOUT OR CFM_FACE OR CFM_COLOR OR CFM_SIZE
CHARFORMAT.dwEffects% = 0
CHARFORMAT.yHeight% = fontsize%*20
CHARFORMAT.crTextColor% = textcolour%
CHARFORMAT.szFaceName&() = fontname$
SYS "SendMessage", hRichEdit%, EM_SETCHARFORMAT, SCF_ALL, CHARFORMAT{}
SYS "SendMessage", hRichEdit%, EM_SETBKGNDCOLOR, 0, bckgrdcolour%
SYS "SendMessage", hRichEdit%, EM_SHOWSCROLLBAR, SB_VERT, _TRUE
SYS "SendMessage", hRichEdit%, EM_SHOWSCROLLBAR, SB_HORZ, _TRUE
SYS "SendMessage", hRichEdit%, EM_SETEVENTMASK, 0, ENM_KEYEVENTS OR ENM_MOUSEEVENTS OR ENM_CHANGE
SYS "SendMessage", hRichEdit%, EM_EXLIMITTEXT, 0, 20000
ON ERROR PROC_Cleanup:PROC_Error:QUIT
ON CLOSE PROC_Cleanup:QUIT
:\
\\ Main Loop
\
DIM Msg%(2), msg%(2)
Msg%() = -1
ON SYS Msg%() = @msg%,@wparam%,@lparam% : RETURN
REPEAT
msg%(0) = INKEY(1)
SWAP Msg%(), msg%()
CASE msg%(0) OF
WHEN WM_COMMAND:
:\
\\ when the user selects a command item from a menu,
\\ when a control sends a notification message to its parent window,
\\ or when an accelerator keystroke is translated.
\\
\\ msg%(0) = WM_COMMAND
\\ msg%(1) = wParam
\\ msg%(2) =lParam
\\
\\ msg%(1) = high word, 0 Menu, 1 Accelerator, x control
\\ msg%(1) = low word, IDM_* menu, IDM_* accelerator, control id
\
PRINT msg%(0), msg%(1), msg%(2)
highword% = msg%(1) >> 16
lowword% = msg%(1) AND &FFFF
CASE msg%(1) OF
WHEN 24:
PROC_Cleanup
QUIT
ENDCASE
ENDCASE
UNTIL FALSE
:\
\\ Free Library at the end
\
DEF PROC_Cleanup
hRichEdit% += 0 : PROC_closewindow (hRichEdit%)
SYS "FreeLibrary", hRichEditDLL%
ENDPROC
DEF PROC_Error
SYS "MessageBox", @hwnd%, REPORT$, STR$ERR, 0
ENDPROC
I suppose it would be 'easy' to get the characters you want with this?
Michael
Re: * key 1 "è" in textedit.bbc
Post by Michael Hutton on Nov 12th, 2009, 09:02am
Just found it :
In your SDK :
ms-help://MS.LHSMSSDK.1033/MS.LHSWinSDK.1033/Controls/controls/richedit/richeditcontrols/aboutricheditcontrols.htm
look for Rich Edit Shortcut Keys
Ctrl+' (apostrophe) Accent acute After pressing the short cut key, press the appropriate letter (for example a, e, or u). This applies to English, French, German, Italian, and Spanish keyboards only.
Ctrl+` (grave) Accent grave See Ctrl+' comments.
Ctrl+~ (tilde) Accent tilde See Ctrl+' comments.
Ctrl+; (semicolon) Accent umlaut See Ctrl+' comments.
Ctrl+Shift+6 Accent caret (circumflex) See Ctrl+' comments.
Ctrl+, (comma) Accent cedilla See Ctrl+' comments.
So with the above program type
[ctrl+`] then e - "è",
etc
Michael
Re: * key 1 "è" in textedit.bbc
Post by Danny72 on Nov 12th, 2009, 3:34pm
Thanks very much.
I have implemented the WM_CHAR idea, and it is working perfectly.
I noticed that textedit.bbc doesn't automatically place the cursor in the typing area like notepad does. Is there a simple way to do this?
Re: * key 1 "è" in textedit.bbc
Post by admin on Nov 12th, 2009, 4:11pm
Quote:I noticed that textedit.bbc doesn't automatically place the cursor in the typing area like notepad does. Is there a simple way to do this? |
|
Try a PROC_setfocus immediately after the call to FN_createwindow:
Code: Hedit% = FN_createwindow("EDIT", "", 0, 0, @vdu%!208, @vdu%!212, 0, &200044, 0)
PROC_setfocus(Hedit%)
Richard.
Re: * key 1 "è" in textedit.bbc
Post by Michael Hutton on Nov 26th, 2009, 02:13am
Out of interest I was trying to create a Rich Edit text editor. I have got this far....
http://tech.groups.yahoo.com/group/bb4w/files/%22Temp%20Folder%22/MDCH/Rich%20Edit%20text%20editor/Unicode%20Text%20Editor%20testing%20callback.bbc
I am able to load and save unicode rtf files with the PROCLoadsave routine. I thought I should try to get the EM_STREAMIN message to work, but am getting an error returned in the EDITSTREAM.dwError% member. It seems to successfully call the EditStreamCallback function, fills the buffer, but doesn't show anything in the RichEdit control.
I know there are other memory leaks in the code at the moment, but will tidy these up once I get the callback to work.
I have also tried using CALLBACK.BBC but have had trouble figuring out a way of getting the address of the callback function into the EDITSTREAM{}.
Can anyone see what I am doing wrong?
Michael
Re: * key 1 "è" in textedit.bbc
Post by Michael Hutton on Nov 26th, 2009, 12:44pm
I have also tried:
Code:
...enter function
REM Create the EDITSTREAM structure
LOCAL EDITSTREAM{}
DIM EDITSTREAM{dwCookie%, dwError%, pfnCallBack%}
EDITSTREAM.dwCookie% = hFile%
EDITSTREAM.pfnCallBack% = FN_callback(FNEditStream(),4)
SYS FN_syscalls("SendMessage"), hRichEdit%, EM_STREAMIN, SF_RTF, EDITSTREAM{}
R% = FN_sysresult
REM Close the file
SYS "CloseHandle", hFile%
=R%
DEF FNEditStream(dwCookie%, buffer%, cb%, pcb%)
SYS "ReadFile", dwCookie%, buffer%, cb%, pcb% TO R%
IF R% THEN =0 ELSE = -1
but must admit confusion. Does the RichEdit create a buffer - or do I need to?
Still musing on this problem. Still no results.
Michael
Re: * key 1 "è" in textedit.bbc
Post by Michael Hutton on Nov 26th, 2009, 12:59pm
ooo..! es.dwError = -16 may mean invalid RTF..... which would explain a bit.
http://www.winehq.org/pipermail/wine-patches/2008-April/054295.html
Michael
Re: * key 1 "è" in textedit.bbc
Post by admin on Nov 26th, 2009, 10:21pm
Quote:Still musing on this problem. Still no results. |
|
Your code contains at least one significant error:
Code:SYS "ReadFile", dwCookie%, buffer%, cb%, pcb% TO R%
ReadFile takes five parameters but you've supplied only four (the missing parameter is lpOverlapped).
Code:
Last time you did this I pointed out that a nicer way (which avoids the end-of-function being buried) is:
Code:
I'm sure you said on that occasion that you'd use this method in future.
Richard.
Re: * key 1 "è" in textedit.bbc
Post by Michael Hutton on Nov 27th, 2009, 02:30am
Ah ha.
Code:
DEFFNRichEditStreamIn(filename$)
LOCAL hFile%, R%
REM Get the file handle
SYS "CreateFile", filename$, GENERIC_READ, FILE_SHARE_READ, 0, OPEN_EXISTING, FILE_FLAG_SEQUENTIAL_SCAN, 0 TO hFile%
IF hFile% = INVALID_HANDLE_VALUE THEN
SYS "MessageBox",@hwnd%, "File not found.","",0
= 0
ENDIF
REM Create the EDITSTREAM structure
LOCAL EDITSTREAM{}
DIM EDITSTREAM{dwCookie%, dwError%, pfnCallBack%}
EDITSTREAM.dwCookie% = hFile%
EDITSTREAM.pfnCallBack% = FN_callback(FNEditStream(),4)
SYS FN_syscalls("SendMessage"), hRichEdit%, EM_STREAMIN, SF_RTF, EDITSTREAM{}
R% = FN_sysresult
REM Close the file
SYS "CloseHandle", hFile%
=R%
DEF FNEditStream(dwCookie%, buffer%, cb%, pcb%)
LOCAL R%
SYS "ReadFile", dwCookie%, buffer%, cb%, pcb%, 0 TO R%
= (R%=0)
This now works. Thank you. A typical mixture of errors on my part.
Michael
Re: * key 1 "è" in textedit.bbc
Post by admin on Nov 27th, 2009, 08:21am
Code:SYS "CreateFile", filename$, GENERIC_READ, FILE_SHARE_READ, 0, OPEN_EXISTING, FILE_FLAG_SEQUENTIAL_SCAN, 0 TO hFile%
I'm surprised that you didn't use OPENIN here; is it because you found FILE_FLAG_SEQUENTIAL_SCAN to be necessary? Although that flag may occasionally improve performance, I've never actually found it to be essential.
Or was it simply because you'd forgotten about @hfile%() ?
I'd be a little concerned if you became so enamoured of the Windows API that you started using it even when there's a perfectly suitable BBC BASIC equivalent. Although if that means you're thinking about abandoning BBC BASIC for another language altogether I'd be delighted!!
Richard.
Re: * key 1 "è" in textedit.bbc
Post by Michael Hutton on Nov 27th, 2009, 11:00am
Quote:I'm surprised that you didn't use OPENIN here; is it because you found FILE_FLAG_SEQUENTIAL_SCAN to be necessary? Although that flag may occasionally improve performance, I've never actually found it to be essential. |
|
No, it was a literal translation of the C++ code in the SDK. No other reason.
Quote:Or was it simply because you'd forgotten about @hfile%() |
|
No, same again, I was just trying to make sure I got it working first.
Quote:I'd be a little concerned if you became so enamoured of the Windows API that you started using it even when there's a perfectly suitable BBC BASIC equivalent. Although if that means you're thinking about abandoning BBC BASIC for another language altogether I'd be delighted!! |
|
Poo to you too! Unfortunately for you BB4W is the only way I have found to communicate effectively with my computer. Please remember that this is a hobby for me.
I am definitely not arrogant enough to assume that I could give up my six figure day job to become a computer programmer. I hope my mistakes can be helpful to someone else reading them.
Michael
Re: * key 1 "è" in textedit.bbc
Post by Danny72 on Nov 30th, 2009, 1:47pm
Hello
Ive implemented the additions including the
Hedit% = FN_createwindow("EDIT", "", 0, 0, @vdu%!208, @vdu%!212, 0, &200044, 0)
PROC_setfocus(Hedit%)
It seems to work for a while, then the cursor is sent back to the beginning whilst editing a larger amount. Could anyone suggest how this could work better.
Also, to access the French or Spanish chars from using the Alt key seems to sometimes work, and sometimes not work.
Thanks for the help. I have pasted the whole code below.
rem. A simple text editor in BBC BASIC for Windows, 19-Aug-2007
install @lib$+"WINLIB5"
rem. Set up menus:
AM$ = "AppendMenu"
sys "CreatePopupMenu" to char%
sys "AppendMenu", char%, 0, 232, "è"
sys "AppendMenu", char%, 0, 200, "È"
sys "AppendMenu", char%, 0, 233, "é"
sys "AppendMenu", char%, 0, 201, "É"
sys "AppendMenu", char%, 0, 226, "â"
sys "AppendMenu", char%, 0, 194, "Â"
sys "AppendMenu", char%, 0, 234, "ê"
sys "AppendMenu", char%, 0, 202, "Ê"
sys "AppendMenu", char%, 0, 251, "û"
sys "AppendMenu", char%, 0, 217, "Û"
sys "AppendMenu", char%, 0, 231, "ç"
sys "AppendMenu", char%, 0, 199, "Ç"
sys "AppendMenu", char%, 0, 239, "ï"
sys "AppendMenu", char%, 0, 207, "Ï"
sys "AppendMenu", char%, 0, 244, "ô"
sys "AppendMenu", char%, 0, 212, "Ô"
sys "AppendMenu", char%, 0, 235, "ë"
sys "AppendMenu", char%, 0, 203, "Ë"
sys "AppendMenu", char%, 0, 249, "ù"
sys "AppendMenu", char%, 0, 217, "Ù"
rem spanish characters
sys "CreatePopupMenu" to charv%
sys "AppendMenu", charv%, 0, 225, "á"
sys "AppendMenu", charv%, 0, 193, "Á"
sys "AppendMenu", charv%, 0, 233, "é"
sys "AppendMenu", charv%, 0, 201, "É"
sys "AppendMenu", charv%, 0, 237, "í"
sys "AppendMenu", charv%, 0, 205, "Í"
sys "AppendMenu", charv%, 0, 241, "ñ"
sys "AppendMenu", charv%, 0, 209, "Ñ"
sys "AppendMenu", charv%, 0, 243, "ó"
sys "AppendMenu", charv%, 0, 211, "Ó"
sys "AppendMenu", charv%, 0, 250, "ú"
sys "AppendMenu", charv%, 0, 218, "Ú"
sys "AppendMenu", charv%, 0, 252, "ü"
sys "AppendMenu", charv%, 0, 220, "Ü"
sys "AppendMenu", charv%, 0, 191, "¿"
sys "AppendMenu", charv%, 0, 161, "¡"
sys "AppendMenu", charv%, 0, 171, "«"
sys "AppendMenu", charv%, 0, 187, "»"
rem sys "AppendMenu", charv%, 0, 249, "ù"
rem sys "AppendMenu", charv%, 0, 217, "Ù"
rem"Ç"
rem"ï"
rem"Ï"
rem"ô"
rem"Ô"
rem"ë"
rem"Ë"
rem"ù"
rem"Ù"
sys "CreatePopupMenu" to H%
sys AM$, H%, 0, 20, "&New"
sys AM$, H%, 0, 21, "&Open"
sys AM$, H%, 0, 22, "&Save"
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"
sys AM$, E%, &800, 0, 0
sys AM$, E%, 0, 31, "Cu&t"
sys AM$, E%, 0, 32, "&Copy"
sys AM$, E%, 0, 33, "&Paste"
sys AM$, E%, 0, 34, "De&lete"
sys AM$, E%, &800, 0, 0
sys AM$, E%, 0, 35, "Select &All"
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 "AppendMenu", M%, 16, char%, "F&rench Accents"
sys "AppendMenu", M%, 16, charv%, "&Spanish Accents"
sys "DrawMenuBar", @hwnd%
rem. Create edit window:
Hedit% = fn_createwindow("EDIT", "", 0, 0, @vdu%!208, @vdu%!212, 0, &200044, 0)
Hedit% = fn_createwindow("EDIT", "", 0, 0, @vdu%!208, @vdu%!212, 0, &200044, 0)
proc_setfocus(Hedit%)
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
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%
F% = true
case K% 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%, &C7, 0, 0
when 31: sys "SendMessage", Hedit%, &300, 0, 0
when 32: sys "SendMessage", Hedit%, &301, 0, 0
when 33: sys "SendMessage", Hedit%, &302, 0, 0
when 34: sys "SendMessage", Hedit%, &303, 0, 0
when 35: sys "SendMessage", Hedit%, &B1, 0, -1
when 232,200,233,201,226,194,234,202,251,217,231,199,239,207,244,212,235,203,249,217,225,193,237,205,241,209,243,211,250,218,252,220,191,161,171,187: sys "SendMessage", Hedit%, &102, K%, 0
when 40: procfont
otherwise: F% = false
endcase
if F% sys "SetForegroundWindow", Hedit%
wait 1
until false
end
def procexit
proc_closewindow(Hedit%)
quit
def procmove(M%, W%, L%)
if M%=5 sys "MoveWindow", Hedit%, 0, 0, L% and &FFFF, L% >> 16, 1
endproc
def procfont : local F%, R%
sys "ChooseFont", cf{} to R%
if R% then
sys "SendMessage", Hedit%, &31, 0, 0 to F%
if F% sys "DeleteObject", F%
sys "CreateFontIndirect", cf.lpLogFont% to F%
sys "SendMessage", Hedit%, &30, F%, 1
endif
endproc
def procnew : local F%
?Fn% = 0 : proctitle
sys "SendMessage", Hedit%, &C, 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%, &C, 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%, &E, 0, 0 to L%
sys "GlobalAlloc", 0, L%+1 to F%
sys "SendMessage", Hedit%, &D, L%+1, F%
oscli "SAVE """+$$Fn%+""" "+str$~F%+"+"+str$~L%
sys "GlobalFree", F%
= true
def fnchanged : local R%
sys "SendMessage", Hedit%, &B8, 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%, &B9, 0, 0
endproc
Re: * key 1 "è" in textedit.bbc
Post by admin on Nov 30th, 2009, 3:52pm
Quote:Could anyone suggest how this could work better |
|
Well, there's a pretty serious and obvious error here:
Code: REM. Create edit window:
Hedit% = FN_createwindow("EDIT", "", 0, 0, @vdu%!208, @vdu%!212, 0, &200044, 0)
Hedit% = FN_createwindow("EDIT", "", 0, 0, @vdu%!208, @vdu%!212, 0, &200044, 0)
PROC_setfocus(Hedit%)
You create two edit controls, which is likely to cause all sorts of problems!
Richard.
Re: * key 1 "è" in textedit.bbc
Post by Danny72 on Dec 2nd, 2009, 12:29pm
Thanks. Yes, removing the duplicate line has sorted out the main problem.
Could someone advise me as to how to get the pop-up windows working consistently with the Alt Key e.g. Alt F for File.
Many thanks
Re: * key 1 "è" in textedit.bbc
Post by admin on Dec 2nd, 2009, 1:58pm
Quote:Could someone advise me as to how to get the pop-up windows working consistently with the Alt Key e.g. Alt F for File. |
|
Try replacing the main loop with this:
Code: REM. Main loop:
REPEAT
K% = 0 : SWAP K%, Menu%
CASE K% 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%, &C7, 0, 0
WHEN 31: SYS "SendMessage", Hedit%, &300, 0, 0
WHEN 32: SYS "SendMessage", Hedit%, &301, 0, 0
WHEN 33: SYS "SendMessage", Hedit%, &302, 0, 0
WHEN 34: SYS "SendMessage", Hedit%, &303, 0, 0
WHEN 35: SYS "SendMessage", Hedit%, &B1, 0, -1
WHEN 232,200,233,201,226,194,234,202,251,217,231,199,239,207,244,212,235,203, \
\ 249,217,225,193,237,205,241,209,243,211,250,218,252,220,191,161,171,187:
SYS "PostMessage", Hedit%, &102, K%, 0
WHEN 40: PROCfont
ENDCASE
PROC_setfocus(Hedit%)
WAIT 1
UNTIL FALSE
END
Richard.
Re: * key 1 "è" in textedit.bbc
Post by Danny72 on Dec 4th, 2009, 3:06pm
Thanks very much, it is all working now.
Danny