AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Embed an HTML control in your own window ... [Dll]
Goto page 1, 2, 3, 4, 5, 6, 7  Next
 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Utilities & Resources
View previous topic :: View next topic  
Author Message
BoBo
Guest





PostPosted: Sat Sep 09, 2006 10:32 am    Post subject: Embed an HTML control in your own window ... [Dll] Reply with quote

Quote:
Embed an HTML control in your own window using plain C
By Jeff Glatt.

Specifically shows how to embed a browser OLE object in your own window, and more generally demonstrates how to manipulate and create COM/OLE objects, in plain C (ie, no MFC, WTL, ATL, .NET, C#, nor even C++). The latter is applicable to many other uses, such as creating your own script engine.

Introduction
There are numerous examples that demonstrate how to embed Internet Explorer as an OLE/COM object in your own window. But these examples typically use Microsoft Foundation Classes (MFC), .NET, C#, or at least Windows Template Library (WTL) because those frameworks have pre-fabricated "wrappers" to easily give you an "HTML control" to embed in your window. If you're trying to use plain C, without MFC, WTL, .NET, C#, or even any C++ code at all, then there is a dearth of examples and information how to deal with COM objects such as IE's IWebBrowser2. Here is an article and working example in C to specifically show you what you need to do in order to embed IE in your own window.

In fact, I've even wrapped up the example C code (to embed IE in your own window) into a Dynamic Link Library (DLL) so that you can simply call one function to display a web page or some HTML string in a window you create. You won't even need to get your hands dirty with COM (unless you plan to modify the source of the DLL).

Before proceeding with this article, you should first read my series of articles regarding COM in plain C. Part 1 discusses information you'll need to know in order to use COM objects. We will also have to deal with objects that have multiple interfaces, as discussed in Part 4. We'll be using automation datatypes, as discussed in Part 2. Finally, we'll also be dealing with events (callbacks), discussed in Part 5.

[More...]
Back to top
BoBo
Guest





PostPosted: Sat Sep 09, 2006 10:36 am    Post subject: Reply with quote

Given on the same page:
Quote:
[Introduction to COM] - What It Is and How to Use It. A tutorial for programmers new to COM that explains how to reuse existing COM components, for example, components in the Windows shell.

[Introduction to COM Part II] - Behind the Scenes of a COM Server
A tutorial for programmers new to COM that explains the internals of COM servers, and how to write your own interfaces in C++
Might be of interest. Cool
Back to top
BoBo
Guest





PostPosted: Sat Sep 09, 2006 11:16 am    Post subject: Reply with quote

Please check all other links/cross references pointing to articels of the same author. It looks like here's some potential to improve AHK regarding COM support. But as always, I might be (completely) wrong ... Smile
Back to top
Chris
Site Admin


Joined: 02 Mar 2004
Posts: 10474

PostPosted: Sat Sep 09, 2006 5:28 pm    Post subject: Reply with quote

Thanks for the links. I'll browse those links now, and then one of these days I'll dig into COM/OLE.
Back to top
View user's profile Send private message Send e-mail
majkinetor



Joined: 24 May 2006
Posts: 3644
Location: Belgrade

PostPosted: Sat Sep 09, 2006 7:37 pm    Post subject: Reply with quote

Great.
Thanx Bobo
_________________
Back to top
View user's profile Send private message MSN Messenger
PhiLho



Joined: 27 Dec 2005
Posts: 6721
Location: France (near Paris)

PostPosted: Sun Sep 10, 2006 9:17 am    Post subject: Reply with quote

Excellent, I will look into these resources soon. Thanks.
_________________
vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2")
Back to top
View user's profile Send private message Visit poster's website
not-logged-in-daonlyfreez
Guest





PostPosted: Sun Sep 10, 2006 3:23 pm    Post subject: Reply with quote

I got the basics working! Cool

Code:
hModule := DllCall("LoadLibrary", "str", "cwebpage.dll") 

OnExit, Cleanup

Gui, Show, w600 h400, test
WinGet, ourHWND, ID, A
res := DLLCall("cwebpage\EmbedBrowserObject", UInt, ourHWND)
If (res != 0 Or ErrorLevel != 0) ; error
  Goto, Cleanup

res := DLLCall("cwebpage\DisplayHTMLPage", UInt, ourHWND, Str, "http://www.autohotkey.com")
If (res != 0 Or ErrorLevel != 0) ; error
  Goto, Cleanup

return

Cleanup:
GuiClose:
DLLCall("cwebpage\UnEmbedBrowserObject", UInt, ourHWND)
DllCall("FreeLibrary", "UInt", hModule)
ExitApp
return
Back to top
BoBo
Guest





PostPosted: Sun Sep 10, 2006 6:46 pm    Post subject: Reply with quote

Quote:
I got the basics working!
Dafür dürft ihr dann auch bei der EM Zweiter werden, im Endspiel gegen Deutschland Laughing

Would you mind to provide the mandatory Dll too? Maybe on Autohotkey.net?? Wouldn't it make sense to provide both at the Script&Function section??

Btw. Thx for sharing it. Dank u wel Smile
Back to top
SKAN



Joined: 26 Dec 2005
Posts: 6223

PostPosted: Sun Sep 10, 2006 7:45 pm    Post subject: Reply with quote

@daonlyfreez: Many thanks for the working code Very Happy

Code:
hModule := DllCall("LoadLibrary", "str", "cwebpage.dll") 

OnExit, Cleanup
Gui -Sysmenu +AlwaysOnTop
Gui, Show, x20 y20 w126 h50, IP Address
WinGet, ourHWND, ID, A
res := DLLCall("cwebpage\EmbedBrowserObject", UInt, ourHWND)
If (res != 0 Or ErrorLevel != 0) ; error
  Goto, Cleanup

res := DLLCall("cwebpage\DisplayHTMLPage", UInt, ourHWND
              , Str, "http://www.netikus.net/show_ip.html")
If (res != 0 Or ErrorLevel != 0) ; error
  Goto, Cleanup

return

Cleanup:
GuiClose:
GuiEscape:
  DLLCall("cwebpage\UnEmbedBrowserObject", UInt, ourHWND)
  DllCall("FreeLibrary", "UInt", hModule)
  ExitApp
return

_________________
Back to top
View user's profile Send private message
majkinetor



Joined: 24 May 2006
Posts: 3644
Location: Belgrade

PostPosted: Sun Sep 10, 2006 8:38 pm    Post subject: Reply with quote

This is the link with dll
http://www.codeguru.com/code/legacy/ieprogram/cwebpage.zip

It works nice.

I will remember this page. Very useful.
_________________
Back to top
View user's profile Send private message MSN Messenger
BoBo
Guest





PostPosted: Sun Sep 10, 2006 8:51 pm    Post subject: Reply with quote

[Step by Step COM Tutorial - By Saurabh Dasgupta]

[COM from scratch - PART ONE - By Aria Ansari.]
[COM from scratch - PART TWO - By Aria Ansari]
[COM from scratch - PART THREE - By Aria Ansari]

Now with a lot of images WinkVery Happy
Back to top
not-logged-in-daonlyfreez
Guest





PostPosted: Mon Sep 11, 2006 12:03 am    Post subject: Reply with quote

More elaborate example:

Code:
#NoEnv
SetBatchLines, -1
SetWinDelay, 0

; Load cwebpage.dll
cwebpageHandle := DllCall("LoadLibrary", "str", "cwebpage.dll") 

; Exit handler
OnExit, Cleanup

; Create menu
Menu, browserMenu, Add, Back
Menu, browserMenu, Add, Forward
Menu, browserMenu, Add, Refresh
Menu, browserMenu, Add, Stop
Menu, browserMenu, Add, Home
Menu, browserMenu, Add, Search

; Parent window
Gui, 1: Add, Button, y8 x0 w50 gBack, Back
Gui, 1: Add, Button, y8 x50 w50 gBack, Forward
Gui, 1: Add, Button, y8 x100 w50 gRefresh, Refresh
Gui, 1: Add, Button, y8 x150 w50 gStop, Stop
Gui, 1: Add, Button, y8 x200 w50 gHome, Home
Gui, 1: Add, Button, y8 x250 w50 gSearch, Search
Gui, 1: Add, Button, y370 x0 w150 gGoExample, Open example html
Gui, 1: Add, Button, y370 x150 w150 gGoAHKCHM, Open AHK chm
Gui, 1: Add, Button, y370 x300 w150 gGoAHKHome, Go to AHK homepage
Gui, 1: Show, w600 h400, Internet Explorer container in AHK with cwebpage.dll
WinGet, mainGuiHandle, ID, A

; Child window for Browser object
Gui, 2: Margin, 0, 0
Gui, 2: +ToolWindow -Caption +Border
Gui, 2: Show, w590 h320
WinGet, browserGuiHandle, ID, A
; Set as child window to main gui
Gui, 2: +LastFound
DllCall("SetParent", "uint", WinExist(), "uint", mainGuiHandle)

; Create the Browser object
res := DLLCall("cwebpage\EmbedBrowserObject", "uint", browserGuiHandle)
If (res != 0 Or ErrorLevel != 0) ; error
  Goto, Cleanup

; Position the Browser "control" in the Gui
WinMove, ahk_id %browserGuiHandle%, , 4, 40

; Load welcome html
Gosub, GoExample

; Monitor for right clicks on browser control
; WM_CONTEXTMENU ; 0x7B
OnMessage(0x7B, "Web_WM_CONTEXTMENU")

Return

; *** Routines:

; Browser control rightclick
Web_WM_CONTEXTMENU(wParam, lParam)
{
  Menu, browserMenu, Show
}
Return

; Browser control actions
Back:
res := DLLCall("cwebpage\DoPageAction", "uint", browserGuiHandle, "uint", 0)
Return

Forward:
res := DLLCall("cwebpage\DoPageAction", "uint", browserGuiHandle, "uint", 1)
Return

Home:
res := DLLCall("cwebpage\DoPageAction", "uint", browserGuiHandle, "uint", 2)
Return

Search:
res := DLLCall("cwebpage\DoPageAction", "uint", browserGuiHandle, "uint", 3)
Return

Refresh:
res := DLLCall("cwebpage\DoPageAction", "uint", browserGuiHandle, "uint", 4)
Return

Stop:
res := DLLCall("cwebpage\DoPageAction", "uint", browserGuiHandle, "uint", 5)
Return

; Examples

; Load welcome/example html
GoExample:
HTML2Load =
(
<html><head><title>HTML Template</title></head><body>
Welcome to the <a href="http://www.codeproject.com/com/cwebpage.asp">
cwebpage.dll</a> browser control embedded into an AutoHotkey GUI<br><br>
<ol><li>Pressing the <b>Open example html</b> button will load some example html
<li>Pressing the <b>Open AHK chm</b> button will load the startpage of the AutoHotkey chm helpfile locally on your computer.<br>
<font color="green"><b>Cwebpage.dll can open and navigate in chm-files too!</b></font>
<li>Pressing the <b>Go to AHK homepage</b> button will load the AutoHotkey homepage online
<li>Pressing the <b>Open welcome html</b> button will reload this page</ol>
You can control the browser object with the top buttons and the context menu...
<br><br><br><br>
<font color="red"><b>Enjoy!</b></font>...
</body></html>
)
Gosub, LoadHTML
Return

GoAHKCHM:
URL2Load = its:%A_ProgramFiles%\AutoHotkey\AutoHotkey.chm::docs\AutoHotkey.htm
Gosub, LoadURL
Return

GoAHKHome:
URL2Load = http://www.autohotkey.com
Gosub, LoadURL
Return

; Load URL
LoadURL:
res := DLLCall("cwebpage\DisplayHTMLPage"
                  , "uint", browserGuiHandle
                  , "str", URL2Load)
If (res != 0 Or ErrorLevel != 0) ; error
  Goto, Cleanup
URL2Load =
Return

; Load HTML
LoadHTML:
res := DLLCall("cwebpage\DisplayHTMLStr"
                  , "uint", browserGuiHandle
                  , "str", HTML2Load)
If (res != 0 Or ErrorLevel != 0) ; error
  Goto, Cleanup
HTML2Load =
Return

; Cleanup and exit
Cleanup:
GuiEscape:
GuiClose:
DLLCall("cwebpage\UnEmbedBrowserObject", "uint", browserGuiHandle)
DllCall("FreeLibrary", "uint", cwebpageHandle)
ExitApp
Return


For your convenience, alternative download links:

cwebpage.dll
cwebpage_src.zip
Back to top
deefault



Joined: 03 Aug 2006
Posts: 18

PostPosted: Mon Sep 11, 2006 4:51 am    Post subject: Reply with quote

Thanks for the great example!
Back to top
View user's profile Send private message
SKAN



Joined: 26 Dec 2005
Posts: 6223

PostPosted: Mon Sep 11, 2006 5:13 am    Post subject: Reply with quote

@daonlyfreez: Your examples are great!. Not many people would
be visiting this section. I suggest you to post the links and the examples
in the Scripts & Functions section.

Many thanks again for the working examples!

Regards, Smile
_________________
Back to top
View user's profile Send private message
majkinetor



Joined: 24 May 2006
Posts: 3644
Location: Belgrade

PostPosted: Mon Sep 11, 2006 9:36 am    Post subject: Reply with quote

Yes, its great...

Although i miss save option.... I didn't notice encapsulation of that part of WebBrowser interface in dll.
_________________
Back to top
View user's profile Send private message MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Utilities & Resources All times are GMT
Goto page 1, 2, 3, 4, 5, 6, 7  Next
Page 1 of 7

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group