Slick-C Macro Programming Guide
Total Page:16
File Type:pdf, Size:1020Kb
® Slick-C Macro Programming Guide for SlickEdit 2008 Information in this documentation is subject to change without notice and does not represent a commitment on the part of SlickEdit Inc. The software described in this documentation is protected by U.S. and international copyright laws and by other applicable laws, and may be used or copied only in accordance with the terms of the license or nondisclosure agreement that accompanies the software. It is against the law to copy the software on any medium except as specifically allowed in the license or nondisclosure agreement. The licensee may make one copy of the software for backup purposes. No part of this documentation may be reproduced or transmitted in any form or by any means, electronic or mechanical, including photocopying, recording, or information storage and retrieval systems, for any purpose other than the licensee's personal use, without the express written permission of SlickEdit Inc. Copyright 1988-2008 SlickEdit Inc. Cover design copyright by SlickEdit Inc. Produced in the United States of America. SlickEdit, Visual SlickEdit, Clipboard Inheritance, DIFFzilla, SmartPaste, Context Tagging, Slick-C, and Code Quick | Think Slick are registered trademarks of SlickEdit Inc. All other products or company names are used for identification purposes only and may be trademarks of their respective owners. Protected by U.S. Patent 5,710,926. SE-1301-061108 TABLE OF CONTENTS Table of Contents Table of Contents 3 Welcome 9 Getting Help 9 Documentation 9 Product Support 9 Other Resources 10 Conventions Used in This Guide 10 Contacting SlickEdit Inc. 10 Introduction 13 Working with the Slick-C® Source Code 13 Slick-C® Naming Conventions 13 Four Ways to Use Slick-C® 15 Recording Slick-C® Macros 15 Key Bindable Command 15 Event-Driven Dialog Boxes 16 Creating a Simple Event-Driven Dialog Box 16 Loading Code and Displaying Dialog Boxes 18 Binding Commands to Keys for Dialog Box Display 18 Batch Macros 18 Language Constructs 21 Identifiers 21 Reserved Words and Keywords 21 Comments 23 String Literals 23 Numeric Literals 24 Defining Constants Using #define 25 Defining Constants Using const 25 Defining Constants Using Enumerators 26 Namespaces 26 Types 27 Strings 27 Enumerated Types 27 Arrays 28 Differences from C++ 28 Hash Tables 29 Structs 29 Differences from C++ 30 Unions 30 Anonymous Unions 31 Interfaces 32 Classes 32 Introspection 33 Implicit Conversion to Strings 34 Overloading Comparison and Assignment Operators 34 Slick-C® Macro Programming Guide 3 TABLE OF CONTENTS Overloading Array Index Operators 34 Overloading Assignment/Copy Semantics 35 Overloading Iteration Semantics 35 SlickEdit® Class Libraries 35 Differences from C++ and Java 35 Pointers 36 Pointers to Variables 36 Pointers to Functions 36 Typeless 36 Mathematical Operators 39 Declarations 43 Scoping and Declaring Variables 43 Simple Variables 43 Details About Variable Initializations 43 Type Casting 44 Implicit Local Variables 44 Declaring Local Variables With := 45 Declaring Variables With auto 45 Statements 47 Assignment Operator 47 if Statement 47 Block Statement 48 Loops 48 do 48 for 48 foreach 49 loop 49 while 50 break 50 continue 50 parse Statement 51 switch Statement 52 Functions 55 Defining a Procedure 55 Argument Declarations 56 Default Arguments 56 Defining a Command 57 name_info Attributes 58 OnUpdate Functions 60 Class Methods 60 Function Prototypes 61 Library Functions 62 Built-in Functions 62 Finding Functions 62 Differences Between Commands, Built-ins, and Defs 62 defmain: Writing Slick-C® Batch Files 63 Preprocessing 65 #if 65 4 Slick-C® Macro Programming Guide TABLE OF CONTENTS #pragma 66 #region and #endregion 69 Including Header Files 70 Importing Slick-C Modules 70 Defining Controls 73 Defining Events and Event Tables 75 def Primitive 75 Event-Driven Dialog Boxes 77 Module Initializations 79 Compiling and Loading Macros 81 Debugging Macros 83 Finding Procedures 83 Finding Run-Time Errors 83 Performance Profiling 84 Slick-C® Debugger 85 Error Handling and the rc Variable 87 Dialog Editor 89 Microsoft Visual Basic and Slick-C® 89 Creating Dialog Boxes 91 Dialog Editor Summary 91 Adding and Deleting Controls 91 Setting Properties 92 Aligning Controls 93 Sizing Controls 93 Moving Controls 93 Miscellaneous Assignments When the Form is Active 93 Miscellaneous Menu Items 94 Creating a Form 94 Saving a Form 94 Adding Event Handlers 94 Inherited Code Found Dialog Box 95 Loading and Running the Form 95 Adding a Cancel Button 95 Adding an OK Button and Closing a Dialog Box 96 Displaying Dialog Boxes 97 Modal and Modeless Dialog Boxes 99 Dialog Box Parent Window 100 Remembering a Dialog Box’s Previous Position 100 Clipboard Inheritance® 101 Clipboard Inheritance® Overview 101 Clipboard Inheritance® Example 102 Dialog Box Inheritance Order 103 Objects and Instances 105 Slick-C® Macro Programming Guide 5 TABLE OF CONTENTS Active Object 105 Active Form 105 Instance Expressions 105 Using Functions as Methods 107 Built-in Controls 109 Label Control 109 Spin Control 109 Text Box Control 110 Editor Control 111 Frame Control 111 Command Button Control 111 Radio Button Control 111 Check Box Control 112 List Box Control 112 Combo Box Control 113 Scroll Bar Controls 116 Drive List Control 117 File List Box Control 117 Directory List Box Control 118 Picture Box Control 118 Gauge Control 118 Image Control 119 Adding a Bitmap Command Button or Check Box 119 Adding Dialog Box Retrieval 121 Menus 123 Menu Editor Dialog Box 123 Menu Item Alias Dialog Box 123 Auto Enable Properties Dialog Box 123 Creating and Editing Menu Resources 124 Defining a Menu Resource 124 Predefined Attributes for Auto-Enabling Commands 125 Macro Callbacks for Enabling Commands 125 Placing a Menu Bar on a Form 126 Displaying a Menu as a Pop-Up 126 Common Macro Dialog Boxes 129 String Functions 131 Search Functions 135 Selection Functions 139 Writing Selection Filters 141 Unicode and SBCS or DBCS Macro Programming 143 Shelling Programs from a Slick-C® Macro 145 Interfacing With Other Languages (DLL) 147 Command Line Interface 149 6 Slick-C® Macro Programming Guide TABLE OF CONTENTS Command Line Arguments 149 get_string Procedure 149 Single Argument Prompting with Support for Prompt Style 149 Hooking Startup and Exit 151 Invoking a Macro on Startup 151 Invoking a Macro on Exit 151 State File Caching 153 Windows Data Structure 155 Window Properties 157 View Properties 157 Buffer Properties 157 Tutorials 159 Defining Stack Routines 159 Searching for a String Within a Current Function 161 Creating the Macro 161 Analyzing the Macro 162 Command Line Search Options 163 Reading and Modifying Buffers 164 Functions for Reading and Modifying Buffers 164 Common Functions for Navigating Buffers 164 Escape Backslashes Example 165 Comment Out Debug Print Lines Example 165 Working with Existing Macros 166 Example: Turning on Line Numbers for All Files 166 Example: Counting Lines of Code 167 Events 171 Event Names 171 Keys 171 ASCII Characters 171 Function Keys 171 Extended Keys 171 Miscellaneous Keys 172 Key Name Examples 172 Mouse Events 173 on Events 173 Differences Between Slick-C® and C++ 175 Structures 175 Arrays 175 Hash Tables 175 Assignment Statement 176 Comparison Operator 176 Preprocessing 176 switch Statement 176 Labeled Loops 176 Variable Argument Functions 176 Built-in Graphics Primitives 177 Clipboard Inheritance® 177 Slick-C® Macro Programming Guide 7 TABLE OF CONTENTS End of Statement Semicolon 177 Type Checking 177 Capability not Supported by Slick-C® 177 Index 179 8 Slick-C® Macro Programming Guide WELCOME Welcome Welcome to the Slick-C® Macro Programming Guide. This guide is bundled with SlickEdit products to help you understand and become familiar with Slick-C, the language upon which the SlickEdit® programming editor is based. By learning Slick-C, you can modify the look and feel of the editor, write macros to perform custom operations, add new language support, and essentially extend the editor’s functionality until it is completely customized according to your preferences. Just another way SlickEdit lets you work the way you want. Getting Help Documentation This guide often refers to the SlickEdit® Help system for more information. In the SlickEdit application, the Help system can be accessed by selecting one of the Help submenu items. The contents of the SlickEdit Help system match the combined contents of the SlickEdit User Guide and this Slick-C Macro Programming Guide, both available as PDFs in the SlickEdit docs installation subdirectory. Documentation for all SlickEdit products is available for download from the documentation section of our Web site at www.slickedit.com/docs. TIP The best way to look up a Help keyword is to use the Index. In SlickEdit, from the main menu, select Help > Index. Index keywords are special terms that we have included to help you find specific information. To find all occurrences of a term in the Help, use the Help system’s Search tab (Help > Search). Use quotes around the term to find whole-word matches. Comments and suggestions about our documentation are appreciated. Please send feedback to [email protected]. Product Support For problem reports, please gather the following information and provide it to Product Support: • A description of the problem. • The language in which you are working (C/C++, Java, etc.) • Your SlickEdit program information including version and serial number. To get this information, click the SlickEdit menu item Help > About SlickEdit, then select the Program Information tab. Use the Copy to Clipboard button to copy the information so you can paste it into your problem report. • A code snippet to help us reproduce the problem (if possible). There are several ways to contact our Product Support team: • Use the SlickEdit® menu item Help > Contact Product Support. This will automatically gather your SlickEdit program information. • Send e-mail directly to [email protected].