The following code (released to public domain) illustrates the use of ATL controls with Liberty Basic 4.03 running under Windows. More advanced uses may require event trapping and 3rd party DLLs.
' ATL Viewer - thanks to Doyle Whisenant for the concept and the basic atl dll code' - and to Alyce Watson for the technique of remembering the filedialog directory' - and a little code borrowed from Eddie' - and all the good stuff in the LB4 Companion and past support' - and to the LB community (Sean Brown, Dan, ElEdwards, Stefan Pendl, Janet Terra...)' - and, of course, Carl Gundel.global hWndViewer, hATL, curstyle, styleIndex, typemax, cw, ch, FileOpen, true, false
false =0
true =not(false)
FileOpen = false
global CurDir$, curFileType$
CurDir$ =DefaultDir$nomainwinWindowWidth=DisplayWidthWindowHeight=DisplayHeightUpperLeftX=0:UpperLeftY=0menu#main,"File",_
"Open",ViewFile,_
"Type",SelectFileType,_
"Close",CloseViewerFromMenu
listbox#main.type, filetype$(),FileType,0,0,60,130
filetype$(1)="txt": style(1)= _WS_CHILD or _WS_VISIBLE or _WS_VSCROLL
filetype$(2)="rtf": style(2)= _WS_CHILD or _WS_VISIBLE or _WS_VSCROLL :ed(2)=true
filetype$(3)="doc": style(3)= _WS_CHILD or _WS_VISIBLE :ed(3)=true
filetype$(4)="pdf": style(4)= _WS_CHILD or _WS_VISIBLE :ed(4)=true
filetype$(5)="htm": style(5)= _WS_CHILD or _WS_VISIBLE or _WS_VSCROLL
filetype$(6)="jpg": style(6)= _WS_CHILD or _WS_VISIBLE or _WS_VSCROLL
filetype$(7)="gif": style(7)= _WS_CHILD or _WS_VISIBLE
filetype$(8)="png": style(8)= _WS_CHILD or _WS_VISIBLE
filetype$(9)="xls": style(9)= _WS_CHILD or _WS_VISIBLE :ed(9)= true
curFileType$ ="txt"
curstyle = style(1)
typemax =9Open"Liberty Basic ATL Viewer"For Window_nf As#main
#main "TrapClose CloseViewer"#main.type "hide"Open"atl"ForDLLAs#atl
CallDLL#atl,"AtlAxWinInit", Ret Aslong
hWndViewer =hWnd(#main)STRUCT Rect,_ 'struct for storing client area rectangle
leftX aslong,_ 'upper left x
upperY aslong,_ 'upper left y
rightX aslong,_ 'lower right x
lowerY aslong'lower right ycalldll#user32,"GetClientRect",_
hWndViewer asulong,_ 'window handle
Rect asstruct,_ 'name of struct
r aslong'return
cw = Rect.rightX.struct
ch = Rect.lowerY.struct' for later calls to CreateWindowExA which creates a child window'WindowWidth=cw'WindowHeight=ch'UpperLeftX=0:UpperLeftY=0 top left corner of client area of main windowwaitsub SelectFileType
call CloseMainView
#main.type "show"#main.type "setfocus"endsubsub FileType handle$
#handle$,"selectionindex? styleIndex"
curFileType$ = filetype$(styleIndex)
curstyle = style(styleIndex)call editmode
#handle$ "hide"call ViewFile
endsubsub editmode
if ed(styleIndex)then
msg$ ="When editing features are enabled, right click for popup menu."+chr$(13)+_
"Ctrl S will save changes overwriting the file! Okay to view in edit mode?"confirm msg$; resp$
if resp$="no"then curstyle = curstyle + _WS_DISABLED
endifendsubfunction indextype()
i =1
indextype =0while indextype=0and i<=typemax
if filetype$(i)=curFileType$ then
indextype = i
endif
i = i+1wendendfunctionsub ViewFile
filedialog"Open file", CurDir$+"\*."+curFileType$, fileName$
if fileName$ =""thenexitsub
CurDir$ = FilePath$(fileName$)
fileExt$ = FileExtension$(fileName$)if fileExt$<>curFileType$ then' get filetype index and make changes
curFileType$ = fileExt$
styleIndex = indextype()if styleIndex =0thennotice"Cannot view this file type!"exitsubelsecall editmode
endifendifif FileOpen thencall CloseMainView
onerrorgoto[error]CallDLL#user32,"GetWindowLongA", _
hWndViewer Asulong, _
_GWL_HINSTANCE Aslong, _
hInst AslongCallDLL#user32,"CreateWindowExA", _
_WS_EX_STATICEDGE Aslong, _
"AtlAxWin"Asptr, _
fileName$ Asptr, _
curstyle Aslong, _
0Aslong, _
0Aslong, _
cw Aslong, _
ch Aslong, _
hWndViewer Asulong, _
100Aslong, _
hInst Aslong, _
0Aslong, _
hATL Asulong
FileOpen = true
exitsub[error]notice"There is a problem reading this file"endsubsub CloseMainView
' destroy the atl childCallDLL#user32,"DestroyWindow", _
hATL Asulong, _
r asboolean
FileOpen = false
endsubsub CloseViewer handle$
call CloseViewerFromMenu
endsubsub CloseViewerFromMenu
Close#atl
if FileOpen thencall CloseMainView
Close#main
endendsubfunction FilePath$(f$)
fileindex=len(f$)
filelength=len(f$)whilemid$(f$, fileindex,1)<>"\"
fileindex=fileindex-1wend
FilePath$=left$(f$,fileindex)endfunctionfunction FileExtension$(f$)
fileindex=len(f$)
filelength=len(f$)whilemid$(f$, fileindex,1)<>"."
fileindex=fileindex-1wend
FileExtension$=mid$(f$,fileindex+1,filelength-fileindex)endfunction' end of code '
You might like to try adding the bmp file type to see what you get!
The following code (released to public domain) illustrates the use of ATL controls with Liberty Basic 4.03 running under Windows. More advanced uses may require event trapping and 3rd party DLLs.
You might like to try adding the bmp file type to see what you get!
The following relevant article was referred to me by Alyce Watson.
http://www.pluralsight.com/articlecontent/cpprep0799.htm