计算机二级DELPHI:thread中实现消息循环计算机二级考试

文章作者 100test 发表时间 2009:05:07 18:06:33
来源 100Test.Com百考试题网


  2009年下半年全国计算机等级考试你准备好了没?考计算机等级考试的朋友,2009年下半年全国计算机等级考试时间是2009年9月19日至23日。更多优质资料尽在百考试题论坛 百考试题在线题库
  unit MsgThreadUnit.
  interface
  uses
  Classes, Windows, Messages, ComCtrls, SysUtils, Dialogs.
  type
  TMsgThread = class(TThread)
  private
  { Private declarations }
  FWinHandle: HWND.
  procedure DeallocateHWnd(Wnd: HWND).
  protected
  procedure Execute. override.
  procedure WndProc(var msg: TMessage).
  public
  constructor Create.
  destructor Destroy. override.
  property WinHandle: HWND read FWinHandle.
  end.
  implementation
  { THookThread }
  constructor TMsgThread.Create.
  begin
  FreeOnTerminate := true.
  FWinHandle := AllocateHWND(WndProc).
  Inherited Create(false).
  end.
  destructor TMsgThread.Destroy.
  begin
  DeallocateHWnd(FWinHandle).
  inherited.
  end.
  procedure TMsgThread.DeallocateHWnd(Wnd:HWND).
  var
  Instance: Pointer.
  begin
  Instance := Pointer(GetWindowLong(Wnd, GWL_WNDPROC)).
  if Instance <.>. @DefWindowProc then
  SetWindowLong(Wnd, gwl_wndproc, LongInt(@DefWindowProc)).
  FreeObjectInstance(Instance).
  DestroyWindow(Wnd).
  end.
  {这里可以根据自己需要处理的消息进行处理,所有消息都是windows的标准消息,当然也可以自定义消息,也可以使用RegisterWindowMessage注册消息,然后再在这里面使用,在这里列举了一个wm_copydata消息,是这个消息经常用于进程间的数据交换,比较难用}
  procedure TMsgThread.WndProc(var msg: TMessage).
  begin
  if msg.Msg = WM_COPYDATA then
  begin
  //ProcessCopyDataMsg(msg)
  end
  else Msg.Result := DefWindowProc(FWinHandle, Msg.Msg, Msg.wParam, Msg.lParam).
  end.
  procedure TMsgThread.Execute.
  begin
  { Place thread code here }
  while not Terminated do
  begin
  sleep(10).
  end.
  end.
  end.

  特别推荐:

  2009年9月全国计算机等级考试时间及科目预告

  2009年上半年全国计算机等级考试参考答案请进入计算机考试论坛

  2009年全国计算机等级考试报名信息汇总

  2009年NCRE考试有新变化

  2009年全国计算机等级考试-大纲

  2009年上半年全国计算机二级考试试题及答案

  2009年上半年全国计算机等级考试试题答案汇总



相关文章


计算机二级DELPHI:对文本文件进行写操作计算机二级考试
计算机二级DELPHI:thread中实现消息循环计算机二级考试
DELPHI中创建语言资源文档DLL的方法计算机二级考试
delphi程序恢复ctrl space切换输入法计算机二级考试
计算机二级:Delphi数据网格自动适应宽度计算机二级考试
Delphi6项目迁移到Delph7时最常见问题计算机二级考试
澳大利亚华人论坛
考好网
日本华人论坛
华人移民留学论坛
英国华人论坛