registerwindowmessage
这个例子讲述了如何在程序间传递消息,如何获得屏幕图形。代码如下,同时运行这两个程序,在form1中按下按纽,则在form2中会出现form1的图形。为简便,只列出窗体代码。
-----------------------form1代码------------------------------
unit Unit1;
interface
uses
windows, messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Edit1: TEdit;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
INTERMSG : UINT;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.FormCreate(Sender: TObject);
begin
INTERMSG := RegisterWindowMessage('窗口通信的例子');
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
sendmessage(HWND_BROADCAST,INTERMSG,handle,0);
end;
end.
---------------------form2代码----------------------------------
unit Unit2;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ExtCtrls;
type
TForm2 = class(TForm)
Image1: TImage;
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
Msg2 : UINT;
procedure GetImage(Form1Window : HWND);
public
{ Public declarations }
procedure WndProc(var Message: TMessage); override;
end;
var
Form2: TForm2;
implementation
{$R *.DFM}
procedure TForm2.FormCreate(Sender: TObject);
begin
Msg2 := RegisterWindowMessage('窗口通信的例子');
end;
procedure TForm2.WndProc(var Message: TMessage);
begin
if Message.Msg = Msg2 then
GetImage(Message.WParam)
else inherited;
end;
procedure TForm2.GetImage(Form1Window : HWND);
var
Form1DC: HDc;
Form1Rect: TRect;
begin
image1.Picture := nil;
Form1DC := GetWindowDC(Form1Window);
GetWindowRect(Form1Window,Form1Rect);
image1.Width := Form1Rect.Right-Form1Rect.Left;
image1.Height := Form1Rect.Bottom - Form1Rect.Top;
BitBlt(Image1.Canvas.Handle,0,0,image1.Width,
image1.Height,
Form1DC, 0,
0, SRCCOPY);
Image1.Refresh;
ReleaseDC(Form1Window, Form1DC);
SetForegroundWindow(handle);
beep; //收到信号并且成功完成
end;
end.
--------------------------------------------------------------------------
www.pigtour.com/bbs/CreateUser.asp?menu=Check&welcome=9474
相关阅读
群发信息很多朋友都不陌生了,现在很多商家朋友做活动的时候,都会通过淘宝旺旺群发的形式向自己的老客户进行推送,今天要给大家分享就
[核心提示] 微信新推出的消息撤回是想要做阅后即焚?别想多,微信其实是变得更加严肃了。微信在前不久发布的最新 v5.3.1 版本中推出
怎样查看手淘历史消息?手淘历史记录怎么查?各位淘宝用户们,如果您有需要必须要奥去查看手机淘宝历史消息,可以往下看小编整理的
期待已久的“微信支付分”终于上线了,微信将对标蚂蚁金服“芝麻信用”。以前朋友之间互相对比“芝麻信用”的分数,得分高的就好像信
无意间发现,王兴在“饭否”依旧活跃着…他在饭否的个人签名,是这样的:自述:如果我一整天都没看到、想到、或做过什么值得在饭否上说的