'2018-03-05 T 01:42:51
'
'LATE BINDING TO DLL
====================
'
'BASIC WITH PROTOTYPE
'! ptr MessageBox (sys hwnd,char*msg,*title,int mode) as int
'C STYLE
'int (*MessageBox) (sys hwnd,char*text,char*title,int mode)
'BASIC UNPROTOTYPED
!* MessageBox
'
sys u32=LoadLibrary "user32.dll"
@MessageBox=GetProcAddress u32, "MessageBoxA"
'
'USE LIKE ANY OTHER FUNCTION CALL
MessageBox 0,"helo","greet",0
'EXPLICIT CALL
call MessageBox 0,"helo","greet",1
... its RVA is simply added as an offset to the library handle.
But what do we do about all those wretched equates that take up the bulk of header files?
... we should use this facility for generating unprototyped 'omni' headers ... low priority, until called forth
'2018-03-10 T 15:53:37
------------
'CoreWin.inc
============
'equates,types,macros
=====================
uses WinData
'dll declarations
=================
uses Kernel '1595
uses User '985
uses Gdi '945
uses Comctl '118
uses Comdlg '28
uses Oleaut '409
uses Shell '484
'4564 declarations
extern lib "Comdlg32.dll"
! ChooseColor "ChooseColorA"
! ChooseColorW
! ChooseFont "ChooseFontA"
! ChooseFontW
! CommDlgExtendedError
! DllCanUnloadNow
! DllGetClassObject
! FindText "FindTextA"
! FindTextW
! GetFileTitle "GetFileTitleA"
! GetFileTitleW
! GetOpenFileName "GetOpenFileNameA"
! GetOpenFileNameW
! GetSaveFileName "GetSaveFileNameA"
! GetSaveFileNameW
! LoadAlterBitmap
! PageSetupDlg "PageSetupDlgA"
! PageSetupDlgW
! PrintDlg "PrintDlgA"
! PrintDlgEx "PrintDlgExA"
! PrintDlgExW
! PrintDlgW
! ReplaceText "ReplaceTextA"
! ReplaceTextW
! Ssync_ANSI_UNICODE_Struct_For_WOW
! WantArrows
! dwLBSubclass
! dwOKSubclass
end extern
'2018-03-11 T 10:13:29
'prototype overlay
uses corewin
'Create protype with default values for MessageBox
! messagebox(
sys hwnd=0,
char*text="",
char*title="OxygenBasic",
int mode=0
) at @messagebox
'
'TEST
messagebox
messagebox text="helo"
'/*
'2018-03-11 T 15:55:30
'prototype overlay
uses corewin
'Create protype with default values for MessageBox
! messagebox(
sys hwnd=0,
char*text="",
char*title="OxygenBasic",
int mode=0
) as int, at @messagebox
'
'TEST
messagebox
a=messagebox text="helo", mode=1
print a
'2018-03-11 T 17:55:05
'c-style prototype overlay
uses corewin
'Create protype with default values for MessageBox
int messagebox(
sys hwnd=0,
char*text="",
char*title="OxygenBasic",
int mode=0
) at @messagebox
'
'TEST
messagebox
a=messagebox text="helo", mode=2
print a
MessageBox without the 'A': a modest compromise for the sake of common usage.
Interesting that you raise the subject of name mangling.
This will import the mangled '_fname@4' within the quotes, and extract 'fname' as the internal reference for it.
I don't understand why many people are still using the "A" functions ...
//#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
uses Kernel '1595
uses User '985
uses Gdi '945
uses Comctl '118
uses Comdlg '28
uses Oleaut '409
uses Shell '484
uses Msvcrt '1429 -58
'5935 declarations
PS Does Alt (keypad)130 é work for you?
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?
#include once "Afx/CWStr.inc"
DIM cws AS CWSTR = "Дмитрий Дмитриевич Шостакович"
DIM f AS LONG = FREEFILE
OPEN "test.txt" FOR OUTPUT ENCODING "utf16" AS #f
PRINT #f, cws
CLOSE #f
Since PB 10+, DDT dialogs are unicode aware.
use corewin
wstring russian = "Привет, Михаил"
wstring caption = "Nice to meet you"
MessageBoxW null, russian, caption ,0
Is there a special trick to run unicode with OxygenBasic?
... dreadfully mangled names in MSVCRT, they are clearly not intended for public use ...
... they are an improvement on declare function, and pass through the compiler pronto ...
'2018-03-14 T 04:10:15
'UNICODE LOADING AND DISPLAY
% filename "t.exe"
'use rtl64
use corewin
wstring ws
ws=(wstring) getfile "t.txt"
messageboxW 0,ws,"",0
'
'EXAMINE UNICODING
word ww at strptr ws
string t
for i=1 to 512
t+=hex(ww[i],4)+" "
next
print t
I would like to include your demo in WinDynDialogs.
You could have variable names in ... Cyrillic :). It opens up new possibilities