Solved

Getting Child Windows from Parent

Posted on 2002-03-10
12
221 Views
Last Modified: 2013-11-20
Hi everyone,

I am writing an MFC program which interfaces with AOL Instant Messenger. The idea is, I want to send a message to my buddy on a given interval. My program gets sports scores from a website and then notifies my buddy every 10 minutes or so.

I've got the data-from-the-website thing finished. What I'd like to do now is find a way to automate the messaging to AIM.

Right now, I'm trying to use FindWindow. I am able to find the main message window using a call like this:

CString wndIMTitle = m_BuddyName + " - Instant Message";
CWnd *wndIM = FindWindow("AIM_IMessage", (LPCTSTR)wndIMTitle);

Using Spy++, I discovered that there are 2 child windows - the input box and the message log. However, they are both of class Ate32Class and uncaptioned.

I want a pointer to CWnd which is equal to the second child window of wndIM.

Thanks in advance,
-Dan
0
Comment
Question by:SuperMario
12 Comments
 
LVL 3

Expert Comment

by:cypherljk
ID: 6855485
How about this (it's not pretty but it should work)  Get the top left corner of each windows rect and the lower one is the input box always (since they can't be reordered.  Use the window which is positioned lower.

My 2 cents...
0
 
LVL 3

Author Comment

by:SuperMario
ID: 6855494
What code can I use to do that?
0
 
LVL 86

Accepted Solution

by:
jkr earned 200 total points
ID: 6855534
Use 'EnumChildWindows()', then 'GetWindowRect()' to achive what cypherljk suggested.
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 86

Expert Comment

by:jkr
ID: 6855539
Oh, BTW, here's a sample:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/windows_6w4z.asp ("Creating, Enumerating, and Sizing Child Windows")
0
 
LVL 3

Expert Comment

by:aphillips
ID: 6859160
wndIM->GetWindow(GW_CHILD)->GetWindow(GW_HWNDNEXT);
0
 
LVL 3

Author Comment

by:SuperMario
ID: 6859645
jkr: can you clear up for me what exactly "enumerating" a window is? is that passing the CWnd pointer to every child window to some callback procedure until there are no more children left?

Thanks,
Dan
0
 
LVL 86

Expert Comment

by:jkr
ID: 6860401
"Enumerating child windows" means to have Windows call an application-supplied callback for every child, e.g. like

BOOL CALLBACK EnumChildProc(HWND hwndChild, LPARAM lParam)
{
    return TRUE;
}

EnumChildWindows( m_hWnd, EnumChildProc, (LPARAM) 0);
0
 
LVL 3

Author Comment

by:SuperMario
ID: 6863741
Okay, guys, one last question.

Everything is working fine. I am able to send a WM_KEYDOWN message to the window (to simulate pressing ENTER).

However, SetWindowText doesn't seem to be working. Here's the code for the enum procedure.

BOOL CALLBACK EnumChildProc(HWND hWndChild, LPARAM lParam)
{
     CWnd *wndAim = NULL;
     wndAim = wndAim->FromHandle(hWndChild);

     wndAim->SetFocus();
     wndAim->SendMessage(WM_KEYDOWN, VK_RETURN, NULL);

     wndAim->SetWindowText("Hi there...");
     
     return TRUE;
}

It sends the ENTER message but does not set the window text to "Hi there..."

Any reason for this?
thanks again, one last time ;)
-Dan
0
 
LVL 3

Author Comment

by:SuperMario
ID: 6863742
Oh, and it's not because I have them in that order. It's on a timer, so it just sets it to "Hi there" after pressing enter, then the next time around it sets the window text.
0
 
LVL 86

Expert Comment

by:jkr
ID: 6865719
Hum...

Have you tried

PostMessage ( hWndChild, WM_SETTEXT, 0, (LPARAM) "Hi there...");
0
 
LVL 86

Expert Comment

by:jkr
ID: 6865725
Ooops, alternatively, you could also do some error checking using

LRESULT lr = SendMessage ( hWndChild, WM_SETTEXT, 0, (LPARAM) "Hi there...");

and examine the return value...
0
 
LVL 3

Author Comment

by:SuperMario
ID: 6961944
Yay! Finally got it to work. Thanks jkr.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

792 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question