Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsVB SyntaxEnterprise DevelopmentDatabase AccessControlsCOMWin APICrystal ReportDeploymentGeneralGeneral 2
Related Topics
VB.NET / ASP.NETMS SQL ServerMS AccessOther Database ProductsMore Topics ...

VB Forum / Win API / April 2008



Tip: Looking for answers? Try searching our database.

FindWindow("#32770", null) returning wrong window

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
vidishasharma@gmail.com - 29 Apr 2008 11:59 GMT
I want to add the button in reading pane of outlook 2003. I am using
win32 api's to do that. I found the class name of reading pane using
spy++. It was #32770 (dialog) however when I programatically try to
find all the child window of this class name I get all the child
window of 'outlook send and recieve progress'. I agree that it is also
a dialog window. there are many such dialog windows in outlook how do
I instruct my outlook to get all the child windows of my reading pane
only and not any other dialog window.

Please help.....
Dean Earley - 29 Apr 2008 12:17 GMT
> I want to add the button in reading pane of outlook 2003. I am using
> win32 api's to do that. I found the class name of reading pane using
[quoted text clipped - 4 lines]
> I instruct my outlook to get all the child windows of my reading pane
> only and not any other dialog window.

Enumerate them all and pick the one that best matches.
Or, use the proper documented API for Outlook automation.

Signature

Dean Earley (dean.earley@icode.co.uk)
i-Catcher Development Team

iCode Systems

vidishasharma@gmail.com - 29 Apr 2008 13:53 GMT
As I am altogether new to win 32 api can you guide me how I can
enumaare through all and how I can pick the best match....Any pointer
will be of great help......
Dean Earley - 29 Apr 2008 14:07 GMT
> As I am altogether new to win 32 api can you guide me how I can
> enumaare through all and how I can pick the best match....Any pointer
> will be of great help......

You can use the EnumWindows() function.
I can't help much on its use, but there are plenty of samples online like:
http://www.vbaccelerator.com/home/vb/code/Libraries/Windows/Enumerating_Windows/
article.asp


As you've seen, FindWindow requires specific/easily differentiated
window captions or classes to be useful.

Signature

Dean Earley (dean.earley@icode.co.uk)
i-Catcher Development Team

iCode Systems

vidishasharma@gmail.com - 29 Apr 2008 14:25 GMT
Thanks for the prompt replies
In the meanwhile I would like to mention that classname is "#32770
(Dialog)" and caption is ""(empty)
mayayana - 29 Apr 2008 14:45 GMT
If you haven't used EnumChildWindows before you might find
it a little bit tricky. It enumerates all child windows, all the
way down, using a callback function.

Private Declare Function EnumChildWindows Lib "user32" (ByVal hWndParent As
Long, ByVal lpEnumFunc As Long, lParam As Long) As Long

Dim LRet as Long, H1 as long
LRet = EnumChildWindows(H1, AddressOf EnumChildProc, 0)

  In the two lines above, H1 is the handle of window
you want to find all children of. EnumChildProc is the
callback.

As shown below, EnumChildProc receives the handle of each
child window in turn. You can then use that to check classname,
title, etc. The sample here uses a global variable HCur to
receive the handle of the relevant window when it's found.
This sample is looking for a window with class name that
matches another global variable, sClassName. But of course
you can put any check, or combination of checks, into your
EnumChildProc function.
 The EnumChildWindows function will continue until either
all children have been returned or you return 0 from EnumChildProc.

Public Function EnumChildProc(ByVal hWnd As Long, lParam As Long) As Long
  Dim s2 As String
    s2 = GetWinClass(hWnd)
   If InStr(1, s2, sClassName, 1) > 0 Then
     HCur = hWnd
     EnumChildProc = 0
   Else
     EnumChildProc = 1
   End If
End Function
vidishasharma@gmail.com - 29 Apr 2008 14:47 GMT
Hi I used the following code:

//I found the window(which gives wrong window)
 _windowHandle = FindWindow("#32770", null);

           if (_windowHandle != IntPtr.Zero)
           {
               //I try to get all the child windows for that window
              List<IntPtr> childWindows =
OutlookWin32Window.EnumChildWindows(_windowHandle);
               // get a list of captions for the child windows
              List<string> childWindowNames =
OutlookWin32Window.GetWindowNames(childWindows);
           }

This is all getting me wrong window basically  _windowHandle =
FindWindow("#32770", null); itself is returning wrong window.

How do I get the right window. Sorry if I am asking very basic
question as I am not at all familiar with win32 api's
Thorsten Albers - 29 Apr 2008 16:00 GMT
vidishasharma@gmail.com schrieb im Beitrag
<0ef7cc4f-0608-4ec3-8fa9-702d1c3967f8@z24g2000prf.googlegroups.com>...
>   _windowHandle = FindWindow("#32770", null);

Obviously you are in the wrong newsgroup since your code is C/C++ code.
This newsgroup is for API programming with MS Visual Basic <= 6.0 (aka
'classic'). You should ask your question in an appropriate newsgroup!

Signature

----------------------------------------------------------------------
Thorsten Albers                               albers(a)uni-freiburg.de
----------------------------------------------------------------------

mayayana - 29 Apr 2008 14:03 GMT
Your subject line refers to FindWindow while
your post refers to enumerating child windows.
FindWindow doesn't enumerate child windows. ??
I have no idea what Outlook looks like, much less
what the Spy++ window layout for it looks like, but
from your description it sounds like you're starting too
high up - starting at the top and just grabbing the
first one with a matching class name. There are other
options:

* You can use GetWindow to get only the next child,
if you want to control your steps down through the
hierarchy.

* You can use GetWindowText to get the window's
title.

 The title should be unique in the window that you
want. If it's not, you might try doing a first child window
enum to find a parent window that's unique, then step down
from there using GetWindow, or do a second enum from
that level.

 If none of that is feasible due to a clutter of similar
windows, you could use Active Accessibility to get
more window info. But that's a pain in the neck. You
don't want to use it if you don't have to.

> I want to add the button in reading pane of outlook 2003. I am using
> win32 api's to do that. I found the class name of reading pane using
[quoted text clipped - 6 lines]
>
> Please help.....
Kevin Provance - 30 Apr 2008 07:05 GMT
Well, FindWindow does not do any enumerating, but once you have a valid
handle from that call, you can use FindWindowEx to manually enermate through
the window list until you find what you want.  It superscedes
GetWindow/GW_CHILD.

If you like, I can supply you with an example to do this.  Just say the
word.  :)

- Kev

|   Your subject line refers to FindWindow while
| your post refers to enumerating child windows.
[quoted text clipped - 34 lines]
| >
| > Please help.....
vidishasharma@gmail.com - 30 Apr 2008 07:23 GMT
I agree to that and I was trying using FindWindowEx also. However my
basic problem is I am not getting the right handle for  reading pane.
How can I get the right handle that is the basic question. All my
efforts are in vain till now. any pointers please....
expvb - 30 Apr 2008 08:00 GMT
>I agree to that and I was trying using FindWindowEx also. However my
> basic problem is I am not getting the right handle for  reading pane.
> How can I get the right handle that is the basic question. All my
> efforts are in vain till now. any pointers please....

As others said, FindWindow will find any window that matches the criteria.
It doesn't let you pick and choose if multiple windows match the criteria.
Use EnumWindows/EnumChildWindows to get the right window. See this sample:

http://vbnet.mvps.org/code/enums/enumwindowsdemo.htm
vidishasharma@gmail.com - 30 Apr 2008 12:58 GMT
I finally got the handle

System.Diagnostics.Process[] procs =
System.Diagnostics.Process.GetProcessesByName("Outlook");
           _windowHandle = procs[0].MainWindowHandle;

childWindows = OutlookWin32Window.EnumChildWindows(hParentWnd);

StringBuilder windowName = new StringBuilder(260);
           foreach (IntPtr hWnd in childWindows )
           {
               int textLen = GetWindowText(hWnd, windowName, 260);

               // get the windowtext
               windowNameList.Add(windowName.ToString());
               if (windowName.ToString().Equals("To:"))
               {
                   _windowLike = GetParent(hWnd);

               }

           }

So I got the main process for outlook, iteratated through all the
windows compared for "To:" and if the comparison is true I got the
parent of the window which gave me the reading pane.

Thanks you all for helping me out.
Thorsten Albers - 30 Apr 2008 13:38 GMT
vidishasharma@gmail.com schrieb im Beitrag
<78c6ab1b-4869-4678-8df8-d934258ee41e@v26g2000prm.googlegroups.com>...
> So I got the main process for outlook, iteratated through all the
> windows compared for "To:" and if the comparison is true I got the
> parent of the window which gave me the reading pane.
> Thanks you all for helping me out.

The next time please ask your question in an appropriate newsgroup!

Signature

----------------------------------------------------------------------
Thorsten Albers                               albers(a)uni-freiburg.de
----------------------------------------------------------------------

mayayana - 30 Apr 2008 13:44 GMT
What the heck is that? C#?

 As Thorsten Albers said, you're in the wrong
group. If you end up needing any more help
you should provide more information about the
window hierarchy AND post it to a .Net group.
This group is for VB and NOT for VB.Net, and
certainly not for C#.Net or whatever it is that
you're using.

> I finally got the handle
>
[quoted text clipped - 24 lines]
>
> Thanks you all for helping me out.
vidishasharma@gmail.com - 30 Apr 2008 14:21 GMT
I am sorry If that has offended you all. however all you comments were
of great help. I would like to thank you all surly take care from next
time.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.