在我的C++应用程序的GUI对象中,我在主窗口过程中有以下内容:
case WM_SIZE:
{
OutputDebugString(L"WM_SIZE received.\n");
RECT rect = {0};
GetWindowRect(hwnd, &rect);
if (!PostMessage(0, GUI_MSG_SIZECHANGED, w, MAKELONG(rect.bottom - rect.top, rect.right - rect.left))) {
OutputDebugString(L"PostMessage failed.\n"); // <--- never called
}
}
return 0; // break;
Run Code Online (Sandbox Code Playgroud)
GUI对象还具有以下getMessage()方法:
int GUI::getMessage(MSG & msg) {
BOOL result = 0;
while ((result = GetMessage(&msg, 0, 0, 0)) > 0) {
if (msg.message > (GUI_MSG_BASE-1) && msg.message < (GUI_MSG_LAST+1)) {
OutputDebugString(L"GUI message received.\n");
break;
}
else {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
return result;
}
Run Code Online (Sandbox Code Playgroud)
应用程序对象以下列方式调用此方法:
while …Run Code Online (Sandbox Code Playgroud) 假设我有两个选项卡,每个选项卡都在不同的域上加载了一个网页.两个选项卡中的页面想要进行通信.
我能看到的最简单的解决方案就是这个 (我在搜索重复项时发现的一个密切相关的问题的答案),其中一个或两个页面加载一个中间页面iFrame,它代理事件postMessage()和localStorage事件.但是,这确实需要在某处托管此页面,以及客户端的额外请求.
是否有任何技术可以不需要专门的"代理页面"由其中一个域提供服务?(即可以通过没有支持服务器的JavaScript库实现?)
使用给定的函数发布消息,但收到错误"DataCloneError:无法克隆该对象".at line"target ['postMessage'](message,target_url.replace(/([^:] +:// [^ /] +).*/,'$ 1'));" 在FireFox-34中,相同的代码在Chrome和旧版FireFox上运行良好.
var storage = function() {
return {
postMessage : function(message, target_url, target) {
if (!target_url) {
return;
}
var target = target || parent; // default to parent
if (target['postMessage']) {
// the browser supports window.postMessage, so call it with a targetOrigin
// set appropriately, based on the target_url parameter.
target['postMessage'](message, target_url.replace( /([^:]+:\/\/[^\/]+).*/, '$1'));
}
}
}
}();
Run Code Online (Sandbox Code Playgroud) 有人用过AngsJS的JsPanel吗?
我找不到那个例子.否则,是否有任何类似的框架来管理页面内的模态窗口,打开并访问其中的iframe,并使用postmessage通信?
我使用React Native webview来显示index.html,HTML将在应用程序中发布消息.然后,应用程序将接收消息并将其写入控制台.问题是app无法接收消息,何时postMessage立即在头上运行.我认为它可能与HTML没有完成加载有关.然后setTimeout,我使用了延迟,并且它有效.
现在我想知道:
我使用的是React Native版本0.39.0和Node版本7.2.0.
这是我到目前为止的代码:
的index.html
<head>
<title>Index</title>
<script type="text/javascript" src="index.js"></script>
<script type="text/javascript">
// can not be received
postMessage('send to react native from index inline, no delay', '*');
// can not be received
setTimeout(function(){
postMessage('send to react native from index inline, delay 0 milliscond', '*')
}, 0);
// can received
setTimeout(function(){
postMessage('send to react native from index inline, delay 100 milliscond', '*')
}, 100);
onload = function() {
// can …Run Code Online (Sandbox Code Playgroud) postMessage的文档意味着可以进行跨域消息传递.然而:
// When the popup has fully loaded, if not blocked by a popup blocker
Run Code Online (Sandbox Code Playgroud)
这不是一个非常清楚的说明如何实际做到这一点.
想象一下两个网站:
qc-a.nfshost.comqc-b.quadhome.com在父母:
document.addEventListener('message', function(e) {
alert('Parent got (from ' + e.origin + '): ' + e.data);
e.source.postMessage('Round-tripped!', 'http://qc-b.quadhome.com');
}, false);
function go() {
var w = window.open('http://qc-b.quadhome.com', 'test');
/* This doesn't work because same-origin policy prevents knowing when
the opened window is ready. */
w.postMessage('Vain attempt.', 'http://qc-b.quadhome.com');
}
Run Code Online (Sandbox Code Playgroud)
并且,在孩子:
document.addEventListener('message', function(e) {
alert('Child got (from ' + …Run Code Online (Sandbox Code Playgroud) 我刚刚开始大量使用TFrames(好吧,是的,我一直生活在摇滚......).我认为框架支持消息处理程序声明 - 我已经看到很多这样的例子.那么为什么这个用于TFrame的简单测试单元永远不会看到它发布给自己的消息?(当我发现在我的大型应用程序中没有调用消息处理程序时,我创建了测试.)
unit JunkFrame;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls;
const
DO_FORM_INITS = WM_USER + 99;
type
TFrame1 = class(TFrame)
Panel1: TPanel;
private
procedure DoFormInits(var Msg: TMessage); message DO_FORM_INITS;
public
constructor Create(AOwner: TComponent); override;
end;
implementation
{$R *.dfm}
constructor TFrame1.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
PostMessage(self.Handle, DO_FORM_INITS, 0, 0);
end;
procedure TFrame1.DoFormInits(var Msg: TMessage);
begin
ShowMessage('In DoFormInits!');
end;
end.
Run Code Online (Sandbox Code Playgroud)
此框架仅包含TPanel,框架用于仅包含框架和关闭按钮的简单主文件.
我错过了什么?
在Dephi中,我创建了一个这样的线程,它会不时地向主表单发送消息
Procedure TMyThread.SendLog(I: Integer);
Var
Log: array[0..255] of Char;
Begin
strcopy(@Log,PChar('Log: current stag is ' + IntToStr(I)));
PostMessage(Form1.Handle,WM_UPDATEDATA,Integer(PChar(@Log)),0);
End;
procedure TMyThread.Execute;
var
I: Integer;
begin
for I := 0 to 1024 * 65536 do
begin
if (I mod 65536) == 0 then
begin
SendLog(I);
End;
End;
end;
Run Code Online (Sandbox Code Playgroud)
其中WM_UPDATEDATA是自定义消息,定义如下:
const
WM_UPDATEDATA = WM_USER + 100;
Run Code Online (Sandbox Code Playgroud)
在主要表单中,它将执行以下更新列表:
procedure TForm1.WMUpdateData(var msg : TMessage);
begin
List1.Items.Add(PChar(msg.WParam));
end;
Run Code Online (Sandbox Code Playgroud)
但是,由于发送到主窗体的日志字符串是一个局部变量,在调用SendLog后将被销毁.虽然TForm1.WMUpdateData异步处理消息,但是在调用它时,Log字符串可能已被销毁.如何解决这个问题呢?
我想也许我可以在全局系统空间中分配字符串空间,然后将其传递给消息,然后在TForm1.WMUpdateData处理消息之后,它可以破坏全局空间中的字符串空间.这是一个可行的解决方案吗?怎么实现这个?
谢谢
我正在尝试使用Jasmine 2.0为AngularJS应用程序中的某些逻辑编写单元测试,但逻辑在一个事件监听器中.从控制器:
window.addEventListener('message', function(e) {
if (e.data === "sendMessage()") {
$scope.submit();
}
}, false);
Run Code Online (Sandbox Code Playgroud)
并从测试文件:
describe("post message", function() {
beforeEach(function(done) {
var controller = createController(controllerParams);
spyOn($scope, 'submit');
window.postMessage('sendMessage()', '*');
done();
});
it('should submit on a sent message', function (done) {
expect($scope.submit).toHaveBeenCalled();
done();
});
});
Run Code Online (Sandbox Code Playgroud)
但是测试失败了,间谍从未被击中.放入控制台调试语句的额外信息:
window.addEventListener 在控制器IS被调用.beforeEach和it块都得到调用.我的测试缺少什么?
我正在尝试将 react url 作为 iframe 加载到我的 jsp 项目中。
这是我的发送方代码块:
<iframe id="eda"
style="display: none;"
src="http://myhost:3000/"
width="100%" height="600" border="0" marginwidth="0"
marginheight="0" scrolling="no">
</iframe>
****
function loadReactIframe(){
document.getElementById("eda").contentWindow.postMessage('GET MESSAGE FROM ME', '*');
}
Run Code Online (Sandbox Code Playgroud)
我还尝试了以下方法:
function loadReactIframe(){
document.getElementById("eda").contentWindow.postMessage(
'GET MESSAGE FROM ME',
'http://myhost', 3000
);
}
Run Code Online (Sandbox Code Playgroud)
我的接收器(反应)代码块:
componentDidMount() {
window.addEventListener('load', this.handleLoad);
alert('componentDidMount')
}
handleLoad(event) {
alert(event.data);
}
Run Code Online (Sandbox Code Playgroud)
但我无法从事件中获取数据。
postmessage ×10
javascript ×6
angularjs ×2
cross-domain ×2
delphi ×2
message ×2
c++ ×1
handler ×1
html ×1
html5 ×1
jasmine ×1
jquery ×1
modal-dialog ×1
mozilla ×1
razor ×1
react-native ×1
reactjs ×1
tframe ×1
unit-testing ×1
webview ×1
winapi ×1