Solved

Getting Child Windows from Parent

Posted on 2002-03-10
12
219 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Decoding 32 bit binary streams 6 37
Adapt this command to show who installed 29 106
Unix Command -- Challenging  question 7 87
Not needed 13 95
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
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.
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…

863 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

27 Experts available now in Live!

Get 1:1 Help Now