• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 175
  • Last Modified:

Sending data from one dialog to another..?

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
middlel
Asked:
middlel
  • 11
  • 8
  • 4
1 Solution
 
middlelAuthor Commented:
I forgot to mention that these dialogs are in two different exes..
0
 
Vinayak KumbarSr Program ManagerCommented:
Hi,

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

VinExpert
0
 
WynCommented:
Using WM_COPYDATA for small amount of info .
Using Mapping File for huge amount.

Free to ask.

Regards
W.Yinan
0
Independent Software Vendors: 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!

 
WynCommented:
WM_COPYDATA is intended for this.Dont use other messages ,it's not reliable.
0
 
middlelAuthor Commented:
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
 
Vinayak KumbarSr Program ManagerCommented:
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
 
Vinayak KumbarSr Program ManagerCommented:
Hi,

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

VinExpert
0
 
WynCommented:
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
 
middlelAuthor Commented:
I would appreciate the code thanks..
emzyme20@hotmail.com
0
 
middlelAuthor Commented:
I am trying to exchange data...
0
 
middlelAuthor Commented:
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
 
Vinayak KumbarSr Program ManagerCommented:
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
 
WynCommented:
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
 
middlelAuthor Commented:
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
 
middlelAuthor Commented:
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
 
middlelAuthor Commented:
Adjusted points to 250
0
 
middlelAuthor Commented:
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
 
middlelAuthor Commented:
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
 
WynCommented:
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
 
middlelAuthor Commented:
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
 
WynCommented:
You should find the dialog by FindWindow()...or by other ways.
I will back home later and hope give you details.
W.Yinan
0
 
WynCommented:
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
 
WynCommented:
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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 11
  • 8
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now