ArtinSoft's Blogs

Software Migration Experts
Welcome to ArtinSoft's Blogs Sign in | Join | Help
in Search

Mauricio Rojas Blog

May 2009 - Posts

  • And the WebBrowser keeps going…

    Well recently Kingsley has point me to a lot of useful links to improve the ExtendedWebBrowser. However he found another detail. When in Javascript you do something like a:

    window.open(‘url’,’window’,’width=200;height=300’);

    Those width and height settings were not being considered in the new window. I researched for I while until I found this great link:

     

    HOW TO: Get Width and Height from window.open() Inside a WebBrowser Host by Using Visual Basic .NET

    So basicly I follow the sugested code and added logic in my EventSink class:

            public void WindowSetLeft(int Left)
            {
                ///Should I calculate any diff?
                _Browser.Parent.Left = Left;
    
            }
    
            public void WindowSetTop(int Top)
            {
                _Browser.Parent.Top = Top;
    
            }
    
            public void WindowSetWidth(int Width)
            {
                int diff = 0;
                diff = _Browser.Parent.Width - _Browser.Width;
                _Browser.Parent.Width = diff + Width;
    
            }
            public void WindowSetHeight(int Height)
            {
                int diff = 0;
                diff = _Browser.Parent.Height - _Browser.Height;
                _Browser.Parent.Height = diff + Height;
    
            }
    So now when the window opens it takes the specified width, heigth, left and top.

    As always

    HERE IS THE UPDATED CODE

  • WebBrowser Control and window.Close()

    I had previously posted an extended version of the WebBrowser Control. This code posted in Opening Popup in a NewWindow and NewWindow2 Events in the C# WebBrowserControl, dealt with some issues when you want to have a form with a WebBrowser and in the enclosed page you have a Javascript code like:

    window.open(“ <some url to a page”)

    But recently another problem arised. What if you have a Javascript snippet like:

    window.close()

    OMG!!! Why haven’t I thought about it. Well Kelder wrote me about this problem and he also sent me some of his\her research results:

    Solution (Add WebBrowser as unmanaged code):  blogs.msdn.com/jpsanders/archive/2008/04/23/window-close-freezes-net-2-0-webbrowser-control-in-windows-form-application.aspx

    Solution (Add WebBrowser using WM_NOTIFYPARENT override):blogs.msdn.com/jpsanders/archive/2007/05/25/how-to-close-the-form-hosting-the-webbrowser-control-when-scripting-calls-window-close-in-the-net-framework-version-2-0.aspx

    http://blogs.msdn.com/jpsanders/archive/2007/05/25/how-to-close-the-form-hosting-the-webbrowser-control-when-scripting-calls-window-close-in-the-net-framework-version-2-0.aspx

    Solution (Implementation not detailed): social.msdn.microsoft.com/forums/en-US/winforms/thread/1199c004-9eb2-400d-a118-6e06bca9f1f0/

    Proposes changing pop-up links to WebBrowser navigate: dotnetninja.wordpress.com/2008/02/26/prevent-opening-new-window-from-webbrowser-control/Close

    problem observed (no solution):www.codeproject.com/KB/cpp/ExtendedWebBrowser.aspx

     

    It seams to me that the better solution is to use jpsanders solution, so I created an ExtendWebBrowser_v2 (the following is the modified fragment):

    //Extend the WebBrowser control
    public class ExtendedWebBrowser : WebBrowser
    {
        
        // Define constants from winuser.h
        private const int WM_PARENTNOTIFY = 0x210;
        private const int WM_DESTROY = 2;
        
        AxHost.ConnectionPointCookie cookie;
        WebBrowserExtendedEvents events;
    
        protected override void WndProc(ref Message m)
        {
            switch (m.Msg)
            {
                case WM_PARENTNOTIFY:
                 if (!DesignMode) 
                 {
                    if (m.WParam.ToInt32() == WM_DESTROY) 
                    {
                        Message newMsg = new Message();
                        newMsg.Msg = WM_DESTROY;
                        // Tell whoever cares we are closing
                        Form parent = this.Parent as Form;
                        if (parent!=null)
                            parent.Close();
                    }
                 }
                DefWndProc(ref m);
                break;
              default:
                base.WndProc(ref m);
                break;
            }
        }

    The problem that might arise with this solution is that the parent might not be a Form but an user control, etc. For a more general aproach I think I should send a WM_DESTROY directly to the parent, but for most cases it works. I’m attaching the code and a sample page called test0.htm. I hope this helps and rembember you can always donate to programming geeks jejejejeje just kidding

    HERE IS THE CODE

  • List Jobs in Oracle

    If you have created any schedule jobs or you just need to see what jobs are available in a server you use the dba_jobs table.

    The following links provides more details about this view: http://www.praetoriate.com/data_dictionary/dd_dba_jobs.htm

  • Opening Popup in a NewWindow

    In a previous post, i had published an “Extended Version” of the WebBrowser control
    that gave you access to events like the NewWindow2.
    This event that is not public in the common WebBrowser control allows you to intercept
    the NewWindow event but gives you the posibility to setup the the ppDisp property witch sets
    a pointer to the WebBrowser where the new window will be open.

    So i setup a small example using this “ExtendedBrowser”.

    I created a simple page (well really it was my wife, I know about transport-layer, C++, bits etc, but I never remember HTML syntax):

    <html>
    <body>
    <H1> This is sample page to test opening a pop up in a new form </H1>
    <input type="button" onclick="window.open('test0.htm')"/>
    </body>
    </html>

    And created a simple form like in the following picture:

    image

    Instead of using a WebBrowser control i just used an ExtendedWebBrowser from my previous post.

    And added code like:

            private void extendedWebBrowser1_NewWindow2(object sender, NewWindow2EventArgs e)
            {
                //Intercepting this event will allow us to create a new form in which
                //we will open the new webpage, to do that we must set the ppDisp property
                //of the NewWindow2EventArgs
                FormWithExtendedBrowser form1 = new FormWithExtendedBrowser();
                form1.Show();
                e.PPDisp = form1.extendedWebBrowser1.Application;
            }

    When I run the code , it now opens the pop up in my form:

    image

    But test if for yourself! :) HERE IS THE CODE

This Blog

Syndication

Powered by Community Server (Non-Commercial Edition), by Telligent Systems