| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 
 |  
#include "wx/wxprec.h"
 
#ifndef WX_PRECOMP
    #include "wx/wx.h"
#endif
 
#include "wx/image.h"
 
#include "EmcCallBack.h"
 
class MyApp: public wxApp
{
    virtual bool OnInit();
};
 
class MyFrame: public wxFrame
{
public:
 
    MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size);
 
    void OnQuit(wxCommandEvent& event);
    void OnConf(wxCommandEvent& event);
    void OnGrab(wxCommandEvent& event);
 
    DECLARE_EVENT_TABLE()
 
	EmcCallBack *MyCallBack;
	wxBitmap  *my_grab;
};
 
enum
{
    ID_Quit = 1,
    ID_Conf,
	ID_Grab,
};
 
BEGIN_EVENT_TABLE(MyFrame, wxFrame)
    EVT_MENU(ID_Quit, MyFrame::OnQuit)
    EVT_MENU(ID_Conf, MyFrame::OnConf)
	EVT_MENU(ID_Grab, MyFrame::OnGrab)
END_EVENT_TABLE()
 
IMPLEMENT_APP(MyApp)
 
bool MyApp::OnInit()
{
    MyFrame *frame = new MyFrame( _T("Img Grab"), wxPoint(50,50), wxSize(450,340) );
    frame->Show(TRUE);
    SetTopWindow(frame);
    return TRUE;
} 
 
MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size)
: wxFrame((wxFrame *)NULL, -1, title, pos, size)
{
    wxMenu *menuFile = new wxMenu;
 
    menuFile->Append( ID_Conf, _T("&Conf...") );    
	menuFile->Append( ID_Grab, _T("&Grab") );
    menuFile->AppendSeparator();
    menuFile->Append( ID_Quit, _T("E&xit") );
 
    wxMenuBar *menuBar = new wxMenuBar;
    menuBar->Append( menuFile, _T("&File") );
 
    SetMenuBar( menuBar );
 
    CreateStatusBar();
    SetStatusText( _T("") );
	MyCallBack = new EmcCallBack();
}
 
void MyFrame::OnGrab(wxCommandEvent& WXUNUSED(event))
{	
	MyCallBack->Grab();
	wxBitmap MyGrab(MyCallBack->GetImagePtr(),MyCallBack->GetWidth(),MyCallBack->GetHeight(),MyCallBack->GetBitsPerPixel());
	wxImage Mytest = MyGrab.ConvertToImage();
	Mytest.SaveFile(wxT("test.bmp"), wxBITMAP_TYPE_BMP);
 
} | 
Partager