Section Three Editing Source-Code Files Topics 1. Terminology Associated with Editing Files Insert Cursor Insert Position 2. Key Commands to be Used with the Editor Moving Around within a File Move the "insert position" right and left Move the "insert position" up and down Move the "insert position" at end of line Move the "insert position" at beginning of line Move the "insert position" to top of file Move the "insert position" to bottom of file Move up one page Move up one page Deletion of text Delete character to right of the "Insert Position" Delete character to left of the "Insert Position" Delete one or more lines of text Delete an arbitrary "block" of text Insertion of text Insert one character Insert one blank line Cut/Copy and Paste Cut and Paste Copy and Paste 3. The EDITOR WINDOW 4. The WORKSPACE WINDOW 5. Splitting the Editor Window Horizontal split Vertical split 6. Cascade and Tiled Edit Windows 7. How to Edit Source-Code Files 8. Setting and Using BOOKMARKS Permanent (or named) Bookmarks Temporary (or un-named) Bookmarks 9. Searching a File for a String 10. Searching a File Using the INCREMENTAL Search 11. Replace One String with Another 12. Add and Edit a CLASS Add a new class to the source-code Edit a class/member function using the WizardBar Terminology Associated with Editing Files. ---------------------------------------------------------------------- - Insert Cursor - is a screen cursor shaped like a large uppercase "I". It is used to set the current "Insert Position" (see below). The Insert Cursor is moved by moving the mouse. - Insert Position - is the place in the text where any subsequent action taken on the text will occur. To set the insert position, place the "Insert Cursor" at the proper location in the text and click the left mouse button. The "blinking" current screen insert position will move to that location. You can also move the Insert Position by pressing the left, right, up, and down keys on the keyboard. Key Commands to be Used with the Editor. --------------------------------------------------------------------- A. Moving Around within a File. ---------------------------- a. Move the "insert position" right and left on a text line. Press the right-arrow key to move it one character position to the right, or the left-arrow key to move it one character position to the left. b. Move the "insert position" up and down lines within the file. Press the up-arrow key to move it up one line, or the down-arrow key to move it down one line. c. Move the "insert position" to the left-most character position on a line. Press the "Home" key. d. Move the "insert position" to the right-most character position on a line. Press the "End" key. e. Move the "insert position" to the top-most character in the file. Press the "Ctrl" key and then the "Home" key simultaneously. f. Move the "insert position" to the bottom-most character in the file. Press the "Ctrl" key and then the "End" key simultaneously. g. Move up one page (screen full) of the text. Press the "PageUp" key. h. Move down one page (screen full) of the text. Press the "PageDown" key. B. Deletion of text. ----------------- a. Delete one character to the right of the current (blinking) "Insert Position". Press the "Delete" key. b. Delete one character to the left of the current (blinking) "Insert Position". Press the left-pointing arrow key just above the ENTER key. c. Delete one or more lines of text. Place the (blinking) "Insert Cursor" to the left of the first (left-most) character of the top-most line to be deleted, press and hold down the left mouse button, move the "Insert Cursor" to the right of the last (right-most) character on the bottom-most line to be deleted (note that as you move the mouse, characters become highlighted), release the left mouse button, and then press the "Delete" key. d. Delete an arbitrary "block" of text beginning at any character and ending with any character. Place the "Insert Cursor" to the left of the first character of the "block" to be deleted, press and hold down the left mouse button, move the "Insert Cursor" to the right of the last character of the "block" to be deleted (note that as you move the mouse, characters become highlighted), release the left mouse button, and then press the "Delete" key. C. Insertion of text. ------------------ a. Insert one character. Move the "Insert Cursor" to the location where the character is to be inserted, click the left mouse button, and press the key corresponding to the character to be inserted. b. Insert one blank line. Move the "Insert Cursor" to the right of the last character of the line below which you want to insert the new blank line, click the left mouse button, and then press the ENTER (Return) key. To insert a blank line as the new first (top-most) line of the file, place the "Insert Cursor" to the left of the first character in the file, click the left mouse button, and then press the ENTER (Return) key. D. Cut/Copy and Paste. ------------------- a. Cut and Paste If you would like to take a block of text, remove (cut) it from its current location in the file, and then insert (paste) that block of text in some other location in the file, do the following: 1. Move the "Insert Cursor" to the left of the first character of the block to be cut, press and hold the left mouse button, move the "Insert Cursor" to the right of the last character in the block to be cut, and release the left mouse button. Note that as you move (drag) the "Insert Cursor", more and more of the block becomes highlighted. 2. Click the "Cut" button on the STANDARD Button Bar [STAND(5)]. 3. Move the "Insert Cursor" to the location in the file where you want to insert (paste) the just cut block of text, and then click the left mouse button. 4. Click the "Paste" button on the STANDARD Button Bar [STAND(7)]. If you also want to insert (paste) this block at another location in the file, just repeat steps 3 and 4. Note that if you do just steps 1 and 2 above, the block of text will be removed (cut) from the file. You do not have to paste that just cut block somewhere in the file. b. Copy and Paste If you would like to take a block of text, make a copy of it, and then insert (paste) that copy of the block of text at some other location in the file, do the following: 1. Move the "Insert Cursor" to the left of the first character of the block to be copied, press and hold the left mouse key, move the "Insert Cursor" to the right of the last character in the block to be copied, and release the left mouse button. Note that as you move (drag) the "Insert Cursor", more and more of the block becomes highlighted. 2. Click the "Copy" button on the STANDARD Button Bar [STAND(6)]. 3. Move the "Insert Cursor" to the location in the file where you want to insert (paste) the just copied block of text, and then click the left mouse button. 4. Click the "Paste" button on the STANDARD Button Bar [STAND(7)]. If you also want to insert (paste) this block at another location in the file, just repeat steps 3 and 4. Note that if you do just steps 1 and 2 above, the block of text is NOT removed (cut) from the file. This is the main difference between the "cut" and "copy" actions. The EDITOR WINDOW. ---------------------------------------------------------------------- The Editor Window will display source-code. You can have more than one Editor Window displayed concurrently (see below). To see how to get into the Editor and use an Editor Window, see "How to Edit Source-code Files" below. If multiple Editor Windows are on the screen simultaneously, you will see in the upper-right corner of each Editor Window that there are three icons (if only one Editor Window is displayed on the screen, then these three icons will be at the upper-right corner of the screen). - Click the "underscore" icon to remove this Editor Window and make it into an icon (at the bottom of the screen). To have this Editor Window re-displayed, just double click the icon for this Editor window. - Click the "rectangle" icon to have this Editor Window fill the entire screen. Note that this will cause the three icons to move to the top corner of the screen and the "rectangle" icon will become a "double rectangle". If you click the "double rectangle" icon, then this Editor Window will resume its original size (the size it had before you clicked the "rectangle" icon). - Click the "X" icon to permanently remove this Editor Window. If you click the "X" icon, the file displayed in this Edit Window will be removed from the list of files displayed when you click "Window" on the Main Menu [MM(8)]. To get this file's name back on that Window list (so that you can access it again in the future) do the following: 1. Click the "Workspace" button on the STANDARD Button Bar [Stand(10)]. 2. Click the "FileView" tab at the bottom of the Workspace window (if it is not already selected). 3. Double click the name of the file to be added to the list of files that will be displayed when "Window" is clicked on the Main Menu. 4. Click the "Workspace" button on the STANDARD Button Bar [Stand(10)] to remove the "Workspace" window. To move between Editor Windows containing different files, do the following: - Click "Window" in the Main Menu [MM(8)]. - Click the name of the file whose contents you want to have displayed in a Editor Window. If the name of the file you want to see is not in this list, perform the four steps immediately above to get the file's name in this list. The WORKSPACE WINDOW. --------------------------------------------------------------------- The Workspace Window displays information about your project (program) including information about the classes defined in your program and the files that make up your program. The WORKSPACE WINDOW is not by default automatically displayed when you enter the Editor as is an Editor Window. You must take specific action to have the Workspace Window displayed. To display the Workspace Window while in the Editor (it is assumed that the source-code for the project is already loaded into the Editor and one of its source-code files is being displayed in an Editor Window), just click the "Workspace" button on the STANDARD Button Bar [Stand(10)]. To remove the Workspace Window from the screen, just click the same button. When the Workspace Window is displayed you will see three "tabs" at the bottom of that window. Click whichever tab you desire. - Click the "ClassView" tab to see information about ALL the CLASSES (and STRUCTURES) that are defined in your program (no matter in which file the class definition is located). The Workspace Window will be filled with the names of all the classes defined in your program preceded by a small "+" icon. You can do one of two things when this information is displayed: 1. Click the "+" icon (it will turn into a "-" icon) to see all the "members" of the associated class (data members and member functions) or all the "fields" of the associated structure. If you now double click on any one of the member (or field) names, the definition of that member (field) will be displayed in the Editor Window. You can examine and/or edit that definition. To remove the member (field) names and have them replaced by the name of the class in which they are defined, click the "-" icon in front of the class (structure) name. 2. Double click the class/structure name (that is preceded by the "+" icon) and the definition of this class (or structure) will be displayed in the Editor Window. You can examine and/or edit that definition. Remember all "external" functions (ones not defined within a class), and all global variables can be displayed by clicking the "+" icon preceding the word "Globals". - Click the "FileView" tab to see information about all the files that make up your program. A list of all the files that make up your program is displayed in the Workspace Window. If you double click on any of these file names, the content of that file will be displayed in the Editor Window and can be examined or edited. - Click the "InfoView" tab to see the three main categories of help that are available to help you learn and better use the Visual C++ software development environment. The most important of the three categories of help is the "Developer Products" category. Click the "+" icon that precedes the term "Developer Products" to see sub-categories of help related to how to use the Visual C++ compiler, editor, etc. The other two categories provide help in learning to use the advanced features of Visual C++ e.g. ActiveX, Components, the Microsoft Foundation Library, etc. and are not discussed in these introductory materials. Splitting the Editor Window. --------------------------------------------------------------------- You may want to have your source-code file displayed in two different Editor Windows. You would then be able to look at two different sections of your source-code at the same time, or you could copy (or cut) one section of code and place it into another location in the source-code file. Two kinds of window splits can be done; HORIZONTAL and VERTICAL. A. Horizontal split. Just above the upper vertical scroll bar button of the current editing window, you will see a small "horizontal split button". Put the mouse cursor on top of that split button (the mouse cursor will change to become two horizontal bars) and press and hold down the left mouse button. While holding the left mouse key down, drag the bars in a downward direction and you will see a long horizontal bar extending from the left to the right side of the editing window. Move the mouse down and the long bar will move down. Keep moving the mouse down until the current editing window is split to the desired proportions. Release the left mouse button and you will see the current source-code file appear in both sub- windows. To move between the sub-windows, just place the screen cursor inside the sub-window you want to work in and click the left mouse button. That sub-window becomes the "current active sub-window" and any editing actions will be done in that window. You can scroll up and down in the selected sub-window independently of the other sub-window. However, note that any change made in one of the sub-windows will also be made in the other sub-window (thus, both sub-windows will always have the same content). Thus, these two sub-windows are not separate independent windows, but represent two views of the same source- code file. An excellent use of split windows is to copy (or cut) a section of code that appears in one sub-window and insert it into the other sub-window. To do this: a. Get the section of code to be "inserted into" displayed in one sub-window. b. Get the section of code to be copied (or cut) displayed in the other sub-window. c. Put the cursor on the first character of the section of code to be copied (or cut) and press and hold the left mouse button down. While holding that button down, drag the cursor to the last character of the code that is to be copied (or cut). As you drag the mouse, you will see text being "highlighted". All the text that you cause to be highlighted will be the text selected for copying (or cutting). d. When you have highlighted all of the text (code) to be copied (or cut), release the left mouse button. To "copy" the highlighted text, click the "Copy" button on the STANDARD Button Bar [Stand(6)], or To "cut" the highlighted text, click the "Cut" button on the STANDARD Button Bar [Stand(5)]. e. Move the cursor to the location in the "to be inserted into" text, click the left mouse button to set the "insertion position", and then click the "Paste" button on the STANDARD Button Bar [Stand(7)]. All the text you highlighted in step "c" above will be inserted at the current insertion position. B. Vertical split. To split a window vertically (here the window is split into two sub-windows each side-by-side), put the mouse cursor on the small "vertical split button" just to the left of the horizontal scroll bar at the bottom left corner of the editing window (the mouse cursor will change to double vertical bars), press and hold the left mouse button and drag the mouse cursor right across the editing window until the vertical split bar is where you want it, and then release the left mouse button. The source-code currently in the editing window will now be displayed in both of the side-by-side sub-windows. The features and actions that are available with the "horizontal split sub-windows" as described above are also available for the "vertical split sub-windows". For both horizontal and vertical split sub-windows, to remove one of the sub-windows and get back to a single editing window, do the following: - Put the mouse cursor on top of the bar between (that divides) the two sub-windows (the shape of the mouse cursor will change to two vertical bars with a double arrow crossing them). - Then press and hold the left mouse button and drag the dividing bar: (a) Up to the top of the editing window for horizontally split sub-windows, or; (b) To the far left of the editing window for vertically split sub-windows. - Then release the left mouse button. Cascade and Tiled Windows. --------------------------------------------------------------------- The section immediately above show how to split one Editor Window (vertically or horizontally). However, what if you want to have more than one Editor Window displayed on the screen simultaneously. Having multiple Editor Windows displayed on the screen at the same time can make it easier to search through files quickly, and jump from one file to another easily. You can also view the contents of several files at the same time which could help you do such things as view the INTERFACE and the IMPLEMENTATION of a class at the same time. To get multiple files displayed concurrently (assuming your project is made up of more than one file), do the following: - Click "Window" in the Main Menu [MM(8)]. - Click one of the following three options in the menu that appears: 1. Cascade = this option will cause all the files currently listed when you click "Window" to be displayed in an OVERLAPPING format. 2. Tile Horizontally = this option will cause all the files currently listed when you click "Window" to be displayed with NO overlapping from left to right. 3. Tile Vertically = this option will cause all the files currently listed when you click "Window" to be displayed with NO overlapping from top to bottom. Note - Having multiple Editor Windows displayed in "cascade" form is usually more useful than "tiled" form. How to Edit Source-Code Files. --------------------------------------------------------------------- If the source-code file does not yet exist, follow the document entitled "How to Create and Run a Simple Project" to see how to create a source-code file. Once you have created the source-code file and have put it into a project, you can use the information below to learn how to edit the source-code file using the Visual C++ Editor. To get an already created source-code file into an Editor Window of the Visual C++ Editor, you must get the project that contains the source-code file loaded into the Developer Studio. To do this: 1. Click "File" in the Main Menu {MM(1)]. 2. Select the "Open Workspace" option from the menu that appears. 3. You now see the "Open Workspace" dialog box. Double click on the name of the project you want to load. 4. You will now see the name "projname.dsw" where "projname" is the name of the project you want to load (and ".dsw" is an extension). Double click on the file whose extension is ".dsw" and one of two things will happen: a. The source-code file(s) that makes up the project will be loaded into the Developer Studio and one of these files will appear in an Editor Window and you can now begin editing that file (or any of the files that made up the project). If the file that is displayed in the Editor Window is not the one you want to edit, get to the file you do want to edit by doing ONE of the following: - Click "Window" in the Main Menu [MM(8)], and then select the name of the file you want to edit from the menu of file names that appears, or; - Click the "Workspace" button on the STANDARD Button Bar [Stand(10)]. Then click the "FileView" tab at the bottom of the "Workspace Window", and then double click the name of the file you want to edit. or; b. A "blank" edit screen will appear in which case you must do the following to get the source-code for this project loaded and displayed in the editor. i. Click the "Workspace" button on the STANDARD Button Bar [Stand(10)]. Then click the "FileView" tab at the bottom of the "Workspace Window. ii. Double click on the name of the source-code file you want to have displayed in an Editor Window. If you need to have other files (that are not currently part of the current project) loaded into the editor (so you can edit them simultaneously), click the "Open" button on the STANDARD button bar [Stand(2)] and double click on the name of the file you want to also have loaded into the editor. If you load more than one file into the editor, to switch between the open files, click on "Window" in the Main Menu [MM(8)] and select the name of the file you want to be the "currently displayed" file. 5. The source-code file for the project is now loaded into the source-code editor. You can now edit the source-code file and (re)compile it, or you can build and run the program associated with this project. Once you have loaded the project and source-code files, you can use the following Visual C++ Editor commands and features. Setting and Using BOOKMARKS. --------------------------------------------------------------------- You can mark a location in your source-code and immediately "jump" to that location no matter were you currently are in the source-code. "Jump" means that the "Insert" Position is moved to the specific location in the source-code associated with that Bookmark. Setting a location to jump to is called setting a BOOKMARK. Setting various Bookmarks allows you to immediately jump to important locations in the source-code or to portions of the code that need to be frequently accessed. There are two kinds of Bookmarks; permanent and temporary. A. Permanent (or named) Bookmarks. ------------------------------- This type of Bookmark is saved with your source-code file when you do a source-code file save. All "permanent" Bookmarks continue to exist between editing sessions (i.e., ending an editing session will not cause permanent Bookmarks to disappear). To create a permanent Bookmark, do the following: 1. Place the "Insert" Cursor (it is a cursor shaped like a large uppercase "I") at the location in the source-code file where you want to create a Bookmark and click the left mouse button to "set" that position. 2. Click "Edit" in the Main Menu [MM(2)]. 3. Select the "Bookmarks" option from the menu that appears. 4. In the "Name" text field at the top of the "Bookmark Dialog Box" that appears, type the name you want to give this Bookmark. 5. Click the "Add" button on the Bookmark Dialog Box to add this Bookmark to the active Bookmarks list. 6. Click the "close" button on the Bookmark Dialog Box. You can now "jump" to the location in the source-code where this Bookmark was set from anywhere in the file that contains this source-code by doing the following: 1. Display the "Edit" Button Bar by doing the following: a. Place the mouse cursor over an empty area of the Main Menu (at the top of the screen). b. Click the RIGHT mouse button. c. Select the "Edit" option from the menu that appears. You can then move and/or dock this Edit Button Bar where you wish. 2. Click the "Next Bookmark" BUTTON ON THE "Edit" Button Bar [Edit(2)]. Each time you click the "Next Bookmark" button, the "Insert Position" will be moved to the next Bookmark and the text surrounding the Insert Position will be displayed. You can also click the "Previous Bookmark" button [Edit(3)] to move to the previous Bookmark. In this manner, you can "cycle" through all Bookmarks. If you want to skip intervening Bookmarks, see the next section to see how to do this. The above method of "jumping" to a Bookmark will not skip Bookmarks and will not work if the Bookmark to be jumped to is in another file. To "jump" to a specific Bookmark (by-passing intervening Bookmarks), either in the same file you are currently in or to one that is in a different file, do the following: 1. Click "Edit" in the Main Menu [MM(2)]. 2. Select the "Bookmarks" option from the menu that appears. 3. In the window of the "Bookmark" dialog box that appears, click the name of the Bookmark to jump to. 4. Click the "Goto" button on the "Bookmark" dialog box. Note that this will work even if the file that contains the Bookmark being jumped to is not currently displayed in the Editor Window (the file MUST, however, be one that has been loaded into the Editor). That file will automatically be displayed in the Editor Window and the "Insert Position" will be placed at the specified Bookmark. If you create a permanent Bookmark in an editing session, when you go to exit the Editor, you will be asked if you want to "Save all changes". Since the creation of a permanent Bookmark is an editing change, click the "Yes" button to save all changes. To remove a permanent Bookmark, do the following: 1. Click "Edit" in the Main Menu [MM(2)]. 2. Select the "Bookmarks" option from the menu that appears. 3. In the Bookmark list in the Bookmark Dialog Box that appears, click the name of the Bookmark to be remove. 4. Click the "Delete" button on the Bookmark Dialog Box. To remove more than one permanent Bookmark, do the following: 1. Click "Edit" in the Main Menu [MM(2)]. 2. Select the "Bookmarks" option from the menu that appears. 3. In the Bookmark list in the Bookmark Dialog Box that appears, do the following: - Click the name of the first Bookmark to be removed. - Now do a CTRL-click on the next Bookmark to be removed. "CTRL-click" means to move the mouse cursor over the name of the Bookmark and press the left-mouse button and the CTRL key on the keyboard at the same time and then release both at the same time. Repeat this step for as many other Bookmarks you want to remove. 4. Click the "Delete" button on the Bookmark Dialog Box and all the "selected" Bookmarks will be removed. B. Temporary (or un-named) Bookmarks. Use temporary Bookmarks if you do NOT want a Bookmark to be retained from one editing session and the Bookmark will be in the source-code file currently displayed in the Editor Window (and not in some other file). Temporary Bookmarks are preferred if you just want to quickly set a small number of Bookmarks and "jump" back and forth between them, or you frequently want to change the Bookmarks you are working with. To set a temporary Bookmark, do the following: 1. Display the "Edit" Button Bar by doing the following: a. Place the mouse cursor over an empty area of the Main Menu (at the top of the screen). b. Click the RIGHT mouse button. c. Select the "Edit" option from the menu that appears and the Edit Button Bar will appear. You can then move and/or dock this Edit Button Bar where you wish. 2. Place the "Insert Cursor" on the line where you want to set a temporary Bookmark and click the left mouse button to "set" the location of the new Bookmark. 3. Click the "Toggle Bookmark" button on the Edit Button Bar [Edit(1)] and you will see a small "box" appear at the left side of the line you marked in step "2" above. A Bookmark is now set for that line and that Bookmark will be added to the set of "active" Bookmarks (but it will not be posted on the Bookmark Dialog Box Bookmark list). You can now "jump" to the location in the source-code where this temporary Bookmark was set from anywhere in the file in which this Bookmark was set (but NOT from another file) by doing the following: 1. Display the "Edit" Button Bar by doing the following: a. Place the mouse cursor over an empty area of the Main Menu (at the top of the screen). b. Click the RIGHT mouse button. c. Select the "Edit" option from the menu that appears. You can then move and/or dock this Edit Button Bar where you wish. 2. Click the "Next Bookmark" BUTTON ON THE "Edit" Button Bar [Edit(2)]. Each time you click the "Next Bookmark" button, the "Insert Position" will be moved to the line that contains the next temporary (or permanent) Bookmark that is in the file currently displayed in the Editor Window (but not to a temporary or permanent Bookmark that is in some other file). You can also click the "Previous Bookmark" button [Edit(3)] to move to the previous Bookmark. In this manner, you can "cycle" through all Bookmarks (temporary or permanent). Note that for temporary Bookmarks (unlike permanent Bookmarks), you CANNOT: a. "Jump" over intervening temporary Bookmarks. b. "Jump" to a temporary Bookmark that is located in another file. You can only "jump" to temporary Bookmarks that have been set in the file currently being edited. Therefore, do not try to use the "GoTo" button on the Bookmark Dialog Box to get to a temporary Bookmark; use the "Next Bookmark" or "Previous Bookmark" buttons on the "Edit" Button Bar. Also note that all temporary Bookmarks are destroyed when you terminate the current editing session (they are not saved and re-set when the current file is reloaded at a later time as are permanent Bookmarks). To remove a temporary Bookmark, do the following: 1. Place the "Insert Cursor" anywhere on the line of source- code for which a temporary Bookmark has been set. Now click the left mouse button to select that line. 2. Bring up the Edit Button Bar (see above instructions for doing this) and click the "Toggle Bookmark" button [Edit(1)]. The small "box" to the left of the current line will disappear to signal that the Bookmark for this line has been removed and can no longer be "jumped" to. To remove all TEMPORARY Bookmarks with one command, click the "Clear All Bookmarks" button on the EDIT Button Bar [Edit(4)]. Note this will NOT remove any permanent Bookmarks. Searching a Source-code File for a String Using the FIND Dialog Box. ---------------------------------------------------------------------- You can search the current file for a string (term, word, or group of words) by using the Find dialog box SEARCH features of the Editor. There are two methods for searching for a string in the current file. a. "Mark" first and then enter the Search mode. i. To "mark" a single string to be searched for, place the "Insert Cursor" on any character making up the string and click the left mouse button to "select" that string. ii. To "mark" a group of words (containing one or more blanks) to be searched for, place the "Insert Cursor" to the left of the first character of the group of words and press and hold down the left mouse button. While holding this button down, "drag" the mouse to a position just to the right of the last character of the group of words to be searched for and release the left mouse button. As you "drag" the mouse, the words become highlighted. Now that the term, word, or group of words is "marked", enter the Search mode and begin the search by doing the following: 1. Get the Edit Button Bar displayed (see above for how to do this). 2. Click the "Find" button on the Edit Button Bar [Edit(5)] and the Find dialog box will appear with the term, word, or group of words marked in step "i" or "ii" above shown in the "Find What" text field. You can now do step 3 below, or before doing step 3 you can set certain search preferences (see a description of these below) and then do step 3. 3. Click the "Find Next" button on the Find dialog box to find the first match. Once the first match is found, if you want to find the next match, just repeat steps 2 and 3 immediately above. b. Enter the Search mode and then specify a string to be searched for. To do this, do the following: 1. Get the Edit Button Bar displayed (see above for how to do this). 2. Click the "Find" button on the Edit Button Bar [Edit(5)] and the Find dialog box will appear. The "Find What" text field in this dialog box may contain some term. If it happens to contain the exact term you want to search for, just click the "Find Next" button on the Find dialog box. However, if the term displayed in the "Find What" text field is not the term you want to search for, then type in the term (or set of terms) to be searched for and then click the "Find Next" button on the Find dialog box. Once the first match is found, if you want to find the next match, just click the "Find" button on the Edit Button Bar [Edit(5)] and then click the "Find Next" Button Bar on the Find Dialog Box. Search Preferences in the "Find" dialog box. There are many search "preferences" you can select from the Find Dialog Box. These preferences/setting are discussed below. a. From the checkboxes (on the left side of the Find Dialog Box). - Match Whole Word Only Click this checkbox if you want the search to find a match with your search string only when it finds the search string enclosed within non-alphabetic non-digit characters. For example, if your search string is "any", the search would NOT match: "company", "many", "anything", or "9any" It would match " any ", "(any)", "any.", and "any?" To "turn off" this checkbox selection, just click this checkbox again. If this checkbox is not selected (i.e. is turned off) then the search string will be matched with any term in the file that uses the same characters in the same order even if the search string is part of a larger string. For example, with this checkbox turned off, the string "any" WOULD match: "company", "many", "anything", and "9any" - Match Case Click this checkbox if you want the search to find a match with your search string only if the possible match is made up of the same characters where each character is in the same case. For example, if your search string is "CodeView" the search would NOT match: codeview, Codeview, or CODEVIEW It would only match CodeView To "turn off" this checkbox selection, just click this checkbox again. If this checkbox is not selected (i.e. is turned off) then the search string will be matched with any term in the file that uses the same characters in the same order whether or not each character in the match is in the same case as the search string characters. For example, with this checkbox turned off, the string search "CodeView" WOULD match: codeview, Codeview, and CODEVIEW - Regular Expression This is an advanced feature, and will not be discussed here. - Search All Open Documents If this checkbox is selected (turned on), then a match for the indicated search string will be sought in ALL files that are currently loaded into the Editor. If this checkbox is not selected (turned off), then a match for the indicated search string will be sought only in the file currently displayed in the Editor Window. b. The Radio Buttons under "Direction". Click the "Down" radio button if you want the search to be done from the current "Insert Position" toward the END of the file (finds next match BELOW the current "Insert Position"). Click the "Up" radio button if you want the search to be done from the current "Insert Position" toward the BEGINNING of the file (finds next match ABOVE the current "Insert Position"). c. The "action" buttons on the right side of the Find Dialog Box. - The "Find Next" button. Click the "Find Next" button to begin the string search. The search will be done using the settings you have selected with the checkboxes and radio buttons. - The "Mark All" button. Click the "Mark All" button to begin the string search. The search will be done using the settings you have selected with the checkboxes and radio buttons. In addition, a temporary Bookmark will be set on every line of text that contains a match for the search string. To clear all these Bookmarks, click the "Clear All Bookmarks" button on the Edit Button Bar [Edit(4)]. - The "Cancel" button. Click the "Cancel" button if you want to exit the Find mode (exit the Find dialog box) with no search action taken. Search Using the INCREMENTAL Search Feature. ---------------------------------------------------------------------- Press the control key of the keyboard (CTRL) and the 'i' key at the same time and you will be put in the INCREMENTAL search mode (you will see the words "Incremental Search" displayed at the bottom right corner of the edit window). Now you can search for a string by just typing its characters (you do not have to use the Find Dialog Box). As you enter each character of the string the INCREMENTAL search will find the first string match that contains the characters thus far keyed in. Note that this is the way a string search is done in the "emacs" editor in the unix environment. Once the INCREMENTAL search has located the desired matching string in the text, you can do one of two things: a. Press the ENTER key and the current INCREMENTAL search will be ended. The editor will now work in its usual way. b. Press the F3 key if you want to immediately find the next instance of the search string in the text. Each time you press the F3 key, the next instance of the search string will be found for you. Note that even if you get out of the INCREMENTAL search mode, you can press the F3 key and the last string you searched for will be used to find another match. Pressing the CTRL-i keys will do a "forward" INCREMENTAL search from the current "Insert Position" toward the end of the file. If you want to do a "backward" (reverse) INCREMENTAL search, press the SHIFT, CTRL, and 'i' keys simultaneously. The backward INCREMENTAL search works just like the forward search, but searches from the current "Insert Position" toward the beginning of the file. Note that the INCREMENTAL search (forward or backward) mode does not allow you to select the kinds of "preferences" available when using the Find Dialog Box as described above. Replace One String with Another. --------------------------------------------------------------------- If you want to specify a "search" string and have the editor find a match to that string within the file and replace that match with a specified "replacement" string, then you can do either of the following. a. Examine the entire file for possible replacements. - Click "Edit" in the Main Menu [MM(2)]. - Select the "Replace" option from the menu that appears. The Replace Dialog Box will now appear. - In the "Find What" text field of the Replace Dialog Box, type the string you want to search for (i.e. the search string). Do not press the ENTER key when you finish typing this search string. - Move the cursor inside the "Replace With" text field and click the left mouse button to select this field. Now type the "replacement" string you want to use to replace the search string you entered in the above step. Do not press the ENTER key when you finish typing this replacement string. - Now, click the "Find Next" button on the dialog box and the next string in the file that matches what you entered in the "Find What" text field (i.e. that matches the search string) is found and highlighted. You can now do one of two things: * Replace each match one at a time. - If you want to replace the highlighted string with the replacement string, click the "Replace" button. Once the currently highlighted string is replaced with the replacement string, the editor will immediately find the next match for the search string and you can click the "Replace" button to do another replace, or if you do not want to replace the highlighted string with the replacement string, but you want to find the next search string match for possible replacement, then click the "Find Next" button again. If you want to get out of the Replace mode at any time, click the "Close" (or Cancel) button. After exiting the Replace mode, if you decide you made a mistake and want to un-do the replacements you just made, then repeatedly click the UnDo button on the STANDARD Button Bar [STAND(8)]. * Replace all matches at once (without further prompting). If you want to replace every string in the file that matches the search string with the replacement string, do the following: - Click the "Replace All" button. Note that this action can be dangerous as ALL the strings that match the search string will be immediately replaced with the replacement string (you will not be able to select which matches are replaced as you are able to do with the "Replace one at a time" method described above). If before clicking the "Replace All" button you decide you do not want to make any replacements, press the "Cancel" button to get out of the Replace mode. - Click the "Close" button to exit the Replace mode and dismiss the Replace Dialog Box. If after exiting the Replace mode you decide you made a mistake and would like to put the file back into the same form it had before you did the Replace action, Click the UnDo button on the STANDARD Button Bar [STAND(8)]. b. Search only a sub-section of the file for possible replacement. If you want to search only a sub-section of the file (not the entire file) to find a match for the search string (and possibly replace it), then do the following. 1. Move the "Insert Cursor" to the left of the first character of the section to be searched, press and hold the left mouse key, move the "Insert Cursor" to the right of the last character in the section to be searched, and release the left mouse button. Note that as you move (drag) the "Insert Cursor", more and more of the text becomes highlighted. 2. Click "Edit" in the Main Menu [MM(2)]. 3. Select the "Replace" option in the menu that appears. The Replace Dialog Box will appear. Note under "Replace In", the "Selection" radio button is selected (not the "Whole File" button). If you change your mind and want to do the search and replace for the whole file, just click the "Whole File" radio button. 4. In the "Find What" text field of the Replace Dialog Box, type the string you want to search for (and that will be replaced if you choose). Do not press the ENTER key when you finish typing this search string. 5. Move the cursor inside the "Replace With" text field and click the left mouse button to select this field. Now type the string you want to use to replace the search string you entered in the above step. Do not press the ENTER key when you finish typing this replacement string. 6. Click the "Replace All" button on the dialog box. Note that you are not allowed to click the "Find Next" or "Replace" buttons. You have only the option to replace all instances of the search string with the replacement string. If before clicking the "Replace All" button you decide you do not want to make any replacements, press the "Cancel" button to get out of the Replace mode. 7. Click the "Close" button to exit the Replace mode and dismiss the Replace Dialog Box. If after exiting the Replace mode you decide you made a mistake and would like to put the file back into the same form it had before you did the Replace action, Click the UnDo button on the STANDARD Button Bar [STAND(8)]. No matter whether you use method "a" or "b" above to search and replace, you can click on any of the "Checkboxes" on the "Replace" Dialog Box to set specific search/replace preferences including: - Match Whole Word Only Click this checkbox if you want the search to find a match with your search string only when it finds the search string enclosed within non-alphabetic non-digit characters. For example, if your search string is "any", the search would NOT match: "company", "many", "anything", or "9any" It would match " any ", "(any)", "any.", and "any?" To "turn off" this checkbox selection, just click this checkbox again. If this checkbox is not selected (i.e. is turned off) then the search string will be matched with any term in the file that uses the same characters in the same order even if the search string is part of a larger string. For example, with this checkbox turned off, the string "any" would match: "company", "many", "anything", and "9any" - Match Case Click this checkbox if you want the search to find a match with your search string only if the possible match is made up of the same characters where each character is in the same case. For example, if your search string is "CodeView" the search would NOT match: codeview, Codeview, or CODEVIEW It would only match CodeView To "turn off" this checkbox selection, just click this checkbox again. If this checkbox is not selected (i.e. is turned off) then the search string will be matched with any term in the file that uses the same characters in the same order whether or not each character in the match is in the same case as the search string characters. For example, with this checkbox turned off, the string search "CodeView" would match: codeview, Codeview, and CODEVIEW Add and Edit a CLASS. --------------------------------------------------------------------- You can add one or more classes to your program any time. You can also edit the class and any of its member functions quickly and easily. A. Add a new class to the source-code. ----------------------------------- Note that you can always add a class to your source-code by just typing its interface and its member function implementations into the source-code file. The following just gives you a "short-hand" way to add classes to your program. a. Get the source-code file that contains the "main" function loaded into the editor (see a previous section to see how to do this). b. Click "Insert" in the Main Menu [MM(4)]. c. Select the "New Class" option from the menu that appears and the "New Class" Dialog Box will appear. d. Click the left mouse button inside the "Name" text field which is under the "Class Information" section of the New Class Dialog Box. e. Type the name of the class that is to be added (do not press the enter key when the name has been typed). f. Click the "Ok" button in the "New Class" dialog box (or if you have changed your mind and do not want to add a new class, then click the "Cancel" button). Two new source-code files will automatically be created for you and they will be inserted into the current project. These two files include (where "classname" is the name you gave the new class in step "e" above): - classname.h Which will store a very simple class interface that contains only the prototype for the class CONSTRUCTOR and the class DESTRUCTOR. You can bring this ".h" file into the editor and add whatever you want to it. - classname.cpp Which will store a "stub" implementation of the class CONSTRUCTOR and the class DESTRUCTOR. You can bring this ".cpp" file into the editor and add whatever you want to it. Be sure to put: #include "classname.h" a. Near the top of the source-code file that contains the "main" function, and; b. Near the top of "classname.cpp" or the program will not compile properly. You will need to edit both the new ".h" and ".cpp" files to make them work properly. You will need to add the missing C++ code and you may want to remove some of the code that is automatically put into the ".h" and ".cpp" files when they are first created. To do this editing: 1. Click the "Workspace" button on the STANDARD Button Bar [STAND(10)]. 2. Double click either the new ".h" or the new ".cpp" file name in the list of file names that appears. The file that is doubled-clicked will now appear in an Editor Window and you can add or remove code. To edit the other new file, just repeat steps "1" and "2" above. Note that in both the new ".h" and ".cpp" files there are COMMENTS and/or MACROS that you may want to delete as they are not really necessary to make the new files work properly. B. Edit a class/member function using the WizardBar. ------------------------------------------------- When a new class is added (using the above instructions), or if a class already exists, you can quickly and easily edit that class or any member function of that class. You can edit any of the following: - The interface of the class. You can add/remove data members and member functions - The prototype for any member function - The implementation of any member function by using the WizardBar. To display the WizardBar, do the following: a. Place the mouse cursor over an empty area of the Main Menu (at the top of the screen). b. Click the RIGHT mouse button. c. Select the "WizardBar" option from the menu that appears. You can then move and/or dock the WizardBar where you wish. The "WizardBar" contains three small "windows" each with a small "menu icon" immediately to the right of each window. A "menu icon" is a small solid triangle with a point facing down (or to the right). When such an icon is clicked, a menu will appear from which you can select a variety of options. The left-most window has displayed in it the name of the CLASS that can be currently examined. If you want to examine some other class in your program, click the menu icon to the right of that window and a pop-up menu appears which contains the name of every class that you can examine. Just click the name of the class you want to examine and its name is now displayed in that window (and is the currently active class). Look at the right side of the WizardBar and you will see an icon between two menu icons (it is the "default" icon). If you repeatedly click that icon, you will be alternately moved between the "prototype" of the CONSTRUCTOR for the currently active class and the "implementation" of that CONSTRUCTOR. This is a quick way to have the editor move between a prototype and the associated implementation. When the prototype (or implementation) is displayed in the editor, you can edit it any way you wish. The middle window is of no concern to beginning users of Visual C++. The right-most of the three windows has displayed in it the name of the MEMBER FUNCTION that can be currently examined. If a class name is currently displayed in that window, it means that there is no currently active member function and you must choose one. To choose a member function and make it the currently active member function, do the following: 1. Get the part of you source-code that contains either the prototype or the implementation of the member function you want to examine loaded and displayed in the Editor Window. 2. Place the cursor on the member function name and click once. You will see the name of that function appear in the right-most small window. That member function is now the current active function. Look at the right side of the WizardBar and you will see an icon between two menu icons (it is the "default" icon). If you repeatedly click that icon, you will be alternately moved between the "prototype" for the currently active member function and the "implementation" of that function. This is a quick way to move the Editor between a prototype and the associated implementation of a member function. When the prototype (or implementation) is displayed in the editor, you can edit it any way you wish. Once you have a member function name in the right-most small window, you can select other member functions to be the current active function by clicking the menu icon to the right of the right-most window and a pop-up menu appears which contains the name of every member function (this includes the CONSTRUCTOR since it is also a member function) that you can examine. Just click the name of the member function you want to examine and its name is now displayed in that window (and is made the currently active member function). Once you have made a class the "current active class" or you have made a member function the "current active member function", you can perform some special actions by using the WizardBar Menu. To have the WizardBar Menu displayed, click the right-most menu icon in the WizardBar. The following menu options will appear. - Go to Function Definition This option will move the insert position in the Editor Window to the "definition" (implementation) of either: a. The class CONSTRUCTOR if a class name is currently displayed in the right-most small window in the WizardBar, or b. The member function if a member function name is currently displayed in the right-most small window in the WizardBar. The header of that function/constructor is highlighted. This will work even if the function/constructor definition (implementation) is in a file other than the file currently displayed in the Editor Window. The file containing the appropriate function/constructor definition (implementation) will be displayed in an Editor Window. - Go to Function Declaration This option will move the "Insert Position" in the Editor Window to the "prototype" of either: a. The class CONSTRUCTOR if a class name is currently displayed in the right-most small window in the WizardBar, or b. The member function if a member function name is currently displayed in the right-most small window in the WizardBar. The prototype is highlighted. This will work even if the prototype is in a file other than the file currently displayed in the Editor Window. The file containing the appropriate prototype will be displayed in an Editor Window. - Add a Member Function This will allow you to add a member function to the class whose name currently appears in the left-most text field of the WizardBar. A stub prototype for that member function is placed in the implementation of that class (in the ".h" file for that class), and a stub definition (implementation) for that member function is placed in the ".cpp" file for that class. You can then edit the appropriate ".h" and ".cpp" files to add to the prototype and/or implementation. To add a member function, do the following: a. Select this option from the WizardBar menu and the "Add Member Function" Dialog Box will appear. b. In the text field named "Function Type" in this dialog box, type the name of the data type returned by this member function (e.g. int, float, char, double *, etc). Do not press the ENTER key after typing in the appropriate term. c. Place the cursor in the text field named "Function Declaration" and click the left mouse button to select this text field. Now type the "signature" for this member function (which is the name of the function followed by the list of formal parameters enclosed in parentheses) as in: doit(int &qty, double cost, double prices[]) d. Click on one of the three "Access" radio buttons to make this member function "Public", "Private", or "Protected". You can now do step "e" below, or you can select to make this member function "Static" or "Virtual" by clicking on the appropriate checkbox option, and then do step "e" below. Until you learn what a "Static" and "Virtual" function is, do not select either option. Just do step "e" below. e. Click the "OK" button on the "New Member Function" Dialog Box to add the member function, or click on the "Cancel" button if you have changed your mind about adding a new member function. - Go to Class Definition This option will move the "Insert Position" in the Editor Window to the "class definition" (interface) for the class whose name currently appears in the left-most text field of the WizardBar. The header of that class definition is highlighted. This will work even if the class definition (interface) is in a file other than the file currently displayed in the edit window. The file containing the appropriate class definition (interface) will be displayed in an Editor Window. - New class This will allow you to perform the same actions as described in "Add a new class to the source-code" in "A" above. - Go to Next Function This option will move the "Insert Position" in the Editor Window to the next "prototype" or the next "definition" (implementation) of a different member function of the current class. This will be done ONLY if that function is in the same file that is currently displayed in the edit window. It will NOT jump to a member function in another file. If you want to "jump" among function prototypes and definitions that are in a different file, you must bring up that file in an Editor Window and then you can jump among the prototypes/definitions in that file using this menu option. The prototype or header of that function definition (implementation) is highlighted. Note - although in the discussion above it specifically talks about the "next" function being a MEMBER function, this will "jump to the next prototype or function definition" will work even if the next function is not a member of any class (i.e. even if it is an EXTERNAL function). However, this feature is most useful when jumping to the next MEMBER function. - Go to Previous Function This option will move the insert position in the edit window to the previous "prototype" or the previous "definition" (implementation) of a function in the same file that is currently displayed in the edit window. It will NOT jump to functions in another file. If you want to "jump" among function prototypes/definitions that are in a different file, you must bring up that file in the editor window and then you can jump among its prototypes/definitions using this menu option. That prototype or header of that function definition is highlighted. Note that this will jump to the previous prototype or function definition even if the associated function is not a member of any class (i.e. even if it is an EXTERNAL function). - Open Include File This option will let you display in an Editor Window any "header" file related to the term displayed in the right-most text field of the WizardBar. You can then add or remove statements from this header file. To have a header file loaded into an Editor Window, do the following: a. When you select this menu item, the "Open File Included ..." dialog box is displayed. b. Place the cursor on the name of the header file to be loaded into an Editor Window and then click the left mouse button to select that file. c. Click the "OK" button on the dialog box (or if you change your mind and decide not to load any header file, click the "Cancel" button). - WizardBar Help Select this menu option to obtain detailed help on how to use the WizardBar.