if msg.hwnd=button1.handle then
    showmessage('fsdk');

解决方案 »

  1.   

    for i:=0 to Form1.ComponentCount -1 do
      if Form1.Componets[i] is TButton then
        ........
      

  2.   

    怎么知道鼠标点在Label控件上
      

  3.   

    我要实现在窗体中用鼠标拖动所有控件,但MSG返回的是HANDLE属性,而LABEL没有这个属性,没法判断是否点击在LABEL上,SOS。
      

  4.   

    前面我说的不是很清楚,我写的代码如下:
    procedure TForm1.Msg(var Msg: TMsg; var Handled: Boolean);
    var i,x,y : integer ;
    begin
       try
        if Msg.message = WM_MOUSEMOVE then
        begin
            if Msg.wParam = MK_LBUTTON then
            for i := Form1.ComponentCount - 1 downto 0 do
            begin
                if  TWinControl(Form1.Components[i]).handle = Msg.hwnd then
                begin //LABEL判断不了
                    x := LOWORD(Msg.lParam);
                    y := HIWORD(Msg.lParam);
                    TWinControl(Form1.Components[i]).Left := TWinControl(Form1.Components[i]).Left + x ;
                    TWinControl(Form1.Components[i]).Top := TWinControl(Form1.Components[i]).Top + y ;
                end;
            end;
        end;
       finally
          Handled := False ;
       end;
    end;
    但LABEL控件的上级是TControl,没有HANDLE 属性,不知道怎么判断。
      

  5.   

    为什么不在Label的OnMouseMove中写代码?
      

  6.   

    类层次关系:TControl->TGraphicControl->TCustomLabel->TLabel
    VCL设计时候象 TLabel、TImage等从TGraphicControl继承下来的轻型控件因为不接受焦点,所以没有给他们分配句柄。
    你可否用 TEdit 来代替 TLabel 呢?或者自己做一个TLabel控件。
      

  7.   

    GETFOCUS得到当前点击控件句柄,