Howto: 如何在独立的ArcGIS应用程序中动态地停止Windows Aero theme?

文章编号 : 38465
软件: ArcGIS - ArcEditor 9.3.1, 10 ArcGIS - ArcInfo 9.3.1, 10 ArcGIS - ArcView 9.3.1, 10 ArcGIS Engine Developer Kit 9.3.1, 10 ArcGIS
操作系统: Windows Vista, Win 7
已邀请:

易智瑞技术支持

赞同来自:

摘要:
如何在独立的ArcGIS应用程序中动态地停止Windows Aero theme?
内容:
在运行独立的ArcGIS应用程序时,记得在程序运行期间关闭Windows Aero theme。因为有时Windows Aero theme会导致一些显示上的问题,特别在使用动态图层和显示3D模型时。
以下是采用windows API向独立的.net应用程序里加代码,以关闭windows Aero theme。当应用程序关闭时,windows Aero theme将自动恢复。 以下C#写法: using System;
using System.Collections.Generic;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using ESRI.ArcGIS;

namespace MyApp
{
static class Program
{
[DllImport("kernel32", SetLastError = true)]
static extern IntPtr LoadLibrary(string lpFileName);
[DllImport("kernel32", CharSet = CharSet.Ansi, ExactSpelling = true, SetLastError = true)]
static extern IntPtr GetProcAddress(IntPtr hModule, string procName);
internal delegate int DwmEnableComposition(int enable);

[STAThread]
static void Main()
{
if (!RuntimeManager.Bind(ProductCode.Engine))
{
if (!RuntimeManager.Bind(ProductCode.Desktop))
{
MessageBox.Show("Unable to bind to ArcGIS runtime. Application will be shut down.");
return;
}
}
DisableAeroDesktopWindowManager();
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new MainForm());
}

private static void DisableAeroDesktopWindowManager()
{

IntPtr pDll = IntPtr.Zero;
try
{
// Load the Desktop Windows Manger library, if the library does not exist
// then bail out because we are on an OS older than Vista.
pDll = LoadLibrary("dwmapi.dll");
if (pDll == IntPtr.Zero)
return;

// Get the DwmEnableComposition Function
IntPtr pFunc = GetProcAddress(pDll, "DwmEnableComposition");
if (pFunc == IntPtr.Zero)
return;


DwmEnableComposition enableDwm = (DwmEnableComposition)System.Runtime.InteropServices.Marshal.GetDelegateForFunctionPointer(pFunc, typeof(DwmEnableComposition));
if (enableDwm == null) return;
{
// Disable Desktop Window Manager
enableDwm(0);
}
}
catch
{
//Todo: log error
}

}

}
}
以下是VB.Net写法: Imports System.Runtime.InteropServices

Namespace My

Partial Friend Class MyApplication

<DllImport("kernel32", SetLastError:=True)> _
Public Shared Function LoadLibrary(ByVal lpFileName As String) As IntPtr
End Function
<DllImport("kernel32", CharSet:=CharSet.Ansi, ExactSpelling:=True, SetLastError:=True)> _
Public Shared Function GetProcAddress(ByVal hModule As IntPtr, ByVal procName As String) As IntPtr
End Function
Friend Delegate Function DwmEnableComposition(ByVal enable As Integer) As Integer


Private Sub MyApplication_Startup(ByVal sender As Object, ByVal e As Microsoft.VisualBasic.ApplicationServices.StartupEventArgs) Handles Me.Startup
If Not ESRI.ArcGIS.RuntimeManager.Bind(ESRI.ArcGIS.ProductCode.Engine) Then
If Not ESRI.ArcGIS.RuntimeManager.Bind(ESRI.ArcGIS.ProductCode.Desktop) Then
MessageBox.Show("Unable to bind to ArcGIS runtime. Application will be shut down.")
e.Cancel = True 'Abort application start up
End If
End If

DisableAeroDesktopWindowManager()


End Sub

Private Sub DisableAeroDesktopWindowManager()
Dim pDll As IntPtr = IntPtr.Zero
Try
pDll = LoadLibrary("dwmapi.dll")
If (pDll = IntPtr.Zero) Then
Return
End If
' Get the DwmEnabledComposition Function
Dim pFunc As IntPtr = GetProcAddress(pDll, "DwmEnableComposition")
If (pFunc = IntPtr.Zero) Then
Return
End If
Dim enableDwm As DwmEnableComposition
enableDwm = DirectCast(System.Runtime.InteropServices.Marshal.GetDelegateForFunctionPointer(pFunc, GetType(DwmEnableComposition)), DwmEnableComposition)
If (enableDwm Is Nothing) Then
Return
End If
' Disable Desktop Window Manager
enableDwm(0)
Catch
'Todo: log error
End Try

End Sub

End Class

End Namespace





创建时间:2010-05-11
最近更新: 2011-03-30


原文链接
http://support.esrichina.com.c ... .html

要回复问题请先登录注册