]>
Commit | Line | Data |
---|---|---|
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$ | |
8 | // Copyright: (c) Julian Smart and Markus Holzem | |
9 | // Licence: wxWindows license | |
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 | ||
28 | #include "wx/date.h" | |
29 | ||
47908e25 RR |
30 | #ifdef __WXGTK__ |
31 | #include "mondrian.xpm" | |
32 | #endif | |
33 | ||
b2aef89b | 34 | #if !WXDEBUG |
e3e65dac | 35 | #error You must set WXDEBUG to 1 on the 'make' command line (MSW) or with configure (GTK) |
457814b5 JS |
36 | #endif |
37 | ||
46dc76ba | 38 | // #define new WXDEBUG_NEW |
457814b5 JS |
39 | |
40 | // Define a new application type | |
41 | class MyApp: public wxApp | |
42 | { public: | |
43 | bool OnInit(void); | |
44 | }; | |
45 | ||
46 | // Define a new frame type | |
47 | class MyFrame: public wxFrame | |
48 | { public: | |
49 | MyFrame(wxFrame *parent); | |
50 | void OnQuit(wxCommandEvent& event); | |
51 | ||
52 | DECLARE_EVENT_TABLE() | |
53 | }; | |
54 | ||
55 | IMPLEMENT_APP(MyApp) | |
56 | ||
57 | // `Main program' equivalent, creating windows and returning main app frame | |
58 | bool MyApp::OnInit(void) | |
59 | { | |
60 | // Create the main frame window | |
c67daf87 | 61 | MyFrame *frame = new MyFrame((wxFrame *) NULL); |
457814b5 JS |
62 | |
63 | // Give it an icon | |
64 | #ifdef wx_msw | |
65 | frame->SetIcon(wxIcon("mondrian")); | |
47908e25 | 66 | frame->SetIcon(wxIcon(mondrian_xpm)); |
457814b5 JS |
67 | #endif |
68 | ||
69 | // Make a menubar | |
70 | wxMenu *file_menu = new wxMenu; | |
71 | ||
72 | file_menu->Append(wxID_EXIT, "E&xit"); | |
73 | wxMenuBar *menu_bar = new wxMenuBar; | |
74 | menu_bar->Append(file_menu, "File"); | |
75 | frame->SetMenuBar(menu_bar); | |
76 | ||
77 | // Make a panel with a message | |
78 | wxPanel *panel = new wxPanel(frame); | |
79 | ||
80 | (void)new wxStaticText(panel, -1, "Hello, this is a minimal debugging wxWindows program!", wxPoint(10, 10)); | |
81 | ||
82 | // Show the frame | |
83 | frame->Show(TRUE); | |
84 | ||
bd7d06f2 RR |
85 | wxDebugContext::SetCheckpoint(); |
86 | wxDebugContext::SetFile("debug.log"); | |
457814b5 JS |
87 | |
88 | wxString *thing = new wxString; // WXDEBUG_NEW wxString; | |
89 | wxDate* date = new wxDate; | |
90 | ||
91 | // Proves that defining 'new' to be 'WXDEBUG_NEW' doesn't mess up | |
92 | // non-object allocation | |
93 | char *ordinaryNonObject = new char[1000]; | |
94 | ||
95 | const char *data = (const char*) thing ; | |
96 | ||
bd7d06f2 RR |
97 | wxDebugContext::PrintClasses(); |
98 | wxDebugContext::Dump(); | |
99 | wxDebugContext::PrintStatistics(); | |
457814b5 JS |
100 | |
101 | // Don't delete these two objects, to force wxApp to flag a memory leak. | |
102 | // delete thing; | |
103 | // delete date; | |
104 | // delete[] ordinaryNonObject; | |
105 | ||
106 | return TRUE; | |
107 | } | |
108 | ||
109 | BEGIN_EVENT_TABLE(MyFrame, wxFrame) | |
110 | EVT_MENU(wxID_EXIT, MyFrame::OnQuit) | |
111 | END_EVENT_TABLE() | |
112 | ||
113 | // My frame constructor | |
114 | MyFrame::MyFrame(wxFrame *parent): | |
115 | wxFrame(parent, -1, "MemCheck wxWindows Sample", wxPoint(-1, -1), wxSize(400, 200)) | |
116 | {} | |
117 | ||
118 | // Intercept menu commands | |
119 | void MyFrame::OnQuit(wxCommandEvent& event) | |
120 | { | |
121 | Close(TRUE); | |
122 | } | |
123 |