globallabo
asked on
How focus to IE window by API
Hello every one
I create a add-on for IE7. The focus of my add-on is auto print html page without print dialog
I have 1 problem please help me. This is my code:
Win32Lib.cs
class Win32Lib
{
[DllImport("User32.dll", CharSet = CharSet.Auto)]
public static extern Int32 FindWindow(string lpClassName, string lpWindowName);
[DllImport("User32.dll", CharSet = CharSet.Auto)]
public static extern Int32 PostMessageA(Int32 hwnd, Int32 wMsg, Int32 wParam, Int32 lParam);
[DllImport("User32.dll", CharSet = CharSet.Auto)]
public static extern Int32 BringWindowToTop(Int32 hwnd);
[DllImport("User32.dll", CharSet = CharSet.Auto)]
public static extern Int32 SetForegroundWindow(Int32 hwnd);
[DllImport("User32.dll", CharSet = CharSet.Auto)]
public static extern Int32 SetActiveWindow(Int32 hwnd);
}
file PrintTool.cs
public class Download : IDownload
{
/// <summary>
/// COM exposed Method.
/// </summary>
///
public const Int32 BM_CLICK = 0xF5;
public const Int32 VK_MENU = 0x12;
public const Int32 VK_F = 0x46;
public const Int32 VK_P = 0x50;
public void InvokeMethod(string inputTest)
{
Int32 hMain, sButton;
hMain = Win32Lib.FindWindow("IEFra me", "TestPrint - Windows Internet Explorer");
if (hMain != 0)
{
//Win32Lip.BringWindowToTo p(hMain);
//hMain = Win32Lib.FindWindowEx(hMai n, 0, "TabWindowClass", null);
// hMain = Win32Lib.FindWindowEx(hMai n, 0, "Shell DocObject View", null);
//hMain = Win32Lib.FindWindowEx(hMai n, 0, "Internet Explorer_Server", null);
Win32Lib.SetForegroundWind ow(hMain);
// Win32Lib.SetActiveWindow(h Main);
//SendKeys.SendWait("^(p)" );
System.Threading.Thread.Sl eep(2000);
SendKeys.SendWait("^{p}");
hMain = Win32Lib.FindWindow("#3277 0", "Print");
sButton = Win32Lib.FindWindowEx(hMai n, 0, "Button", "&Print");
Win32Lib.PostMessageA(sBut ton, BM_CLICK, 0, 0);
}
}
}
My add-on can run correct when i call another page, example click a button on Page A print Page B
but it can't run correct when print itself , example click a button on Page A and print Page A
Please help me, thank you
I create a add-on for IE7. The focus of my add-on is auto print html page without print dialog
I have 1 problem please help me. This is my code:
Win32Lib.cs
class Win32Lib
{
[DllImport("User32.dll", CharSet = CharSet.Auto)]
public static extern Int32 FindWindow(string lpClassName, string lpWindowName);
[DllImport("User32.dll", CharSet = CharSet.Auto)]
public static extern Int32 PostMessageA(Int32 hwnd, Int32 wMsg, Int32 wParam, Int32 lParam);
[DllImport("User32.dll", CharSet = CharSet.Auto)]
public static extern Int32 BringWindowToTop(Int32 hwnd);
[DllImport("User32.dll", CharSet = CharSet.Auto)]
public static extern Int32 SetForegroundWindow(Int32 hwnd);
[DllImport("User32.dll", CharSet = CharSet.Auto)]
public static extern Int32 SetActiveWindow(Int32 hwnd);
}
file PrintTool.cs
public class Download : IDownload
{
/// <summary>
/// COM exposed Method.
/// </summary>
///
public const Int32 BM_CLICK = 0xF5;
public const Int32 VK_MENU = 0x12;
public const Int32 VK_F = 0x46;
public const Int32 VK_P = 0x50;
public void InvokeMethod(string inputTest)
{
Int32 hMain, sButton;
hMain = Win32Lib.FindWindow("IEFra
if (hMain != 0)
{
//Win32Lip.BringWindowToTo
//hMain = Win32Lib.FindWindowEx(hMai
// hMain = Win32Lib.FindWindowEx(hMai
//hMain = Win32Lib.FindWindowEx(hMai
Win32Lib.SetForegroundWind
// Win32Lib.SetActiveWindow(h
//SendKeys.SendWait("^(p)"
System.Threading.Thread.Sl
SendKeys.SendWait("^{p}");
hMain = Win32Lib.FindWindow("#3277
sButton = Win32Lib.FindWindowEx(hMai
Win32Lib.PostMessageA(sBut
}
}
}
My add-on can run correct when i call another page, example click a button on Page A print Page B
but it can't run correct when print itself , example click a button on Page A and print Page A
Please help me, thank you
How does it fail?
ASKER
Thank you for your comment.
The function not auto print for me ( print without dialog). I call this function via javascript
But there is a strange. When i call this function, then i click to URL bar. The function run correct :(. I think there is some thing wrong with SetForegroundWindow API window i use
The function not auto print for me ( print without dialog). I call this function via javascript
But there is a strange. When i call this function, then i click to URL bar. The function run correct :(. I think there is some thing wrong with SetForegroundWindow API window i use
ASKER
No expert can help me :(( . Please.
I am interested if you found the solution or not.
Also I am trying to find url of running IE 7 using similar methods, but failed to retrieve it. I am wondering if you have any suggestion.
Thanks!
Also I am trying to find url of running IE 7 using similar methods, but failed to retrieve it. I am wondering if you have any suggestion.
Thanks!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.