 |
|
 |
I usually use Environment.Exit(0) to close everything and any service running at the background by my application but, using directly Environment.Exit(0) causes crashes with this code.
what you should do when exiting your application is to first WindowsInterop.Unhook(); then use Environment.Exit(0) if you are my kind of lazy coder 
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
I've rewrite your example for Dialog "File download", but there is a problem. When I debug my project using breakpoints, everything is ok, but when I run .exe file this dialog is shown again!!! What's wrong??
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Without knowing all the conditions you are talking about it is hard to diagnose but, if you are running (without debug) on a different machine then it is possible the dialog has a slightly different title. This can happen if the IE versions you are loking at under the 2 different conditions (i.e. machines etc) are not exactly the same. Hope this helps.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
I loved this bit of code as it did exactly what I needed! However, the runtime of the code going through all of the messages has caused the webBrowser control to completely skip the onDocument_Complete event. Did you have any troubles like this? It seems to happen intermittently or when there are javascript errors on the page.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Sorry but it seems like ages since I worked on this and my memory is foggy!
I do vaguely remember getting issues with document complete not firing sometimes, but I don't believe that it was due to the hook code.
What I think might have caused it is when a page had references to an external domain and those parts of the page were not fully loading/loaded (for some unknown reason). Consequently, the Web Browser control would never fire the Document Complete event in those cases. We assumed that's why it seemed that the problem was only occurring sometimes whereas most of the time those same pages would load/fire the event just fine. Frustrating, I know!
Anyway, a good test would be to see if you get this occurring when you are not branching through this code (i.e. when the hooks are not engaged).
Also, another thing I noted was that the event won't fire when the WebBrowser Control is not visible (as per this[^] MS KB article), although I doubt this is your issue.
Good luck, I'll try to think of other possibilities and let you know here if anything springs back to mind.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Also,
This is quite likely very "hacky" and/or dodgy, but perhaps you could start a timer in the Navigating event handler for the particular page(s) giving you grief and if Document Complete hasn't fired in a 'reasonable' amount of time you could just ignore that fact and call your processing code as if it had anyway.
May not always work, but could possibly get you out of a bind if this is a real problem for you.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Thanks for the reply and advice!
I actually did find the same test to work completely once I commented out the hook code but I think it may be due to another reason. The page it was missing the Document_Complete event was a page with several javascript errors. I set the browser to suppress script errors and this nice bit of code still handles the security and connect windows But for whatever reason, the javascript errors still prevent the document_complete event from firing.
I stepped through step by step and noticed a lot more hooks had to be called which I'm guessing is because of the javascript errors? My only other idea was to have a check and a running boolean on the webBrowser_ProgressChanged event haha :(
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Hi,
Your code works like magic. I modified it slightly to suppressing the open/save/cancel dialog. However, after the save button was automatically click, another dialog pops up - the "Save As" Dialog box. I can't seem to capture the "Save As" dialog box caption in the code.
Can anyone help? I need to pass in the predefined path and click the ok button.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
 |
Yes. I found out that the save as dialog pop out by the IE is actually through the SHDocVw object. There for it belongs to the global domain. Therefore, a global hook is required for that. However the hooking windows method will only work with an active window session. For example, once the computer is locked, the hook will not be able to work.
Thanks anyway for the article.
|
| Sign In·View Thread·PermaLink | 2.00/5 |
|
|
|
 |
|
 |
Hi BimJeam and thank you very much for your work! I'm using your code and now I have some problems: I'm working with webbrowser giving the user the ability to download large files from remote site by clicking on links; when I detect a click on a link pointing to a file I use a WebClient to download the file; I show a listview with progressbar embedded to visualize the download progress. In this scenario randomly appears an Unhandled exception of type 'System.StackOverflowException' (occurred in mscorlib.dll) in function
private static Int32 WH_CALLWNDPROCRET_PROC(Int32 iCode, IntPtr pWParam, IntPtr pLParam)
at line
CWPRETSTRUCT cwp = (CWPRETSTRUCT)Marshal.PtrToStructure(pLParam, typeof(CWPRETSTRUCT)); I think the problem is caused by the massive calling to WndProc() in my listview due to progress bars.....how can avoid this error?
Best regards
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Hi Gian77 and thanks for the kind words.
Without actually seeing your code and whats going on in there the only thing I can suggest is that you temporarily unhook the events while downloading via the static Unhook() method of the WindowsInterop class.
I realise this probably doesn't help much though!
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Love it. I converted it to vb.net and it works perfectly. There are a few changes I needed to make because vb doesn't support delegates with returns. I just passed them by ref. Also in vb, you must instantiate the WindowsInterop class in the class where you are using it. Otherwise the hooks and events won't be in the same namespace. A few more nights of work and I'll finally be able to get a bag of crap on woot.com!
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
|
 |
|
 |
Yep, have done that in the past when hosting the WebBrowser control in C++ and/or .Net 1.1 over the years, however this is probably easier in 2.0 given the way they have abstracted away easy access to most of the 'low-level' stuff like IDocHostShowUI. Furthermore, at times we need to can text in the title bar and/or various controls of the certain dialogs so this way allows for that - as opposed to just dissmissing them.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Works great, only the article could use a little more documentation on how to use the code. e.g. WindowsInterop.Hook() WindowsInterop.Unhook()
modified on Monday, January 19, 2009 8:37 AM
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
 |
Hi, I need to do the same task in Visual C++ 6.0 application project? How it will be possible there? Can we use the same Library in that.
Thanks and Regards Wahaj Khan
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Not as it is in the code sample, Wahaj. What I mean is that the way I posted it you can't just build agaainst the funcitons in that .Net assembly from C++, as there's no Lib for that. You could/can however just add some attibutes to my code to expose the public .Net functions I wrote with a COM callable wrapper as per the .Net Interop assembly, System.Interop. Look at MSDN docco on the .Net 'COM Interop' stuff they provide in .Net (e.g. attributes like [ComVisible] etc), and add you could add those to the code I provided then get an import lib.
On the other hand, even easier for you, since you are already using C++, is that you can just call out to the "C" style exports in the User32.DLL import lib from C++ (like how the .Net Interop API does it 'under the covers'). It's pretty much exactly the same as for .Net, just approached from a more direct level. Look at installing the "Windows 2008 SDK" to get the Header (.h) files and Libs for the Win32 API functions that I used in the .Net version (e.g. D:\Program Files\Microsoft SDKs\Windows\v6.1\Include\WinodwsX.h and Winuser.h etc) in your project. MS have provided headers/libs for all the exported functions that I used. Google it up a bit as well, there are heaps of good examples of calling out to Win32 API code littered around the place!
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
I was wondering if thepossible outcomes of all of the functions involved in the elective is the same?
Thanks a lot. Troy
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Thank you for your article. I just completed a project that required me to download files from a website and I had a lot of trouble working around the download dialog. I will go back and see if I can't incorporate some of your insight into the tools I've written.
Here are some thoughts and notes on what I found as well:
* Working with the download dialog.[^]
Thanks
Paige Watson
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Thanks Paige,
I had a look at your post and it looks cool.
Just a couple of thoughts for you
1) To Click an HtmlElement instance you can generally just call InvokeMember() directly on the instance, there is no need to do the Object.GetType() stuff.
For example,
HtmlElement htmlButton = document.GetElementByID("SomeButton"); htmlButton.InvokeMember("click");
2) This may not be of use to you with your current project but may be handly later, or help others.
To select the option (particularly if/when you know the Index of the target selection) you can simply set the selectedIndex attribute of the Select HtmlElement.
For example,
String sDesiredIdx = "5";
HtmlElement htmlSelect = document.GetElementByID("SomeSelectBox");
String sCurrentIdx = htmlSelect.GetAttribute("selectedIndex"); if (!currentIndex.Equals(selectedIndex, StringComparison.InvariantCultureIgnoreCase)) { htmlSelect.SetAttribute("selectedIndex", selectedIndex); }
3) Again, although this may not affect your current project it may handy down the track, or help others.
I have found that sometimes - particularly when dealing with ASP.Net select objects - that if you modified the selectedIndex property, you may also need to raise an onchange notifcation event on the select object for anything to happen (e.g. a Postback etc)
For example,
htmlSelect.RaiseEvent("onchange");
|
| Sign In·View Thread·PermaLink | 3.00/5 |
|
|
|
 |