home *** CD-ROM | disk | FTP | other *** search
/ Borland Programmer's Resource / Borland_Programmers_Resource_CD_1995.iso / code / wxwin140 / samples / minimal / minimal.cc < prev    next >
Encoding:
C/C++ Source or Header  |  1995-05-19  |  2.7 KB  |  93 lines

  1. /*
  2.  * File:     minimal.cc
  3.  * Purpose:  Minimal wxWindows app
  4.  *
  5.  *                       wxWindows 1.40
  6.  * Copyright (c) 1993 Artificial Intelligence Applications Institute,
  7.  *                   The University of Edinburgh
  8.  *
  9.  *                     Author: Julian Smart
  10.  *                        Date: 18-4-93
  11.  *
  12.  * Permission to use, copy, modify, and distribute this software and its
  13.  * documentation for any purpose is hereby granted without fee, provided
  14.  * that the above copyright notice, author statement and this permission
  15.  * notice appear in all copies of this software and related documentation.
  16.  *
  17.  * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, EXPRESS,
  18.  * IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF
  19.  * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
  20.  *
  21.  * IN NO EVENT SHALL THE ARTIFICIAL INTELLIGENCE APPLICATIONS INSTITUTE OR THE
  22.  * UNIVERSITY OF EDINBURGH BE LIABLE FOR ANY SPECIAL, INCIDENTAL, INDIRECT OR
  23.  * CONSEQUENTIAL DAMAGES OF ANY KIND, OR ANY DAMAGES WHATSOEVER RESULTING FROM
  24.  * LOSS OF USE, DATA OR PROFITS, WHETHER OR NOT ADVISED OF THE POSSIBILITY OF
  25.  * DAMAGE, AND ON ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH
  26.  * THE USE OR PERFORMANCE OF THIS SOFTWARE.
  27.  */
  28.  
  29. #include <windows.h> // Included only for benefit of MSC7 precompiled headers
  30. #include "wx.h"
  31.  
  32. // Define a new application type
  33. class MyApp: public wxApp
  34. { public:
  35.     wxFrame *OnInit(void);
  36. };
  37.  
  38. // Define a new frame type
  39. class MyFrame: public wxFrame
  40. { public:
  41.     MyFrame(wxFrame *frame, char *title, int x, int y, int w, int h);
  42.     void OnMenuCommand(int id);
  43. };
  44.  
  45. // ID for the menu quit command
  46. #define MINIMAL_QUIT 1
  47.  
  48. // This statement initializes the whole application and calls OnInit
  49. MyApp myApp;
  50.  
  51. // `Main program' equivalent, creating windows and returning main app frame
  52. wxFrame *MyApp::OnInit(void)
  53. {
  54.   // Create the main frame window
  55.   MyFrame *frame = new MyFrame(NULL, "Minimal wxWindows App", 50, 50, 400, 300);
  56.  
  57.   // Give it an icon
  58.   frame->SetIcon(new wxIcon("aiai_icn"));
  59.  
  60.   // Make a menubar
  61.   wxMenu *file_menu = new wxMenu;
  62.   file_menu->Append(MINIMAL_QUIT, "Quit");
  63.   wxMenuBar *menu_bar = new wxMenuBar;
  64.   menu_bar->Append(file_menu, "File");
  65.   frame->SetMenuBar(menu_bar);
  66.  
  67.   // Make a panel with a message
  68.   wxPanel *panel = new wxPanel(frame, 0, 0, 400, 300);
  69.   (void)new wxMessage(panel, "Hello, this is a minimal wxWindows program!", 0, 0);
  70.  
  71.   // Show the frame
  72.   frame->Show(TRUE);
  73.  
  74.   // Return the main frame window
  75.   return frame;
  76. }
  77.  
  78. // My frame constructor
  79. MyFrame::MyFrame(wxFrame *frame, char *title, int x, int y, int w, int h):
  80.   wxFrame(frame, title, x, y, w, h)
  81. {}
  82.  
  83. // Intercept menu commands
  84. void MyFrame::OnMenuCommand(int id)
  85. {
  86.   switch (id) {
  87.     case MINIMAL_QUIT:
  88.       delete this;
  89.     break;
  90.   }
  91. }
  92.  
  93.