首页 > 代码库 > HelloWorld3
HelloWorld3
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 - we105 *will clean this up in the termination method of our106 *app class107 */108 m_tmpDummyBuffer = new char[4096];109 110 /**111 *Create a new instance of our window class112 */113 Window* mainWindow = new HelloWorld3Window();114 115 116 /**117 *set the app‘s main window118 */119 setMainWindow(mainWindow);120 121 return result;122 }123 124 /**125 *terminates the running application. This is where126 *you can do your clean up of resources127 *In our case we‘ll clean up the memory we had allocated in our128 *initRunningApplication() method above129 *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 to137 *debug messages. In Win32 these get138 *resolved to a call to OutputDebugString139 *thus if you‘re debugging with VC++ you‘ll140 *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
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。