how to show desktop screen on wxBitmapButton? Topic is solved

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
smallwolf
Experienced Solver
Experienced Solver
Posts: 69
Joined: Sun Aug 26, 2007 11:02 pm

how to show desktop screen on wxBitmapButton?

Post by smallwolf »

hello:
i want to show my desktop screen on the wxBitmapButton,
what's wrong with my code?


Code: Select all

        wxSize screensize=wxGetDisplaySize();
	wxBitmap bitmap(screensize.x,screensize.y);
	wxScreenDC dc;
	wxMemoryDC memDC;
	memDC.SelectObject(bitmap);
	memDC.Blit(0,0,screensize.x,screensize.y,&dc,0,0);
	memDC.SelectObject(wxNullBitmap);

	WxBitmapButton1->SetBitmapHover(bitmap);
have a nice day!
Auria
Site Admin
Site Admin
Posts: 6695
Joined: Thu Sep 28, 2006 12:23 am
Contact:

Post by Auria »

Just tried this code, works fine for me :

Code: Select all

#include "wx/wx.h"

class MyApp: public wxApp
	{
		bool OnInit();
		
		wxFrame *frame;
	public:
        
	};

IMPLEMENT_APP(MyApp)


bool MyApp::OnInit()
{
    wxBoxSizer* sizer = new wxBoxSizer(wxHORIZONTAL);
    frame = new wxFrame((wxFrame *)NULL, -1,  wxT("Hello wxWidgets"), wxPoint(50,50), wxSize(800,600));
	
    wxInitAllImageHandlers();
	
    wxSize screensize=wxGetDisplaySize();
    wxBitmap bitmap(screensize.x,screensize.y);
    wxScreenDC dc;
    wxMemoryDC memDC;
    memDC.SelectObject(bitmap);
    memDC.Blit(0,0,screensize.x,screensize.y,&dc,0,0);
    memDC.SelectObject(wxNullBitmap); 
    
    bitmap.SaveFile( wxT("/tmp/shot.png"), wxBITMAP_TYPE_PNG );
    
    frame->Show();
    return true;
} 
Post Reply