PDA

Click to See Complete Forum and Search --> : Getting a window handle without findwindow or getwindow


Falcondl
Jan 6th, 2001, 04:31 AM
How would i do something like that?

I've run into some problems trying to get the window handle of the "Enter Password" dialog box for Outlook when it starts up, as in it wont fricking work. ;)

its one of those windows that's not a child of "microsoft outlook" but "microsoft outlook" is the parent of the window. (to see what i mean go in SpyXX and find some window at the top level that has a parent.

i tried FindWindow(vbNullString, "Enter Password"), which didn't work, and then

hwnd = FindWindow(vbNullstring, "Microsoft Outlook"
tmphwnd = getWindow(getdesktopwindow(), GW_CHILD)
do while true
if getparent(tmphwnd)=hwnd
MSGBOX "SUCCESS"
tmphwnd = Getwindow(tmphwnd, GW_HWNDNEXT)
Loop

so that gets the handle of outlook, then gets the handle of the desktop, then find first child window. Checks to see if the parent of that child window is the handle of Microsoft Outlook, and if not, goes on to the next child window. rinse and repeat. ;)

The problem is, it never finds it. When i run this with notepad, or the calculator, and then have the About box open with them (the about box is a dialog box also, and isn't really a child window, but its parent is the calculator. It shows up on the same level as the calculator in SpyXX) it works fine. But it wont work with outlook, and its driving me crazy.

anyone run into any similiar problems, have any suggestions, or know how to do this without getwindow/findwindow? :)

Bill Crawley
Jan 17th, 2001, 04:02 AM
Not Much help, But look on Microsofts web site. There is an API called somthing like GetChildWindow that may do what you want. It does not appear in the standard VB API Viewer.

It may be worth going to the http://www.themandelbrotset.co.uk Ether that or its a .com. and download the stuff they have for the API since I think that may have the above api in it.

crispin
Jan 19th, 2001, 09:30 AM
Have you tried using the following function:

HWND FindWindowEx(
HWND hwndParent, // handle to parent window
HWND hwndChildAfter, // handle to a child window
LPCTSTR lpszClass, // pointer to class name
LPCTSTR lpszWindow // pointer to window name
);


FindwindowEx if you pass the handle of the outlook window as hwndparent it will start looking at that level, and recurse all child windows, i guess if you pass "Edit" as lpszClass and VbNullString as the windowname then you may find it.

hope this helps

crispin
Jan 19th, 2001, 09:37 AM
Heres a sample, once you have found the handle to the main outlook window, pass it to this function to get the handle of the first edit control "under" the parent window:


'paste into a module
Option Explicit
Public Const API_TRUE As Long = 1&
Public Const API_FALSE As Long = 0&
Public Declare Function FindWindow& Lib "user32" Alias "FindWindowA" (ByVal lpClassName$, ByVal lpWindowName$)

Public Declare Function FindWindowEx& Lib "user32" Alias "FindWindowExA" (ByVal hWndParent&, _
ByVal hWndChildAfter&, ByVal lpClassName$, ByVal lpWindowName$)

Public Function ChildWindow(m_hwnd As Long) As Long
Dim hButton1&
hButton1 = FindWindowEx(m_hwnd, API_FALSE, "Edit", vbNullString)
If hButton1 Then
ChildWindow = hButton1
Else
ChildWindow = -1
End If
End Function