码迷,mamicode.com
首页 > 其他好文 > 详细

HelloWorld3

时间:2014-12-18 10:13:02      阅读:182      评论:0      收藏:0      [点我收藏+]

标签:des   style   blog   ar   io   color   os   sp   for   

  1 //HelloWorld3.cpp
  2 
  3 /*
  4 Copyright 2000-2004 The VCF Project.
  5 Please see License.txt in the top level directory
  6 where you installed the VCF.
  7 */
  8 
  9 
 10 /**
 11 *The purpose of this example is to demonstrate creating not only
 12 *our own custom application class, but our first case of deriving
 13 *a new window class
 14 */
 15 
 16 #include "vcf/ApplicationKit/ApplicationKit.h"
 17 
 18 using namespace VCF;
 19 
 20 
 21 /**
 22 *This is our main window class. The code that was previously
 23 *in the initialization method of our app class, but will now
 24 *migrate to our constructor
 25 */
 26 class HelloWorld3Window : public Window {
 27 public:
 28     HelloWorld3Window() {
 29         /**
 30         *Here we get the current running Application instance for
 31         *this process
 32         */
 33         Application* runningApp = Application::getRunningInstance();
 34 
 35         /**
 36         *This gets the app instance‘s class name to put in the
 37         *caption of our man window
 38         */
 39         String appname = runningApp->getClassName();
 40 
 41         /**
 42         *this sets the caption of the main window
 43         */
 44         setCaption( appname + " - Hello World!" );
 45 
 46         /*
 47         *This will set the bounds of the window, see the
 48         *previous HelloWorld example for a more in depth
 49         *discussion of this.
 50         */
 51         Rect bounds( 100.0, 100.0, 500.0, 500.0 );
 52         setBounds( &bounds );
 53 
 54         /**
 55         *Here we can use the debug trace with variable
 56         *arguments just like printf(), in this
 57         *case printing out the value of our "this" pointer
 58         *and the string value returned by the Rect‘s toString()
 59         *method
 60         */
 61         StringUtils::trace( Format("HelloWorld3Window constructor @%p, bounds: %s\n")
 62                                     % this % bounds.toString().c_str() );
 63 
 64         /**
 65         *Show the main window. Previously we had used
 66         *the show(), but setVisible(true) also works
 67         */
 68         setVisible( true );
 69 
 70         Locale loc(Locale::lcPolish, Locale::ccPoland );
 71         System::setCurrentThreadLocale( &loc );
 72 
 73     }
 74 
 75     /**
 76     *Always, always, always make our destructor virtual
 77     */
 78     virtual ~HelloWorld3Window(){};
 79 
 80 
 81     virtual void paint( GraphicsContext* c ) {
 82         Window::paint( c );
 83 
 84         Locale loc(Locale::lcPolish, Locale::ccPoland );
 85         c->getCurrentFont()->setName( "Arial" );
 86         c->textAt( 20, 20, loc.translate( "Hello" ) );
 87     }
 88 };
 89 
 90 
 91 
 92 
 93 class HelloWorld3Application : public Application {
 94 public:
 95 
 96     HelloWorld3Application( int argc, char** argv ): Application(argc, argv) {
 97 
 98     }
 99 
100     virtual bool initRunningApplication(){
101         bool result = Application::initRunningApplication();
102 
103         /**
104         *allocate some dummy temporary memory - we
105         *will clean this up in the termination method of our
106         *app class
107         */
108         m_tmpDummyBuffer = new char[4096];
109 
110         /**
111         *Create a new instance of our window class
112         */
113         Window* mainWindow = new HelloWorld3Window();
114 
115 
116         /**
117         *set the app‘s main window
118         */
119         setMainWindow(mainWindow);
120 
121         return result;
122     }
123 
124     /**
125     *terminates the running application. This is where
126     *you can do your clean up of resources
127     *In our case we‘ll clean up the memory we had allocated in our
128     *initRunningApplication() method above
129     *and then call the super classes terminateRunningApplication()
130     */
131     virtual void terminateRunningApplication() {
132         delete [] m_tmpDummyBuffer;
133         m_tmpDummyBuffer = NULL;
134 
135         /**
136         *here‘s an example of outputting to
137         *debug messages. In Win32 these get
138         *resolved to a call to OutputDebugString
139         *thus if you‘re debugging with VC++ you‘ll
140         *see this in the Output window.
141         */
142         StringUtils::trace( "HelloWorld3Application::terminateRunningApplication() cleaned up memory\n" );
143         Application::terminateRunningApplication();
144     }
145 
146 
147     char* m_tmpDummyBuffer;
148 };
149 
150 
151 int main(int argc, char *argv[])
152 {
153     Application* app = new HelloWorld3Application( argc, argv );
154 
155     Application::main();
156 
157     return 0;
158 }
159 
160 
161 /**
162 $Id: HelloWorld3.cpp 3625 2008-06-22 02:47:47Z ddiego $
163 */

 

HelloWorld3

标签:des   style   blog   ar   io   color   os   sp   for   

原文地址:http://www.cnblogs.com/elitiwin/p/4171060.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!