Skip to content

Commit

Permalink
Release ver 1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
ChenglongMa committed May 7, 2020
1 parent fcb43ae commit 777af13
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 6 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -348,3 +348,5 @@ MigrationBackup/

# Ionide (cross platform F# VS Code tools) working folder
.ionide/
/AutoIME安装使用说明.pdf
/AutoIME.zip
77 changes: 73 additions & 4 deletions AutoIME/AutoIME/Program.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Runtime;
using System;
using System.Runtime.InteropServices;
using System.Text;
using System.Windows.Forms;
using AcadApplication = Autodesk.AutoCAD.ApplicationServices.Application;

Expand All @@ -9,8 +12,33 @@ namespace AutoIME
{
public class Program : IExtensionApplication
{
//delegate void WinEventDelegate(IntPtr hWinEventHook, uint eventType, IntPtr hwnd, int idObject, int idChild, uint dwEventThread, uint dwmsEventTime);

//[DllImport("user32.dll")]
//static extern IntPtr SetWinEventHook(uint eventMin, uint eventMax, IntPtr hmodWinEventProc, WinEventDelegate lpfnWinEventProc, uint idProcess, uint idThread, uint dwFlags);

//private const uint WINEVENT_OUTOFCONTEXT = 0;
//private const uint EVENT_SYSTEM_FOREGROUND = 3;
//[DllImport("user32.dll")]
//static extern IntPtr GetForegroundWindow();

//[DllImport("user32.dll")]
//static extern IntPtr GetActiveWindow();

//[DllImport("user32.dll")]
//static extern int GetWindowText(IntPtr hWnd, StringBuilder text, int count);

//[DllImport("user32.dll", SetLastError = true)]
//static extern uint GetWindowThreadProcessId(IntPtr hWnd, out uint lpdwProcessId);

//[DllImport("user32.dll", ExactSpelling = true, CharSet = CharSet.Auto)]
//public static extern IntPtr GetParent(IntPtr hWnd);

//static WinEventDelegate dele = null;


public const string AppName = "AutoIME";
public static readonly Editor Editor = AcadApplication.DocumentManager.MdiActiveDocument.Editor;
public static Editor Editor => AcadApplication.DocumentManager.MdiActiveDocument.Editor;
private readonly Config _config = Config.GetConfigInstance();

[CommandMethod("iAutoIME")]
Expand All @@ -31,7 +59,7 @@ public static void Uninstall()
{
Editor.WriteMessage("================<<卸载开始>>================\n");
UnregisterApp();
// unbind command
Setup.UnbindCommandToDoc(AcadApplication.DocumentManager.MdiActiveDocument);
Editor.WriteMessage("================<<卸载完成>>================\n");
}

Expand Down Expand Up @@ -66,6 +94,12 @@ public static void UnregisterApp()
Editor.WriteMessage("================<<注销成功>>================\n");
}

internal static void TearDown()
{
Config.GetConfigInstance().Switch2DefaultIME();
//dele = null;
}

[CommandMethod("SetIME")]
public static void SetIME()
{
Expand All @@ -92,16 +126,51 @@ public static void SetIME()

public void Initialize()
{
//dele = new WinEventDelegate(WinEventProc);
//IntPtr m_hhook = SetWinEventHook(EVENT_SYSTEM_FOREGROUND, EVENT_SYSTEM_FOREGROUND, IntPtr.Zero, dele, 0, 0, WINEVENT_OUTOFCONTEXT);
_config.Initialize();
_config.Switch2CommandIME();
Setup.InitialBinding();
AppDomain currentDomain = AppDomain.CurrentDomain;
currentDomain.UnhandledException += CurrentDomain_UnhandledException;


Editor.WriteMessage("================<<AutoIME 初始化完成>>================\n");
}

private void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs args)
{
System.Exception e = (System.Exception)args.ExceptionObject;
System.IO.File.AppendAllText(@"autoimeerror.txt", e.Message);
System.IO.File.AppendAllText(@"autoimeerror.txt", e.StackTrace);
System.IO.File.AppendAllText(@"autoimeerror.txt", "\n");
}

//private string GetActiveWindowTitle()
//{
// const int nChars = 256;
// IntPtr handle = IntPtr.Zero;
// StringBuilder Buff = new StringBuilder(nChars);
// handle = GetForegroundWindow();
// if (GetWindowText(handle, Buff, nChars) > 0)
// {
// return Buff.ToString();
// }
// return null;
//}

//private void WinEventProc(IntPtr hWinEventHook, uint eventType, IntPtr hwnd, int idObject, int idChild, uint dwEventThread, uint dwmsEventTime)
//{
// var threadID = GetWindowThreadProcessId(GetForegroundWindow(), out uint processID);
// var title = GetActiveWindowTitle();
// var lines = $"PID: {processID} TID: {threadID} Title: {title}\n";

// System.IO.File.AppendAllText(@"gettitle.txt", lines);
//}

public void Terminate()
{
_config.Switch2DefaultIME();
TearDown();

}
}
Expand Down
2 changes: 1 addition & 1 deletion AutoIME/AutoIME/Setup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ private static void DocumentManager_DocumentDestroyed(object sender, DocumentDes

private static void QuitWillStart(object sender, EventArgs e)
{
_config.Switch2DefaultIME();
Program.TearDown();
}

public static void UnbindCommandToDoc(AcadDocument doc)
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,6 @@
2. `rhfa` -- 此为 “卸载” 的五笔编码
3. `xzAutoIME` -- `xz`为 ”卸载“ 拼音首字母

2. 显示以下信息即为安装成功
2. 显示以下信息即为卸载成功

![image-20200504231359788](README/image-20200504231359788.png)

0 comments on commit 777af13

Please sign in to comment.