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