473,395 Members | 1,466 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Instance of Windows::Form

hi there,

i have the following problem:

i have 2 normal Windows Forms classes, declared as:

public __gc class MainForm : public System::Windows::Forms::Form
and
public __gc class FormLayout : public System::Windows::Forms::Form

my application starts like this:

....
MainForm *myform;
myform = new MainForm();
System::Threading::Thread::CurrentThread->ApartmentState =
System::Threading::ApartmentState::STA;
Application::Run(myform);
....

somewhere in my MainForm class, i have the following code:
....
FormLayout *formLayout;
formLayout = new FormLayout();
formLayout->Show();
formLayout->InitGL();
....etc...

now my problem: i want to send status messages or change the behavior of
my MainForm window by pressing a key in my FormLayout form, but i can't
because i don't know the instance of my MainForm ... because __gc
objects can't be declared global. so how do i get the instance of my
form generated by Application::Run() ?

any suggestions ?

thx a LOT...

bye
michael

Nov 16 '05 #1
2 1237
try the gcroot<managedClass*> class template. This makes it possible to
declare __gc classes global

/Morten

"Michael Zeile" <bo**@primusnetz.de> wrote in message
news:bo*************@news.t-online.com...
hi there,

i have the following problem:

i have 2 normal Windows Forms classes, declared as:

public __gc class MainForm : public System::Windows::Forms::Form
and
public __gc class FormLayout : public System::Windows::Forms::Form

my application starts like this:

...
MainForm *myform;
myform = new MainForm();
System::Threading::Thread::CurrentThread->ApartmentState =
System::Threading::ApartmentState::STA;
Application::Run(myform);
...

somewhere in my MainForm class, i have the following code:
...
FormLayout *formLayout;
formLayout = new FormLayout();
formLayout->Show();
formLayout->InitGL();
...etc...

now my problem: i want to send status messages or change the behavior of
my MainForm window by pressing a key in my FormLayout form, but i can't
because i don't know the instance of my MainForm ... because __gc
objects can't be declared global. so how do i get the instance of my
form generated by Application::Run() ?

any suggestions ?

thx a LOT...

bye
michael

Nov 16 '05 #2
TGF
You could also force the constructor to take a System::Object gc* parameter
and call the layout form as such...

FormLayout *formLayout;
formLayout = new FormLayout(this); // where 'this' is the MainForm class
instance
.....then in the FormLayout class, declare a member as "System::Object gc*
parentMember". Then you can save the memory address of the parent class in
your FormLayout constructor....

FormLayout (System::Object __gc *parent)
{
parentMember = parent;
}

....Then whenever you have to call a function in the parent, you can do this
(Make sure you put the #include "MainForm.h" in the FormLayout.cpp file...

MainForm *mf = dynamic_cast<MainForm *>(parentMember);

// check for valid ptr to parent before referencing
if (mf) {

mf->SomeFunction(someParementer);

}

Hope this helps.....

-TGF

"Michael Zeile" <bo**@primusnetz.de> wrote in message
news:bo*************@news.t-online.com...
hi there,

i have the following problem:

i have 2 normal Windows Forms classes, declared as:

public __gc class MainForm : public System::Windows::Forms::Form
and
public __gc class FormLayout : public System::Windows::Forms::Form

my application starts like this:

...
MainForm *myform;
myform = new MainForm();
System::Threading::Thread::CurrentThread->ApartmentState =
System::Threading::ApartmentState::STA;
Application::Run(myform);
...

somewhere in my MainForm class, i have the following code:
...
FormLayout *formLayout;
formLayout = new FormLayout();
formLayout->Show();
formLayout->InitGL();
...etc...

now my problem: i want to send status messages or change the behavior of
my MainForm window by pressing a key in my FormLayout form, but i can't
because i don't know the instance of my MainForm ... because __gc
objects can't be declared global. so how do i get the instance of my
form generated by Application::Run() ?

any suggestions ?

thx a LOT...

bye
michael

Nov 16 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Hamed | last post by:
Hello I have employed as a developer in a software company that its team uses FoxPro / VB 6.0 / VC++ 6.0 as the developing tools and newly is going to migrate to VS.NET. There is a project...
5
by: Xarky | last post by:
Hi, I am creating a windows form, and when a specified event occurs (button click), I am hiding the windows form and opening a new windows form. When opening the new windows form and closing...
5
by: Dave | last post by:
How do I check in a Windows Forms app if any controls have changed? I have a form that collects data, and I want to prompt the user if they try to exit the app, or load a new file, without saving...
9
by: Rajat Tandon | last post by:
Hello there, I am relatively new to the newsgroups and C#. I have never been disappointed with the groups and always got the prompt replies to my queries.This is yet another strange issue, I am...
8
by: Alison | last post by:
Hi, Al I am trying to design a user interface which provides both menus and toolbars for some users to click on whatever they want to do, at the same time, I would like to have a console window...
4
by: Rod Gill | last post by:
Hi, I have a form that when opened in the designer appears of the screen. The form selector can't be dragged (or resized) and if I scroll right and down to centralise it the form simply jumps...
9
by: mohit.akl | last post by:
Hey guys & gals I am havng trouble modifying the control box. I want to make the maximise button invisible and have minimisise button instead of it. Like this _ X (not like _ o X ) How...
3
by: Mark Jerde | last post by:
VS 2005. When I google "CSharp single instance form" the returned pages usually use a Mutex or the VB.NET runtime library....
7
by: Jwe | last post by:
Hi, I've written a program which has both a command line interface and Windows form interface, however it isn't quite working correctly. When run from command line with no arguments it should...
1
by: Prats | last post by:
I have a windows form application developed in C++/CLR How can I verify that only one instance of the application is running on the user system at any given time. Thanks
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.