问题如下:
1 delphi 把windows的TMsg记录中的信息映射为:TMessage记录:
type TMessage = packed record Msg: Cardinal; case Integer of 0: ( WParam: Longint; LParam: Longint; Result: Longint); 1: ( WParamLo: Word; WParamHi: Word; LParamLo: Word; LParamHi: Word; ResultLo: Word; ResultHi: Word); end; 我想问下 'case Integer of ' 是什么意思,为什么有个Integer?
2.通知消息是怎么处理的,要是能给个实例就好了
3.在TForm1中定义的通知消息处理过程procedure NoticeMsgHandle(var Msg:TMessage);message BN_CLICKED;
为什么报错:[Error] NoticeMsg.pas(15): Illegal message method index

解决方案 »

  1.   

    1.
    case integer of 没有什么别的意思,不知道你是否了解C语言里面的共用体.
    case integer of,这种语法,就是来做共用体定义的.2.通知消息是怎么处理的?不太明白你的意思. 你是说怎么样写消息响应函数来响应这个消息?直接在TForm1里面加个成员函数: procedure WMYourMsg(var msg: TMessage); message WM_YourMsg;就行了.
    private, protected, public都行
    3.不知道
      

  2.   

    第二个问题不知道你是否是问消息怎么循环的.你首先可能得看看tapplication的源码
    procedure TApplication.Run;
    begin
      FRunning := True;
      try
        AddExitProc(DoneApplication);
        if FMainForm <> nil then
        begin
          case CmdShow of
            SW_SHOWMINNOACTIVE: FMainForm.FWindowState := wsMinimized;
            SW_SHOWMAXIMIZED: MainForm.WindowState := wsMaximized;
          end;
          if FShowMainForm then
            if FMainForm.FWindowState = wsMinimized then
              Minimize else
              FMainForm.Visible := True;
          repeat
            try
              HandleMessage;
            except
              HandleException(Self);
            end;
          until Terminated;
        end;
      finally
        FRunning := False;
      end;
    end;procedure TApplication.HandleMessage;
    var
      Msg: TMsg;
    begin
      if not ProcessMessage(Msg) then Idle(Msg);
    end;function TApplication.ProcessMessage(var Msg: TMsg): Boolean;
    var
      Handled: Boolean;
    begin
      Result := False;
      if PeekMessage(Msg, 0, 0, 0, PM_REMOVE) then
      begin
        Result := True;
        if Msg.Message <> WM_QUIT then
        begin
          Handled := False;
          if Assigned(FOnMessage) then FOnMessage(Msg, Handled);
          if not IsHintMsg(Msg) and not Handled and not IsMDIMsg(Msg) and
            not IsKeyMsg(Msg) and not IsDlgMsg(Msg) then
          begin
            TranslateMessage(Msg);
            DispatchMessage(Msg);
          end;
        end
        else
          FTerminate := True;
      end;
    end;
    在DispatchMessage(Msg);之后,消息被分发到各对应的窗体,然后由注册的窗体函数来处理消息,可以看看tform的
    procedure WndProc(var Message: TMessage); override;
    第三个问题,可能是不能截BN_CLICKED=0吧.
      

  3.   

    来晚了,,顶一下吧。。
    对1补充一下,case integer of 相当与C语言里 union (共同体)
    他和struct/packed record 的最大区别就是节省空间,即:分配时按照最大的分配。
      

  4.   

    case integer of 是变体记录,目的是节省内存
      

  5.   

    var
      s:string;
    begin
      s:='abc';
      sentmessage(edit1.handle,WM_SETTEXT,0,pchar(s));
    end;
      

  6.   

    BN_CLICKED是用来通知父窗体时的WM_COMMAND中一个参数的。是不可以拦截的。如果你想拦截按钮被按下的消息,就在父窗体中拦截WM_COMMAND消息就可以了。参数:
      wParam: 就是你想要的BN_CLICKED
      lParam: 按钮的句柄
      

  7.   

    case integer of 相当于c里的union,下面的各项占用相同的内存,所占用的内存以各项中占用最大的内存为准。其实这几个问题你可以打开《delphi5开发人员指南》第二、三章,系统的看一下就会很明白了。