Shortcut for Microsoft Word Document only

Add-in Express™ Support Service
That's what is more important than anything else

Shortcut for Microsoft Word Document only
 
Andrew Szczeszynski




Posts: 44
Joined: 2007-02-02
Hi all,

I'm using ADX .Net, enjoying it a lot, good work guys.

I have a question: I added a shortcut to Word that I wish to be active when the user is editing a document. The ADX shortcut is working fine, except that it is activated everywhere, even when editing properties of a property page edit box that I added. I only want the short-cut to work when editing a document - what's the best approach to this? (Is there a way to associate a short-cut with the Microsoft Word Document only? Is there a way to check if the user is currently editing the document, rather than some popup/dialog? etc.)

Thank you in advance,
Andrew Szczeszynski
Posted 04 Feb, 2007 23:50:46 Top
Sergey Grischenko


Add-in Express team


Posts: 7233
Joined: 2004-07-05
Hi Andrew.

Here is a workaround:


[DllImport("user32.dll")]
private static extern int GetWindowText(int hWnd, IntPtr lpString, int nMaxCount);

[DllImport("user32.dll")]
private static extern int GetActiveWindow();

private void adxKeyboardShortcut1_Action(object sender)
{
IntPtr lpBuffer = IntPtr.Zero;
try
{
int hwnd = GetActiveWindow();
lpBuffer = Marshal.AllocHGlobal(1024);
if (GetWindowText(hwnd, lpBuffer, 1024) > 0)
{
string text = Marshal.PtrToStringAnsi(lpBuffer);
if (text.IndexOf("Microsoft Word") > 0)
{
MessageBox.Show("The document is in the 'edit' mode.");
}
}
}
finally
{
if (lpBuffer != IntPtr.Zero)
Marshal.FreeHGlobal(lpBuffer);
}
}

P.S. Note that we take up your forum requests in the order we receive them.
Besides, it may take us some time to investigate your issue. Please be sure we will let you know as soon as the best possible solution is found.
Posted 05 Feb, 2007 10:12:26 Top