Lost Password?


  #1 (permalink)  
Old 07-01-2006, 10:41 AM
Void's Avatar   
Void Void is offline
Programming Expert
 
Join Date: Jun 2006
Posts: 411
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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
  #2 (permalink)  
Old 07-01-2006, 10:44 AM
Void's Avatar   
Void Void is offline
Programming Expert
 
Join Date: Jun 2006
Posts: 411
Rep Power: 12
Void is on a distinguished road
Default

Now, you have to handle the callbacks in the parent form

Code:
		////////////////////////////////////////////////////////////
		// Override to get messages from child
		//////////////////////////////////////////////////////////
public: virtual System::Void WndProc(System::Windows::Forms::Message % message) override
		{
			try {
				switch (message.Msg)
				   {
					  // Handle our incoming custom message
					  case MSG_CHILDTEXT:
					  {
						 // This custom message should set the text of the parent's
						 // main textbox
						 break;
					  }
					  // Start the Timer - Run
					  case MSG_CHILDPLAY:
					  {
						  toolStripButton1_Click(nullptr,nullptr);
						  break;
					  }
					  case MSG_CHILDSTOP:	  
					  {
						stopBtn_Click(nullptr,nullptr);
						break; 
					  }
					  case MSG_CHILDRESTART:
					  {
						  restartBtn_Click(nullptr,nullptr);
						  break;
					  }
					  case MSG_CHILDPAUSE:
					  {
						  pauseBtn_Click(nullptr,nullptr);
						  break;
					  }
					  case MSG_CHILDEXIT:
					  {
						  myFullTrans->Close();
						  this->Close();
						  break;
					  }

					  // All other messages should be sent to the default WndProc
					  // for System::Windows::Forms
					  default:
					  {
						 Form::WndProc (message);
						 break;
					  }
				   
				   } // End Case
			}
			catch (System::Exception^)
			{
				MessageBox::Show("Error");
			}
					
		}
Change the message code to whatever you like and enjoy!
__________________
Void
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Email form v2 Jaan PHP Tutorials 7 07-25-2008 01:44 PM
Coding a change password form InternetGeek Visual Basic Programming 11 02-16-2008 02:53 PM
Lost form InternetGeek Visual Basic Programming 3 02-10-2007 06:26 PM
C# calling parent functions from child form NeedHelp C# Programming 8 08-10-2006 12:53 PM


All times are GMT -5. The time now is 06:02 PM.

Contest Stats

WingedPanther ........ 2753.6
Xav ........ 2704
Brandon W ........ 1702.32
John ........ 1207.73
marwex89 ........ 1175.24
morefood2001 ........ 966.05
dcs ........ 655.75
Steve.L ........ 475.59
orjan ........ 418.58
Aereshaa ........ 383.54

Contest Rules

CodeCall Goal

Goal: 100,000 Posts
Complete: 100%


Complete - Celebrate!

Ads