...
! GetWindowLongPtr lib "user32.dll" alias "GetWindowLongPtrA" (sys hWnd, sys nIndex) as sys
'% Win_64
'-------------------------------------------------------------
function EnumChildProc(sys hwndChild, lParam) as bool callback
'=============================================================
{
RECT * rcParent;
sys i, idChild;
sys v,w,info
// Retrieve the child-window identifier. Use it to set the
// position of the child window.
info=GWL_ID
#ifdef Win_64
idChild = GetWindowLongPtr(hwndChild, info)
#else
idChild = GetWindowLong(hwndChild, info)
#endif
...
...
! GetWindowLongPtrA lib "user32.dll" alias "GetWindowLongPtrA" (sys hWnd, sys nIndex) as sys
'% Win_64
function GetWindowLongPtr(sys h, sys i) as sys
#ifdef Win_64
return GetWindowLongPtrA(h,i)
#else
return GetWindowLong(h,i)
#endif
end function
'-------------------------------------------------------------
function EnumChildProc(sys hwndChild, lParam) as bool callback
'=============================================================
{
RECT * rcParent;
sys i, idChild;
sys v,w,info
// Retrieve the child-window identifier. Use it to set the
// position of the child window.
info=GWL_ID
idChild = GetWindowLongPtr(hwndChild, info)
...
#ifdef mode64bit
! GetWindowLongPtr "GetWindowLongPtrA" '2
! SetWindowLongPtr "GetWindowLongPtrA" '3
#else
! GetWindowLongPtr "GetWindowLongA" '2
! SetWindowLongPtr "SetWindowLongA" '3
#endif
extern lib "user32.dll"
...
#ifdef mode64bit
! GetWindowLongPtr "GetWindowLongPtrA"
#else
! GetWindowLongPtr "GetWindowLongA"
#endif
...
end extern
print @GetWindowLongPtr
#ifndef mode64bit
def GetClassLongPtr GetClassLong
def SetClassLongPtr SetClassLong
def GetWindowLongPtr GetWindowLong
def SetWindowLongPtr SetWindowLong
def GetClassLongPtrW GetClassLongW
def SetClassLongPtrW SetClassLongW
def GetWindowLongPtrW GetWindowLongW
def SetWindowLongPtrW SetWindowLongW
#endif
#ifdef mode64bit
! GetWindowLongPtr "GetWindowLongPtrA" '2
! SetWindowLongPtr "SetWindowLongPtrA" '3
#endif
#ifdef mode64bit
! GetClassLongPtr "GetClassLongPtrA"
! SetClassLongPtr "SetClassLongPtrA"
! GetWindowLongPtr "GetWindowLongPtrA"
! SetWindowLongPtr "SetWindowLongPtrA"
! GetClassLongPtrW
! SetClassLongPtrW
! GetWindowLongPtrW
! SetWindowLongPtrW
#endif
$ filename "ExistFilePath.exe"
'uses rtl32
'uses rtl64
uses corewin
uses console
% INVALID_FILE_ATTRIBUTES = (dword -1) '0xffffffff
function existFP(string szFilePath) as bool
'path, filename?
dword attrib = GetFileAttributes(szFilePath)
printl attrib
'if attrib != 0xffffffff then return true
if attrib != INVALID_FILE_ATTRIBUTES then return true
return false
end function
sub checkFP(string fp)
if existFP(fp) then
printl fp " exists"
else
printl fp " does not exist"
end if
end sub
'check folder
checkFP("c:\temp")
checkFP("C:\temp\Get Start\Tgh")
checkFP("c:\oxygenbasic\examples")
checkFP("c:\program files")
'check file
checkFP("C:\OxygenBasic\Oxygen.dll")
checkFP("C:\OxygenBasic\Oxygen.?ll")
checkFP("C:\OxygenBasic\Oxygen.*")
checkFP("c:\oxygenbasic\projectsA\Controls\CtrlSliders.o2bas")
printl "Enter ... " : waitkey
' ExistFilePath.o2bas
' http://www.oxygenbasic.org/forum/index.php?topic=1544.msg18057;topicseen#msg18057
$ filename "ExistFilePath.exe"
'uses rtl32
uses rtl64
uses corewin
uses console
% INVALID_FILE_ATTRIBUTES = -1 ' 0xffffffff ' (dword -1) '0xffffffff
function existFP(string szFilePath) as bool
'path, filename?
' dword attrib = GetFileAttributes(szFilePath)
int attrib = GetFileAttributes(szFilePath)
printl " attrib " attrib
'if attrib != 0xffffffff then return true
' if attrib != INVALID_FILE_ATTRIBUTES then return true
if attrib <> INVALID_FILE_ATTRIBUTES then
return true
end if
return false
end function
sub checkFP(string fp)
if existFP(fp) then
printl fp " exists"
else
printl fp " does not exist"
end if
end sub
'check folder
checkFP("c:\temp")
checkFP("C:\temp\Get Start\Tgh")
checkFP("c:\oxygenbasic\examples")
checkFP("c:\program files")
'check file
checkFP("C:\OxygenBasic\Oxygen.dll")
checkFP("C:\OxygenBasic\Oxygen.?ll")
checkFP("C:\OxygenBasic\Oxygen.*")
checkFP("c:\oxygenbasic\projectsA\Controls\CtrlSliders.o2bas")
printl "Enter ... " : waitkey
$ filename "ExistFilePath.exe"
'uses rtl32
'uses rtl64
uses corewin
uses console
% INVALID_FILE_ATTRIBUTES = -1 '(dword -1) '0xffffffff
function existFP(string szFilePath) as bool
'path, filename?
int attrib = GetFileAttributes(szFilePath)
if attrib != INVALID_FILE_ATTRIBUTES then return true
return false
end function
sub checkFP(string fp)
if existFP(fp) then
printl fp " exists"
else
printl fp " does not exist"
end if
end sub
'check folder
...
'check file
...
printl "Enter ... " : waitkey
$ filename "t.exe"
uses rtl64
uses corewin
uses console
string f
do
print cr "filename "
f=ltrim rtrim input
if not f then exit do
dword a=GetFileAttributes f
'dword n=-1'INVALID_FILE_ATTRIBUTES
'if a=n then
if a=dword -1 then
print "invalid file/folder name" cr
else
print "attrib code " a cr
end if
'invalid=-1 folders=16 files=32
loop
'https://msdn.microsoft.com/de-de/library/windows/desktop/hh298367(v=vs.85).aspx
$ filename "win_tabnotify.exe"
'uses rtl32
'uses rtl64
uses WinUtil
'uses console
#autodim off
indexbase 0
% WC_TABCONTROL="SysTabControl32"
% WC_STATIC="Static"
% ICC_TAB_CLASSES = 8
% TCIF_TEXT=1
% TCIF_IMAGE=2
% TCM_INSERTITEM=4871
% TCM_GETCURSEL=4875
dword TCN_SELCHANGE= -551
dword TCN_SELCHANGING= -552
% SWP_SHOWWINDOW=64
% HWND_TOP=0
type TCITEM
int mask,dwState,dwStateMask
char* pszText
int cchTextMax,iImage
sys lParam
end type
typedef TCITEM TC_ITEM
% DAYS_IN_WEEK 7
string day[]={"Sun","Mon","Tue","Wed","Thu","Fri","Sat"}
' Initialize common controls.
INITCOMMONCONTROLSEXt icex
icex.dwSize = sizeof(INITCOMMONCONTROLSEX)
icex.dwICC = ICC_TAB_CLASSES
InitCommonControlsEx(&icex)
sys hInstance=inst
MainWindow 480,360,WS_OVERLAPPEDWINDOW
function WndProc(sys hwnd, uMsg, wParam, lParam) as sys callback
static sys hwndTab, hwndStatic
select uMsg
case WM_CREATE
' Get the dimensions of the parent window's client area, and
' create a tab control child window of that size.
RECT rcClient
TCITEM tie
GetClientRect(hwnd, &rcClient)
hwndTab = CreateWindowEx(0,WC_TABCONTROL, "",
WS_CHILD | WS_CLIPSIBLINGS | WS_VISIBLE,
0, 0, rcClient.right, rcClient.bottom,
hwnd, null, hInstance, null)
if (hwndTab = null) then
mbox "Create Tab Control failed"
return null
end if
' Add tabs for each day of the week.
tie.mask = TCIF_TEXT | TCIF_IMAGE
tie.iImage = -1
int i
for i = 0 to <DAYS_IN_WEEK
' Load the day string
tie.pszText=day[i]
if SendMessage(hwndTab,TCM_INSERTITEM,i, @tie) = -1 then
mbox "InsertItem Tab failed"
DestroyWindow(hwndTab)
return null
end if
next i
' Creates a child window (a static control) to occupy the tab control's display area.
' hwndTab - handle of the tab control.
hwndStatic = CreateWindowEx(0,WC_STATIC, "",
WS_CHILD | WS_VISIBLE | WS_BORDER,
100, 100, 100, 100, ' Position and dimensions; example only.
hwndTab, null, hInstance, ' g_hInst is the global instance handle
null)
SendMessage(hwndStatic, WM_SETTEXT, 0, strptr day[0]) 'Sunday
case WM_SIZE
' Handles the WM_SIZE message for the main window by resizing the tab control.
' hwndTab - handle of the tab control.
' lParam - the lParam parameter of the WM_SIZE message.
' RECT rc
' Resize the tab control to fit the client are of main window.
' SetWindowPos(hwndTab, HWND_TOP, 0, 0, GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam), SWP_SHOWWINDOW)
int x=loword(lParam) : int y=hiword(lParam)
SetWindowPos(hwndTab, HWND_TOP, 0,0, x,y, SWP_SHOWWINDOW)
case WM_NOTIFY
' Handles notifications from the tab control, as follows:
' TCN_SELCHANGING - always returns FALSE to allow the user to select a different tab.
' TCN_SELCHANGE - loads a string resource and displays it in a
' static control on the selected tab.
' hwndTab - handle of the tab control.
' lParam - the lParam parameter of the WM_NOTIFY message.
NMHDR pnmhdr at lParam
select pnmhdr.code
case TCN_SELCHANGING
' Return FALSE to allow the selection to change.
return FALSE
case TCN_SELCHANGE
'' int iPage = TabCtrl_GetCurSel(hwndTab)
int iPage = SendMessage(hwndTab, TCM_GETCURSEL, 0,0)
SendMessage(hwndStatic, WM_SETTEXT, 0, strptr day[iPage])
end select
return TRUE
case WM_CLOSE
DestroyWindow(hwnd)
case WM_DESTROY
PostQuitMessage(0)
case else
return DefWindowProc(hwnd, uMsg, wParam, lParam)
end select
return 0
end function
$ filename "TestInput.exe"
uses rtl64
uses console
cls
printl "Do wish to see the answer? (Y/N)"
string ans=input()
ans=ltrim rtrim ans 'Enter in Win64 does not work
if lcase(ans) = "y" then
printl "Your answer is Yes"
else
printl "Your answer is not Yes"
end if
printl "Enter ... " : waitkey
$ filename "LoadFile.exe"
'uses rtl32
'uses rtl64
string s
string fname="aFile.txt" 'does not exist
getfile fname, s
's=ltrim rtrim(s) 'without comment will crash in 64-bit mode
if len(s)=0 then print "Error loading " + fname else print "Loaded File " fname
$filename "o.exe"
uses rtl64
string s
print ltrim(rtrim(s))
print "ok"
$ Filename "Test_iob.exe"
'uses rtl32
'uses rtl64
uses corewin
'uses console
'sys _iob = __p__iob()
'print _iob
print __p__iob()
'10:12 12/12/2019
'float variadic params are passed in cpu in 64bit mode
$filename "o.exe"
uses rtl64
uses corewin
char c[64] 'string buffer
double v1=123
extern
'create an overlay of sprintf with variadic prototype
! sprintf (char *s,*f,...) at @sprintf
#show sprintf (c,"%4.2f",v1) '123.00
print c
char strg
int a = 10, b = 38, double c
c = a / b
sprintf(strg, "Value of Pi = %15.10f" + chr(10) + "Division of %d by %d is: %15.10f", pi, a, b, c)
print strg
$ Filename "Test_iob.exe"
'uses rtl32
'uses rtl64
uses corewin
uses console
indexbase 0
% STDIN_FILENO 0
% STDOUT_FILENO 1
% STDERR_FILENO 2
#ifndef mode64bit
// extern import _iob(0 to 2) alias "_iob" as FILE
sys _iob = __p__iob()
sys stdin = @_iob(STDIN_FILENO)
sys stdout = @_iob(STDOUT_FILENO)
sys stderr = @_iob(STDERR_FILENO)
#else
// declare function __iob_func() as FILE ptr
// #define stdin (@(__iob_func())[STDIN_FILENO])
// #define stdout (@(__iob_func())[STDOUT_FILENO])
// #define stderr (@(__iob_func())[STDERR_FILENO])
sys stdin = call @__iob_func[STDIN_FILENO]
sys stdout = call @__iob_func[STDOUT_FILENO]
sys stderr = call @__iob_func[STDERR_FILENO]
#endif
printl stdin
printl stdout
printl stderr
printl "Enter"
waitkey
$ Filename "Test_printf.exe"
'uses rtl32
'uses rtl64
uses corewin
uses console
indexbase 0
extern
! printf (char* a, ...) at @printf
% STDIN_FILENO 0
% STDOUT_FILENO 1
% STDERR_FILENO 2
type FILE
char* _ptr
int _cnt
char* _base
int _flag
int _file
int _charbuf
int _bufsiz
char* _tmpfname
end type
#define _O_TEXT 0x4000 // CRLF in file becomes LF in memory!
#define _IONBF 0x4
#ifndef mode64bit
// extern import _iob(0 to 2) alias "_iob" as FILE
FILE* _iob = __p__iob()
sys stdin = @_iob(STDIN_FILENO)
sys stdout = @_iob(STDOUT_FILENO)
sys stderr = @_iob(STDERR_FILENO)
#else
// declare function __iob_func() as FILE ptr
sys stdin = call @__iob_func()
sys stdout = stdin + sizeof(FILE)
sys stderr = stdout + sizeof(FILE)
#endif
'printl stdin
'printl stdout
'printl stderr + cr
sys hCrt = _open_osfhandle(ConsOut, _O_TEXT)
sys hf = _fdopen(hCrt, "w")
memcpy stdout, hf, sizeof(FILE)
setvbuf stdout, NULL, _IONBF, 0
fprintf(stdout, "loading %s" + chr(10), "Testfile.txt")
fprintf(stdout, "Oxygen ")
printf (chr(10) + "OxygenBasic")
printl "Enter"
waitkey
#ifndef mode64bit
// extern import _iob(0 to 2) alias "_iob" as FILE
FILE* _iob = __p__iob()
sys stdin = @_iob(STDIN_FILENO)
sys stdout = @_iob(STDOUT_FILENO)
sys stderr = @_iob(STDERR_FILENO)
#else
// declare function __iob_func() as FILE ptr
FILE* _iob = __iob_func()
sys stdin = @_iob(STDIN_FILENO)
sys stdout = @_iob(STDOUT_FILENO)
sys stderr = @_iob(STDERR_FILENO)
'sys stdin = __iob_func()
'sys stdout = stdin + sizeof(FILE)
'sys stderr = stdout + sizeof(FILE)
#endif
#ifndef mode64bit
FILE* _iob = __p__iob()
#else
FILE* _iob = __iob_func()
#endif
sys stdin = @_iob(STDIN_FILENO)
sys stdout = @_iob(STDOUT_FILENO)
sys stderr = @_iob(STDERR_FILENO)