Windows API 设置窗口下控件Enable属性,apienable

参考页面:

相关接口C#互操作封送处理

    [DllImport("user32.dll")]
    unsafe public static extern bool UpdateWindow(IntPtr hWnd);//更新窗口

    [DllImport("user32.dll")]
    unsafe public static extern bool EnableWindow(IntPtr hWnd, bool bEnable);//设置Enable属性

    [DllImport("user32.dll")]
    unsafe public static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow);//查找窗口/控件

NOTE:
 【FindWindowEx】:https://msdn.microsoft.com/en-us/library/ms633500(VS.85).aspx
 【UpdateWindow】:https://msdn.microsoft.com/library/windows/desktop/dd145167
 【FindWindowEx】:https://msdn.microsoft.com/en-us/library/windows/desktop/ms646291(v=vs.85).aspx

获取窗口子控件句柄代码段

  private List<IntPtr> GetAllChildrenWindowHandles(IntPtr hParent, int maxCount)
  {
      var handles = new List<IntPtr>();
      int ct = 0;
      IntPtr prevChild = IntPtr.Zero;
      IntPtr currChild = IntPtr.Zero;
      while (true && ct < maxCount)
      {
          currChild = FindWindowEx(hParent, prevChild, null, null);
          if (currChild == IntPtr.Zero) break;
          handles.Add(currChild);
          prevChild = currChild;
          ++ct;
      }
      return handles;
  }

API 设置窗口下控件Enable属性,apienable
参考页面:

Using the Common Data Source API in a Web application

在WEB APP中使用普通的数据源API接口

 

Through the Common Data Source API, the Web ADF provides endpoints()
for retrieving(重新得到,收回,挽回) and manipulating(操纵,操控)
data that can be used against any underlying(含蓄的、潜在的) data-source
type. The classes of the Common API enable developers to build tools and
applications that rely on resources and functionalities of
varying(变化的、不同的) data-source types without having to write
data-source specific implementations(落实、实施). The following
walkthrough(演练) will show how to query(疑问、询问) resources and
create graphics showing query results using only the Common API.

通过通用的数据源API接口,WEB
ADF能够回收和操作利用任何潜在的数据源类型。这些API能够让开发者创建依赖于不同数据源类型的资源和功能的工具和应用程序,而不用去动手代码来实现这些功能。下面的例子讲解使用这个通用的API累如何查询数据源并将查询结果显示在集合图层。

 

This tutorial will provide step-by-step instructions for creating a Web
ADF application in Visual Studio 2008 that contains a custom selection
tool. This tool will use classes from the Common API to retrieve feature
data from a user-specified resource and layer and spatially
(空间的)display this data as a Web ADF GraphicsLayer. Attributes for
these features will be displayed in a Web ADF TaskResults control and in
callouts (i.e. MapTips) that appear when the mouse passes over a feature
on the map. The tutorial also demonstrates(论证、显示) the use of
ASP.NET AJAX functionality to dynamically update web controls via
partial postback. The following Web ADF controls are used in the
tutorial: MapResourceManager, Map, Toc, Toolbar, and TaskResults.  

      
这个教程将会手把手的一步一步地叫你在VS2008里面创建一个包含用户所选择工具的WEB
ADP 应用程序。这个工具将会使用common
API来回收那些来自用户指定的数据源和图层并将他们作为一个WEB ADF
集合图层在空间上面展示。在鼠标移动到地图上的一个元素上面并且单击后,这些元素的属性信息就会显示在一个Web
ADF任务结果控件里面。

这个教程也演示了使用ASP.NET
AJAX的功能通过回调来动态的显示更新Web控件。下面的这些ADF控件就是在教程中使用的:MapResourceManager,Map,Toc,Toolbar和任务窗口栏

 

Designing the Web application
设计Web 应用程序。
Our web application will consist of a subset of Web ADF controls that
provide basic GIS functionality and several other controls (Web ADF and
non-Web ADF) that will be used in conjunction(结合、联合) with our
custom selection tool implementation. The basic controls include a Map
for display of GIS data, a Toc to allow toggling of map layer
visibility, a Toolbar to enable interaction with the map, and a
MapResourceManager to provide the Web ADF controls access to map
services. We will also add a Web ADF TaskResults control to display the
attributes of features selected with our custom tool, and two ASP.NET
DropDownLists to enable run time specification of the resource and layer
to select features from. We will embed(嵌入) the DropDownLists in an
ASP.NET AJAX UpdatePanel to allow asynchronous updating of these
controls via partial postback, and we will include an ASP.NET AJAX
ScriptManager to support asynchronous functionality.

我们的应用程序将会包含一些Web
ADF控件来提供基本的GIS功能,和一些其他的控件被用来和用户选择的工具联合起来使用。这些基本的控件包括:一个用来显示GIS数据的地图控件,一个用来调整地图图层可见性的树状控件,一个用来和地图进行交互的控件,一个用来提供获取访问Map服务的MapResrouceManager控件。我们还有添加一个任务结果控件用来显示使用自定义控件所选择要素的属性信息,和两个下拉框控件,用来选择程序在运行的时候选择指定的数据源和图层。我们把这个下拉框组件嵌入到一个ASP.NET
AJA的面板控件,使他能够通过回调来动态的更新内容,我们还需要一个ASP.NET
AJAX脚本管理者来支持异步的功能。

 

 

1:Create a new web application using the steps in the Creating a Web
application with the Web
controls
tutorial. While that tutorial uses Visual Studio 2005, all the steps
except for absolutely positioning the Toc (step eleven) are the same in
Visual Studio 2008. In Visual Studio 2008, perform this step as
follows:
根据在《使用WEB控件创建一个Web应用程序》中一步一步讲的那样创建一应用何程序。除了设置TOC的位置样式有所不同外,其他的在VS2008和VS2007中是没有什么区别的。
a. In design view, click the Toc control so that it is highlighted.

在设计视图下,单击TOC控件,TOC控件高亮显示

b. From the Format menu, select 揚osition厰

从弹出的格式菜单里面选择属性。
c. On the dialog that appears (figure to the right), in the Positioning
Style section, select Absolute, then click OK. 

上面出现的对话框里面的位置样式选择对话框里面选择绝对样式,然后单击OK按钮。

 

 

2:In design view, drag a ScriptManager control from the AJAX Extensions
section of the Visual Studio toolbox and drop it in the top left corner
of the Default.aspx page, above the Map and MapResourceManager controls.
For ASP.NET AJAX functionality to work properly, the ScriptManager must
be located on the page before any controls that employ AJAX
functionality.

在设计视图下,从VS里面的AJAX扩展选择工具箱里面拖拽一个ScriptManager控件,并把他拖到Default.aspx页面左上角在Map以及MapResourceManager上面的位置。为了让ASP.NET
AJAX能够正常的工作,scriptManager 必须在使用AJAX功能之前放置在页面上。

3:Drag and drop a Web ADF TaskResults control onto the page. We will
use this control to display the attributes of selected features.

拖拽一个Web
ADF任务结果控件到页面我们将要用它来显示用户所选择的要素的属性信息。

4:Position the TaskResults control below the Toc. First, make the
control absolutely positioned. Do this by using the Visual Studio
Position dialog as described in step one. Then, drag the control until
it is positioned below the Toc. Expand the width of the control so it is
at least 300 pixels wide

将任务结果控件放置到TOC控件的下面。第一:设置控件的位置为绝对位置,根据我们在第一步介绍的那样,在VS的位置属性框里面设置这个属性,然后拖动这个控件的位置一直到TOC控件的下方。扩展控件的宽度,至少为300像素。

5:Set the TaskResults control抯 BuddyControl property. Select the
TaskResults control in design view or in the Properties window, then
click the drop-down list for the BuddyControl property. The list will
include the names of Map controls available on the page. Select the name
of the Map control added previously (“Map1” by default).

设置任务窗口的Buddy属性。在视图设计模式下选择任务栏控件,或者在属性窗口里面,然后单击BuddyControl属性后面的下拉框,下拉框里会面包含在整个页面中可以得到的Map控件的名称。选择前面的添加的Map控件的名称,默认的情况下是:Map1.

6:From the AJAX Extensions section of the Visual Studio toolbox, drag
an UpdatePanel onto the page and drop it below the toolbar. We will use
this to enable AJAX functionality for the two drop-down lists that will
specify the resource and layer to select features from.

从VS中的AJAX扩展工具箱里面拖拽一个更新控件到页面,并把她放置到工具条的下面。我们将要用这个控件来实现两个下拉框的AJAX功能,他们分贝指向我们能选择到的资源和图层。

7:Drag a DropDownList control from the Standard section of the Visual
Studio toolbox and drop it in the UpdatePanel. On the menu that appears,
check the Enable AutoPostBack item. This will make it so that the
DropDownList issues a postback when a new item is selected at run time.
And because we are placing the control within an UpdatePanel, the
postback will be an asynchronous partial postback, rather than a full
page postback. This DropDownList will be used to specify the map
resource to select features from.

从VS的标准工具象部分选择一个下拉框控件到异步面板控件,在出现的菜单中,选择AutoPostBack项为Enable属性。在运行的状态下当下拉框中选择的项改变后,控件就会随时发回一个回调的事件。因为我们把控件放置到异步更新的面板上面,回调事件将会是一个异步事件,而不是一个全页面刷新事件。这个下拉框将会指定我们可以从中选择要素的地图资源。

8:Drag and drop another DropDownList into the UpdatePanel. Enable
AutoPostBack for this list as well. We will use this control to specify
the layer to select features from. In design view, the application
should appear as shown in the figure below.

拖放另一个下拉框控件到异步更新面板,同样的设置她的AutoPostBack属性为Eable,我们将用这个下拉框来制定我们要从中选择要素的图层。在设计视图下,这个应用程序应该如下图所示的布局。

Implementing Page and Control Event Handlers

实现页面和控件的事件处理函数。

In configuring our application user interface, we added two DropDownList
controls to allow users to specify the resource and layer to select
features from, and a TaskResults control to display the attributes of
selected features. The DropDownLists won抰 contain any items
out-of-the-box, so we抣l have to explicitly initialize them with the
names of the application抯 resources and layers. We also want the layers
list to dynamically update any time a new resource is selected, which
will require some code as well. As for the TaskResults control, since we
want to use it to display our custom tool抯 results, we need to somehow
give our custom tool access to it. We can implement logic to handle all
of these requirements in the Default page抯 code-behind class. 

在配置我们应用程序接口的中,我们添加了两个下拉框来允许用户制定我们选择要素的数据源以及相应的图层,以及用来显示我们选择要素属性的任务结果控件。下拉框不会显示在工具箱外边显示任何的选项,因此我们需要明确用应用程序相关的资源以及图层来的初始化他们。我们当然还想要当一个新的资源被选择后,图层的列表会自动的更新,当然这个可能需要一些代码来辅助实现。对于任务结果窗口,因为我们需要她来显示用户工具的查询结果,因此我们需要让用户工具能够访问她,在后台的代码中,我们逻辑上可以实现处理来自于于默认页面的任何请求

相关文章