AutoHotkey Community

It is currently May 27th, 2012, 7:38 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 113 posts ]  Go to page 1, 2, 3, 4, 5 ... 8  Next
Author Message
PostPosted: September 9th, 2006, 11:32 am 
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...]


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: September 9th, 2006, 11:36 am 
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. 8)


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: September 9th, 2006, 12:16 pm 
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 ... :)


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: September 9th, 2006, 6:28 pm 
Offline

Joined: March 2nd, 2004, 3:36 pm
Posts: 10720
Thanks for the links. I'll browse those links now, and then one of these days I'll dig into COM/OLE.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 9th, 2006, 8:37 pm 
Offline

Joined: May 24th, 2006, 2:49 pm
Posts: 4511
Location: Belgrade
Great.
Thanx Bobo

_________________
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 10th, 2006, 10:17 am 
Offline

Joined: December 27th, 2005, 1:46 pm
Posts: 6837
Location: France (near Paris)
Excellent, I will look into these resources soon. Thanks.

_________________
Image vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2")


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 10th, 2006, 4:23 pm 
I got the basics working! 8)

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


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: September 10th, 2006, 7:46 pm 
Quote:
I got the basics working!
Dafür dürft ihr dann auch bei der EM Zweiter werden, im Endspiel gegen Deutschland :lol:

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 :)


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: September 10th, 2006, 8:45 pm 
Online
User avatar

Joined: December 26th, 2005, 4:40 pm
Posts: 8776
@daonlyfreez: Many thanks for the working code :D

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

_________________
URLGet - Internet Explorer based Downloader
StartEx - Portable Shortcut Link


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 10th, 2006, 9:38 pm 
Offline

Joined: May 24th, 2006, 2:49 pm
Posts: 4511
Location: Belgrade
This is the link with dll
http://www.codeguru.com/code/legacy/iep ... ebpage.zip

It works nice.

I will remember this page. Very useful.

_________________
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 10th, 2006, 9:51 pm 
[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 :wink::D


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: September 11th, 2006, 1:03 am 
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


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: September 11th, 2006, 5:51 am 
Offline

Joined: August 3rd, 2006, 3:24 am
Posts: 18
Thanks for the great example!


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 11th, 2006, 6:13 am 
Online
User avatar

Joined: December 26th, 2005, 4:40 pm
Posts: 8776
@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, :)

_________________
URLGet - Internet Explorer based Downloader
StartEx - Portable Shortcut Link


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 11th, 2006, 10:36 am 
Offline

Joined: May 24th, 2006, 2:49 pm
Posts: 4511
Location: Belgrade
Yes, its great...

Although i miss save option.... I didn't notice encapsulation of that part of WebBrowser interface in dll.

_________________
Image


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 113 posts ]  Go to page 1, 2, 3, 4, 5 ... 8  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 1 guest


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group