Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate

Embed an HTML control in your own window ... [Dll]


  • Please log in to reply
112 replies to this topic
BoBo
  • Guests
  • Last active:
  • Joined: --
Can someone confirm that (all given samples) are working with AHK <= 1.0.42.00 ?
I doubt it as eg. #NoEnv isn't available ...
Daofr's first script snippet: Gui showed up and collapsed. TNA icon is staying till mouse is hovering it
Goyyah's script snippet. The same. Webpage/-content won't be displayed. TNA ... (see above)
Daofr's second script: Gui shows up, if a Web related event should be triggered (click the link cwebpage.dll or load AHK.com) the Gui collpased ... (see above)

What are the system requirements? Dll's destination (eg. on access restricted systems/areas like ..\system32) etc.

My env: XPpro /SP2 /AHK 1.0.42.00

SKAN
  • Administrators
  • 9115 posts
  • Last active:
  • Joined: 26 Dec 2005

Can someone confirm that (all given samples) are working with AHK <= 1.0.42.00 ?


I confirm a crash with 1.0.41.00 / Win2000 SP4

Regards, :)
kWo4Lk1.png

majkinetor
  • Moderators
  • 4512 posts
  • Last active: May 20 2019 07:41 AM
  • Joined: 24 May 2006
There is no reason not to work. It is a dll call. It has nothing to do with, for instance #NoEnv
Posted Image

SKAN
  • Administrators
  • 9115 posts
  • Last active:
  • Joined: 26 Dec 2005

It has nothing to do with, for instance #NoEnv


No! This is not about #NoEnv ( I commented it out! )

The scripts crashes in 1.0.41.00

Regards, :)
kWo4Lk1.png

not-logged-in-daonlyfreez
  • Guests
  • Last active:
  • Joined: --
I use 1.0.44.10 on XP SP2, no problems.

If you experience the 'Gui collapsing', it is probably an errorcode calling for the 'Cleanup and Exit' routine, so to know what went wrong, you'll have to adapt the code to study the returned errorcodes and 'res' values instead.

@majkinetor: True, there seems to be not an option to save the contents of the control, but that might be 'workaroundable'.

I tried getting more out of the DLL (there are more available functions), but they are way over my head.

Exported functions:

BStr2TStr
CreateWebEvtHandler
DisplayHTMLPage
DisplayHTMLStr
DoPageAction
EmbedBrowserObject
FreeWebEvtHandler
GetWebElement
GetWebPtrs
GetWebSrcElement
ResizeBrowser
SetWebReturnValue
TStr2BStr
UnEmbedBrowserObject
WaitOnReadyState


Remark 1: According to the source, it is possible using GetWebPtrs/GetWebElement and then CreateWebEvtHandler to monitor for messages from a specific element from the page, which would allow for real interaction, but it uses all kinds of weird calls to weird objects, which I'm not sure can be called with AHK at all...

Remark 2: I couldn't get WaitOnReadyState (to know when a page is loaded for example) to work. Even started as an extra thread (timer), wont give the desired result, for the 'waiting' halts the processing even then.

Remark 3: I do not know what BStr2TStr and TStr2BStr are supposed to be used for.

Remark 4: Apparently all controls added to the parent Gui after the 8th appear also as a copy underneath the browser control. I'm not sure whether this is a positioning issue or a control order issue or a bug in the DLL.

Here are the relevant parts of the header file (for the coders):

#if UNICODE
BSTR WINAPI TStr2BStr(HWND, const WCHAR *);
typedef BSTR WINAPI TStr2BStrPtr(HWND, const WCHAR *);
#else
BSTR WINAPI TStr2BStr(HWND, const char *);
typedef BSTR WINAPI TStr2BStrPtr(HWND, const char *);
#endif
#define TSTR2BSTR TStr2BStr
#define TSTR2BSTRNAME "TStr2BStr"

void * WINAPI BStr2TStr(HWND, BSTR);
typedef void * WINAPI BStr2TStrPtr(HWND, BSTR);
#define BSTR2TSTR BStr2TStr
#define BSTR2TSTRNAME "BStr2TStr"

long WINAPI EmbedBrowserObject(HWND);
#define EMBEDBROWSEROBJECT EmbedBrowserObject
typedef long WINAPI EmbedBrowserObjectPtr(HWND);
#define EMBEDBROWSEROBJECTNAME "EmbedBrowserObject"

void WINAPI UnEmbedBrowserObject(HWND);
#define UNEMBEDBROWSEROBJECT UnEmbedBrowserObject
typedef long WINAPI UnEmbedBrowserObjectPtr(HWND);
#define UNEMBEDBROWSEROBJECTNAME "UnEmbedBrowserObject"

#ifdef UNICODE
long WINAPI DisplayHTMLPage(HWND, const WCHAR *);
typedef long WINAPI DisplayHTMLPagePtr(HWND, const WCHAR *);
#else
long WINAPI DisplayHTMLPage(HWND, const char *);
typedef long WINAPI DisplayHTMLPagePtr(HWND, const char *);
#endif
#define DISPLAYHTMLPAGE DisplayHTMLPage
#define DISPLAYHTMLPAGENAME "DisplayHTMLPage"

#ifdef UNICODE
long WINAPI DisplayHTMLStr(HWND, const WCHAR *);
typedef long WINAPI DisplayHTMLStrPtr(HWND, const WCHAR *);
#else
long WINAPI DisplayHTMLStr(HWND, const char *);
typedef long WINAPI DisplayHTMLStrPtr(HWND, const char *);
#endif
#define DISPLAYHTMLSTR DisplayHTMLStr
#define DISPLAYHTMLSTRNAME "DisplayHTMLStr"

#ifdef UNICODE
IHTMLElement * WINAPI GetWebElement(HWND, IHTMLDocument2 *, const WCHAR *, INT);
typedef IHTMLElement * WINAPI GetWebElementPtr(HWND, IHTMLDocument2 *, const WCHAR *, INT);
#else
IHTMLElement * WINAPI GetWebElement(HWND, IHTMLDocument2 *, const char *, INT);
typedef IHTMLElement * WINAPI GetWebElementPtr(HWND, IHTMLDocument2 *, const char *, INT);
#endif
#define GETWEBELEMENT GetWebElement
#define GETWEBELEMENTNAME "GetWebElement"

IHTMLElement * WINAPI GetWebSrcElement(IHTMLEventObj *);
typedef IHTMLElement * WINAPI GetWebSrcElementPtr(IHTMLEventObj *);
#define GETWEBSRCELEMENT GetWebSrcElement
#define GETWEBSRCELEMENTNAME "GetWebSrcElement"

void WINAPI ResizeBrowser(HWND, DWORD, DWORD);
#define RESIZEBROWSER ResizeBrowser
typedef void WINAPI ResizeBrowserPtr(HWND, DWORD, DWORD);
#define RESIZEBROWSERNAME "ResizeBrowser"

#define WEBPAGE_GOBACK 0
#define WEBPAGE_GOFORWARD 1
#define WEBPAGE_GOHOME 2
#define WEBPAGE_SEARCH 3
#define WEBPAGE_REFRESH 4
#define WEBPAGE_STOP 5

void WINAPI DoPageAction(HWND, DWORD);
#define DOPAGEACTION DoPageAction
typedef void WINAPI DoPageActionPtr(HWND, DWORD);
#define DOPAGEACTIONNAME "DoPageAction"

#define WORS_SUCCESS 0
#define WORS_TIMEOUT -1
#define WORS_DESTROYED -2

HRESULT WINAPI WaitOnReadyState(HWND, READYSTATE, DWORD, IWebBrowser2 *);
typedef HRESULT WINAPI WaitOnReadyStatePtr(HWND, READYSTATE, DWORD, IWebBrowser2 *);
#define WAITONREADYSTATE WaitOnReadyState
#define WAITONREADYSTATENAME "WaitOnReadyState"

void * WINAPI BStr2TStr(HWND, BSTR);
typedef void * WINAPI BStr2TStrPtr(HWND, BSTR);
#define BSTR2TSTR BStr2TStr
#define BSTR2TSTRNAME "BStr2TStr"

#if UNICODE
BSTR WINAPI TStr2BStr(HWND, const WCHAR *);
typedef BSTR WINAPI TStr2BStrPtr(HWND, const WCHAR *);
#else
BSTR WINAPI TStr2BStr(HWND, const char *);
typedef BSTR WINAPI TStr2BStrPtr(HWND, const char *);
#endif
#define TSTR2BSTR TStr2BStr
#define TSTR2BSTRNAME "TStr2BStr"

HRESULT WINAPI GetWebPtrs(HWND, IWebBrowser2 **, IHTMLDocument2 **);
typedef HRESULT WINAPI GetWebPtrsPtr(HWND, IWebBrowser2 **, IHTMLDocument2 **);
#define GETWEBPTRS GetWebPtrs
#define GETWEBPTRSNAME "GetWebPtrs"

HRESULT WINAPI SetWebReturnValue(IHTMLEventObj *, BOOL);
typedef HRESULT WINAPI SetWebReturnValuePtr(IHTMLEventObj *, BOOL);
#define SETWEBRETURNVALUE SetWebReturnValue
#define SETWEBRETURNVALUENAME "SetWebReturnValue"

void WINAPI FreeWebEvtHandler(IDispatch *);
typedef void WINAPI FreeWebEvtHandlerPtr(IDispatch *);
#define FREEWEBEVTHANDLER FreeWebEvtHandler
#define FREEWEBEVTHANDLERNAME "FreeWebEvtHandler"

IDispatch * WINAPI CreateWebEvtHandler(HWND, IHTMLDocument2 *, DWORD, long, IUnknown *, void *);
typedef IDispatch * WINAPI CreateWebEvtHandlerPtr(HWND, IHTMLDocument2 *, DWORD, long, IUnknown *, void *);
#define CREATEWEBEVTHANDLER CreateWebEvtHandler
#define CREATEWEBEVTHANDLERNAME "CreateWebEvtHandler"


I'll continue experimenting, but I think I already reached my boundaries on the DLLCall front now....

SKAN
  • Administrators
  • 9115 posts
  • Last active:
  • Joined: 26 Dec 2005

I use 1.0.44.10 on XP SP2, no problems.


I use 1.0.44.09 on WIN2K SP4, no problems.

I downgraded to 1.0.41.00 just to check BoBo's problem and yes! The script crashes!

Regards, :)
kWo4Lk1.png

BoBo
  • Guests
  • Last active:
  • Joined: --

as eg. #NoEnv isn't available (remark: in 1.0.42.00)

Of course I've commented it out as well - before I gave my statement. The above descripped failure happend anyway :(

majkinetor
  • Moderators
  • 4512 posts
  • Last active: May 20 2019 07:41 AM
  • Joined: 24 May 2006
This is very limited set of functions to control WebBrowser. ITs created only as example of usage on codeguru, not for serous use. You don't have any browser events, i.e you can't now when page is loading, when it finsihed loading or failed to do so, you can't save etc....

So, I don't reccomend usage of this dll in your scripts. There are possibly better wrappers for WebBrowser Interface.
Posted Image

not-logged-in-daonlyfreez
  • Guests
  • Last active:
  • Joined: --
@majkinetor: Unfortunately there are not many alternatives around, and we have been looking thoroughly.

The QHTM control you mentioned in another post looks very nice, but seems to be even more difficult to handle.

There is also Micha's project we could use if everything else fails (not that I don't like it, it's just the dependencies and size that bother me).

BoBo
  • Guests
  • Last active:
  • Joined: --
I took Daofr's initial code and added 2 MsgBoxes to get the Errorlevels. Interestingly I've got '0' all the time, even the first attemp to load the page failed. A second attempt to load AHK.com suceeded, but collapsed once I clicked a link at the displayed page.
A timing issue ???

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

OnExit, Cleanup 

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

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

return 

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


SKAN
  • Administrators
  • 9115 posts
  • Last active:
  • Joined: 26 Dec 2005

In v1.0.42.03+, the built-in variable A_LastError will contain the result of the operating system's GetLastError() function, which is called immediately after the function is called (this has no measurable impact on performance). A_LastError is a number between 0 and 4294967295 (always formatted as decimal, not hexadecimal). Like ErrorLevel, A_LastError is a per-thread setting; that is, interruptions by other threads cannot change it. However, A_LastError is also set by Run/RunWait.


kWo4Lk1.png

not-logged-in-daonlyfreez
  • Guests
  • Last active:
  • Joined: --
@BoBo:

- Did you try with a newer version of AHK?
- Did you use the DLL from the download provided by majkinetor or by me (they seem to be different)?
- And yes, can you have a look at the A_LastError value and 'res' value too?
- Have you checked your firewall/antivirus settings?
- Which version of IE do you use? If you use IE7 already, that might be the cause of your problems too.

Chris
  • Administrators
  • 10727 posts
  • Last active:
  • Joined: 02 Mar 2004
I know this web page component is still very limited in functionality. But if anyone gets it to the point where you think it would be useful enough for the general public, I can link to it from the GUI section of the documentation.

Thanks.

not-logged-in-daonlyfreez
  • Guests
  • Last active:
  • Joined: --
I think this DLL unfortunately is too limited by design and it would need some extra's to be really useful. It apparently only works with IE6 and I think it will break with IE7 (have not tested), so I doubt this - as is - is worth adding to the 'frontpage'.

But, as majkinetor has shown with his ISense script, it can be used.

majkinetor
  • Moderators
  • 4512 posts
  • Last active: May 20 2019 07:41 AM
  • Joined: 24 May 2006
No, it will not break as such is the nature of COM. New IE7 control will be registered in different name space.

IT is limited however..
Posted Image