AutoCAD.net(一):更改AutoCAD窗口的标题和图标
对AutoCAD二次开发方向的发展,是我为从事.net前就有的愿望,现在.net + ObjectARX 已经形成很完美的结合,遗憾的是目前国内关于.net对 ObjectARX 开发的资料太少。我会将自己的学习经验不断的与大家分享,希望关注。
WinAPI的引用:
效果图:
WinAPI的引用:
public class WinAPI
{
#region 宏定义
public const int WM_SETICON = 0x80;
public const int IMAGW_ICON = 1;
public const int LR_LOADFROMFILE = 0x10;
#endregion
#region WinAPI定义
[DllImport("User32.dll", EntryPoint = "SendMessage")]
public static extern int SendMessage(
int hWnd, // handle to destination window
int Msg, // message
int wParam, // first message parameter
int lParam // second message parameter
);
[DllImport("user32", EntryPoint = "LoadImage")]
public static extern int LoadImageA(int hInst, string lpsz, int un1, int n1, int n2, int un2);
[DllImport("user32", EntryPoint = "SetWindowText")]
public static extern int SetWindowTextA(int hwnd, string lpString);
#endregion
}
{
#region 宏定义
public const int WM_SETICON = 0x80;
public const int IMAGW_ICON = 1;
public const int LR_LOADFROMFILE = 0x10;
#endregion
#region WinAPI定义
[DllImport("User32.dll", EntryPoint = "SendMessage")]
public static extern int SendMessage(
int hWnd, // handle to destination window
int Msg, // message
int wParam, // first message parameter
int lParam // second message parameter
);
[DllImport("user32", EntryPoint = "LoadImage")]
public static extern int LoadImageA(int hInst, string lpsz, int un1, int n1, int n2, int un2);
[DllImport("user32", EntryPoint = "SetWindowText")]
public static extern int SetWindowTextA(int hwnd, string lpString);
#endregion
}
using System;
using System.IO;
//using Microsoft.Win32;
using System.Collections;
using System.Windows.Forms;
using System.Resources;
using Autodesk.AutoCAD.ApplicationServices;
using AcadApp = Autodesk.AutoCAD.ApplicationServices.Application;
using Autodesk.AutoCAD.Colors;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.Windows;
using Autodesk.AutoCAD.Interop;
using Autodesk.AutoCAD.Interop.Common;
using Autodesk.AutoCAD.Customization;
public class AsdkClass1 : IExtensionApplication
{
#region 实现接口函数,完成初始化操作
//要实现这个接口,你必须实现Initialize() 和Terminate()函数。
/// <summary>
/// 初始化操作
/// </summary>
public void Initialize()
{
//--------------------
//AddContextMenu();
//AddToolbar();
//AddMenuBar();
SetTitle();
SetIcon();
//--------------------
}
/// <summary>
/// 清除操作
/// </summary>
public void Terminate()
{
}
#endregion
#region 更改AutoCAD窗口的标题和图标
/// <summary>
/// 更改AutoCAD窗口的标题名称
/// </summary>
private void SetTitle()
{
AcadApplication acadApp = AcadApp.AcadApplication as AcadApplication;
int AcadHwnd = acadApp.HWND;//获取AutoCAD应用程序的窗口句柄
WinAPI.SetWindowTextA(AcadHwnd, "明信供电CAD 2.0");
}
/// <summary>
/// 更改AutoCAD窗口的图标
/// </summary>
private void SetIcon()
{
AcadApplication acadApp = AcadApp.AcadApplication as AcadApplication;
int AcadHwnd = acadApp.HWND;//获取AutoCAD应用程序的窗口句柄
string path = acadApp.Path;
//从文件载入图标(16*16大小)
string FileName = "G:\\cad.ico";
if (File.Exists(FileName))
{
int hIcon = WinAPI.LoadImageA(0, FileName, WinAPI.IMAGW_ICON, 16, 16, WinAPI.LR_LOADFROMFILE);
if (hIcon != 0)
{
WinAPI.SendMessage(AcadHwnd, WinAPI.WM_SETICON, 0, hIcon);
}
}
}
#endregion
}
using System.IO;
//using Microsoft.Win32;
using System.Collections;
using System.Windows.Forms;
using System.Resources;
using Autodesk.AutoCAD.ApplicationServices;
using AcadApp = Autodesk.AutoCAD.ApplicationServices.Application;
using Autodesk.AutoCAD.Colors;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.Windows;
using Autodesk.AutoCAD.Interop;
using Autodesk.AutoCAD.Interop.Common;
using Autodesk.AutoCAD.Customization;
public class AsdkClass1 : IExtensionApplication
{
#region 实现接口函数,完成初始化操作
//要实现这个接口,你必须实现Initialize() 和Terminate()函数。
/// <summary>
/// 初始化操作
/// </summary>
public void Initialize()
{
//--------------------
//AddContextMenu();
//AddToolbar();
//AddMenuBar();
SetTitle();
SetIcon();
//--------------------
}
/// <summary>
/// 清除操作
/// </summary>
public void Terminate()
{
}
#endregion
#region 更改AutoCAD窗口的标题和图标
/// <summary>
/// 更改AutoCAD窗口的标题名称
/// </summary>
private void SetTitle()
{
AcadApplication acadApp = AcadApp.AcadApplication as AcadApplication;
int AcadHwnd = acadApp.HWND;//获取AutoCAD应用程序的窗口句柄
WinAPI.SetWindowTextA(AcadHwnd, "明信供电CAD 2.0");
}
/// <summary>
/// 更改AutoCAD窗口的图标
/// </summary>
private void SetIcon()
{
AcadApplication acadApp = AcadApp.AcadApplication as AcadApplication;
int AcadHwnd = acadApp.HWND;//获取AutoCAD应用程序的窗口句柄
string path = acadApp.Path;
//从文件载入图标(16*16大小)
string FileName = "G:\\cad.ico";
if (File.Exists(FileName))
{
int hIcon = WinAPI.LoadImageA(0, FileName, WinAPI.IMAGW_ICON, 16, 16, WinAPI.LR_LOADFROMFILE);
if (hIcon != 0)
{
WinAPI.SendMessage(AcadHwnd, WinAPI.WM_SETICON, 0, hIcon);
}
}
}
#endregion
}
效果图: