This tutorial demonstrates how to create a tree to browse points in the DataHub.
/* All user scripts should derive from the base "Application" class */ require ("Application"); require ("WindowsSupport"); /* * The real implementation of the point browser is in * c:\program files\cogent\opc datahub\require\GPointBrowser.g */ require ("GPointBrowser"); class TreeViewExample Application { window; gtree; } /* * Specialize the GPointBrowser object so that we get our own callbacks when * certain events occur in the point tree. The default event handling will * still be processed to fill the tree as the user traverses it. */ class MyGPointBrowser GPointBrowser { } method MyGPointBrowser.OnSelect (pointname) { princ ("Selected: ", pointname, "\n"); } method MyGPointBrowser.OnDoubleClick(pointname) { princ ("Double Click: ", pointname, "\n"); } method MyGPointBrowser.OnRightClick(pointname) { princ ("Right Click: ", pointname, "\n"); } method MyGPointBrowser.OnExpanded (pointname) { princ ("Expanded: ", pointname, "\n"); } method MyGPointBrowser.OnCollapsed (pointname) { princ ("Collapsed: ", pointname, "\n"); } /* Write the 'main line' of the program here. */ method TreeViewExample.constructor () { local rect = CreateRect (0, 0, 300, 300); .window = new GWindow(); .window.Create (0, rect, "GPointBrowser Test", WS_OVERLAPPEDWINDOW, 0); .window.CenterWindow(); .window.GetClientRect (rect); .gtree = .window.CreateControl (MyGPointBrowser, 0, 0, rect.right-rect.left, rect.bottom-rect.top, "Hello world", SS_CENTER); .gtree.CenterWindow(); .gtree.debugging = t; .window.MessageHandler (WM_DESTROY, `instance_p(@self) ? destroy(@self) : nil); .window.AddControlResizeFlags (.gtree, DLSZ_SIZE_X | DLSZ_SIZE_Y); .window.ShowWindow (SW_SHOW); } /* Any code to be run when the program gets shut down. */ method TreeViewExample.destructor () { if (instance_p(.window)) destroy (.window); } /* Start the program by instantiating the class. */ ApplicationSingleton (TreeViewExample);
Copyright © 1995-2010 by Cogent Real-Time Systems, Inc. All rights reserved.