Microsoft Visual Studio .NET: an Integrated Windows Program
Total Page:16
File Type:pdf, Size:1020Kb
Microsoft Visual Using Microsoft Visual Studio .NET Studio .NET: ? Self-contained environment for Windows program development: An Integrated – creating – compiling Windows Program – linking – testing/debugging Development ? IDE that accompanies Visual C++, Visual Basic, Visual C#, and other Microsoft Environment Windows programming languages ? See Chapter 2 and Appendix D of Deitel text ? Also Appendix C of Gregory text Some Visual Studio Visual Studio Capabilities Components ? Generate starter applications without writing ? The Editors code C, C++, C#, VB source program text editors ? View a programming project in many different • cut/paste, color cues, indentation, ways • generates text files ? Edit source and include files Resource Editors ? Build the application’s user interface visually • icons, bitmaps, cursors, menus, dialog boxes, etc. • graphical, WYSIWYG, Integrated ? Compile and link • generates resource script (.rc) files ? Debug an application while it runs • integrated with text editor ? Obtain online help • Done visually ? Lots of others VC++ Unmanaged Code The Linker Compiler ? C/C++ Compiler ? Reads compiler .obj/.res files – translates source programs to machine language ? – detects and reports errors Accesses C/C++/Windows libraries – generates object (.obj) files for linker ? Generates executable (.exe or .dll) ? Resource Compiler – Reads .rc file – Generates binary resource (.res) file for linker 1 The Debugger ? powerful source code debugger ? integrated with all parts of Visual Studio ? Features – breakpoints – tracing through/over functions – variable watch windows – much more The Wizards Help ? Hover over key words in edit window and a ? AppWizard one-line help message appears – Windows code generator for MFC apps ? More detailed help can be obtained by: – automatically creates working program templates – ‘Start Page’ – ‘Search Online’ & skeleton code • To access the MSDN Online Library ? ClassWizard ? Easier to use the ‘Help’ Menu Item – facilitates easy extension of AppWizard-generated – ‘Dynamic Help’ – context sensitive classes • Click on text in edit window and corresponding topic – creation of new classes and response functions appears in help window – used to tailor AppWizard-generated MFC & .NET • Click on topic in help window to get help skeletons – ‘Contents’: Select a topic – Replaced by Properties Window in .NET – ‘Search’: Enter a topic – ‘Index’: Enter a topic Win32 API Online Help MFC Online Help ? ‘Help’ – ‘Contents’ ? ‘Help’ – ‘Contents’ – Filtered by: (Visual C++) – Filtered by: (no filter) Visual Studio .NET MSDN Library Visual C++ Windows Development Visual C++ Reference Win32 API Visual C++ Libraries SDK Documentation MFC Reference Reference Hierarchy Chart Functions by category MFC Classes Functions in alphabetical order Class Library Overview MFC Classes (!!) etc. 2 MSDN Library (on Web) Using Visual Studio .NET ? To prepare many kinds of applications ? Go to: http://msdn.microsoft.com – Win32 Console Applications (DOS programs) – Search MSDN for desired topic – Win32 API Apps in C or VC++ – Good URL for MFC: – MFC Apps in VC++ http://msdn.microsoft.com/library/default.asp?url=/library/en- us/vcmfc98/html/_mfc_class_library_reference_introduction.asp – DLLs – .NET Windows Forms Apps in Managed C#, VB, C++, and other languages – ASP.NET Web Apps and Services – ADO.NET Data Base Apps – Others Visual Studio Layout ? Menu bar ? Several tool bars ? View Windows (to the side) – Solution Explorer – Class View – Resource View – Properties Window ? Working Area (main window) – Text Editor to enter/modify source code – Resource Editors ? Output Window & Status Bar (bottom). – System messages (errors) ? Windows can be moved around, docked and undocked Toolbars ? Contain icons --instant routes to main menu functions ? Many of them ? May not be visible ? If not, right click on any visible toolbar ? Brings up following popup window ? Can activate a toolbar by clicking on its check box 3 Keyboard Shortcuts Solutions and Projects ? Solution – A single application ? All menu/toolbar selections are available from the keyboard using key – Can contain one or more projects • In Managed applications, can be in different combinations languages ? Can be faster – Overall solution information stored in a .SLN file – Open this when you want to work on a solution ? More information in Online Help ? Project – ‘Index’ | ‘Keyboard Shortcuts’ | ‘Shortcut Keys’ – Collection of files: • Source, headers, resources, settings, configuration information Important Visual Studio Temporary Visual Studio Generated Files generated files ? .sln Solution ? Many are very big and can (should) be removed! ? .vcproj Project ? .obj Compiler machine code translation ? .c, .cpp, .cs C/C++/C# Windows App source code ? .ilk Incremental link file ? .h C/C++ header ? .pch Precompiled header (huge!!!) ? .rc Resource script ? .pdb Precompiled debugging info ? .res Compiled resource ? .idb Incremental debug info ? .ico Icon ? .ncb Supports viewing classes ? .bmp Bitmap image ? .aps Supports viewing resources ? .exe Executable program ? others ? .dll Dynamic Link Library (if used) ? .aspx ASP.NET Web Form source code ? .asmx ASP.NET Web Service source code Program Configurations Setting the Configuration ? Debug ? Click ‘Build’ on Main Menu – appends debugging information ? Choose ‘Configuration Manager’ – produces more and larger files ? Choose desired configuration (‘Debug’ ? Release or ‘Release’) in ‘Active Configuration – no debugging information Box’ – optimized for size & efficiency ? Default is ‘Debug’ 4 Create a Win32 Application with Visual Studio ? Click ‘Application Settings’ in resulting ? Startup ‘Application Wizard’ Box – click ‘Start’ on Task Bar – ‘All Programs’ – Select ‘Windows Application’ from – ‘Microsoft Visual Studio .NET 2003’ | ‘Microsoft ‘Application Type’ radio buttons Visual Studio .NET 2003’ – Select ‘Empty Project’ from ‘Additional ? Creating a new solution Options’ check boxes – ‘File’ | ‘New’ | ‘Project’ from Menu Bar – In ‘New Project’ box, select ‘Visual C++ Project’ from – Click ‘Finish’ ‘Project Types:’ & click on ‘Win32 Project’ in ? Click ‘OK’ in ‘New Project Information’ ‘Templates’ – Set the ‘Location’ to a convenient directory & name Window the project (e.g. win32app1) – ‘OK’ ? Inserting source files into project: ? Alternative Way of Adding a Source – Open a new C++ file & type or copy/paste the code File to a Project: into the program: • ‘File’ | ‘New’ | ‘File’ from menu – You can also copy an existing source code • Choose ‘Visual C++’ from ‘Categories’, C++ file (.cpp) from file into the project’s directory ‘Templates’, & click ‘Open’ – Then as before: • Type or paste source code into the resulting Edit window • Save the file in the project’s directory as a C++ source file, • Choose ‘Project’ | ‘Add Existing Item’ from the giving it an appropriate name (e.g., win32app1) menu – Add the source file to the project: • Select the .cpp file & click ‘Open’ • Choose ‘Project’ | ‘Add Existing Item’ from menu – Should appear in Solution Explorer window • Click on the file you saved (e.g. win32app1.cpp) – Open it by double clicking on it • Confirm that it was added to the project by expanding ‘Source Files’ in the Solution Explorer Window – If Solution Explorer is not visible, select ‘View – Solution Explorer’ from the menu Compiling from Command Line ? Building the Solution: ? Command Line Compilers: – ‘Build’ | ‘Build Solution’ from menu – C++: CL.EXE – Project will be compiled/linked – C# : CSC.EXE – Messages/errors will appear in Output Window – Visual Basic: VBC.EXE ? All are run from a DOS session, but directory ? Running the Program: paths must be set correctly – ‘Debug’ | ‘Start’ from menu ? Easiest to start a Visual Studio .NET • Shortcut key: F5 Command Prompt (paths already set) – Or ‘Debug’ | ‘Start Without Debugging’ from – From Task Bar: • Start | All Programs | Microsoft Visual Studio 2003 | menu Visual Studio .NET Tools | Visual Studio .NET Command • Shortcut key: Ctrl-F5 Prompt (2003 version) • Start | All Programs | Microsoft Visual Studio .NET | • or click exclamation point Visual Studio .NET Tools, Visual Studio .NET Command Prompt (2002 version) 5 Command Line Compiling, ? Cleanup: continued – Copy solution, project, source, header, resource files to disk ? To compile our first Visual C++, Win32 API – Copy .exe file from project's Debug directory application from the command line: – cl kernel32.lib user32.lib gdi32.lib win32a1.cpp – Best: Delete all temporary files & copy entire solution (project directory) to floppy – Note that any required libraries (DLLs) must be specified – Delete project directory from hard drive ? There are many compiler options: ? Exiting Developer Studio: – See Online Help: – ‘File’ | ‘Exit’ from menu – ‘Index’ | ‘cl.exe compiler’ | ‘Compiler Options (C++)’ – For C#: ‘Index’ | ‘csc.exe’ 6.