I've been trying everything I can to load and show an image onto my window, but to no avail. I've read all of the wxDC documents I could find (including the sample programs), but fail to make much sense of them. I included my code below; Could someone tell me what I'm doing wrong, or give me some example code. Thanks
Main.cpp
#include <wx/wxprec.h>
#ifndef WX_PRECOMP
#include <wx/wx.h>
#endif
#include "base.h"
IMPLEMENT_APP(MainApp)
bool MainApp::OnInit()
{
wxImage::AddHandler( new wxGIFHandler );
wxImage Pic_Splash;
if (Pic_Splash.LoadFile("bitmaps\\splash.gif", wxBITMAP_TYPE_GIF)) {
new wxSplashScreen(Pic_Splash,
wxSPLASH_CENTRE_ON_SCREEN|wxSPLASH_TIMEOUT,
6000, NULL, -1, wxDefaultPosition, wxDefaultSize,
wxSIMPLE_BORDER|wxSTAY_ON_TOP);
}
MainFrame *MainWin = new MainFrame("BlakkCount", wxPoint(1, 1),
wxSize(290, 190)); MainWin->Show(TRUE); SetTopWindow(MainWin);
return TRUE;
}
MainFrame::MainFrame(const wxString &title, const wxPoint &pos, const wxSize &size)
: wxFrame((wxFrame *) NULL, -1, title, pos, size)
{
Center(); SetSizeHints(290, 190, 290, 190, -1, -1);
CreateStatusBar();
MainMenu = new wxMenuBar(); wxMenu *FileMenu = new wxMenu(); wxMenu *OtherMenu = new wxMenu();
FileMenu->Append(MENU_Open, "&Open", "Open a file");
FileMenu->Append(MENU_Close, "&Close", "Close currently open file");
FileMenu->AppendSeparator();
FileMenu->Append(MENU_Quit, "&Quit", "Quit the program");
OtherMenu->Append(MENU_About, "&About", "About the program");
MainMenu->Append(FileMenu, "File");
MainMenu->Append(OtherMenu, "Other");
SetMenuBar(MainMenu);
TestIcon.LoadFile("bitmaps\\ball2.ico", wxBITMAP_TYPE_ICO);
if (TestIcon.Ok()) SetStatusText("LOADED ICON!");
else SetStatusText("FAILED TO LOAD ICON!");
TestIconDC.DrawIcon(TestIcon, 1, 1);
}
void MainFrame::OpenFile()
{
wxTextFile *TxtFile;
wxFileDialog *OpenDialog = new wxFileDialog(this, "Choose a file to open", "", "", "Text files (*.txt)|*.txt|", wxOPEN, wxDefaultPosition);
if (OpenDialog->ShowModal() == wxID_OK) {
CurrentDocPath = OpenDialog->GetPath();
delete NoFileLoaded;
SetFont(wxFont(10, wxDEFAULT, wxNORMAL, wxNORMAL, FALSE, wxEmptyString, wxFONTENCODING_DEFAULT));
LinesInFile = new wxStaticText(this,
STATICTEXT_LinesInFile,
"Lines in File: ",
wxDefaultPosition,
wxSize(290,190),
wxALIGN_CENTRE,
"LinesInFile");
SetTitle(wxString("BlakKount - ") << OpenDialog->GetFilename()); }
}
void MainFrame::CloseFile()
{
LinesInFile->SetLabel("Lines in File: ");
SetTitle("BlakKount");
}
void MainFrame::Maximize()
{
SetStatusText("Yeah, just try maximizing the window again");
}
void MainFrame::Quit()
{
Close(TRUE); }
void MainFrame::About()
{
wxDialog AboutDlg(this, DLG_Main, "About",
wxDefaultPosition, wxDefaultSize,
wxTHICK_FRAME | wxCAPTION, "DIALOGBOX");
if (AboutDlg.ShowModal() == TRUE) SetStatusText("Oh yeah");
AboutDlg.Destroy();
SetStatusText("ABOUT");
}
Base.h
#ifndef __BASE_H #define __BASE_H
#include <wx/window.h>
#include <wx/image.h>
#include <wx/splash.h>
#include <wx/bitmap.h>
#include <wx/textctrl.h>
#include <wx/menu.h>
#include <wx/filedlg.h>
#include <wx/msgdlg.h>
#include <wx/event.h>
#include <wx/object.h>
#include <wx/textfile.h>
#include <wx/cmndata.h>
#include <wx/dc.h>
#include <wx/dcmemory.h>
#include <wx/icon.h>
class MainApp: public wxApp { public: virtual bool OnInit();
};
class MainFrame: public wxFrame { public:
MainFrame( const wxString &title, const wxPoint &pos, const wxSize &size );
wxIcon TestIcon;
wxDC TestIconDC;
wxStaticText *NoFileLoaded; wxStaticText *LinesInFile; wxString CurrentDocPath; wxString CurrentFilename; wxTextCtrl *MainTextBox; wxMenuBar *MainMenu;
void OpenFile();
void CloseFile();
void Quit();
void About();
bool DrawImages(wxDC &dc);
void Maximize();
private:
DECLARE_EVENT_TABLE() };
enum
{
TEXT_Main = wxID_HIGHEST + 1, DLG_Main,
STATICBMP_Main,
MENU_Open,
MENU_Close,
MENU_Quit,
MENU_About,
STATICTEXT_NoFileLoaded,
STATICTEXT_LinesInFile,
};
BEGIN_EVENT_TABLE ( MainFrame, wxFrame )
EVT_MAXIMIZE(MainFrame::Maximize) EVT_MENU(MENU_Open, MainFrame::OpenFile) EVT_MENU(MENU_Close, MainFrame::CloseFile) EVT_MENU(MENU_Quit, MainFrame::Quit) EVT_MENU(MENU_About, MainFrame::About) END_EVENT_TABLE()
#endif
|