Hi Charles,
Thank you for picking up the glove!
MessageBox without the 'A': a modest compromise for the sake of common usage.
This doesn't explain what I should do with my MessageBox
A!
Interesting that you raise the subject of name mangling.
Actually I was raising it for the second time in this thread!
This will import the mangled '_fname@4' within the quotes, and extract 'fname' as the internal reference for it.
I agree that can handle the underscore prefixes and mangled postfixes. But you still won't be able to avoid aliases that would map
??3@YAXPAX@Z horrors into a limited subset of characters allowable in an intelligent language's function name. (that mumbo-jumbo is actually a real export from
msvcrt.dll)
Now my question is, if you still need a pling, function name and alias to describe a single entry point among the
2,500+ first-aid APIs that you could have automated the entire process of importing, then why bother at all? Let us all fall prone before José and plead him to write a set of rock solid classic BASIC headers for us that we'll keep overlooking to supply, as is only natural for human beings, when deploying or exchanging our code?
I don't understand why many people are still using the "A" functions ...
Hi José,
I will tell you why.
- How many businesses that are still dependent on PB would ever need anything but ASCII in their programs, do you think?
- How many Indians, Chinese or Japanese followers do you think Charles is ever going to have?
- It is quite feasible (though arguably practical) to produce sterling Unicode programs in a 100% ANSI language. The last person to register on the FBSL forum was a guy from India, a native Malayalam. He never advanced past very basic examples from an obscure installation of FBSL v3.4 but I showed him it is not that difficult. Here is an example of the 100% ANSI FBSL engine running a 100% Unicode demo to display mixed Hindi and Malayalam messages under his localized MS Windows installation. (It is written in medieval v3.4 notation when FBSL was still using unprototyped declares -- wink-wink, Charles -- rather than automatic imports I'm advocating here. Still usable with minor corrections in modern FBSL v3.5 though)
As you can see, apart from the notorious curly braces, the code is hardly discernible from its imaginary ANSI C counterpart or, as it happens, from FreeBASIC's so called "modern syntax". AnsiToWide("") stands for its C/C++ L"" (or TEXT("")) counterpart. A matching WideToAnsi(varname$$) (in PB notation) has no C/C++ equivalent:
//#AppType Console
#Option Strict
#DllDeclare Kernel32(GetModuleHandleW, LoadLibraryW)
#DllDeclare User32(RegisterClassExW, CreateWindowExW, LoadIconW, LoadCursorW, _
MessageBoxW, IsDialogMessageW, PeekMessageW, DispatchMessageW, DefWindowProcW, _
SendMessageW, PostMessageW, TranslateMessage, GetSystemMenu)
#DllDeclare Gdi32(CreateFontW)
// Window style constants
#Define ES_MULTILINE 4
#Define WS_OVERLAPPEDWINDOW &HCF0000
#Define WS_CLIPCHILDREN &H2000000
#Define WS_CLIPSIBLINGS &H4000000
#Define WS_HSCROLL &H100000
#Define WS_VSCROLL &H200000
#Define WS_VISIBLE &H10000000
#Define WS_CHILD &H40000000
// Window extended style constants
#Define WS_EX_NOPARENTNOTIFY 4
#Define WS_EX_WINDOWEDGE 256
#Define WS_EX_APPWINDOW &H40000
// Child control ID constants
#Define IDC_RICHEDIT &H1000
#Define IDC_BUTTON &H1001
// Global variables
Dim hindi = "{\rtf1\ansi\ansicpg1251\deff0\deflang1049{\fonttbl{\f0\fswiss\fcharset1 Mangal;}{\f1\fswiss Mangal;}}" & _
"{\colortbl ;\red192\green0\blue0;}\viewkind4\uc1\pard\qc\cf1\b\f0\fs20\u2330?\u2368?\u2344?\u2368? \u2360?\u2366?" & _
"\u2341?\u2367?\u2351?\u2379?\u2306? \u2325?\u2375? \u2346?\u2381?\u2352?\u2348?\u2354? \u2348?\u2343?\u2366?\u2312?\f1 !" & _
"\par\f0\u2346?\u2381?\u2352?\u2327?\u2340?\u2368? \u2310? \u2352?\u2361?\u2368? \u2361?\u2376?\f1 !\par}"
Dim malayalam = "{\rtf1\ansi\ansicpg1251\deff0\deflang1049{\fonttbl{\f0\fnil\fprq2\fcharset1 Akshar Unicode;}{\f1\fnil\fprq2 Akshar Unicode;}" & _
"{\f2\fnil\fprq2\fcharset0 Akshar Unicode;}}{\colortbl ;\red0\green35\blue255;}\viewkind4\uc1\pard\qc\cf1\f0\fs28\u3335?\u3368?\u3405?\u3364?" & _
"\u3405?\u3375?\u3451? \u3384?\u3350?\u3390?\u3349?\u3405?\u3349?\u3454? \u3378?\u3399?\u3349?\u3405?\u3349?\u3393?\u3379?\u3405?\u3379? \u3338?\" & _
"u3383?\u3405?\u3374?\u3379?\u3374?\u3390?\u3375? \u3334?\u3382?\u3330?\u3384?\u3349?\u3454?\f1 !\par\f0\u3370?\u3393?\u3376?\u3399?\u3390?" & _
"\u3351?\u3364?\u3391? \u3381?\u3376?\u3393?\u3368?\u3405?\u3368?\u3393?\f1 !\lang1033\f2\par}"
Dim font = CreateFontW(18, 0, 0, 0, 700, 0, 0, 0, 0, 0, 0, 0, 0, AnsiToWide("Akshar Unicode"))
Dim library = LoadLibraryW(AnsiToWide("riched20.dll"))
Dim window = Unicode_Form("Vinod's Unicode Special")
Dim button = Unicode_Control("Button", window, "Click me...", IDC_BUTTON, 670, 710, 90, 30, WS_CHILD BOr WS_VISIBLE)
Dim edit = Unicode_Control("RichEdit20W", window, "", IDC_RICHEDIT, _
212, 370, 370, 125, WS_CHILD BOr WS_VISIBLE BOr WS_VSCROLL BOr WS_HSCROLL BOr ES_MULTILINE)
// ================== EXECUTION STARTS HERE ====================
Sub Main()
MakeNonResizable(window) // for artistic reasons
If STANDALONE Then
Fbsl_Tile(window, Fbsl_LoadImage(APPEXEPATH & "\Smile.jpg"))
Else
Fbsl_Tile(window, Fbsl_LoadImage(Left(Command(1), InStrRev(Command, "\")) & "Smile.jpg"))
End If
Resize(window, 0, 0, 800, 800)
Center(window): Show(window)
Unicode_Main()
End Sub
// =================== EXECUTION ENDS HERE =====================
// - Equivalent to FBSL built-in ASCII Begin Events/End Events -
Function Unicode_Events(ByVal hwnd As Integer, ByVal msg As Integer, ByVal wparam As Integer, ByVal lparam As Integer) As Integer
#Define IDCANCEL 2
#Define WM_CLOSE 16
#Define WM_COMMAND 273
Select Case msg
Case WM_COMMAND
If wparam = IDCANCEL Then
PostMessageW(window, WM_CLOSE, 0, 0)
ElseIf wparam = IDC_BUTTON Then
OnClick()
Return 0
End If
Case WM_CLOSE
ExitProgram(0)
End Select
Return DefWindowProcW(hwnd, msg, wparam, lparam)
End Function
Sub Unicode_Main()
#Define CS_DBLCLKS 8
#Define WM_QUIT 18
#Define PM_REMOVE 1
Type MESSAGE
hWnd As Integer
message As Integer
wParam As Integer
lParam As Integer
dwTime As Integer
ptX As Integer
ptY As Integer
End Type
Dim msg As MESSAGE
While 1
PeekMessageW(@msg, 0, 0, 0, PM_REMOVE)
If msg.message = WM_QUIT Then Exit While
If Not IsDialogMessageW(window, @msg) Then
TranslateMessage(@msg)
DispatchMessageW(@msg)
End If
WEnd
End Sub
// -------------------------------------------------------------
// ---------------------- Event handlers -----------------------
Sub OnClick()
#Define WM_SETTEXT 12
SendMessageW(button, WM_SETTEXT, 0, AnsiToWide("Clicked!"))
Edit_Append(edit, hindi)
Edit_Append(edit, malayalam)
End Sub
// ---------------------- Window creation ----------------------
Function Unicode_Form(FormTitle As String, _
X As Integer = 0, Y As Integer = 0, Width As Integer = 320, Height As Integer = 200, _
hWndOwner As Integer = NULL) As Integer
#Define IDI_APPLICATION 32512
#Define IDC_ARROW 32512
#Define COLOR_BTNFACE 15
Type WNDCLASSEXW
cbSize As Integer
style As Integer
lpfnWndProc As Integer
cbClsExtra As Integer
cbWndExtra As Integer
hInstance As Integer
hIcon As Integer
hCursor As Integer
hbrBackground As Integer
lpszMenuName As Integer
lpszClassName As Integer
hIconSm As Integer
End Type
Dim wcx As WNDCLASSEXW, szClassName = AnsiToWide("_FBSL_UNICODE_")
wcx.cbSize = LenB(wcx)
wcx.style = CS_DBLCLKS
wcx.lpfnWndProc = AddressOf Unicode_Events
wcx.hInstance = GetModuleHandleW(NULL)
wcx.hIcon = LoadIconW(GetModuleHandleW, 101)
wcx.hCursor = LoadCursorW(NULL, IDC_ARROW)
wcx.hbrBackground = COLOR_BTNFACE + 1
wcx.lpszClassName = @szClassName
If Not RegisterClassExW(@wcx) Then
MessageBoxW(NULL, $AnsiToWide("Unable to register Unicode window class"), $AnsiToWide("Error" & Chr(0)), 0)
ExitProgram(-1)
End If
Dim hwin = CreateWindowExW( _
WS_EX_APPWINDOW BOr WS_EX_WINDOWEDGE, _
szClassName, AnsiToWide(FormTitle & Chr(0)), _
WS_OVERLAPPEDWINDOW BOr WS_CLIPSIBLINGS BOr WS_CLIPCHILDREN, _
X, Y, Width, Height, _
NULL, NULL, GetModuleHandleW, NULL)
If Not hwin Then
MessageBoxW(NULL, $AnsiToWide("Unable to create Unicode window"), $AnsiToWide("Error" & Chr(0)), 0)
ExitProgram(-1)
End If
Return hwin
End Function
Function Unicode_Control(ClassName As String, hWndParent As Integer, Caption As String, hCtlID As Integer = 0, _
X As Integer = 0, Y As Integer = 0, Width As Integer = 0, Height As Integer = 0, _
Style As Integer = WS_CHILD BOr WS_VISIBLE, XStyle As Integer = 0) As Integer
#Define WM_SETFONT 48
Dim hctl = CreateWindowExW( _
XStyle, _
$AnsiToWide(ClassName & Chr(0)), $AnsiToWide(Caption & Chr(0)), _
Style, _
X, Y, Width, Height, _
hWndParent, hCtlID, GetModuleHandleW(NULL), NULL)
If Not hctl Then
MessageBoxW(NULL, $AnsiToWide("Unable to create Unicode control"), $AnsiToWide("Error" & Chr(0)), 0)
ExitProgram(-1)
End If
SendMessageW(hctl, WM_SETFONT, font, TRUE)
Return hctl
End Function
// ------------------------- Utilities -------------------------
Sub MakeNonResizable(hwnd As Integer)
#Define WS_MAXIMIZEBOX &H10000
#Define WS_MINIMIZEBOX &H20000
#Define SC_SIZE &HF000
#Define SC_MINIMIZE &HF020
#Define SC_MAXIMIZE &HF030
#Define SC_RESTORE &HF120
#Define MF_BYCOMMAND 0
Style_Remove(hwnd, WS_MINIMIZEBOX BOr WS_MAXIMIZEBOX)
DeleteMenu(GetSystemMenu(hwnd, FALSE), SC_SIZE, MF_BYCOMMAND)
DeleteMenu(GetSystemMenu, SC_MINIMIZE, MF_BYCOMMAND)
DeleteMenu(GetSystemMenu, SC_MAXIMIZE, MF_BYCOMMAND)
DeleteMenu(GetSystemMenu, SC_RESTORE, MF_BYCOMMAND)
End Sub
Sub Edit_Append(who As Integer, what As String)
#Define ST_SELECTION 2
#Define EM_SETTEXTEX 1121
Type SETTEXTEX
flags As Integer
codepage As Integer
End Type
Dim ste As SETTEXTEX: ste.flags = ST_SELECTION
SendMessageW(who, EM_SETTEXTEX, @ste, what)
End Sub
(BTW José, I find it extremely difficult to handle diacritics on my standard primary US English/secondary Cyrillic keyboard. Every time I type your name, I have to walk an extra mile to your site and use copy-paste to spell it "politically" correctly. Can I have your kind permission to spell it henceforth as
Jose rather than
José in my, er, simplified Anglo-Saxon?
)