1.我有一个窗体 VAR FORM1:TFROM1;
为什么findwindow('TForm1',PChar('Form1'))<>Form1.handle?2.       ReleaseCapture;
      (Sender as TWinControl).Perform(WM_SYSCOMMAND, $F012, 0);这两句话是什么意思?
 ReleaseCapture有什么用?

解决方案 »

  1.   

    1、换成这样试试
      findwindow('TForm1',nil)<>Form1.handle?2、捕捉光标
       用鼠标移动控件
      

  2.   

    findwindow('TForm1',nil),
    findwindow(nil,PChar('Form1')),都试过了,没有用!
      

  3.   

    var
      hwnd: THandle;
    begin
      hwnd := FindWindow('TForm1',nil);
      ShowMessage(IntToStr(hwnd));
    end;
    返回的是一个窗口句柄,上面是对的。
      

  4.   

    ReleaseCapture一般跟SetCapture一起使用
      

  5.   

    SetCapture捕捉光标
    ReleaseCapture不用时,释放捕捉
      

  6.   

    ReleaseCapture使窗口失去鼠标焦点
    然后移动控件
      

  7.   

    ouyang75928(Borland是我一生所爱) :
    那为什么findwindow('TForm1',nil)的返回值和TForm1.handle不一样呢?
      

  8.   

    setcapture把鼠标限制在某个范围
    release释放鼠标光标,自由移动
      

  9.   

    setcppture和releasecapture俺就不多说了,不过楼主的findwindow那个问题确实很有趣,我把这两个窗口列出来比了一下,还真是不一样,通过findwindow拿到的那个是不变的,也跟用spy++查看的相同,而form1.handle拿到的每次都变,还有就是如果用findwindow拿到的句柄操作的话,好象是不好使的。举例来说。
    procedure TForm1.Button1Click(Sender: TObject);
    var
      handle1, handle2: HWND;
      dc1, dc2: HDC;
      pen1, pen2, oldpen: HPEN;
    begin
      handle1 := FindWindow('TForm1', nil);
      handle2 := form1.Handle;
      Edit1.Text := inttostr(handle1);
      Edit2.Text := inttostr(handle2);  try
        dc2 := GetDC(handle2);
        pen1 := CreatePen(PS_SOLID, 1, clBlue);
        oldpen := SelectObject(dc2, pen1);
        Lineto(dc2, 600, 300);
      finally
        ReleaseDC(handle2, dc2);
        Selectobject(dc2, oldpen);
      end;  try
        dc1 := GetDC(handle1);
        pen2 := CreatePen(PS_SOLID, 1, clRed);
        oldpen := SelectObject(dc1, pen2);
        Lineto(dc1, 300, 600);
      finally
        ReleaseDC(handle1, dc1);
        Selectobject(dc1, oldpen);
      end;
    end;
    执行的结果只能看到那条蓝线,哪位高手给解决了,我可以令开贴给分。
      

  10.   

    killlaoli说的可能是因为在Delphi IDE环境下直接运行Project的原因,
    因为Delphi IDE的Design Form的类名和Window Text是随属性改变而改变的,
    所以,如果不独立运行Project,那么FindWindow可能Find到的是Delphi IDE
    的Design Form,而不是Project的Form1。当企图往Design Form画线时,发现自己白费劲:因为它的设置可能是,当运行时,Design Form隐藏。
      

  11.   

    to alphax(尽我所知帮助你吧) 
    抱歉,昨天有事走的早,没看到您回的帖子,我觉得您说的很有道理,可试了一下,单独运行exe文件,也只有一条蓝线,不知道您试过没有?我马上令开一贴,请继续关注......
      

  12.   

    to all:
    已经另开贴,请查看
    http://expert.csdn.net/Expert/topic/1225/1225191.xml?temp=.4109918
      

  13.   

    findwindow('TForm1',PChar('Form1'))<>Form1.handle
    你的Form1.Caption是什么呢是“Form1”吗?如果Caption是“试试FindWindow”
    这样作就行了:
    FindWindow(nil,'试试FindWindow')<>Form1.Handle;ReleaseCapture是释放鼠标(如果鼠标的某个键先前被按下了)的意思。
    (Sender as TWinControl).Perform(WM_SYSCOMMAND, $F012, 0);
    发一个消息给Sender as TWinControl,能拖拽它。
      

  14.   

    FindWindow
    如果用枚据线程的话,每个Delphi的Exe至少会有三个线程:Application、MainForm、输入法。但是听别人说如果是VC的Exe只有两个,Application、输入法。具体结果我没有试,这或者是一个原因吧。
      

  15.   

    procedure TForm1.Button1Click(Sender: TObject);
    var
      HHand: HWnd;
      szCaption:Array[0..20] of char;
      szResult :String;
    begin
      HHand := FindWindow(PChar('TForm1'), PChar(Form1.Caption));
      GetWindowText(HHand, szCaption, 20);
      szResult := Format('Application handle is %d; Form handle is %d; Find handle is %d and Text is %s',
        [Application.Handle, Form1.Handle, HHand, szCaption]);
      Edit1.Text := szResult;
    end;显示的结果是:Application handle is 1311716; Form handle is 1115116; Find handle is 1115116 and Text is Form1
      

  16.   

    根据上面的结果,和搂主的结论不一致啊。你再试试,很明显,上面的试验表明:Form1.hand = Findwindow(pchar(Tform1), pchar(Form1));
      

  17.   

    killlaoli(菜鸟):
    我这是两条线
      

  18.   

    谢谢各位的建议:-)经过这三个月来的实践,我发现FindWindow(nil,Pchar('Form1'))与Form1.Handle两者有时相等有时又不相等(运行的是同一个Exe),所以........不知哪位大侠能给出一个最终的论断?
      

  19.   

    The FindWindow function retrieves the handle to the top-level window whose class name and window name match the specified strings. This function does not search child windows. HWND FindWindow(    LPCTSTR lpClassName, // pointer to class name
        LPCTSTR lpWindowName  // pointer to window name
       );
     ParameterslpClassNamePoints to a null-terminated string that specifies the class name or is an atom that identifies the class-name string. If this parameter is an atom, it must be a global atom created by a previous call to the GlobalAddAtom function. The atom, a 16-bit value, must be placed in the low-order word of lpClassName; the high-order word must be zero. lpWindowNamePoints to a null-terminated string that specifies the window name (the window's title). If this parameter is NULL, all window names match.  Return ValuesIf the function succeeds, the return value is the handle to the window that has the specified class name and window name.
    If the function fails, the return value is NULL. To get extended error information, call GetLastError. 第一个参数是类名
    第二个参数是窗体标题名,如为空,则所有类名是第一个参数指定的类名
    而标题任意的窗口都可找到
    不知道为啥写成
    FindWindow(nil, PChar('Form1'));
      

  20.   

    楼主,俺另开那个帖子都结了,里面诸位高手分析的挺清楚的,进去看看吧。
    http://expert.csdn.net/Expert/topic/1225/1225191.xml?temp=.3369867