Creating a Wizard for Developing Web Application Using Managed C++ In this section, we’ll look at how to create a custom application wizard that generate a Web application using ASP.NET and managed C++. We’ll look at the details involved in writing a Web Forms applications using ASP.NET and managed C++ in the second half of the book. For now, we’ll create an application wizard that can generate Web Forms applications. A Web Forms application involves several different kinds of files to be generated. In addition, we can add several options such as tracing/debugging options and include several kinds of controls to see how the application wizard works. The files included in the Web Forms application include source code for a Managed C++ DLL, an ASP.NET(ASPX) files, a Web.Config file, and a Visual Studio Solution file. Each of these files will need to contain a couple of different substitutions made by the application wizard. We’ll create our wizard using the Custom Wizard. As mentioned, the Custom Wizard is a canned Visual Studio.NET wizard that creates a custom wizard. The name of the sample wizard for this chapter will be ManagedCWebForm-Wizard. The wizard will have a user interface consisting of one page in this example to make the sample more digestible. 使用托管C++开发WEB应用程序的向导 在本节,我们将使用ASP.NET和托管C++来产生WEB应用程序的向导.在本书的后半部分我将看到ASP.NET和托管C++写WEB窗体的应用程序的详细资料.现在,我们将生成WEB窗体应用程序的向导.WEB应用程序包括几个特别的性质的文件.另外,我能增加单独选项例如跟踪/调试选项和包括个别性质的控件来查看应用向导是怎么工作的.WEB窗体应用程序包括托管C++ DLL的源代码,一些ASP.NET(ASPX)文件,一个WEB.CONFIG文件和一个VS解决方案文件.这些文件将需要替换包含向导不同的连接.???? 我们用自定义向导建立自己的向导.象提到的一样,自定义向导是VS.NET向导建立的自定义向导. 在本章该样例向导的名字叫ManagedCWebForm-Wizard.这个例子非常的简单也很容易消化,它由一个页面组成的用户界面. The user interface itself will include check boxes for adding controls to the page and for turning on debugging and tracing options. Solution Explorer lets you get to the HTML page representing the wizard user interface. Editing this page is much like editing normal dialog boxes. You can select a control from the Toolbox on the left side of the Visual Studio .NET’s IDE, place the control on the page, and set its properties using the Properties window. The wizard has six check boxes on the interface page. Three of the check boxes will manage the controls on the Web Form—one each for adding a CheckBox control to the Web Form , for adding a Label control, and for adding a TextBox control. You can use the Properties window to provide Ids for each of the controls. The TextBox Check box has an ID of UseTextBox, the Label check box has an ID of UseLabel, and the CheckBox check box an ID of UseCheckBox. When the wizard generates the code, it looks for these symbols to add code to the ASPX page and the code page. 用户界面自己将在页面上增加跟踪调试的选择框控制选项.解决方案让你得到HTML页面的向导用户界面.编辑这个页面就象是编辑一般的对话框一样.你可以从VS.NET的IDE左边的工具栏上选择控件,将控件摆放出在页面上或在属性窗口中设置它的属性.这向导有六个选项框在用户界面上.三个选项框将管理WEB窗体的控件.每增加个勾选框控件到WEB窗体,就增加个LABEL控件和文本控件.你可以在属性窗口中为每个窗口提供一个ID.TextBox勾选框的ID叫UseTextBox,Label框的ID叫UseLabel,CheckBox叫UseCheckBox.当向导产生代码,你能看到这些符号在ASPX中和代码页中出现. The three other check boxes are for managing debug options: one for page tracing, one fro request tracing, and one to turn on debugging. The check boxes have Ids of UsePageTracing, UseRequestTracing, and UsePageDebugging. As with the user interface page, the wizard will look for these symbols to add the right code to the generated project. Figure 4-1 shows default.htm, the user interface page, as it will appear in the finished wizard. Once the controls are on the page, they need to be associated with symbols that the wizard can use to make substitutions. The wizard’s default user interface page(default.htm) has a block of symbol entries. You then modify the symbols for the Web application wizard, as shown here: 这上个勾选框是管理调试选项的,一个页面跟踪,一个请求跟踪,一个启动和调试.这些勾选框的ID分别为UsePageTracing,UseRequestTracing,和UsePageDebugging.同样使用用户界面,向导将寻找这些符号并将正确的代码添加到项目中去. 图4-1显示的default.htm.用户界面,同样将出现在完成向导中. 一旦控件在页面上,它们就需要向导使用替换符号来联合它们.向导的缺省用户界面(default.htm)有整块符号.你可以在WEB应用程序向导上修改这些符号,如下显示:
Notice that each of these symbols is associated with a check box on the wizard user interface page. The next step is to take the original source code and insert annotations where you want the wizard to add replacement code. Once we have the original boilerplate code, all the original boilerplate source code for the wizard will live under the Templates directory for that wizard. The final ManagedCWeb-Form will need to include three files: the header file containing the C++ class, the ASPX file containing the Web page layout information, and the Web.Config file containing the configuration settings. The boilerplate code for these files will be included in the Template directory for the wizard. Let’s take a look at the boilerplate code the wizard will use to generate the applications. Here’s the code for the C++ header file: 注意在向导用户界面上每个符号都是用CHECK BOX关联的. 下一步就是组织源代码并插入注释到你想在向导中的什么地方替换代码.一旦你准备好了样本文件,所有的样本源代码都将在向导的模板目录之下.完成的ManagedCWeb-Form必须包含三个文件:一个包含C++类的头文件,一个包含WEB规划信息的ASPX文件,一个包含配置信息的配置文件.这些文件也将包含在向导的模板目录.让我门看看向导使用这样本文件来产生的应用程序.这些代码是C++头文件里的: // ManagedCWebForm.h #pragma once using namespace System; #using
#using
using namespace System; using namespace System::Web; using namespace System::Web::UI using namespace System::Web::UI::WebControls; using namespace System::Collections; using namespace System::ComponentModel; namespace ProgVSNET_ManagedCWebForm { public __gc class ManagedCWebPage : pulbic Page { public: Button * m_button; [!if UseLabel] Label* m_label; [!endif] [!if UseTextBox] Textbox* m_text; [!endif] [!if UseChockBox] Checkbox* m_check; [!endif] ManagedCWebPage() { //To do: Construction code here… } void SubmitEntry(Object* o ,EventArgs* e) { //Called when Submit button pressed //To do : insert Page Loading code here… String* Str; Str= new sting(“Hello “); Str=str->Concat(str,m_text->get_Text()); Str=str->Concat(str,new string(“you pushed Submit”)); [!if UseLabel] m_label->set_Text(str); [!if UseLabel] } void Page_Load(Object* o,EventArgs* e) { //To do: insert Page Loading code here… [!if UsePageTracing] Trace->Write(“Custom”,”Inside Page_Load”); [!endif] if(!IsPostBack){ } } }; } When the wizard generates the final code, it looks for the key symbol contained in the square brace to see whether it is in the symbol table. In our example, the expressions are simply Boolean tests. If the check boxes are selected, the controls or debugging features are turned on. Otherwise, they’re turned off, and the specific code will be omitted from the generated source code. The same principle applies to every file that needs to be generated. For example, the wizard will take the following boilerplate code for the ASP.NET page and examine the UseRequestTracing, UseTextBox, UseLabel, and UseCheckBox symbols to figure out what code to include: 当向导完成了代码,你看到关键字都包含在中括号中而不管他是否在符号表中.比如我们的例子,这个表达式是简单的布尔测试.如果选项框被选择,控制和调试特征开启.否则,它们被关闭,产生的代码将忽略这些细节代码.相同道理应用到产生的每个文件.例如,向导将轮流检查UseRequestTracing, UseTextBox, UseLabel, 和UseCheckBox样本代码的ASP.NET页面文件的符号理解包含了什么代码: <%@ Page Language=”C#” [!If UseRequestTracing] Trace=true [!endif] Inherits=”ProgVSNET_ManagedCWebForm.ManagedCWebPage” %>
Visual C++.NET向导(结束)
最新推荐文章于 2024-10-12 11:03:43 发布