[[code format="vbnet"]] ' ATL TestViewer - 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. globalglobal hWndViewer, hATL, curstyle, 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,62,100 filetype$(1)filetype$(),FileType,0,0,60,130 filetype$(1) = ".txt" filetype$(2)"txt" : style(1) = ".rtf" filetype$(3)_WS_CHILD + _WS_VISIBLE +_WS_VSCROLL filetype$(2) = ".doc" filetype$(4)"rtf" : style(2) = ".pdf" filetype$(5)_WS_CHILD + _WS_VISIBLE +_WS_VSCROLL :ed(2)=1 filetype$(3) = ".jpg" filetype$(6)"doc" : style(3) = ".gif" filetype$(7)_WS_CHILD + _WS_VISIBLE :ed(3)=1 filetype$(4) = ".xls""pdf" : style(4) = _WS_CHILD + _WS_VISIBLE :ed(4)=1 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) = 1 curFileType$ = ".txt""txt" : curstyle = style(1) Open "Liberty Basic ATL Viewer" For Window_nf As #main #main#main "TrapClose CloseViewer" #main.type #main.type "hide" Open Open "atl" For DLL As #atl CallDLL CallDLL #atl, "AtlAxWinInit", Ret As void hWndViewer = hWnd(#main) STRUCTSTRUCT 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 calldllcalldll #user32,"GetClientRect",_ hWndViewer as ulong,_ 'window handle Rect as struct,_ 'name of struct r as long 'return cwcw = Rect.rightX.struct ch ch = Rect.lowerY.struct ' for later calls to CreateWindowExA call which which creates a child window with '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$ "selection? curFileType$"#handle$, "selectionindex? styleIndex" curFileType$ = filetype$(styleIndex) curstyle = style(styleIndex) 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 #handle$ "hide" call ViewFile end sub sub ViewFile filedialog "Open file", CurDir$+"\*"+curFileType$,CurDir$+"\*."+curFileType$, fileName$ if fileName$ = "" then exit sub CurDir$ = SeparatePath$(fileName$) if FileOpen then call CloseMainView style = _WS_CHILD + _WS_VISIBLE +_WS_VSCROLL+_WS_DISABLED FileOpen = true 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, _ stylecurstyle 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 SeparatePath$(f$) fileindex=Len(f$) filelength=Len(f$) while Mid$(f$, fileindex,1)<>"\" fileindex=fileindex-1 wend SeparatePath$=Left$(f$,fileindex) end function ' end of code ' ' end of code ' [[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. The following relevant article was referred to me by Alyce Watson. http://www.pluralsight.com/articlecontent/cpprep0799.htm Regards, Grahame King, April 5th 2006