]> git.saurik.com Git - wxWidgets.git/blame_incremental - samples/memcheck/memcheck.cpp
Tamil translations update from Dinakar T.D.
[wxWidgets.git] / samples / memcheck / memcheck.cpp
... / ...
CommitLineData
1/////////////////////////////////////////////////////////////////////////////
2// Name: memcheck.cpp
3// Purpose: Memory-checking sample
4// Author: Julian Smart
5// Modified by:
6// Created: 04/01/98
7// Copyright: (c) Julian Smart
8// Licence: wxWindows licence
9/////////////////////////////////////////////////////////////////////////////
10
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
22#include "wx/datetime.h"
23
24#ifndef wxHAS_IMAGES_IN_RESOURCES
25 #include "../sample.xpm"
26#endif
27
28#ifndef __WXDEBUG__
29#error This program must be compiled in debug mode.
30#endif
31
32// Normally, new is automatically defined to be the
33// debugging version. If not, this does it.
34#if !defined(new) && defined(WXDEBUG_NEW) && wxUSE_MEMORY_TRACING && wxUSE_GLOBAL_MEMORY_OPERATORS
35#define new WXDEBUG_NEW
36#endif
37
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{
58 if ( !wxApp::OnInit() )
59 return false;
60
61 // Create the main frame window
62 MyFrame *frame = new MyFrame((wxFrame *) NULL);
63
64 // Give it an icon
65 frame->SetIcon(wxICON(sample));
66
67 // Make a menubar
68 wxMenu *file_menu = new wxMenu;
69
70 file_menu->Append(wxID_EXIT, wxT("E&xit"));
71 wxMenuBar *menu_bar = new wxMenuBar;
72 menu_bar->Append(file_menu, wxT("File"));
73 frame->SetMenuBar(menu_bar);
74
75 // Make a panel with a message
76 wxPanel *panel = new wxPanel(frame);
77
78 (void)new wxStaticText(panel, wxID_ANY, wxT("Hello, this is a minimal debugging wxWidgets program!"), wxPoint(10, 10));
79
80 // Show the frame
81 frame->Show(true);
82
83#if wxUSE_MEMORY_TRACING
84 wxDebugContext::SetCheckpoint();
85#endif
86
87 // object allocation
88 wxBrush* brush = new wxBrush(*wxRED_BRUSH);
89 wxBitmap* bitmap = new wxBitmap(100, 100);
90
91 // non-object allocation
92 char *ordinaryNonObject = new char[1000];
93
94 wxString *thing = new wxString;
95
96#if wxUSE_DATETIME
97 wxDateTime* date = new wxDateTime;
98#endif // wxUSE_DATETIME
99
100 const char *data = (const char*) thing ;
101
102#if wxUSE_MEMORY_TRACING
103 // On MSW, Dump() crashes if using wxLogGui,
104 // so use wxLogStderr instead.
105 wxLog* oldLog = wxLog::SetActiveTarget(new wxLogStderr);
106
107 wxDebugContext::PrintClasses();
108 wxDebugContext::Dump();
109 wxDebugContext::PrintStatistics();
110
111 // Set back to wxLogGui
112 delete wxLog::SetActiveTarget(oldLog);
113#endif
114
115 // Don't delete these objects, to force wxApp to flag a memory leak.
116// delete thing;
117// delete date;
118// delete[] ordinaryNonObject;
119
120 return true;
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):
129 wxFrame(parent, wxID_ANY, wxT("MemCheck wxWidgets Sample"), wxDefaultPosition, wxSize(400, 200))
130{}
131
132// Intercept menu commands
133void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
134{
135 Close(true);
136}
137