]>
git.saurik.com Git - wxWidgets.git/blob - samples/power/power.cpp
04b9ab3c63ce71d6485e21e8deb44635c13b0f4a
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxWidgets power management sample
4 // Author: Vadim Zeitlin
7 // Copyright: (C) 2006 Vadim Zeitlin <vadim@wxwindows.org>
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 // ============================================================================
13 // ============================================================================
15 // ----------------------------------------------------------------------------
17 // ----------------------------------------------------------------------------
19 #include "wx/wxprec.h"
30 #include "wx/textctrl.h"
31 #include "wx/msgdlg.h"
35 #if !defined(__WXMSW__) && !defined(__WXPM__)
36 #include "../sample.xpm"
39 // ----------------------------------------------------------------------------
41 // ----------------------------------------------------------------------------
43 class MyFrame
: public wxFrame
47 : wxFrame(NULL
, wxID_ANY
, _T("wxWidgets Power Management Sample"),
48 wxDefaultPosition
, wxSize(500, 200))
50 wxTextCtrl
*text
= new wxTextCtrl(this, wxID_ANY
, _T(""),
51 wxDefaultPosition
, wxDefaultSize
,
52 wxTE_MULTILINE
| wxTE_READONLY
);
53 m_logOld
= wxLog::SetActiveTarget(new wxLogTextCtrl(text
));
55 SetIcon(wxICON(sample
));
62 delete wxLog::SetActiveTarget(m_logOld
);
66 void OnSuspending(wxPowerEvent
& event
)
68 wxLogMessage(_T("System suspend starting..."));
69 if ( wxMessageBox(_T("Veto suspend?"), _T("Please answer"),
70 wxYES_NO
, this) == wxYES
)
73 wxLogMessage(_T("Vetoed suspend."));
77 void OnSuspended(wxPowerEvent
& WXUNUSED(event
))
79 wxLogMessage(_T("System is going to suspend."));
82 void OnSuspendCancel(wxPowerEvent
& WXUNUSED(event
))
84 wxLogMessage(_T("System suspend was cancelled."));
87 void OnResume(wxPowerEvent
& WXUNUSED(event
))
89 wxLogMessage(_T("System resumed from suspend."));
98 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
99 EVT_POWER_SUSPENDING(MyFrame::OnSuspending
)
100 EVT_POWER_SUSPENDED(MyFrame::OnSuspended
)
101 EVT_POWER_SUSPEND_CANCEL(MyFrame::OnSuspendCancel
)
102 EVT_POWER_RESUME(MyFrame::OnResume
)
105 // ----------------------------------------------------------------------------
106 // main application class
107 // ----------------------------------------------------------------------------
109 class MyApp
: public wxApp
112 virtual bool OnInit()