|
Forum Index : Microcontroller and PC projects : SciLexer/Scintilla
| Author | Message | ||||
| Malibu Senior Member Joined: 07/07/2018 Location: AustraliaPosts: 260 |
Ok, so it's not really a MM question, but I'm sure there's plenty out there with more experience (ie: Smarter than me!) that might have an idea where I'm going wrong... I'm fiddling around with a code edit package (just as a future idea) in VB6 using API calls with SciLexer/Scintilla. I can't for the life of me get the font to change in the edit window. Here's the code (remember, it's VB6) Private Sub Form_Load() Dim Font As String Dim Lex As Variant Lex = App.Path & "\SciLexer.DLL" LoadLibrary (Lex) sci = CreateWindowEx(WS_EX_CLIENTEDGE, "Scintilla", _ "TEST", WS_CHILD Or WS_VISIBLE, 0, 0, 200, 200, _ Form1.hWnd, 0, App.hInstance, 0) Font = "Monotype Corsiva" + Chr$(0) SendMessage sci, SCI_SETMARGINTYPEN, 1, 1 SendMessage sci, SCI_MARGINSETSTYLE, 1, 1 SendMessage sci, SCI_SETMARGINTYPEN, 1, 1 SendMessage sci, SCI_SETMARGINWIDTHN, 1, 55 For i = 0 To 50 SendMessage sci, SCI_STYLESETFONT, i, StrPtr(Font) SendMessage sci, SCI_STYLESETSIZE, i, 18 SendMessage sci, SCI_STYLESETFORE, i, vbBlack SendMessage sci, SCI_STYLESETBOLD, i, False SendMessage sci, SCI_STYLESETITALIC, i, False '----------------------------- SendMessage sci, SCI_STYLESETFONT, i, StrPtr(Font) '----------------------------- Next i SendMessageString sci, SCI_ADDTEXT, 13, "Hello World" & vbCrLf End Sub The problem part is between the "-------------" comments and no matter what font I select, it always seems to use the default font (which I believe is Verdana) Everything else is great (bold, italic, size, etc), just the font style... I'm a bit stumped ATM... Has anyone had any experience with this that might pick my stumbling block? John |
||||
| WhiteWizzard Guru Joined: 05/04/2013 Location: United KingdomPosts: 2959 |
Just checking - CHR$(0) is the Null Character. Is that what is required at the end of string when setting Font = "...."? Sorry I can't help otherwise as no experience with Scintilla (and VB6 was last used about 10years ago so have forgotten all the 'detail') |
||||
TassyJim![]() Guru Joined: 07/08/2011 Location: AustraliaPosts: 6351 |
It looks OK to me (but I don't speak VB) In Purebasic the procedure I use is I normally use the default font so not a lot of experience changing fonts. VK7JH MMedit |
||||
| Malibu Senior Member Joined: 07/07/2018 Location: AustraliaPosts: 260 |
Yup, you and me both WW! It's amazing how much 'we' can forget when something's not used for a while! (although, I can still remember words to all my favorite songs from the '70s )Here's a snip of the documentation - I read that as 'a zero terminated' string equates to a null char. I could be wrong though and I've tried it with and without it. UTF-8 encoding is still something I'm trying to get my head around as well. John |
||||
| WhiteWizzard Guru Joined: 05/04/2013 Location: United KingdomPosts: 2959 |
Could 'zero terminated' actually mean '0' ? Maybe try CHR$(48) |
||||
| Malibu Senior Member Joined: 07/07/2018 Location: AustraliaPosts: 260 |
Jim, a quick mental conversion says that what you have and what I have are pretty much the same (I don't speak PureBasic, but the lines look pretty close to each other) Tried that about 2 days ago because I had the same thoughts (no avail on that either, but a good thought!)I even tried this in case adding the Null to the string variable was messing the string up... '----------------------------- SendMessage sci, SCI_STYLESETFONT, i, StrPtr(Font + Chr$(0)) '----------------------------- ... but no luck on that one as well. John |
||||
| ajkw Senior Member Joined: 29/06/2011 Location: AustraliaPosts: 290 |
Quick thought, does it want the font file name not its common name? |
||||
| OA47 Guru Joined: 11/04/2012 Location: AustraliaPosts: 1013 |
Malibu, I had a similar problem with VB only a couple of weeks ago, I was using the MSGraph utility and I could not change fonts during run time but I was able to change them using the properties applet that is attached to MSGraph. Hope that makes sense. OA47 |
||||
| Malibu Senior Member Joined: 07/07/2018 Location: AustraliaPosts: 260 |
Thanks everyone! Looking with fresh eyes this morning and trying out a few more things, I found the solution... Here's the two lines that do all the work - Font = StrConv("Century Gothic", vbFromUnicode) & SendMessage sci, SCI_STYLESETFONT, i, StrPtr(Font) The first line takes the UniCode string (which is what VB uses) and converts it to the default code page - which as this works, I would presume is UTF-8 The second line sends it out to SciLexer correctly formatted. Interestingly, it makes no difference having a NULL char on the end or not, so I don't know what that was all about! Anyway, all good in the end, so thanks to everyone's thoughts John |
||||
TassyJim![]() Guru Joined: 07/08/2011 Location: AustraliaPosts: 6351 |
Good to see it working at last. That is similar to my "PokeS(asciiBuffer, fontName$, -1, #PB_Ascii)" which converts the font name string to ASCII. Scintilla can handle UTF-8 but I am old-fashioned enough to stick with ASCII. I have a lot of trouble getting my head around the various string coding options. The zero terminator is probably present in your string anyway, just like C strings. the extra zero byte would be ignored. Jim VK7JH MMedit |
||||
| Malibu Senior Member Joined: 07/07/2018 Location: AustraliaPosts: 260 |
G'day Jim, It's always a satisfying moment when you hit the 'run' command, and it all works as it should! As you say, your code and mine (ignoring the syntax differences) are pretty much the same - I actually used PowerBasic examples for my guides. Again, a little different, but close enough to figure out the basics. The way I read the documentation is that Scintilla decodes the ascii string sent to it into UTF-8, but as it turned out I need to send in UTF-8. I'm the same as you, I prefer a simple ascii string and when it gets down to conversions between ascii, UTF-8, UTF-16, UniCode and all the other formats (not to mention Dec, Hex, Oct and Chars) things get a little mesmerising! Next on the list is KeyWords! John |
||||
TassyJim![]() Guru Joined: 07/08/2011 Location: AustraliaPosts: 6351 |
Settings the keywords is the same as setting the font. I have my keywords list as a lowercase, space separated list and use SETKEYWORDS to update Scintilla. Scintilla is a great tool but there is much to learn to use it to the max. I rely on work that others have done. Jim VK7JH MMedit |
||||
| Malibu Senior Member Joined: 07/07/2018 Location: AustraliaPosts: 260 |
aaahhh, you make it sound easy! For a good example of using it to the max, check out "Programmers Notepad" John |
||||
| The Back Shed's forum code is written, and hosted, in Australia. | © JAQ Software 2025 |