1.我有一个窗体 VAR FORM1:TFROM1;
为什么findwindow('TForm1',PChar('Form1'))<>Form1.handle?2. ReleaseCapture;
(Sender as TWinControl).Perform(WM_SYSCOMMAND, $F012, 0);这两句话是什么意思?
ReleaseCapture有什么用?
为什么findwindow('TForm1',PChar('Form1'))<>Form1.handle?2. ReleaseCapture;
(Sender as TWinControl).Perform(WM_SYSCOMMAND, $F012, 0);这两句话是什么意思?
ReleaseCapture有什么用?
findwindow('TForm1',nil)<>Form1.handle?2、捕捉光标
用鼠标移动控件
findwindow(nil,PChar('Form1')),都试过了,没有用!
hwnd: THandle;
begin
hwnd := FindWindow('TForm1',nil);
ShowMessage(IntToStr(hwnd));
end;
返回的是一个窗口句柄,上面是对的。
ReleaseCapture不用时,释放捕捉
然后移动控件
那为什么findwindow('TForm1',nil)的返回值和TForm1.handle不一样呢?
release释放鼠标光标,自由移动
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;
执行的结果只能看到那条蓝线,哪位高手给解决了,我可以令开贴给分。
因为Delphi IDE的Design Form的类名和Window Text是随属性改变而改变的,
所以,如果不独立运行Project,那么FindWindow可能Find到的是Delphi IDE
的Design Form,而不是Project的Form1。当企图往Design Form画线时,发现自己白费劲:因为它的设置可能是,当运行时,Design Form隐藏。
抱歉,昨天有事走的早,没看到您回的帖子,我觉得您说的很有道理,可试了一下,单独运行exe文件,也只有一条蓝线,不知道您试过没有?我马上令开一贴,请继续关注......
已经另开贴,请查看
http://expert.csdn.net/Expert/topic/1225/1225191.xml?temp=.4109918
你的Form1.Caption是什么呢是“Form1”吗?如果Caption是“试试FindWindow”
这样作就行了:
FindWindow(nil,'试试FindWindow')<>Form1.Handle;ReleaseCapture是释放鼠标(如果鼠标的某个键先前被按下了)的意思。
(Sender as TWinControl).Perform(WM_SYSCOMMAND, $F012, 0);
发一个消息给Sender as TWinControl,能拖拽它。
如果用枚据线程的话,每个Delphi的Exe至少会有三个线程:Application、MainForm、输入法。但是听别人说如果是VC的Exe只有两个,Application、输入法。具体结果我没有试,这或者是一个原因吧。
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
我这是两条线
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'));
http://expert.csdn.net/Expert/topic/1225/1225191.xml?temp=.3369867