Solved

Getting Child Windows from Parent

Posted on 2002-03-10
12
224 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

Enroll in June's Course of the Month

June's Course of the Month is now available! Every 10 seconds, a consumer gets hit with ransomware. Refresh your knowledge of ransomware best practices by enrolling in this month's complimentary course for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

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

Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…

728 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