findwindow & findwindowex
得到即使本里面的那个文本框
findwindowex( findwindow( "Notepad", vbnullstring ), 0, "Edit", vbnullstring )

解决方案 »

  1.   

    如果我的窗体有多个edit控件怎么办,我怎么区分呢?
      

  2.   

    那就要区分情况了,内容不同还可以按照内容区分,内容相同可以用spy++察看他的ControlID,作为区分标志,还可以用相对的位置区分。
      

  3.   

    楼上朋友分给你了,有了ControlID又怎么区分,可以举一个例子吗?
      

  4.   

    用FIndWindows 取得窗口句柄,然后,
    用WindowFromPoint 取得指定位置的子控件的窗口句柄。
      

  5.   

    GetDlgCtrlID可以得到控件窗口的ID
    GetDlgItem可以通过对话框hWnd和控件ID得到控件窗口的hWnd
    以下为MSDN的SDK帮助:GetDlgCtrlID
    The GetDlgCtrlID function returns the identifier of the specified control. int GetDlgCtrlID(
      HWND hwndCtl   // handle of control
    );
     
    Parameters
    hwndCtl 
    Identifies the control. 
    Return Values
    If the function succeeds, the return value is the identifier of the control.If the function fails, the return value is zero. An invalid value for the hwndCtl parameter, for example, will cause the function to fail. To get extended error information, callGetLastError.Res
    GetDlgCtrlID accepts child window handles as well as handles of controls in dialog boxes. An application sets the identifier for a child window when it creates the window by assigning the identifier value to the hmenu parameter when calling the CreateWindow or CreateWindowEx function. Although GetDlgCtrlID may return a value if hwndCtl identifies a top-level window, top-level windows cannot have identifiers and such a return value is never valid. Windows CE: Identifiers are only valid for child windows.The identifier can be set by passing it in as the hMenu parameter to the CreateWindowEx function. It can also be set and retrieved by calling the SetWindowLong and GetWindowLong functions with the nIndex parameter set to GWL_ID.QuickInfo
      Windows NT: Requires version 3.1 or later.
      Windows: Requires Windows 95 or later.
      Windows CE: Requires version 1.0 or later.
      Header: Declared in winuser.h.
      Import Library: Use user32.lib.
    GetDlgItem
    The GetDlgItem function retrieves the handle of a control in the specified dialog box. HWND GetDlgItem(
      HWND hDlg,       // handle of dialog box
      int nIDDlgItem   // identifier of control
    );
     
    Parameters
    hDlg 
    Identifies the dialog box that contains the control. 
    nIDDlgItem 
    Specifies the identifier of the control to be retrieved. 
    Return Values
    If the function succeeds, the return value is the window handle of the given control. If the function fails, the return value is NULL, indicating an invalid dialog box handle or a nonexistent control. To get extended error information, callGetLastError.Res
    You can use the GetDlgItem function with any parent-child window pair, not just with dialog boxes. As long as the hDlg parameter specifies a parent window and the child window has a unique identifier (as specified by the hMenu parameter in the CreateWindow or CreateWindowEx function that created the child window), GetDlgItem returns a valid handle to the child window. Windows CE: The GetDlgItem function only works for immediate child controls of a dialog box—it will not search through nested dialog boxes.QuickInfo
      Windows NT: Requires version 3.1 or later.
      Windows: Requires Windows 95 or later.
      Windows CE: Requires version 1.0 or later.
      Header: Declared in winuser.h.
      Import Library: Use user32.lib.