summaryrefslogtreecommitdiff
path: root/iup/test/ole.cpp
diff options
context:
space:
mode:
authorPixel <pixel@nobis-crew.org>2009-11-04 11:56:41 -0800
committerPixel <pixel@nobis-crew.org>2009-11-04 11:59:33 -0800
commitd577d991b97ae2b5ee1af23641bcffc3f83af5b2 (patch)
tree590639d50205d1bcfaff2a7d2dc6ebf3f373c7ed /iup/test/ole.cpp
Initial import. Contains the im, cd and iup librairies, and a "working" Makefile for them under linux.
Diffstat (limited to 'iup/test/ole.cpp')
-rwxr-xr-xiup/test/ole.cpp108
1 files changed, 108 insertions, 0 deletions
diff --git a/iup/test/ole.cpp b/iup/test/ole.cpp
new file mode 100755
index 0000000..c3da5fc
--- /dev/null
+++ b/iup/test/ole.cpp
@@ -0,0 +1,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