Solved

Getting Child Windows from Parent

Posted on 2002-03-10
12
218 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
 
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
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

707 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now