Browse Source
git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@1416 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61shortcuts
5 changed files with 26 additions and 279 deletions
@ -1,62 +0,0 @@ |
|||||||
// Button for adding a hook to the selected form |
|
||||||
Button b1 = new Button(); |
|
||||||
b1.Location = new Point(400, 200); |
|
||||||
b1.Text = "Add Hook"; |
|
||||||
b1.Click += new System.EventHandler(this.AddHookButton_Click); |
|
||||||
this.Controls.Add(b1); |
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// CallWndProc callback = new CallWndProc(HookProc); |
|
||||||
// GetMsgProc callback = new GetMsgProc(HookProc); |
|
||||||
MessageProc callback = new MessageProc(HookProc); |
|
||||||
int modHandle = Windows.GetModuleHandle(null); |
|
||||||
DebugMessage("Module handle: " + modHandle); |
|
||||||
// int ret = Windows.SetWindowsHookEx(Windows.WH_CALLWNDPROC, callback, |
|
||||||
// int ret = Windows.SetWindowsHookEx(Windows.WH_GETMESSAGE, callback, |
|
||||||
int ret = Windows.SetWindowsHookEx(Windows.WH_MSGFILTER, callback, |
|
||||||
modHandle, 0); |
|
||||||
if (ret == 0) |
|
||||||
DebugMessage("Error adding hook: " + Windows.GetLastErrorText()); |
|
||||||
else |
|
||||||
DebugMessage("Added hook " + ret); |
|
||||||
} |
|
||||||
|
|
||||||
|
|
||||||
// public int HookProc(int nCode, int wParam, Windows.CWPSTRUCT lParam) |
|
||||||
public int HookProc(int nCode, int wParam, int lParam) |
|
||||||
{ |
|
||||||
// for (int i = 0; i < HookedWindows.Count; i++) |
|
||||||
{ |
|
||||||
// if ((int)HookedWindows[i] == lParam.hWnd) |
|
||||||
{ |
|
||||||
//HookedMessages.Enqueue(lParam); |
|
||||||
// DebugMessage("Hook Called: hWnd: " + lParam.hWnd |
|
||||||
DebugMessage("Hook Called: hWnd: " |
|
||||||
+ " code: " + nCode |
|
||||||
+ " wParam: " + wParam |
|
||||||
+ " lParam: " + lParam); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
if (nCode < 0) |
|
||||||
return Windows.CallNextHookEx(0, nCode, wParam, lParam); |
|
||||||
return 0; |
|
||||||
} |
|
||||||
|
|
||||||
|
|
||||||
protected void AddHookButton_Click (object sender, System.EventArgs e) |
|
||||||
{ |
|
||||||
MainTreeNode node = (MainTreeNode)this.MainTree.SelectedNode; |
|
||||||
|
|
||||||
DebugMessage("add hook " + node); |
|
||||||
|
|
||||||
HookedMessages = new Queue(); |
|
||||||
if (node.WindowInfo != null) |
|
||||||
{ |
|
||||||
HookedWindows.Add(node.WindowInfo.hWnd); |
|
||||||
} |
|
||||||
|
|
||||||
} |
|
||||||
|
|
@ -1,187 +0,0 @@ |
|||||||
using System; |
|
||||||
using System.Collections; |
|
||||||
using System.Diagnostics; |
|
||||||
using System.Runtime.InteropServices; |
|
||||||
using System.Reflection; |
|
||||||
using System.Text; |
|
||||||
using System.Threading; |
|
||||||
using System.Windows.Forms; |
|
||||||
|
|
||||||
using NoGoop.win32; |
|
||||||
using Access; |
|
||||||
|
|
||||||
namespace NoGoop.objb |
|
||||||
{ |
|
||||||
|
|
||||||
|
|
||||||
public class FormInfo |
|
||||||
{ |
|
||||||
public Access.Form Form; |
|
||||||
public int WindowHandle; |
|
||||||
public string WindowName; |
|
||||||
|
|
||||||
public override String ToString() |
|
||||||
{ |
|
||||||
return Form.Name + " win: 0x" |
|
||||||
+ WindowHandle.ToString("X") + ":" + WindowName; |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
|
|
||||||
public class TestDriver |
|
||||||
{ |
|
||||||
|
|
||||||
private Access.Application AccessApp; |
|
||||||
|
|
||||||
private static ArrayList WindowList; |
|
||||||
|
|
||||||
// For locking at the class level |
|
||||||
private static Object Lock; |
|
||||||
|
|
||||||
static TestDriver() |
|
||||||
{ |
|
||||||
Lock = new Object(); |
|
||||||
} |
|
||||||
|
|
||||||
|
|
||||||
public TestDriver() |
|
||||||
{ |
|
||||||
} |
|
||||||
|
|
||||||
public IList GetForms() |
|
||||||
{ |
|
||||||
ArrayList forms = new ArrayList(); |
|
||||||
IEnumerator en = AccessApp.Forms.GetEnumerator(); |
|
||||||
|
|
||||||
while (en.MoveNext()) |
|
||||||
{ |
|
||||||
forms.Add(System.Runtime.InteropServices.Marshal. |
|
||||||
CreateWrapperOfType(en.Current, typeof(Access.Form))); |
|
||||||
// forms.Add(en.Current); |
|
||||||
} |
|
||||||
return forms; |
|
||||||
} |
|
||||||
|
|
||||||
public IList GetFormInfoList() |
|
||||||
{ |
|
||||||
ArrayList forms = new ArrayList(); |
|
||||||
IEnumerator en = GetForms().GetEnumerator(); |
|
||||||
|
|
||||||
while (en.MoveNext()) |
|
||||||
{ |
|
||||||
FormInfo fi = new FormInfo(); |
|
||||||
fi.Form = (Access.Form)en.Current; |
|
||||||
fi.WindowHandle = fi.Form.Hwnd; |
|
||||||
fi.WindowName = Windows.GetWindowText(fi.WindowHandle); |
|
||||||
forms.Add(fi); |
|
||||||
} |
|
||||||
return forms; |
|
||||||
} |
|
||||||
|
|
||||||
public int GetTopWindow() |
|
||||||
{ |
|
||||||
return AccessApp.hWndAccessApp(); |
|
||||||
} |
|
||||||
|
|
||||||
|
|
||||||
public Object GetTopObject() |
|
||||||
{ |
|
||||||
return AccessApp; |
|
||||||
} |
|
||||||
|
|
||||||
public IList GetChildWindows() |
|
||||||
{ |
|
||||||
return GetChildWindows(GetTopWindow()); |
|
||||||
} |
|
||||||
|
|
||||||
|
|
||||||
public IList GetChildWindows(int hWnd) |
|
||||||
{ |
|
||||||
ArrayList winList = new ArrayList(); |
|
||||||
GetChildWindows(hWnd, winList); |
|
||||||
return winList; |
|
||||||
} |
|
||||||
|
|
||||||
|
|
||||||
public void GetChildWindows(int hWnd, ArrayList winList) |
|
||||||
{ |
|
||||||
ArrayList SaveList = WindowList; |
|
||||||
|
|
||||||
// Since WindowList is an class variable, required because |
|
||||||
// its updated with a callback |
|
||||||
lock (Lock) |
|
||||||
{ |
|
||||||
WindowList = winList; |
|
||||||
EnumChildProc callback = new EnumChildProc(TestDriver.ChildWindow); |
|
||||||
Windows.EnumChildWindows(hWnd, callback, 0); |
|
||||||
|
|
||||||
WindowList.Sort(null); |
|
||||||
|
|
||||||
// Now get all of the children |
|
||||||
foreach (Windows.WindowInfo wi in winList) |
|
||||||
{ |
|
||||||
wi.Children = new ArrayList(); |
|
||||||
GetChildWindows(wi.hWnd, wi.Children); |
|
||||||
} |
|
||||||
|
|
||||||
WindowList = SaveList; |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
// This is the callback function, called by windows for each child |
|
||||||
private static bool ChildWindow(int hwnd, int lParam) |
|
||||||
{ |
|
||||||
WindowList.Add(Windows.GetWindowInfo(hwnd)); |
|
||||||
return true; |
|
||||||
} |
|
||||||
|
|
||||||
|
|
||||||
public bool CheckIfRunning() |
|
||||||
{ |
|
||||||
try |
|
||||||
{ |
|
||||||
|
|
||||||
// This is the same as a VB GetObject, more or less |
|
||||||
/*** |
|
||||||
Object o = |
|
||||||
System.Runtime.InteropServices.Marshal.GetActiveObject("Access.Application.9"); |
|
||||||
AccessApp = (Access.Application) |
|
||||||
System.Runtime.InteropServices.Marshal. |
|
||||||
CreateWrapperOfType(o, typeof(Access.Application)); |
|
||||||
|
|
||||||
Console.WriteLine("Found current access: " + AccessApp); |
|
||||||
|
|
||||||
****/ |
|
||||||
return true; |
|
||||||
} |
|
||||||
catch (Exception) |
|
||||||
{ |
|
||||||
Console.WriteLine("No current access running"); |
|
||||||
AccessApp = null; |
|
||||||
return false; |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
|
|
||||||
public void CreateNewAccess(string fileName) |
|
||||||
{ |
|
||||||
AccessApp = new Access.Application(); |
|
||||||
AccessApp.OpenCurrentDatabase(fileName, false); |
|
||||||
AccessApp.Visible = true; |
|
||||||
AccessApp.DoCmd.OpenForm("People", |
|
||||||
Access.AcFormView.acNormal, |
|
||||||
null, |
|
||||||
null, |
|
||||||
Access.AcFormOpenDataMode.acFormEdit, |
|
||||||
Access.AcWindowMode.acWindowNormal, ""); |
|
||||||
} |
|
||||||
|
|
||||||
[STAThread] |
|
||||||
public static void Main(string[] args) |
|
||||||
{ |
|
||||||
TestDriver td = new TestDriver(); |
|
||||||
td.CheckIfRunning(); |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
Loading…
Reference in new issue