BBC BASIC for Windows
« Edit control with Unicode-only language »

Welcome Guest. Please Login or Register.
Apr 5th, 2018, 11:12pm



ATTENTION MEMBERS: Conforums will be closing it doors and discontinuing its service on April 15, 2018.
Ad-Free has been deactivated. Outstanding Ad-Free credits will be reimbursed to respective payment methods.

If you require a dump of the post on your message board, please come to the support board and request it.


Thank you Conforums members.

BBC BASIC for Windows Resources
Online BBC BASIC for Windows documentation
BBC BASIC for Windows Beginners' Tutorial
BBC BASIC Home Page
BBC BASIC on Rosetta Code
BBC BASIC discussion group
BBC BASIC for Windows Programmers' Reference

« Previous Topic | Next Topic »
Pages: 1 2  Notify Send Topic Print
 hotthread  Author  Topic: Edit control with Unicode-only language  (Read 7459 times)
admin
Administrator
ImageImageImageImageImage


member is offline

Avatar




PM


Posts: 1145
xx Re: Edit control with Unicode-only language
« Reply #18 on: Sep 15th, 2011, 08:04am »

on Sep 15th, 2011, 06:02am, Nick wrote:
PeekMessage
IsDialogMessage
DispatchMessage

Yes, I did think after posting my last reply that your keyboard messages were still passing through BB4W's message pump. There are two reasons why I ruled that out as a cause:

  1. You said that when you sent a WM_CHAR message to the edit control yourself the correct character was displayed. Your messages (so long as sent using PostMessage rather than SendMessage) pass through the pump just the same, so I would have expected you to see the same effect.
  2. My belief (since proved incorrect) was that there were not separate A and W versions of GetMessage and DispatchMessage. As a rule different ANSI and Unicode versions of an API only exist when that API is passing text strings in one direction or another, which those do not.
As the second of those turns out not to be the case, it leaves the first to consider. I wonder if you inadvertently called SendMessage rather than PostMessage, thereby invalidating your experiment?

Anyway, the good news is that if the issue is related to the Unicode-ness of the message pump that is easily sorted. BB4W dialogue boxes (created in the WINLIB2 library) use their own private message pump (in order to permit calling the IsDialogMessage API which BB4W doesn't) and there's absolutely no reason why your Edit Control shouldn't use its own message pump too, calling GetMessageW and DispatchMessageW, if it is beneficial.

Quote:
Anyway, he offered to do the same with a simple BBC BASIC programme and make my app work by hacking YOUR runtime generated code!

Please ask him not to do that. It's unnecessary, and wouldn't provide a solution which you could deploy with any confidence.

Richard.
« Last Edit: Sep 15th, 2011, 08:06am by admin » User IP Logged

Nick
New Member
Image


member is offline

Avatar




PM

Gender: Male
Posts: 33
xx Re: Edit control with Unicode-only language
« Reply #19 on: Sep 15th, 2011, 09:11am »

on Sep 15th, 2011, 08:04am, Richard Russell wrote:
I wonder if you inadvertently called SendMessage rather than PostMessage, thereby invalidating your experiment?


Yes indeed I did Richard - sorry.

Quote:
Anyway, the good news is that if the issue is related to the Unicode-ness of the message pump that is easily sorted. BB4W dialogue boxes (created in the WINLIB2 library) use their own private message pump


I just modified WINLIB2 (as shown at the end) and used it to create a edit control within a dialogue box.

It works *PERFECTLY* - even right-to-left Farsi (Persian)

Thank you SO much again for such an amazingly flexible BASIC - this is really terrific. And thank you too for your responsiveness to these tedious threads! But this is real progress, and I suspect to others also.

So, just to be sure, you are saying that if I make a similar addition to WINLIB5 (for rich edit controls) then I can similarly have a modified message pump?

In which case, my only issue is how to code this - it involves assembly which i am REALLY rusty on - but the Russian guy is sharp - he will doubtless figure it out.

I will tell him not to bother hacking the BBC4W runtime - I never intended it as a long-term solution - just a way of getting him to prove his point. There is no need for that anyway now.

Thank you again Richard,

Nick

************** MODIFIED "W" VERSION OF WINLIB2" ***********

REM Dialogue box items:
DEF PROC_pushbutton(dlg%,text$,id%,x%,y%,cx%,cy%,style%): style%+=&50010000:LOCAL class%:class%=&80
DEF PROC_checkbox(dlg%,text$,id%,x%,y%,cx%,cy%,style%): style%+=&50010003:LOCAL class%:class%=&80
DEF PROC_radiobutton(dlg%,text$,id%,x%,y%,cx%,cy%,style%):style%+=&50010009:LOCAL class%:class%=&80
DEF PROC_groupbox(dlg%,text$,id%,x%,y%,cx%,cy%,style%): style%+=&50000007:LOCAL class%:class%=&80
DEF PROC_editbox(dlg%,text$,id%,x%,y%,cx%,cy%,style%): style%+=&50810000:LOCAL class%:class%=&81
DEF PROC_static(dlg%,text$,id%,x%,y%,cx%,cy%,style%): style%+=&50000000:LOCAL class%:class%=&82
DEF PROC_listbox(dlg%,text$,id%,x%,y%,cx%,cy%,style%): style%+=&50A10003:LOCAL class%:class%=&83
DEF PROC_combobox(dlg%,text$,id%,x%,y%,cx%,cy%,style%): style%+=&50210000:LOCAL class%:class%=&85
DEF PROC_dlgitem(dlg%,text$,id%,x%,y%,cx%,cy%,style%,class%)
LOCAL P%, L%
P% = dlg%!12
WHILE (P% AND 3) P% += 1 : ENDWHILE
IF (P%+2*LENtext$+26) > dlg%!8 ERROR 0, "No room for dialogue template"
:
P%!0 = style%
P%!4 = 0
P%!8 = (y% << 16) OR x%
P%!12 = (cy% << 16) OR cx%
P%!16 = &FFFF0000 OR id%
P%!20 = class%
:
SYS "MultiByteToWideChar", 0, 0, text$, -1, P%+22, 65536 TO L%
P%!(2*L%+20) = 0
:
dlg%!12 = P%+2*L%+24
dlg%!24 += 1
ENDPROC
;
REM Display dialogue box:
DEF PROC_showdialog(dlg%) : LOCAL H%, I%
IF !dlg% <> 0 ENDPROC
SYS "CreateThread", 0, 1024, dlg%!4, 0, 0, ^I% TO H%
REPEAT SYS "Sleep", 10 : UNTIL !dlg% <> 0
SYS "CloseHandle", H%
ENDPROC
;
REM Remove dialogue box:
DEF PROC_closedialog(dlg%)
IF !dlg% = 0 ENDPROC
SYS "PostMessageW", !dlg%, 18, 0, 0
REPEAT SYS "Sleep", 10 : UNTIL !dlg% = 0
ENDPROC
;
REM Create a new dialogue box:
DEF FN_newdialog(title$,x%,y%,cx%,cy%,font%,size%)
LOCAL dlg%, msg%, L%, F%, P%, I%, X%, C%, N%, D%, Q%, T%, M%
DIM P% 169, msg% 27, dlg% size%-1
WHILE (dlg% AND 3) dlg% += 1 : size% -= 1 : ENDWHILE
IF (2*LENtitle$+70) > size% ERROR 0, "No room for dialogue template"
:
SYS "GetWindowLongW", @hwnd%, -6 TO I%
[
OPT 2
.X%
push 0 : CALL "PostQuitMessage" : mov eax,1 : ret 16
.C%
push dword [esp+16] : push dword [esp+16] : push eax : push @hwnd% : call "SendMessage"
cmp word [esp+12], 2 : jz X% ; IDCANCEL
.N%
mov eax,1 : ret 16
.D%
mov eax,[esp+8] : cmp eax,&110 : jz N% : cmp eax,&111 : jz C%
xor eax,eax : ret 16
.Q%
xchg eax,[dlg%]
push eax
call "DestroyWindow"
ret
.T%
push 0 ; lParamInit
push D% ; lpDialogFunc
push @hwnd% ; hWndParemt
push dlg%+16 ; lpTemplate
push I% ; hInstance
call "CreateDialogIndirectParam"
mov [dlg%],eax
.M%
push 0
push 0
push 0
push msg%
call "GetMessageW"
or eax,eax
jz Q%
push msg%
push dword [dlg%]
call "IsDialogMessageW"
or eax,eax
jnz M%
push msg%
call "DispatchMessageW"
jmps M%
]
:
dlg%!4 = T%
dlg%!8 = dlg%+size%
dlg%!16 = &90C800C4
dlg%!20 = 0
dlg%!24 = 0
dlg%!26 = x%
dlg%!28 = y%
dlg%!30 = cx%
dlg%!32 = cy%
dlg%!34 = 0
:
SYS "MultiByteToWideChar", 0, 0, title$, -1, dlg%+38, 65536 TO L%
:
dlg%!(2*L%+38) = font%
SYS "MultiByteToWideChar", 0, 0, "Arial", -1, dlg%+2*L%+40, 16 TO F%
:
dlg%!12 = dlg%+2*L%+2*F%+40
= dlg%
;
REM Dialogue box control:
DEF PROC_dlgctrl(dlg%,text$,id%,x%,y%,cx%,cy%,style%,class$)
LOCAL L%,T%
PROC_dlgitem(dlg%,text$,id%,x%,y%,cx%,cy%,style%,0)
T% = dlg%!12-8
IF (T%+2*LENclass$+6) > dlg%!8 ERROR 0, "No room for dialogue template"
SYS "MultiByteToWideChar", 0, 0, class$, -1, T%, 256 TO L%
dlg%!12 = T%+2*L%+4
ENDPROC
User IP Logged

admin
Administrator
ImageImageImageImageImage


member is offline

Avatar




PM


Posts: 1145
xx Re: Edit control with Unicode-only language
« Reply #20 on: Sep 15th, 2011, 9:36pm »

on Sep 15th, 2011, 09:11am, Nick wrote:
So, just to be sure, you are saying that if I make a similar addition to WINLIB5 (for rich edit controls) then I can similarly have a modified message pump?

Yes. I may need to code it for you, because it requires a good understanding of assembler code, but it shouldn't be difficult. You will end up with your Edit Control running in a different thread (just as it was when you modified the dialogue box example) but there's no particular disadvantage to that - and if you have the luxury of a multi-core CPU it could actually be beneficial in distributing the load more evenly.

I don't routinely create child controls, toolbars, status bars etc. in their own threads because the code becomes more complicated and there's usually no significant advantage. So I would want to meet your requirements with a dedicated solution rather than modifying WINLIB5 itself to do so. Maybe a WINLIB5B would be appropriate.

Richard.
User IP Logged

admin
Administrator
ImageImageImageImageImage


member is offline

Avatar




PM


Posts: 1145
xx Re: Edit control with Unicode-only language
« Reply #21 on: Sep 16th, 2011, 08:06am »

I've uploaded a new library here:

http://tech.groups.yahoo.com/group/bb4w/files/Libraries/WINLIB5W.BBC

WINLIB5W is a Unicode version of the WINLIB5A library (i.e. for maximum flexibility it requires the parent window handle to be specified as the first parameter in each of the 'create window' calls).

Richard.
User IP Logged

Nick
New Member
Image


member is offline

Avatar




PM

Gender: Male
Posts: 33
xx Re: Edit control with Unicode-only language
« Reply #22 on: Sep 16th, 2011, 6:03pm »

on Sep 16th, 2011, 08:06am, Richard Russell wrote:
I've uploaded a new library here.


Wow - that was fast Richard!!

I had just logged in to thank you for the kind offer and ask how long the new library might take!!

I will have to get a Yahoo account and download it ASAP

Thank you again - I will let you know the result!

Nick
User IP Logged

Nick
New Member
Image


member is offline

Avatar




PM

Gender: Male
Posts: 33
xx Re: Edit control with Unicode-only language
« Reply #23 on: Sep 16th, 2011, 9:31pm »

on Sep 16th, 2011, 08:06am, Richard Russell wrote:
I've uploaded a new library here:

http://tech.groups.yahoo.com/group/bb4w/files/Libraries/WINLIB5W.BBC


Richard,

Just to let you know that WINLIB5W seems to work perfectly on both XP and Win 7.

I have farmed out an exe to friends who work in other languages to test, but I would be surprised if it does not work for them also. The existing version already worked with right-to-left languages (apart from the "?" issue)

Thank you SO much for this speedy response to the issue. This will really help those who wish to write fully unicode enabled appls with BBC4W.

Congratulations on a really great addition to the programme!

Nick
User IP Logged

Pages: 1 2  Notify Send Topic Print
« Previous Topic | Next Topic »

| |

This forum powered for FREE by Conforums ©
Terms of Service | Privacy Policy | Conforums Support | Parental Controls