' A Simple Image Viewer ' Written by Dirk Noack 2014 option explicit dim appname = "Image Viewer" dim myImg = new wxMemoryDC() dim bmp = new wxEmptyBitmap(0, 0) dim scrollWidth = 1 'creating main frame dim frame = new wxFrame(nothing, -1, appname, wxPoint(0, 0), wxSize(640, 480), wxNO_FULL_REPAINT_ON_RESIZE | wxDEFAULT_FRAME_STYLE ) dim scrollWin = new wxScrolledWindow(frame, -1) 'set the background colour to black scrollwin.SetBackgroundColour( wxBLACK ) 'maximize the frame frame.Maximize(1) 'create a status bar frame.CreateStatusBar(2) frame.SetStatusText("No image loaded", 1) 'create a "File" menu and append two items dim mFile = new wxMenu() mFile.Append( wxID_OPEN, "&Open... \tCtrl-O" , "Load Image from disk") mFile.AppendSeparator() mFile.Append( wxID_EXIT, "E&xit \tAlt-X", "Quit this program") 'create an "About" menu and append an item dim mHelp = new wxMenu() mHelp.Append( wxID_ABOUT, "&About...\tCtrl-A", "Show about dialog") 'create the menubar dim menuBar = new wxMenuBar() 'append the menus to the menu bar menuBar.Append(mFile, "&File") menuBar.Append(mHelp, "&Help") ' ... and attach this menu bar to the frame frame.SetMenuBar(menuBar) 'show the frame frame.Show( true ) ' drawing images sub OnPaint( event ) handles scrollWin.paint(-1) 'create the paintdc dim dc = wxPaintDC(scrollWin) dc.Clear() 'is width, the bitmap is not empty if bmp.GetWidth()> 0 then 'get the picture size dim pw = bmp.GetWidth() dim ph = bmp.GetHeight() 'calculate the scrolling position dim startPicX, startPicY startPicX, startPicY = scrollWin.CalcUnscrolledPosition(0, 0) 'copy the bitmap from the memotydc dc.Blit(0, 0, pw, ph, myImg, startPicX, startPicY) 'don't forget the scrollWin prepare scrollWin.PrepareDC(dc) end if end sub ' load a new file sub onLoad( event ) handles frame.menuselected(wxID_OPEN) 'set the wildcard for all supported files dim wildcard = "All Pictures|*.gif;*.jpg;*.jpeg;*.bmp;*.png;*.pcx;*.pnm;*.tif;*.xpm;*.xbm;*.ico;*.cur|" & "Jpg-Files(*.jpg)|*.jpg|Jpeg-Files(*.jpeg)|*.jpeg|Bitmap-Files(*.bmp)|*.bmp|Gif-Files(*.gif)|*.gif|Png-Files(*.png)|*.png|Pcx-Files(*.pcx)|*.pcx|Pnm-Files(*.pnm)|*.pnm|Tif-Files(*.tif)|*.tif|Xpm-Files(*.xpm)|*.xpm|Xbm-Files(*.xbm)|*.xbm|Icons(*.ico)|*.ico|Cursors(*.cur)|*.cur" dim fileDialog = wxFileDialog(nothing, "Open File", "", "", wildcard, wxOPEN|wxCHANGE_DIR) ' display the dialog if fileDialog.ShowModal() = wxID_OK then 'get full file path dim bmp_path = fileDialog.GetPath() 'use wxFileName to get the file extension dim FName = wxFileName(bmp_path) dim ext = fName.GetExt() 'free memory from wxFileName deallocate(fName) 'get the filetype select case lcase(ext) case "jpg", "jpeg": dim Type = wxBITMAP_TYPE_JPEG case "bmp": Type = wxBITMAP_TYPE_BMP case "png": Type = wxBITMAP_TYPE_PNG case "pcx": Type = wxBITMAP_TYPE_PCX case "pnm": Type = wxBITMAP_TYPE_PNM case "tif": Type = wxBITMAP_TYPE_TIF case "xpm": Type = wxBITMAP_TYPE_XPM case "xbm": Type = wxBITMAP_TYPE_XBM case "ico": Type = wxBITMAP_TYPE_ICO case "icl": Type = wxBITMAP_TYPE_ICO_RESOURCE case "cur": Type = wxBITMAP_TYPE_CUR case "gif": Type = wxBITMAP_TYPE_GIF case else: Type = -1 end select 'delete the bitmap ~bmp 'create a new empty bitmap bmp = wxBitmapFromFile(bmp_path, Type) 'select the bitmap in the memorydc myImg.SelectObject(bmp) 'set the scrollbar widths scrollWin.SetScrollbars(scrollwidth, scrollwidth, bmp.GetWidth() / scrollwidth, bmp.GetHeight() / scrollwidth) 'set the frame infos frame.SetStatusText(" " & bmp_path, 0) frame.SetStatusText(" Bitmap type : " & ucase(ext), 1) frame.SetTitle(appName &" *" &bmp_path &"*") 'force a repaint frame.Refresh() end if end sub sub onAbout( event ) handles frame.menuselected(wxID_ABOUT) 'set the message wxMessageBox( "Simple image viewer written in wxBasic \n\nWritten by Dirk Noack 2014", wxOK + wxICON_INFORMATION , frame ) end sub 'exit application sub onEXIT( event ) handles frame.menuselected( wxID_EXIT) 'close the frame frame.Close() end sub