?
Solved

Sending data from one dialog to another..?

Posted on 2000-02-23
23
Medium Priority
?
167 Views
Last Modified: 2013-11-20
Hi,

I have a main dialog that creates another dialog. When the second dialog is initialised, I would like to send some information to the dialog that created it. I have tried creating a message id and sending a Post Message, but it doesn't work. Can anyone suggest a better way to do it?

thanks

Emma
0
Comment
Question by:middlel
[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
  • 11
  • 8
  • 4
23 Comments
 

Author Comment

by:middlel
ID: 2549607
I forgot to mention that these dialogs are in two different exes..
0
 
LVL 8

Expert Comment

by:VinExpert
ID: 2549634
Hi,

Pls give some relevent code like, how u r creating another dialog and showing it.

VinExpert
0
 
LVL 5

Accepted Solution

by:
Wyn earned 1000 total points
ID: 2549638
Using WM_COPYDATA for small amount of info .
Using Mapping File for huge amount.

Free to ask.

Regards
W.Yinan
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 5

Expert Comment

by:Wyn
ID: 2549651
WM_COPYDATA is intended for this.Dont use other messages ,it's not reliable.
0
 

Author Comment

by:middlel
ID: 2549712
code that launches process..

bool CProcessMgrDlg::LaunchNewProcess( long lPersonalityID )
{
      // Startup info structure
      STARTUPINFO startupInfo;
      // Information about the process
      PROCESS_INFORMATION processInformation;
      processInformation.hProcess = INVALID_HANDLE_VALUE;

      // Close the process handle of any existing process
      // stored in the processInformation structure
      if( processInformation.hProcess != INVALID_HANDLE_VALUE )      
      {
            CloseHandle( processInformation.hProcess );
            processInformation.hProcess = INVALID_HANDLE_VALUE;
      }

      // Get the startup information from this application
      GetStartupInfo(&startupInfo);

      CString sPerson;
      sPerson.Format( "%ld", lPersonalityID );

      bool bRes = CreateProcess( "d:\\source\\utilities\\emma\\systemTester430\\debug\\systemTester430.exe",
                                                sPerson.GetBuffer( sPerson.GetLength() ),
                                                0,
                                                0,
                                                FALSE,
                                                CREATE_DEFAULT_ERROR_MODE,
                                                0,
                                                0,
                                                &startupInfo,
                                                &processInformation)?true:false;

      if( !bRes )
      {
            DWORD dwErr = GetLastError();
      }
      else
      {
            // Store the process information and update front-end.
            m_mapProcesses[ processInformation.hProcess ] = lPersonalityID;
            m_lActiveProcesses++;
            StatusUpdate();
      }
      return bRes;
}
0
 
LVL 8

Expert Comment

by:VinExpert
ID: 2549714
Hi,

Yes, U can do it using the EnumWindows, In the main exe have the user defined message and its handler. Then in the spawned exe, just find the parent window using its title and send that message to it. It will be difficult to explain the whole procedure. But I have the samples now. If U want give me ur email Id. I will send them to U.

VinExpert
0
 
LVL 8

Expert Comment

by:VinExpert
ID: 2549719
Hi,

In my sample I am using WinExec to launch the second exe. But no prob, it still works fine.

VinExpert
0
 
LVL 5

Expert Comment

by:Wyn
ID: 2550470
middlel , what's your problem indeed?

Are you finding way to exchange in between or finding way to launch process ?
My answer is targetting to the first.
Regards
W.Yinan
0
 

Author Comment

by:middlel
ID: 2550630
I would appreciate the code thanks..
emzyme20@hotmail.com
0
 

Author Comment

by:middlel
ID: 2550665
I am trying to exchange data...
0
 

Author Comment

by:middlel
ID: 2550690
Ok, so if I do it the WM_COPYDATA way do I need to handle that event in the application that is supposed to receive it...?
0
 
LVL 8

Expert Comment

by:VinExpert
ID: 2550717
Hi,

I have sent U the zip files. pls go through them. I think they will give some idea to u for specific case.

VinExpert
0
 
LVL 5

Expert Comment

by:Wyn
ID: 2550874
so if I do it the WM_COPYDATA way do I need to handle that event in the application that is supposed to receive it...?
---------------
Deponds on your need.But most likely you need the info.Then you need handle it.
YOu can consult some examples at:

Using WM_COPYDATA for IPC
http://msdn.microsoft.com/library/psdk/winbase/ipc_34o3.htm 

Inter-Process Communication Using WM_COPYDATA
http://codeguru.developer.com/win32/ipcdemo.shtml 

Regards
W.Yinan
0
 

Author Comment

by:middlel
ID: 2550907
I have had a go at using the call back function but it doesn't appear to work... I don't think searching by text name for the dialog is very safe, it must be slow as well...

I have implemented it as you said but it didn't work..?

Emma
0
 

Author Comment

by:middlel
ID: 2551090
I have had a go at using the call back function but it doesn't appear to work... I don't think searching by text name for the dialog is very safe, it must be slow as well...

I have implemented it as you said but it didn't work..?

Emma
0
 

Author Comment

by:middlel
ID: 2551113
Adjusted points to 250
0
 

Author Comment

by:middlel
ID: 2551114
ok, I have tried the WM_COPYDATA because I am desperate to get this to work now.. It has been too long...

void CSystemTester430Dlg::EventLogonReply(short Success, short Reason)
{
      // Write info to log file..
      CLogger::GlobalLog().Write( LOG_INFORMATION, "CSystemTester430Dlg::EventLogonReply",
            "Successfully logged onto market maker." );

//      EnumWindows((WNDENUMPROC)EnumWindowsProc , 0);

      MessageBox("SystemTester::OnConnected" );
      CMMVersionInfo pInfo;// = new CMMVersionInfo();
      pInfo.m_bConnected = (Success == 1)? true : false;
      pInfo.m_sVersion      = "4.3";//m_MM.GetMessagingVersion();
      
      COPYDATASTRUCT data;
      data.cbData      = sizeof(pInfo);
      data.dwData      = 0;
      data.lpData = &pInfo;

      ::SendMessage( ::GetParent(m_hWnd), WM_COPYDATA, (WPARAM) m_hWnd, (LPARAM) &data );

      PostMessage(WM_INITIAL_LOAD);
}

I can debug into this message but then nothing happens.. I then handle the event but it never gets there..
0
 

Author Comment

by:middlel
ID: 2551395
I have found out, why it isn't getting there... The call to GetParent returns a null pointer.. So how can I get hold of my parent.

thanks in advance

Emma
0
 
LVL 5

Expert Comment

by:Wyn
ID: 2553622
Oppppppppppppsssssss!!!
middlel , I'm thoroughly confused.
First I think you want to exchange data between two dialogs of different applications because You gave us the code launching another process as well as your first comment.

But in the code above.It seems the two dialogs are in the same application.

Now ,plz tell us what is your need indeed?
Whatever,it's easy by using message.

------------
The call to GetParent returns a null pointer.. So how can I get hold of my parent.
-----------
It's strange.You'd have gotten the parent handle by your code.
Try GetLastError() to get the concrete info about that null.
How you invoke your second dialog?Do you do it like this(Here I suppose you exchange info in the same .exe,dont know if it's your case):
void CDlg1::OnButton()
{
CDlg2 dlg2;
dlg2.DoModal();
}

Finary,if your two dialogs in respective app,you should find that window first.
Regards
W.Yinan
0
 

Author Comment

by:middlel
ID: 2553682
sorry for the confusion...

The first dialog application calls CreateProcess() to launch the second application (I think my problem lies here).

When the second application is launched it doesn't have a parent??, because it was launched in another process. The code that sends the message is in the second application. I thought by sending it as a windows message, it would get sent to all apps running and they could process it if they wanted to?

HTH,

regards

Emma
0
 
LVL 5

Expert Comment

by:Wyn
ID: 2554631
You should find the dialog by FindWindow()...or by other ways.
I will back home later and hope give you details.
W.Yinan
0
 
LVL 5

Expert Comment

by:Wyn
ID: 2554789
CreateProcess() to launch the second application (I think my problem lies here).

================

Why? I dont think that's your problem.You cannot use GetParent() above if in two apps.

You should use FindWindow()
i.e:

HWND hd=::FindWindow(0,"your first dialog name here");

And pass it into  the SendMessage().

Regards
W.Yinan
0
 
LVL 5

Expert Comment

by:Wyn
ID: 2554803
i.e.
rewrite your code as this:

COPYDATASTRUCT data;
data.cbData = sizeof(pInfo);
data.dwData = 0;
data.lpData = &pInfo;
HWND hd=::FindWindow(0,"your first dialog name here");
::SendMessage( hd, WM_COPYDATA, (WPARAM) m_hWnd, (LPARAM) &data );
0

Featured Post

Industry Leaders: 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

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
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.
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses
Course of the Month11 days, 9 hours left to enroll

752 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