Simple tutorial to create first Windows applications

Windows specific questions.
jj2007
Posts: 2326
Joined: Oct 23, 2016 15:28
Location: Roma, Italia
Contact:

Re: Simple tutorial to create first Windows applications

Post by jj2007 »

Macq wrote:Sorry guys. I didn't mean to create such a stir. I'm using WinFBE Version 2.1.8 (64-bit). I haven't changed any compiler options.
Don't worry, the forum is full of threads that discuss the magic of certain compiler and/or commandline options to make half a dozen different "toolchains" happy. Remember what BASIC once meant? Beginners' ...

Anyway, with #define Unicode as first line, all my 4 "toolchains" are now happy. I see for you it's the opposite, let's see if the toolchain druids come up with an explanation ;-)
Xusinboy Bekchanov
Posts: 782
Joined: Jul 26, 2018 18:28

Re: Simple tutorial to create first Windows applications

Post by Xusinboy Bekchanov »

Macq wrote:Sorry guys. I didn't mean to create such a stir. I'm using WinFBE Version 2.1.8 (64-bit). I haven't changed any compiler options.

Thanks for the input about not using not.

If I
#define Unicode

then I get

.lpszClassName = Strptr(szAppName) <-- Warning: Suspicious pointer assignment

The executable sits in the background and doesn't open a window.
You set a String pointer to ClassName. In the unicode code, you must set the pointer to WString

Code: Select all

.lpszClassName = @WStr(szAppName)
Macq
Posts: 24
Joined: Feb 18, 2021 4:01
Location: Queensland, Australia

Re: Simple tutorial to create first Windows applications

Post by Macq »

Ah, yes. With

#define Unicode

and

.lpszClassName = @WStr(szAppName)
.lpszClassName = @WStr(szChildClass)

all is well with my setup. That should compile for everyone, yes?
Xusinboy Bekchanov
Posts: 782
Joined: Jul 26, 2018 18:28

Re: Simple tutorial to create first Windows applications

Post by Xusinboy Bekchanov »

jj2007 wrote:
dodicat wrote:line ~116
use
if( hPrevInstance=0) then:
That did the trick, plus
#define Unicode
#include once "windows.bi"
#define DIVISIONS 8

Apparently, Macq has a setting in his IDE that defines Unicode via the commandline (?) instead of doing it in the source.
This works without Unicode, too (on ANSI format). Only you saved the file in UTF format, maybe because of this did not work for you.
jj2007
Posts: 2326
Joined: Oct 23, 2016 15:28
Location: Roma, Italia
Contact:

Re: Simple tutorial to create first Windows applications

Post by jj2007 »

Xusinboy Bekchanov wrote:This works without Unicode, too (on ANSI format). Only you saved the file in UTF format, maybe because of this did not work for you.
Nope, I can see at Assembly level what happens:

Code: Select all

Address   Hex dump          Command                                  Comments
00401993  |.  B8 08504000   mov eax, offset 00405008                 ; UNICODE "Checker3"
00401998  |.  8945 D8       mov [local.10], eax
0040199B  |.  CC            int3
0040199C  |.  8D45 B4       lea eax, [local.19]
0040199F  |.  50            push eax                                 ; /pWndclass => offset LOCAL.19
004019A0  |.  E8 8B010000   call <jmp.&USER32.RegisterClassA>        ; \USER32.RegisterClassA
004019A5  |.  B8 40174000   mov eax, 00401740                        ; Entry point
004019AA  |.  8945 B8       mov [local.18], eax
004019AD  |.  C745 C0 02000 mov dword ptr [local.16], 2
004019B4  |.  C745 C8 00000 mov dword ptr [local.14], 0
004019BB  |.  B8 1C504000   mov eax, offset 0040501C                 ; UNICODE "Checker3_Child"
004019C0  |.  8945 D8       mov [local.10], eax
004019C3  |.  8D45 B4       lea eax, [local.19]
004019C6  |.  50            push eax                                 ; /pWndclass => offset LOCAL.19
004019C7  |.  E8 64010000   call <jmp.&USER32.RegisterClassA>        ; \USER32.RegisterClassA
As you can see, UNICODE "Checker3" and UNICODE "Checker3_Child" are passed to RegisterClassA. That API sees only "C" and will therefore complain, at the second attempt, that the class "C" is already registered.

In contrast, CreateWindowExA gets the ANSI class name "Checker3" - and fails miserably because class "C" exists but "Checker3" doesn't:

Code: Select all

Address   Hex dump          Command                                  Comments
004019F3  |.  68 70504000   push offset 00405070                     ; |ClassName = "Checker3"
004019F8  |.  6A 00         push 0                                   ; |ExtStyle = 0
004019FA  |.  E8 99010000   call <jmp.&USER32.CreateWindowExA>       ; \USER32.CreateWindowExA
Now if the druids and gurus can explain why...
.lpszClassName = strptr(szAppName) is Unicode while
CreateWindow(szAppName, ... is passed as Ansi
... us bloody beginners will surely appreciate the easiness of BASIC ;-)

Hint: with CreateWindow(@szAppName .. it works partially, because it gets a UNICODE string
Xusinboy Bekchanov
Posts: 782
Joined: Jul 26, 2018 18:28

Re: Simple tutorial to create first Windows applications

Post by Xusinboy Bekchanov »

Try compiling in WinFBE. It works.
jj2007
Posts: 2326
Joined: Oct 23, 2016 15:28
Location: Roma, Italia
Contact:

Re: Simple tutorial to create first Windows applications

Post by jj2007 »

Xusinboy Bekchanov wrote:Try compiling in WinFBE. It works.
Maybe. Do you seriously suggest that certain sources get compiled only with IDE xyz?
Xusinboy Bekchanov
Posts: 782
Joined: Jul 26, 2018 18:28

Re: Simple tutorial to create first Windows applications

Post by Xusinboy Bekchanov »

jj2007 wrote:
Xusinboy Bekchanov wrote:Try compiling in WinFBE. It works.
Maybe. Do you seriously suggest that certain sources get compiled only with IDE xyz?
No, I wanted you to check the Asm code of the compiled file (I suggested it because the author used WinFBE to compile the code and the program worked fine. WinFBE saves it as ANSI by default).
jj2007
Posts: 2326
Joined: Oct 23, 2016 15:28
Location: Roma, Italia
Contact:

Re: Simple tutorial to create first Windows applications

Post by jj2007 »

I tried with WinFBE, Rebuild All: Line 0 compiling failed: error code 1 (refer to log file) - and there is no log file, nowhere... and no line 0 btw

However, Quick Run works, which is kind of counterintuitive, and under the hood I can see that now the Ansi strings are being passed to RegisterClass. There is no "set Unicode" option in WinFBE. It's a mess, folks - lol
Xusinboy Bekchanov wrote:WinFBE saves it as ANSI by default).
So does my IDE. I had problems in the past with Utf8 sources (Space(...) doesn't like Utf8, for mysterious reasons), but now I don't use the BOM any more.
Xusinboy Bekchanov
Posts: 782
Joined: Jul 26, 2018 18:28

Re: Simple tutorial to create first Windows applications

Post by Xusinboy Bekchanov »

jj2007 wrote:I tried with WinFBE, Rebuild All: Line 0 compiling failed: error code 1 (refer to log file) - and there is no log file, nowhere... and no line 0 btw

However, Quick Run works, which is kind of counterintuitive, and under the hood I can see that now the Ansi strings are being passed to RegisterClass. It's a mess, folks - lol
I tried again. I got the same error. You can see the error in the Compiler Log File tab. It says that the command with the file name is not recognized. Because there was no .bas file extension. Then I re-saved with the extension and it worked.
jj2007 wrote:
Xusinboy Bekchanov wrote:WinFBE saves it as ANSI by default).
So does my IDE. I had problems in the past with Utf8 sources (Space(...) doesn't like Utf8, for mysterious reasons), but now I don't use the BOM any more.
I have no problem with Utf8 and Space. Now I also added ANSI support to my IDE when saving a file. Now my IDE (version 1.2.7) can compile/run such examples too.
jj2007
Posts: 2326
Joined: Oct 23, 2016 15:28
Location: Roma, Italia
Contact:

Re: Simple tutorial to create first Windows applications

Post by jj2007 »

jj2007 wrote:I had problems in the past with Utf8 sources (Space(...) doesn't like Utf8, for mysterious reasons), but now I don't use the BOM any more.
I checked twice, and stand corrected: my source has the Utf8 BOM! So if fbc.exe sees the Utf-8 BOM, it decides that strings (not all of them, but some) must be Utf-16. That is cute ;-)
Xusinboy Bekchanov
Posts: 782
Joined: Jul 26, 2018 18:28

Re: Simple tutorial to create first Windows applications

Post by Xusinboy Bekchanov »

jj2007 wrote:
jj2007 wrote:I had problems in the past with Utf8 sources (Space(...) doesn't like Utf8, for mysterious reasons), but now I don't use the BOM any more.
I checked twice, and stand corrected: my source has the Utf8 BOM! So if fbc.exe sees the Utf-8 BOM, it decides that strings (not all of them, but some) must be Utf-16. That is cute ;-)
Your IDE is RichMasm editor?
jj2007
Posts: 2326
Joined: Oct 23, 2016 15:28
Location: Roma, Italia
Contact:

Re: Simple tutorial to create first Windows applications

Post by jj2007 »

Xusinboy Bekchanov wrote:Your IDE is RichMasm editor?
Yes, but with a plugin and 4 different batch files. It works fine for FB, except when fbc.exe plays foul, as above; but this is a rare case. For example, this compiles and runs fine with RichMasm (my OS is Italian, so Russian needs Utf-8 or Utf-16 to be displayed):

Code: Select all

#include "Windows.bi"
Print String(20, str("x"))	' String(20, "x") used to choke if there was a Utf-8 BOM, but here it works...
Print Left("Добро пожаловать", 5);	' combined output of the three rows:
Print Mid("Добро пожаловать", 6, 5);	' Добро пожалоловать
Print Right("Добро пожаловать", 6)
Print "That was a Russian text printed as Utf8"
MessageBoxW(0, "Добро пожаловать", "Hello title", MB_OK)
If you want to use this in WinFBE, you must first save it as Utf8. You cannot paste it into a non-Utf8 WinFBE windows, probably a "feature" of the Scintilla control.

If, however, you save the file as Utf-16 and open it in WinFBE, for example with ...

Code: Select all

' checker3  from Programming Windows 3.0 (c) 1990 Charles Petzold
' Demonstrates child windows, childWndProc(), mouse use, line drawing
'
' #define Unicode	' Macq: Simple tutorial to create first Windows applications
#include once "windows.bi"
#define DIVISIONS 8
MessageBoxW(0, "Добро пожаловать", "Hello title", MB_OK)
...
... then you will see the MessageBoxW correctly, but the strings get still passed partly as Utf-16, partly as Ansi/Utf8.

Lesson learned today:
if fbc.exe sees the Utf-8 BOM, it decides that strings passed to Windows APIs (not all of them, but some) must be Utf-16
Last edited by jj2007 on Feb 24, 2021 10:09, edited 1 time in total.
Xusinboy Bekchanov
Posts: 782
Joined: Jul 26, 2018 18:28

Re: Simple tutorial to create first Windows applications

Post by Xusinboy Bekchanov »

jj2007 wrote:
Xusinboy Bekchanov wrote:Your IDE is RichMasm editor?
Yes, but with a plugin and 4 different batch files. It works fine for FB, except when fbc.exe plays foul, as above; but this is a rare case. For example, this compiles and runs fine with RichMasm (my OS is Italian, so Russian needs Utf-8 or Utf-16 to be displayed):

Code: Select all

#include "Windows.bi"
Print String(20, str("x"))	' String(20, "x") used to choke if there was a Utf-8 BOM, but here it works...
Print Left("Добро пожаловать", 5);	' combined output of the three rows:
Print Mid("Добро пожаловать", 6, 5);	' Добро пожалоловать
Print Right("Добро пожаловать", 6)
Print "That was a Russian text printed as Utf8"
MessageBoxW(0, "Добро пожаловать", "Hello title", MB_OK)
If you want to use this in WinFBE, you must first save it as Utf8. You cannot paste it into a non-Utf8 WinFBE windows, probably a "feature" of the Scintilla control.
Save is not required. You need to select UTF8 in the status bar and paste this text, then it works.
jj2007 wrote: Lesson learned today:
if fbc.exe sees the Utf-8 BOM, it decides that strings passed to Windows APIs (not all of them, but some) must be Utf-16
We'll leave that question to others more knowledgeable about the workings of the fbc.
jj2007
Posts: 2326
Joined: Oct 23, 2016 15:28
Location: Roma, Italia
Contact:

Re: Simple tutorial to create first Windows applications

Post by jj2007 »

Xusinboy Bekchanov wrote:You need to select UTF8 in the status bar and paste this text, then it works.
Thanks, I had not seen this one. Seems to work, kind of - when clicking there, it chops off several bytes at the end of the document, but Ctrl Z restores them. Macq's unmodified code works then with Ansi but not with the two BOM modes.
Post Reply