Solved

Sending data from one dialog to another..?

Posted on 2000-02-23
23
158 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
  • 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 250 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
 
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
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.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

707 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

14 Experts available now in Live!

Get 1:1 Help Now