/*
* Reading and writing to a SAFEARRAY
*
* This example reads from a PostData object in a BeforeNavigate2 event and
* creates a PostData object in a call to Navigate.
*
* For a list of all SWT example snippets see
* http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-swt-home/dev.html#snippets
*/
import org.eclipse.swt.SWT;
import org.eclipse.swt.SWTException;
import org.eclipse.swt.internal.win32.OS;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.ole.win32.OLE;
import org.eclipse.swt.ole.win32.OleAutomation;
import org.eclipse.swt.ole.win32.OleControlSite;
import org.eclipse.swt.ole.win32.OleEvent;
import org.eclipse.swt.ole.win32.OleFrame;
import org.eclipse.swt.ole.win32.OleListener;
import org.eclipse.swt.ole.win32.Variant;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
public class SWTIE {
static int CodePage = OS.GetACP();
public static void main(String[] args) {
Display display = new Display();
Shell shell = new Shell(display);
shell.setLayout(new GridLayout(2, false));
final Text text = new Text(shell, SWT.BORDER);
text.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
Button go = new Button(shell, SWT.PUSH);
go.setText("Go");
OleFrame oleFrame = new OleFrame(shell, SWT.NONE);
oleFrame.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2,
1));
OleControlSite controlSite;
OleAutomation automation;
try {
controlSite = new OleControlSite(oleFrame, SWT.NONE,
"Shell.Explorer");
automation = new OleAutomation(controlSite);
controlSite.doVerb(OLE.OLEIVERB_INPLACEACTIVATE);
} catch (SWTException ex) {
return;
}
final OleAutomation auto = automation;
go.addListener(SWT.Selection, new Listener() {
public void handleEvent(Event e) {
String url = text.getText();
int[] rgdispid = auto.getIDsOfNames(new String[] { "Navigate",
"URL" });
int dispIdMember = rgdispid[0];
Variant[] rgvarg = new Variant[1];
rgvarg[0] = new Variant(url);
int[] rgdispidNamedArgs = new int[1];
rgdispidNamedArgs[0] = rgdispid[1];
auto.invoke(dispIdMember, rgvarg, rgdispidNamedArgs);
}
});
// Read PostData whenever we navigate to a site that uses it
int BeforeNavigate2 = 0xfa;
controlSite.addEventListener(BeforeNavigate2, new OleListener() {
public void handleEvent(OleEvent event) {
Variant url = event.arguments[1];
Variant postData = event.arguments[4];
if (postData != null) {
System.out.println("PostData = " + readSafeArray(postData)
+ ", URL = " + url.getString());
}
}
});
// Navigate to this web site which uses post data to fill in the text
// field
// and put the string "hello world" into the text box
text.setText("file://" + SWTIE.class.getResource("a.html").getFile());
int[] rgdispid = automation.getIDsOfNames(new String[] { "Navigate",
"URL", "PostData" });
int dispIdMember = rgdispid[0];
Variant[] rgvarg = new Variant[2];
rgvarg[0] = new Variant(text.getText());
rgvarg[1] = writeSafeArray("hello world222");
int[] rgdispidNamedArgs = new int[2];
rgdispidNamedArgs[0] = rgdispid[1];
rgdispidNamedArgs[1] = rgdispid[2];
automation.invoke(dispIdMember, rgvarg, rgdispidNamedArgs);
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
// The following structs are accessed in the readSafeArray and
// writeSafeArray
// functions:
//
// VARIANT:
// short vt
// short wReserved1
// short wReserved2
// short wReserved3
// int parray
//
// SAFEARRAY:
// short cDims // Count of dimensions in this array
// short fFeatures // Flags used by the SafeArray
// int cbElements // Size of an element of the array
// int cLocks // Number of times the array has been locked without
// corresponding unlock
// int pvData // Pointer to the data
// SAFEARRAYBOUND[] rgsabound // One bound for each dimension
//
// SAFEARRAYBOUND:
// int cElements // the number of elements in the dimension
// int lLbound // the lower bound of the dimension
static String readSafeArray(Variant variantByRef) {
// Read a safearray that contains data of
// type VT_UI1 (unsigned shorts) which contains
// a text stream.
int pPostData = variantByRef.getByRef();
short[] vt_type = new short[1];
OS.MoveMemory(vt_type, pPostData, 2);
String result = null;
if (vt_type[0] == (short) (OLE.VT_BYREF | OLE.VT_VARIANT)) {
int[] pVariant = new int[1];
OS.MoveMemory(pVariant, pPostData + 8, 4);
vt_type = new short[1];
OS.MoveMemory(vt_type, pVariant[0], 2);
if (vt_type[0] == (short) (OLE.VT_ARRAY | OLE.VT_UI1)) {
int[] pSafearray = new int[1];
OS.MoveMemory(pSafearray, pVariant[0] + 8, 4);
short[] cDims = new short[1];
OS.MoveMemory(cDims, pSafearray[0], 2);
int[] pvData = new int[1];
OS.MoveMemory(pvData, pSafearray[0] + 12, 4);
int safearrayboundOffset = 0;
for (int i = 0; i < cDims[0]; i++) {
int[] cElements = new int[1];
OS.MoveMemory(cElements, pSafearray[0] + 16
+ safearrayboundOffset, 4);
safearrayboundOffset += 8;
int cchWideChar = OS.MultiByteToWideChar(CodePage,
OS.MB_PRECOMPOSED, pvData[0], -1, null, 0);
if (cchWideChar == 0)
return null;
char[] lpWideCharStr = new char[cchWideChar - 1];
OS.MultiByteToWideChar(CodePage, OS.MB_PRECOMPOSED,
pvData[0], -1, lpWideCharStr, lpWideCharStr.length);
result = new String(lpWideCharStr);
}
}
}
return result;
}
static Variant writeSafeArray(String string) {
// Create a one dimensional safearray containing two VT_UI1 values
// where VT_UI1 is an unsigned char
// Define cDims, fFeatures and cbElements
short cDims = 1;
short FADF_FIXEDSIZE = 0x10;
short FADF_HAVEVARTYPE = 0x80;
short fFeatures = (short) (FADF_FIXEDSIZE | FADF_HAVEVARTYPE);
int cbElements = 1;
// Create a pointer and copy the data into it
int count = string.length();
char[] chars = new char[count + 1];
string.getChars(0, count, chars, 0);
int cchMultiByte = OS.WideCharToMultiByte(CodePage, 0, chars, -1, null,
0, null, null);
if (cchMultiByte == 0)
return null;
int pvData = OS.GlobalAlloc(OS.GMEM_FIXED | OS.GMEM_ZEROINIT,
cchMultiByte);
OS.WideCharToMultiByte(CodePage, 0, chars, -1, pvData, cchMultiByte,
null, null);
int cElements1 = cchMultiByte;
int lLbound1 = 0;
// Create a safearray in memory
// 12 bytes for cDims, fFeatures and cbElements + 4 bytes for pvData +
// number of dimensions * (size of safearraybound)
int sizeofSafeArray = 12 + 4 + 1 * 8;
int pSafeArray = OS.GlobalAlloc(OS.GMEM_FIXED | OS.GMEM_ZEROINIT,
sizeofSafeArray);
// Copy the data into the safe array
int offset = 0;
OS.MoveMemory(pSafeArray + offset, new short[] { cDims }, 2);
offset += 2;
OS.MoveMemory(pSafeArray + offset, new short[] { fFeatures }, 2);
offset += 2;
OS.MoveMemory(pSafeArray + offset, new int[] { cbElements }, 4);
offset += 4;
OS.MoveMemory(pSafeArray + offset, new int[] { 0 }, 4);
offset += 4;
OS.MoveMemory(pSafeArray + offset, new int[] { pvData }, 4);
offset += 4;
OS.MoveMemory(pSafeArray + offset, new int[] { cElements1 }, 4);
offset += 4;
OS.MoveMemory(pSafeArray + offset, new int[] { lLbound1 }, 4);
offset += 4;
// Create a variant in memory to hold the safearray
int pVariant = OS.GlobalAlloc(OS.GMEM_FIXED | OS.GMEM_ZEROINIT,
Variant.sizeof);
short vt = (short) (OLE.VT_ARRAY | OLE.VT_UI1);
OS.MoveMemory(pVariant, new short[] { vt }, 2);
OS.MoveMemory(pVariant + 8, new int[] { pSafeArray }, 4);
// Create a by ref variant
Variant variantByRef = new Variant(pVariant,
(short) (OLE.VT_BYREF | OLE.VT_VARIANT));
return variantByRef;
}
}
分享到:
相关推荐
在描述中提到,原先在开发者的本机环境(IE8和IE6)中使用`<embed>`标签能够正常播放视频,但转移到用户环境时遇到了问题。这可能是因为用户电脑上安装的IE6浏览器存在兼容性问题,或者操作系统与浏览器的配置不支持...
在网页开发中,`<embed>` 标签用于嵌入外部资源,如音频、视频、插件等。本文将深入探讨如何动态修改 `<embed>` 元素的 `src` 属性,以及这样做带来的实际效果和应用场景。 动态修改 `src` 属性是网页交互中的常见...
- **兼容性**:`embed`标签主要针对非IE浏览器设计,而`object`标签适用于所有浏览器,尤其是IE浏览器。 - **使用建议**:为了确保页面在不同浏览器中的兼容性,建议同时使用`<embed>`和`<object>`标签。通常情况下...
`embed`标签在大部分现代浏览器中都有良好的支持,但考虑到老版本的IE和一些不完全支持HTML5的浏览器,可以使用`object`标签作为`embed`的备选方案,以确保跨浏览器的兼容性。 ```html <!--[if !IE]>--> <embed src...
要使用`<embed>`标签嵌入内容,必须通过其`src`属性来指定要嵌入的资源的URL地址,而且该URL地址必须包含具体的文件扩展名。这一点在尝试播放MP3音乐文件时尤为重要。例如,如果要嵌入一个MP3文件,`src`属性的值就...
【embed标签】 embed标签是HTML中用于嵌入外部资源的元素,主要应用于网页中插入音频、视频等多媒体内容。由于HTML5的兴起,现在更多使用video和audio标签来处理多媒体,但embed仍然在某些场景下被使用,尤其是在...
标题“Go-embed:另一个Golang静态内容嵌入器”暗示了`embed`包是Go语言中处理静态内容的一种方法。与其他第三方库相比,`embed`作为内置的解决方案,具有更好的性能和更低的依赖性。 描述“embed: 另一个Golang静态...
### AS3 Embed 用法详解 #### 一、引言 随着ActionScript 3.0 (简称AS3) 的普及与发展,开发人员越来越多地利用AS3进行Flash项目的开发。在AS3环境中,开发者不再像以前版本那样依赖于Flash IDE中的库来存储图形...
在ActionScript 3 (AS3)中,`Embed`元标签是一个非常有用的工具,它允许开发者将各种资源,如图片、字体等,直接内嵌到SWF文件中。这样做的好处在于,即使用户没有网络连接,也可以访问这些资源,提高了应用程序的...
embed 属性详解 embbed 属性是 HTML 中的一种多媒体嵌入标签,用于将音频、视频、图片等多媒体文件嵌入到网页中。下面是 embed 属性的详细解释: 一、基本语法 embed 属性的基本语法为:`embed src=url`,其中 `...
"EMBED用法介绍在网页中播放视频的jsp<embed>标签" EMBED标签是HTML中一种常用的标签,用于在网页中播放音频、视频文件。它可以播放多种格式的文件,包括Windows Media Player支持的格式,如WMA、WMV、ASF、MPG、...
在`pyros2097/go-embed-4274f34` 这个压缩包中,包含了`go-embed` 某一版本的源码,如果你需要深入了解其内部实现或进行二次开发,可以解压并查看源代码。通常,源码中会有更详细的文档和示例来指导你如何使用和扩展...
embed src=url 其中,src 是音频或视频文件的路径,可以是相对路径或绝对路径。 属性设置 1. 自动播放 autostart=true、false 如果 autostart=true,音频或视频文件将在下载完毕后自动播放;如果 autostart=...
tomcat-embed-jasper-9.0.16.jar
tomcat-embed-core-9.0.16.jar
tomcat-embed-core-9.0.27
tomcat-embed-el-9.0.16.jar
tomcat-embed-websocket-9.0.16.jar
`<embed>`标签的使用方式如下: ```html <embed src="资源URL" width="宽度" height="高度" allowfullscreen="true" /> ``` 其中,`src`属性指定了要嵌入的外部资源的URL,`width`和`height`分别定义了嵌入内容的...
tomcat-embed-core-8.5.23.jar