' ATL Test - 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, cw, ch, FileOpen, true, falsefalse=0true=not(false)
FileOpen =falseglobal CurDir$, curFileType$
CurDir$ = DefaultDir$
nomainwin
WindowWidth=DisplayWidth
WindowHeight=DisplayHeight
UpperLeftX=0:UpperLeftY=0
menu #main, "File",_
"Open",ViewFile,_
"Type",SelectFileType,_
"Close" ,CloseViewerFromMenu
listbox #main.type, filetype$(),FileType,0,0,62,100
filetype$(1)=".txt"
filetype$(2)=".rtf"
filetype$(3)=".doc"
filetype$(4)=".pdf"
filetype$(5)=".jpg"
filetype$(6)=".gif"
filetype$(7)=".xls"
curFileType$ =".txt"
Open "Liberty Basic ATL Viewer"For Window_nf As #main
#main "TrapClose CloseViewer"
#main.type"hide"
Open "atl"For DLL As #atl
CallDLL #atl, "AtlAxWinInit", Ret As void
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 y
calldll #user32,"GetClientRect",_
hWndViewer asulong,_ 'window handle
Rect as struct,_ 'name of struct
r aslong'return
cw = Rect.rightX.struct
ch = Rect.lowerY.struct' for CreateWindowExA call which creates a child window with'WindowWidth=cw'WindowHeight=ch'UpperLeftX=0:UpperLeftY=0
wait
sub SelectFileType
call CloseMainView
#main.type"show"
#main.type"setfocus"endsubsub FileType handle$
#handle$ "selection? curFileType$"
#handle$ "hide"call ViewFile
endsubsub ViewFile
filedialog "Open file", CurDir$+"\*"+curFileType$, fileName$
if fileName$ =""thenexitsub
CurDir$ = SeparatePath$(fileName$)if FileOpen thencall CloseMainView
style = _WS_CHILD + _WS_VISIBLE +_WS_VSCROLL+_WS_DISABLED
FileOpen =trueonerrorgoto[error]
CallDLL #user32, "GetWindowLongA", _
hWndViewer Asulong, _
_GWL_HINSTANCE Aslong, _
hInst Aslong
CallDLL #user32, "CreateWindowExA", _
_WS_EX_STATICEDGE Aslong, _
"AtlAxWin"As ptr, _
fileName$ As ptr, _
style Aslong, _
0Aslong, _
0Aslong, _
cw Aslong, _
ch Aslong, _
hWndViewer Asulong, _
100Aslong, _
hInst Aslong, _
0Aslong, _
hATL Asulongexitsub[error]
notice "There is a problem reading this file"endsubsub CloseMainView
' destroy the atl child
CallDLL #user32, "DestroyWindow", _
hATL Asulong, _
r asboolean
FileOpen =falseendsubsub CloseViewer handle$
call CloseViewerFromMenu
endsubsub CloseViewerFromMenu
Close #atl
if FileOpen thencall CloseMainView
Close #main
endendsubfunction SeparatePath$(f$)
fileindex=Len(f$)
filelength=Len(f$)whileMid$(f$, fileindex,1)<>"\"
fileindex=fileindex-1wend
SeparatePath$=Left$(f$,fileindex)endfunction' end of code '
You might like to try adding the bmp file type to see what you get! If you remove the _WS_DISABLED style constant you will be able to input to the window but be warned without the window disabled it is very easy to accidentally change the file you are viewing for those file types which allow it.
You might like to try adding the bmp file type to see what you get! If you remove the _WS_DISABLED style constant you will be able to input to the window but be warned without the window disabled it is very easy to accidentally change the file you are viewing for those file types which allow it.
The following relevant article was referred to me by Alyce Watson.
http://www.pluralsight.com/articlecontent/cpprep0799.htm
Regards,
Grahame King, April 5th 2006