Solved

Getting Child Windows from Parent

Posted on 2002-03-10
12
222 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
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.
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

730 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