//by Grahame King - April, 2006// The following code illustrates the use of ATL controls with Liberty Basic. More advanced uses which require event trapping can only be be managed by using 3rd party DLLs such as WMLiberty.dll. [[code format="vbnet"]] ' 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$ 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,60,130 filetype$(1) = "txt" : style(1) = _WS_CHILD + _WS_VISIBLE +_WS_VSCROLL filetype$(2) = "rtf" : style(2) = _WS_CHILD + _WS_VISIBLE +_WS_VSCROLL :ed(2)=true filetype$(3) = "doc" : style(3) = _WS_CHILD + _WS_VISIBLE :ed(3)=true filetype$(4) = "pdf" : style(4) = _WS_CHILD + _WS_VISIBLE :ed(4)=true filetype$(5) = "htm" : style(5) = _WS_CHILD + _WS_VISIBLE +_WS_VSCROLL filetype$(6) = "jpg" : style(6) = _WS_CHILD + _WS_VISIBLE +_WS_VSCROLL filetype$(7) = "gif" : style(7) = _WS_CHILD + _WS_VISIBLE filetype$(8) = "png" : style(8) = _WS_CHILD + _WS_VISIBLE filetype$(9) = "xls" : style(9) = _WS_CHILD + _WS_VISIBLE :ed(9) = true curFileType$ = "txt" curstyle = style(1) typemax = 9 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 as long,_ 'upper left x upperY as long,_ 'upper left y rightX as long,_ 'lower right x lowerY as long 'lower right y calldll #user32,"GetClientRect",_ hWndViewer as ulong,_ 'window handle Rect as struct,_ 'name of struct r as long '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 window wait sub SelectFileType call CloseMainView #main.type "show" #main.type "setfocus" end sub sub FileType handle$ #handle$, "selectionindex? styleIndex" curFileType$ = filetype$(styleIndex) curstyle = style(styleIndex) call editmode #handle$ "hide" call ViewFile end sub sub 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 end if end sub function indextype() i = 1 indextype = 0 while indextype=0 and i<=typemax if filetype$(i)=curFileType$ then indextype = i end if i = i+1 wend end function sub ViewFile filedialog "Open file", CurDir$+"\*."+curFileType$, fileName$ if fileName$ = "" then exit sub CurDir$ = FilePath$(fileName$) fileExt$ = FileExtension$(fileName$) if fileExt$<>curFileType$ then ' get filetype index and make changes curFileType$ = fileExt$ styleIndex = indextype() if styleIndex = 0 then notice "Cannot view this file type!" exit sub else call editmode end if end if if FileOpen then call CloseMainView on error goto [error] CallDLL #user32, "GetWindowLongA", _ hWndViewer As ulong, _ _GWL_HINSTANCE As long, _ hInst As long CallDLL #user32, "CreateWindowExA", _ _WS_EX_STATICEDGE As long, _ "AtlAxWin" As ptr, _ fileName$ As ptr, _ curstyle As long, _ 0 As long, _ 0 As long, _ cw As long, _ ch As long, _ hWndViewer As ulong, _ 100 As long, _ hInst As long, _ 0 As long, _ hATL As ulong FileOpen = true exit sub [error] notice "There is a problem reading this file" end sub sub CloseMainView ' destroy the atl child CallDLL #user32, "DestroyWindow", _ hATL As ulong, _ r as boolean FileOpen = false end sub sub CloseViewer handle$ call CloseViewerFromMenu end sub sub CloseViewerFromMenu Close #atl if FileOpen then call CloseMainView Close #main end end sub function FilePath$(f$) fileindex=len(f$) filelength=len(f$) while mid$(f$, fileindex,1)<>"\" fileindex=fileindex-1 wend FilePath$=left$(f$,fileindex) end function function FileExtension$(f$) fileindex=len(f$) filelength=len(f$) while mid$(f$, fileindex,1)<>"." fileindex=fileindex-1 wend FileExtension$=mid$(f$,fileindex+1,filelength-fileindex) end function ' end of code ' [[code]] 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 Regards, Grahame King, April 5th 2006 last update April 9th, 2006