<!–Converted with LaTeX2HTML 2022 (Released January 1, 2022) –> <HTML lang="en"> <HEAD> <TITLE>Contents of More advanced features: the hello demo</TITLE>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=utf-8"> <META NAME="viewport" CONTENT="width=device-width, initial-scale=1.0"> <META NAME="Generator" CONTENT="LaTeX2HTML v2022">
<LINK REL="STYLESHEET" HREF="tutorial.css">
<LINK REL="next" HREF="node5_mn.html"> <LINK REL="previous" HREF="node3_mn.html"> <LINK REL="up" HREF="node2_mn.html"> <LINK REL="next" HREF="node5_mn.html"> </HEAD>
<BODY bgcolor="#ffffff" text="#000000" link="#9944EE" vlink="#0000ff" alink="#00ff00">
<H2><A ID="SECTION00022000000000000000"> More advanced features: the <I>hello</I> demo</A> </H2>
<P> The `hello' (source files, <TT>hello.cc</TT> and <TT>hello.h</TT> shows off some more wxWindows features (see Figures <A HREF="node4_ct.html#demo-x"><IMG ALT="[*]" SRC="crossref.png"></A> and <A HREF="node4_ct.html#demo-ms"><IMG ALT="[*]" SRC="crossref.png"></A>). When run, two windows pop up. One is the `main window', with two subwindows - a panel containing various `widgets', and a text window. The other contains a canvas, drawing some simple shapes, and allowing the user to doodle on it by dragging with the left mouse button. The canvas contents can be scaled and printed out, either to a printer supported by Windows or to PostScript, writing to a file or invoking the printer directly. Under Windows, the graphic may be copied to the clipboard as a metafile.
<P>
<DIV class="CENTER"><A ID="demo-x"></A><A ID="52"></A> <TABLE> <CAPTION class="BOTTOM"><STRONG>Figure:</STRONG> Demo program running under X</CAPTION> <TR><TD><IMG STYLE="" SRC="img1.png" ALT="
<DIV class="CENTER"><A ID="demo-ms"></A><A ID="57"></A> <TABLE> <CAPTION class="BOTTOM"><STRONG>Figure:</STRONG> Demo program running under Windows 3</CAPTION> <TR><TD><IMG STYLE="" SRC="img2.png" ALT="
<P> Both frames can be resized, and the subwindows will be resized in an appropriate manner. The text subwindow can be scrolled; on the panel, a button can be pressed for the program to prompt the user with text with which to set the status bar. Clicking on the list box writes a line of text into the text window.
<P> The <B>File</B> menu has options for selecting the `mapping mode' (logical dimensions) used in drawing graphics, a zoom option, and an option for loading a file into the text subwindow using a file selector tool.
<P> The <B>Timer</B> menu allows the user to switch a timer on and off; when on, some text gets written to the text subwindow every five seconds.
<P> The <B>Cursor</B> menu enables the canvas cursor to be changed, and lets the potential wxWindows programmer view the available standard cursors.
<P> The <B>About</B> option of the Help menu pops up a dialog box with some information.
<P> This represents a fair amount of GUI functionality for a relatively small program. This is because wxWindows calls are high level (creating a working text window is a single call) and because an object-oriented approach is taken, where much default functionality is provided.
<P> Note also the lack of explicit coordinates or sizes in the panel item creation calls. This is the preferred approach, leaving wxWindows to lay out the items from left to right and top to bottom, with the user interjecting the occasional <B>NewLine</B> call. Explicit positioning is not recommended since it is less device independent, but can be achieved by using more parameters to the creation calls, or by using <B>SetSize</B> after an item has been created. Coordinates and sizes default to -1, which tells wxWindows to choose appropriate positioning and sizing. In this example, the windows are explicitly sized, but you may size a frame or panel to fit around its contents by calling <B>Fit</B>.
<P> <B>MyFrame's</B> <B>OnSize</B> member sizes each subwindow in proportion to the new size of the frame. <B>MyCanvas's</B> <B>OnPaint</B> draws a couple of lines, a rectangle and a spline whenever the canvas requires repainting (e.g. on creation, and when exposed). The <B>OnEvent</B> member checks for mouse dragging, and draws a line from the last point to the current position. Scrolling the canvas and subsequent repainting is handled automatically by wxWindows.
<P> Finally, two callback functions demonstrate popping up dialog boxes, setting the status line, and inserting text into a text window.
<P> This demo can provide a template for your own application. Gradually modify it for your own needs, and you will rapidly be writing portable X and Windows 3 programs!
<P>
<HR>
</BODY> </HTML>