View Single Post
  #1 (permalink)  
Old 07-01-2006, 10:41 AM
Void's Avatar   
Void Void is offline
Programming Expert
 
Join Date: Jun 2006
Posts: 411
Credits: 0
Rep Power: 12
Void is on a distinguished road
Default Calling a form from another form

Managed C++ does not let you call a form by its form name. In C# you can do formname.function if it is a public function. You can call a perform click in C# just by the formname. In managed c++ it is a little different.

I had to write a callback function that sends messages just to call a previous form. Here is the code:

At the header I inserted:
Code:
//#include <windows.h>    // You could theoretically include Windows.h to get
                                     // all of the WM_ message values, but then your
                                     // basic .NET objects like MessageBox would no longer
                                     // function without a series of #ifndefs.

// Define WM_USER using the value in windows.h
#define WM_USER 0x0400
#define WM_PLAY 0x0401
#define WM_STOP 0x0402
#define WM_RESTART 0x0403
#define WM_PAUSE 0x0404
#define WM_EXITME 0x0405

// Define our custom message
#define MSG_CHILDTEXT (WM_USER+1) // Nothing
#define MSG_CHILDPLAY (WM_PLAY+1)
#define MSG_CHILDSTOP (WM_STOP+1)
#define MSG_CHILDRESTART (WM_RESTART+1)
#define MSG_CHILDPAUSE (WM_PAUSE+1)
#define MSG_CHILDEXIT (WM_EXITME+1)

Declare this in the new form (child form)
Code:
public: System::Windows::Forms::NativeWindow^ m_nwndParent;
Assign a handle in the parent form

Code:
//myFullTrans->StartClick = ionTimer::Form1::childForm_StartClick();
			 myFullTrans->m_nwndParent = gcnew System::Windows::Forms::NativeWindow ();
			 myFullTrans->m_nwndParent->AssignHandle (this->Handle);

Create a functino in the new form

Code:
private: System::Void msgToParentForm(int m)
		 {
			 				// Create a new windows message object
			   System::Windows::Forms::Message msgTextSetter;

			   // Set the message type to our custom message
			   msgTextSetter.Msg = m;

			   // Tell the NativeWindow object to send the message
			   // to the default WndProc of the window whose handle
			   // it represents
			   m_nwndParent->DefWndProc (msgTextSetter);
		 }

Call the function
Code:
msgToParentForm(MSG_CHILDPAUSE);
__________________
Void
Reply With Quote