]> git.saurik.com Git - wxWidgets.git/blame - samples/memcheck/memcheck.cpp
XRC spec: document wxRibbon* XRC handler.
[wxWidgets.git] / samples / memcheck / memcheck.cpp
CommitLineData
457814b5
JS
1/////////////////////////////////////////////////////////////////////////////
2// Name: memcheck.cpp
3// Purpose: Memory-checking sample
4// Author: Julian Smart
5// Modified by:
6// Created: 04/01/98
6aa89a22 7// Copyright: (c) Julian Smart
526954c5 8// Licence: wxWindows licence
457814b5
JS
9/////////////////////////////////////////////////////////////////////////////
10
457814b5
JS
11// For compilers that support precompilation, includes "wx.h".
12#include "wx/wxprec.h"
13
14#ifdef __BORLANDC__
15#pragma hdrstop
16#endif
17
18#ifndef WX_PRECOMP
19#include "wx/wx.h"
20#endif
21
c6376731 22#include "wx/datetime.h"
457814b5 23
e7092398 24#ifndef wxHAS_IMAGES_IN_RESOURCES
3cb332c1 25 #include "../sample.xpm"
47908e25
RR
26#endif
27
6b037754
JS
28#ifndef __WXDEBUG__
29#error This program must be compiled in debug mode.
457814b5
JS
30#endif
31
7fe7d506
JS
32// Normally, new is automatically defined to be the
33// debugging version. If not, this does it.
b58deaec 34#if !defined(new) && defined(WXDEBUG_NEW) && wxUSE_MEMORY_TRACING && wxUSE_GLOBAL_MEMORY_OPERATORS
7fe7d506
JS
35#define new WXDEBUG_NEW
36#endif
37
457814b5
JS
38// Define a new application type
39class MyApp: public wxApp
40{ public:
41 bool OnInit(void);
42};
43
44// Define a new frame type
45class MyFrame: public wxFrame
46{ public:
47 MyFrame(wxFrame *parent);
48 void OnQuit(wxCommandEvent& event);
49
50DECLARE_EVENT_TABLE()
51};
52
53IMPLEMENT_APP(MyApp)
54
55// `Main program' equivalent, creating windows and returning main app frame
56bool MyApp::OnInit(void)
57{
45e6e6f8 58 if ( !wxApp::OnInit() )
3cb332c1 59 return false;
45e6e6f8 60
457814b5 61 // Create the main frame window
c67daf87 62 MyFrame *frame = new MyFrame((wxFrame *) NULL);
457814b5
JS
63
64 // Give it an icon
3cb332c1 65 frame->SetIcon(wxICON(sample));
457814b5
JS
66
67 // Make a menubar
68 wxMenu *file_menu = new wxMenu;
69
9a83f860 70 file_menu->Append(wxID_EXIT, wxT("E&xit"));
457814b5 71 wxMenuBar *menu_bar = new wxMenuBar;
9a83f860 72 menu_bar->Append(file_menu, wxT("File"));
457814b5
JS
73 frame->SetMenuBar(menu_bar);
74
75 // Make a panel with a message
76 wxPanel *panel = new wxPanel(frame);
77
9a83f860 78 (void)new wxStaticText(panel, wxID_ANY, wxT("Hello, this is a minimal debugging wxWidgets program!"), wxPoint(10, 10));
457814b5
JS
79
80 // Show the frame
0c7cbf7d 81 frame->Show(true);
457814b5 82
c242a1ec 83#if wxUSE_MEMORY_TRACING
bd7d06f2 84 wxDebugContext::SetCheckpoint();
ea787af1
JS
85#endif
86
87 // object allocation
ea92bb67 88 wxBrush* brush = new wxBrush(*wxRED_BRUSH);
ea787af1
JS
89 wxBitmap* bitmap = new wxBitmap(100, 100);
90
91 // non-object allocation
92 char *ordinaryNonObject = new char[1000];
457814b5 93
e55ad60e 94 wxString *thing = new wxString;
c6376731
VZ
95
96#if wxUSE_DATETIME
97 wxDateTime* date = new wxDateTime;
98#endif // wxUSE_DATETIME
457814b5 99
457814b5
JS
100 const char *data = (const char*) thing ;
101
c242a1ec 102#if wxUSE_MEMORY_TRACING
2db0bbde
JS
103 // On MSW, Dump() crashes if using wxLogGui,
104 // so use wxLogStderr instead.
105 wxLog* oldLog = wxLog::SetActiveTarget(new wxLogStderr);
106
bd7d06f2
RR
107 wxDebugContext::PrintClasses();
108 wxDebugContext::Dump();
109 wxDebugContext::PrintStatistics();
457814b5 110
2db0bbde
JS
111 // Set back to wxLogGui
112 delete wxLog::SetActiveTarget(oldLog);
ea787af1 113#endif
2db0bbde 114
6b037754 115 // Don't delete these objects, to force wxApp to flag a memory leak.
457814b5
JS
116// delete thing;
117// delete date;
118// delete[] ordinaryNonObject;
0c7cbf7d
WS
119
120 return true;
457814b5
JS
121}
122
123BEGIN_EVENT_TABLE(MyFrame, wxFrame)
124 EVT_MENU(wxID_EXIT, MyFrame::OnQuit)
125END_EVENT_TABLE()
126
127// My frame constructor
128MyFrame::MyFrame(wxFrame *parent):
9a83f860 129 wxFrame(parent, wxID_ANY, wxT("MemCheck wxWidgets Sample"), wxDefaultPosition, wxSize(400, 200))
457814b5
JS
130{}
131
132// Intercept menu commands
cb43b372 133void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
457814b5 134{
0c7cbf7d 135 Close(true);
457814b5
JS
136}
137