CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 10 of 10
  1. #1
    Join Date
    May 1999
    Location
    G day Mayt Land
    Posts
    971

    [RESOLVED] webBrowser Class replacement


    WebBrowser is an Active X control that can display an HTML document within a form.
    Code:
    webBrowser1.Navigate(HTMLfile);
    and to print it
    Code:
    webBrowser1.Print();
    Due to various reasons ,Active X controls can not be allowed in this project and I am trying to find a replacement without losing too much quality that would get the Job done.

    One way is to call Winword to load the file and print it from there but that is one messy way and involves more clicking and I am trying to avoid.

    I'd appreciate any positive thoughts or ideas that you you may have .

    Cheers

  2. #2
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,284

    Re: webBrowser Class replacement

    I come in peace

    Are you allowed to reference DLL fiiles ¿

  3. #3
    Join Date
    May 1999
    Location
    G day Mayt Land
    Posts
    971

    Re: webBrowser Class replacement

    I dont see any white flag waving left and right Mr M M
    Yea ofcourse DLLs are allowed . ActiveX has been identified as unsecure.
    What do you have in mind.

  4. #4
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,284

    Re: webBrowser Class replacement

    Code:
    do
    {
    White_Flag(Left);
    White_Flag(Right);
    }while (Seeking(Peace) == "true");
    OK, Saeed, I have 2 options for you

    First option.
    Add a reference to SHDocVw.dll. If you don't find it in the list, you'll have to browse for it, in the System32 folder. Then, add this :

    Code:
    using SHDocVw; // Internet Explorer Reference
    
     public void OpenIE(string MyURL)
            {
                object NULL = null;
                SHDocVw.InternetExplorer ObjIE = new
                SHDocVw.InternetExplorerClass();
                IWebBrowserApp Browser = (IWebBrowserApp)ObjIE;
                Browser.Visible = true;
                Browser.Navigate(MyURL, ref NULL, ref NULL, ref NULL, ref NULL);
            }
    
     private void Form1_Load(object sender, EventArgs e)
            {
    
               OpenIE("http://www.codeguru.com");
    
            }
    This would open Internet Explorer, navigate to codeguru, when the form is loaded.

    Option 2:

    Add this to the top of your class :
    Code:
    using System.Runtime.InteropServices;
    Then, add this :
    Code:
            [DllImport("user32.dll")]
            static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent);    
            
            private void button1_Click(object sender, EventArgs e)
            {
                Process pr = Process.Start("C:\\Program Files\\Internet Explorer\\iexplore.exe");
                Thread.Sleep(500); 
                SetParent(pr.MainWindowHandle, panel1.Handle);
            }
        }
    When our button is clicked, it will launch Internet Explorer, and display the Internet Explorer window inside a panel. Funky! ( At least I think so )

    So, the IE window is hosted inside the panel. you have to remember though, that it will how the default home page, so perhaps if you could just temporarily set the home page to your file you want, or inform users to browse for it.

    You could always, do this to show your Internet Explorer options, before launching IE :
    Code:
    Process.Start("rundll32.exe", "shell32.dll,Control_RunDLL inetcpl.cpl");
    So, if you put that on a separate button, let users click that first, or you, and set your homepage to whatever so that when Option 2 works, you shouldn't have problems.

    You could also change this registry key :
    HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Main\Start Page

    For your IE home page.

    I hope my post was useful
    Last edited by HanneSThEGreaT; November 18th, 2009 at 07:18 AM. Reason: Adde Peace Making Do Loop :)

  5. #5
    Join Date
    May 1999
    Location
    G day Mayt Land
    Posts
    971

    Re: webBrowser Class replacement

    Thanks mate I liked your peace.c code
    Maybe i shoudl have explained myself better.

    WebBrowser control was enabling me to display an HTML file and
    by another push of a button it would be printing
    Code:
      webBrowser1.Print();
    Firing up another thread to load IE or Winword and load the file and then
    User :FILE/PRINT/.... involves more human interactions (a few more clicks x 1000 a day) that I am trying to avoid.
    If you still have a solution to my probelm by all means drop me a line.

    Thanks for your response anyway.

    Saeed

  6. #6
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,284

    Thumbs up Re: webBrowser Class replacement

    Hello again Saeed.

    I see what you're saying. I think I should have included examples to my previous post.

    I have used both methods in conjunction with each other.
    One button displays the web browser inside the panel - you could always do this in Form Load
    One button prints the document

    I'm attaching a sample here, so that you can see if I understood you right - I really hope so

    I should mention that This was real fun.

    I really hope this helps.

    Hannes
    Last edited by HanneSThEGreaT; June 14th, 2010 at 05:44 AM.

  7. #7
    Join Date
    May 1999
    Location
    G day Mayt Land
    Posts
    971

    Re: webBrowser Class replacement

    Code:
    bool Seeking(peace)
    {
    return true;
     /* comented
    */
    }
    Warning :1 The variable 'peace' is declared but never used

    Thanks for your ZIP file. I am out of town for a few days as soon as I get back I ll give that a go. cheers mate.

  8. #8
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,284

    Re: webBrowser Class replacement

    Let's hope for the best. There might be little tweaking with displaying the IE window maxmised, but let us cross that bridge when we get there.

  9. #9
    Join Date
    May 1999
    Location
    G day Mayt Land
    Posts
    971

    Re: webBrowser Class replacement

    Good work
    I just had time to have a go at your attachment and ran it.
    Yea the idea is there.

    Thanks a lot
    Saeed

  10. #10
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,284

    Re: webBrowser Class replacement

    That's great news, glad I could help

    Keep up the good work!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured