Hello Yanhong Huang,
first thanks a lot for your succesfull help!
I do still post this question here, because now
my problems do not really relate to the IExplorer.
I installed now some hooks to get the messages from
the created windows and therefor I can catch now
wether the user prints or does not print.
BUT now I have a problem with operating system related
"features" ...
Information:
I do identify the user action via my own member:
DialogResult.
Therefor e.g. if the user pushes the "Print" button
within the Printer Dialog I do get this hook and know
now, that the user printed out some stuff.
FIRST PROBLEM:
==============
If the user opens the "Page Setup" I could not find out
a difference between the "Print" and "OK" button.
Therfor I took a look at the WindowTitle, BUT the title
is operating system language depended => therefor thats
BAD!
SECOND PROBLEM:
===============
The main point is, that I have to catch following actions:
1.) The user pushes the "Print" button.
2.) The user pushes the key <ALT>D.
3.) The user pushes <ENTER>.
ad. 1) The "Print" button can be identified via
ID = [OK-ID] ... therefor no language problem.
ad. 2) The <ALT> key kombination depends on the
operating system language ... !?
What can I do here?
ad. 3) If the user pushes <ENTER> it's the same
functionality as pushing the "Print" button.
... should be no problem.
How can I solve the above mentioned problems, so that
I can uniqually identify the difference between
printing and pagesetup dialog without taking care
of the operating system language?
Thanks in advance for your great help!!!
P.S.:
Here you have got my hook functionality:
private void HookEventHandler(object sender,
MsdnMag.HookEventArgs e)
{
StringBuilder sbHelper = new StringBuilder
();
string sWindowText = null;
sbHelper.Capacity = 256;
switch (e.HookCode)
{
case (int)HookEnumerations.HCBT_CREATEWND:
{
if (m_hWnd == (IntPtr)null)
{
m_hWnd = this.Handle; // e.wParam;
}
break;
}
case (int)
HookEnumerations.HCBT_DESTROYWND:
{
GetClassName(e.wParam, sbHelper, 256);
sWindowText = sbHelper.ToString();
/*
GetWindowText(e.wParam, sbHelper,
sbHelper.Capacity);
sWindowText = sbHelper.ToString();
if (sWindowText.CompareTo("Drucken")
== 0)
*/
// this is tricky ... hopefully it
works with
// ALL operating system languages :-(
if (sWindowText.CompareTo
("tooltips_class32") == 0)
{
m_bResultValid = true;
}
//else if (sWindowText.CompareTo
("Seite einrichten") == 0)
else if (sWindowText.CompareTo
("ComboLBox") == 0)
{
m_bResultValid = false;
}
break;
}
case (int)HookEnumerations.HCBT_SETFOCUS:
m_hWndFocusWindow = e.wParam;
//Console.WriteLine("SetFocus: " +
e.wParam.ToString());
break;
case (int)
HookEnumerations.HCBT_KEYSKIPPED:
{
int iKey = (int)e.wParam;
switch (iKey)
{
case (int)Keys.Enter:
GetWindowText
(m_hWndFocusWindow, sbHelper, sbHelper.Capacity);
sWindowText =
sbHelper.ToString();
//if (sWindowText.CompareTo
("Drucken") == 0)
{
int iCtrlID = GetDlgCtrlID
(m_hWndFocusWindow);
if (iCtrlID == (int)
ButtonEnumeration.IDD_CANCEL)
{
m_DialogResult =
DialogResult.Cancel;
}
else if (iCtrlID == (int)
ButtonEnumeration.IDD_PRINT)
{
m_DialogResult =
DialogResult.OK;
}
}
break;
case (int)18: // KeyCode for ALT
int iUp = ( (int)e.lParam >>
31 ) & 1;
if (iUp == 1) m_bAltPressed =
false;
else m_bAltPressed = true;
break;
case (int)Keys.P:
case (int)Keys.D:
// English: Print (ALT-P),
// German: Drucken (ALT-D)
if (m_bAltPressed == true)
m_DialogResult =
DialogResult.OK;
break;
default:
Console.WriteLine("Key: " +
e.wParam.ToString());
break;
}
break;
}
case (int)
HookEnumerations.HCBT_CLICKSKIPPED:
{
MOUSEHOOKSTRUCT msStruct = new
MOUSEHOOKSTRUCT();
Marshal.PtrToStructure(e.lParam,
msStruct);
GetWindowText(m_hWndFocusWindow,
sbHelper, sbHelper.Capacity);
sWindowText = sbHelper.ToString();
//if (sWindowText.CompareTo
("Drucken") == 0)
{
if ((int)e.wParam == (int)
MouseEnumerations.WM_LBUTTONUP)
{
int iCtrlID = GetDlgCtrlID
(msStruct.hwnd);
if (iCtrlID == (int)
ButtonEnumeration.IDD_CANCEL)
{
m_DialogResult =
DialogResult.Cancel;
}
else if (iCtrlID == (int)
ButtonEnumeration.IDD_PRINT)
{
m_DialogResult =
DialogResult.OK;
}
// Get the static window with
the text and the text
/*
StringBuilder sb = new
StringBuilder();
sb.Capacity = 256;
GetWindowText(msStruct.hwnd,
sb, 256);
string text = sb.ToString();
Console.WriteLine(e.ToString
() + " Code:" + e.HookCode.ToString() + " WindowText: " +
text + " wParam: " + e.wParam.ToString());
*/
}
}
break;
}
default:
break;
}
}
[color=blue]
>-----Originalnachricht-----
>Hello Martin,
>
>Thanks for the quick response.
>
>In order to program Win32 Hook in a .NET Winform[/color]
application, we need to[color=blue]
>use PInvoke to call Win32 APIs. There is a good MSDN[/color]
article in this area.[color=blue]
>It introduces how to use Hook in .NET winform[/color]
applications.[color=blue]
>"Windows Hooks in the .NET Framework"
>
http://msdn.microsoft.com/msdnmag/is.../11/CuttingEdg[/color]
e/TOC.ASP?frame=tru[color=blue]
>e
>
>This is a good link to start. There is no existing[/color]
sample code specially on[color=blue]
>this problem. If you want a code sample, I suggest you[/color]
contact Microsoft[color=blue]
>Product Support Service to have one engineer work with[/color]
you on it.[color=blue]
>
>To obtain the telephone numbers for specific technology,[/color]
please review this[color=blue]
>web site:
>
http://support.microsoft.com/default.aspx?scid=fh;EN-[/color]
US;PHONENUMBERS[color=blue]
>
>If you are outside the US, you can find regional[/color]
telephone support numbers[color=blue]
>at
http://support.microsoft.com.
>
>Please post here if you have any more concerns. Thanks[/color]
very much for your[color=blue]
>understanding.
>
>Best regards,
>Yanhong Huang
>Microsoft Online Partner Support
>
>Get Secure! -
www.microsoft.com/security
>This posting is provided "AS IS" with no warranties, and[/color]
confers no rights.[color=blue]
>
>.
>[/color]