从 Windows 方法获取错误 ID:0:FindWindow
我正在尝试向我的 Delphi 应用程序发送 Windows 消息,但我在使用 FindWindow
方法时遇到问题: 我从 GetLastError
方法获取错误 ID 0。 我正在运行 Vista,从我读到的内容来看,此错误在 XP 或更早版本中很常见,但在 Vista 或 Win 7 中应该可以正常工作(也许我误解了?)。
这是我使用的代码,它位于 Delphi DLL 文件中,用 Delphi 5 编写:
procedure SendData(const copyDataStruct: TCopyDataStruct) ;
var
receiverHandle : THandle;
res : integer;
begin
receiverHandle := FindWindow(PChar('TMainForm'),PChar('MainForm')) ;
if receiverHandle = 0 then
begin
ShowMessage(format('Error %x finding MainForm',
[GetLastError()]));
Exit;
end;
res := SendMessage(receiverHandle, WM_COPYDATA, Integer(receiverHandle), Integer(@copyDataStruct)) ;
end;
im trying to send a Windows message to my Delphi application, but im having problems with the FindWindow
method:
im getting error id of 0 from the GetLastError
method.
Im running Vista and from what ive read this error is common in XP or earlier versions, but should work fine in Vista or Win 7 (maybe i misunderstood ?).
This is the code im using and its in a Delphi DLL file, written in Delphi 5 :
procedure SendData(const copyDataStruct: TCopyDataStruct) ;
var
receiverHandle : THandle;
res : integer;
begin
receiverHandle := FindWindow(PChar('TMainForm'),PChar('MainForm')) ;
if receiverHandle = 0 then
begin
ShowMessage(format('Error %x finding MainForm',
[GetLastError()]));
Exit;
end;
res := SendMessage(receiverHandle, WM_COPYDATA, Integer(receiverHandle), Integer(@copyDataStruct)) ;
end;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
根据系统错误代码列表 ,错误 0 表示“ERROR_SUCCESS” 。
是否您的窗口属于
TMainWindow
类,但有一个空的标题?请参阅 GetWindowText 的备注,即当 lpWindowName 参数为非空(就是这种情况:您将
MainWindow
传递到那里)。——杰罗恩
According to the system error codes list, error 0 means "ERROR_SUCCESS".
Could it be that your Window is of class
TMainWindow
, but has an empty Caption?See the remarks for GetWindowText that is internally used by FindWindow when the lpWindowName parameter is non-null (which is the case: you pass
MainWindow
there).--jeroen
向所有窗口广播自定义消息。只有您的窗口知道如何对此做出反应。然后,它可以在另一条消息中回复其当前的 HWND,这样广播公司就不必手动寻找它。使用 RegisterWindowMessage() 注册其他应用程序将忽略的唯一消息 ID。例如:
应用程序 1:
应用程序 2:
Broadcast a custom message to all windows. Only your window will know how to react to it. It can then reply with its current HWND in another message so the broadcaster does not have to hunt for it manually. Use RegisterWindowMessage() to register unique message IDs that other apps will ignore. For example:
App 1:
App 2: