1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
|
#include <stdlib.h>
#include <stdio.h>
#include <windows.h>
#include <exdisp.h>
#include <iup.h>
#include <iupole.h>
#ifndef BIG_TEST
static Ihandle *IupOleCreateBrowser(void)
{
Ihandle *browser=IupOleControl("Shell.Explorer.2");
IupSetAttribute(browser,"DESIGNMODE", "NO");
return browser;
}
static WCHAR* Char2Wide(const char* str)
{
if (str)
{
int n = strlen(str)+1;
WCHAR* wstr = (WCHAR*)malloc(n * sizeof(WCHAR));
MultiByteToWideChar(CP_ACP, 0, str, -1, wstr, n);
return wstr;
}
return NULL;
}
static IWebBrowser2 *IupOleGetWebBrowserInterface(Ihandle *browser)
{
IWebBrowser2 *pweb = (IWebBrowser2*)IupGetAttribute(browser, "IUP_IWebBrowser2");
if (!pweb)
{
IUnknown *punk = (IUnknown*)IupGetAttribute(browser,"IUNKNOWN");
punk->QueryInterface(IID_IWebBrowser2, (void **) &pweb);
punk->Release();
IupSetAttribute(browser, "IUP_IWebBrowser2", (char*)pweb);
}
return pweb;
}
static void IupOleNavigate(Ihandle *browser,char *fname)
{
IWebBrowser2 *pweb = IupOleGetWebBrowserInterface(browser);
WCHAR* url = Char2Wide(fname);
pweb->Navigate(url, NULL, NULL, NULL, NULL);
free(url);
}
static void IupOleClose(Ihandle* browser)
{
IWebBrowser2 *pweb = IupOleGetWebBrowserInterface(browser);
pweb->Release();
}
static int load_cb(Ihandle* ih)
{
Ihandle* txt = (Ihandle*)IupGetAttribute(ih, "MY_TEXT");
Ihandle* browser = (Ihandle*)IupGetAttribute(ih, "MY_BROWSER");
IupOleNavigate(browser, IupGetAttribute(txt, "VALUE"));
return IUP_DEFAULT;
}
static int close_cb(Ihandle* ih)
{
Ihandle* browser = (Ihandle*)IupGetAttribute(ih, "MY_BROWSER");
IupOleClose(browser);
return IUP_DEFAULT;
}
void OleTest(void)
{
Ihandle* txt, *bt;
Ihandle * browser = IupOleCreateBrowser();
// Creates a dlg containing the OLE control
Ihandle* dlg = IupDialog(IupVbox(IupHbox(txt = IupText(""), bt = IupButton("Load", NULL), NULL), browser, NULL));
IupSetAttribute(dlg, "MARGIN", "10x10");
IupSetAttribute(dlg, "GAP", "10");
IupSetAttribute(dlg, "TITLE", "IupOle");
IupSetAttribute(dlg, "MY_TEXT", (char*)txt);
IupSetAttribute(dlg, "MY_BROWSER", (char*)browser);
IupSetAttribute(txt, "EXPAND", "HORIZONTAL");
// IupSetAttribute(txt, "VALUE", "d:/test.doc");
IupSetCallback(bt, "ACTION", (Icallback)load_cb);
IupSetCallback(dlg, "CLOSE_CB", (Icallback)close_cb);
IupSetAttributeHandle(dlg, "DEFAULTENTER", bt);
// Shows dlg
IupShow(dlg);
}
int main(int argc, char* argv[])
{
IupOpen(&argc, &argv);
IupOleControlOpen();
OleTest();
IupMainLoop();
IupClose();
return EXIT_SUCCESS;
}
#endif
|