发新话题
打印

[SDK/API/系统] findwindow和findwindowex这两个api的用法

findwindow和findwindowex这两个api的用法

Findwindow!
话题633743的标题是: Findwindow! (50分)
分类:Windows API coolmyf (2001-09-19 16:52:00)  
请问Findwindow和FindwindowEx这两个函数是如何使用的。
最好能给出例子!谢谢!

卷起千堆雪tyn (2001-09-19 17:01:00)  
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
   );

你首先打开附件里的计算器,

procedure TForm1.Button1Click(Sender: TObject);
var
HWndCalculator : HWnd;
begin
// find the exist calculator window
HWndCalculator := FindWindow(nil, '计算器'); // close the exist Calculator
if HWndCalculator <> 0 then
SendMessage(HWndCalculator, WM_CLOSE, 0, 0);
end;

pcexplorer (2001-09-19 17:06:00)  
根据给出的类名或窗口标题名称取的该窗口的句柄
var
  AHandle:THandle;
begin
  AHandle:=FindWindow(nil,'我的电脑');
  if AHandle<>0 then
  begin
    //To do add your code here
    SendMessage(AHandle,WM_SYSCOMMAND,SC_CLOSE,0);
  end;
end;

//  TMyFrm=class(TForm)

var
  AHandle:THandle;
begin
  AHandle:=FindWindow(TMyFrm,nil);
  if AHandle<>0 then
  begin
    //To do add your code here
    SendMessage(AHandle,WM_SYSCOMMAND,SC_CLOSE,0);
  end;
end;


FindwindowEx 同理只是多一点参数

  

bzmouse (2001-09-19 17:10:00)  
gz

antic_ant (2001-09-19 17:11:00)  
findwindowex 的功能更强
如果 findwindow在win2000 or NT 下实现不了的
findwindowex 可以实现

SDEAST (2001-09-19 17:22:00)  
Wnd1:=FindWindow(PChar(FormName), PChar(FormCaption));
  Wnd1:=FindWindowEx(Wnd1,Hdl,'TEdit', nil);

coolmyf (2001-09-20 14:03:00)
妖城欢迎您!

TOP

新建一窗体,放个label1,两个command
打开一个"1-记事本"
代码如下:
Dim hwd As Long
Dim hwdd As Long
Dim dwda As Long

Private Sub Command1_Click()
hwd = FindWindow(vbNullString, "1 - 记事本")
Label1.Caption = hwd
End Sub

Private Sub Command2_Click()
hwdd = FindWindowEx(hwd, ByVal 0&, "edit", vbNullString)
Label1.Caption = hwdd
End Sub


以下在模块中声明:(也是这两个函数的声明)
Public Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long

然后打下command1就可以看到记事本的句柄了,
按下command2就可以得到编辑框edit类的句柄.

TOP

LS的是VB代码吧....
友情连接:第七大陆

TOP

发新话题