Forms and Label

A

Allen Maki

I wonder if you could help.

The event handler code below, will allow the user to change the phone number
and write it on a label of a message box. I want to replace the message box
with a dialog box.

Can anybody help me replace the message box below to a dialog box. In other
words. I want to write the new phone number on a label (named "labe1")of a
dialog box (named "dialog2),instead of writing the new phone number on the
label of a message box.

private: System::Void dialogBtnItem_Click(System::Object * sender,
System::EventArgs * e)

{

// Create the dialog

MyDialog* box = new MyDialog();


//Fill in the initial data

box->Phone = S"(650)123-3456)"; // <------ This is the phone number to be
changed

//Show dialog

if (box->ShowDialog() == DialogResult::OK)

{

MessageBox::Show(box->Phone); //<-----I tried to change this line


}

}
 
G

Guest

You will need a dialog with a label whose ID is different than IDC_STATIC,
because this ID is generic.

Suposing you have something like a CMyMsgBox class with a IDC_STATIC1 label,
try this:

CMyMsgBox mymsgbox;
CWnd *plabel;

plabel=mymsgbox->GetDlgItem(IDC_STATIC1);
plabel->SetWindowText(box->Phone);
mymsgbox.DoModal();

Regards
 
A

Allen Maki

Hi Luis,

I thank you a lot for trying to help, but you may be so fluent in the
language, that I can not catch up with you or you are speaking different
language. Make it easy for me please.
 
G

Guest

Hi Allen,
I'm sorry because you didn't understood me, certanly my english is a little
poor and the Google translator is not as good as I want.
What I want to say is that you need to make a new dialog from the
ResourceView. That dialog must have an Static Text resource. When you place
it, then Visual C++ asigns a default id: IDC_STATIC. You can't use this
default id in order to get the CWnd object associated to it.
Also you must create a new class associated to the dialog resource. I
usually double click on the Ok button, and Visual C++ ask me if I want that
Visual C++ environment create that class automatically, and I answer yes.
In the example I proposed to you, you must change the id of the static text
from IDC_STATIC to IDC_STATIC1, and you must create a class CMyMsgBox
associated to the dialog.
On your main program, or the function you use to show the new dialog, you
must add the lines I wrote.
CMyMsgBox mymsgbox; // this line defines a variable mymsgbox and calls the
dialog class constructor for that new variable
CWnd *plabel; // this variable is needed in order to get the CWnd pointer
associated to the static text in the new dialog
plabel=mymsgbox->GetDlgItem(IDC_STATIC1); // getting the CWnd pointer to the
label
plabel->SetWindowText(box->Phone); // setting the text you want to the label
mymsgbox.DoModal(); // showing the dialog
I hope that this explanation will be enough for you.
Good luck and regards,
 
D

David Wilkinson

Luis said:
You will need a dialog with a label whose ID is different than IDC_STATIC,
because this ID is generic.

Suposing you have something like a CMyMsgBox class with a IDC_STATIC1 label,
try this:

CMyMsgBox mymsgbox;
CWnd *plabel;

plabel=mymsgbox->GetDlgItem(IDC_STATIC1);
plabel->SetWindowText(box->Phone);
mymsgbox.DoModal();

Luis: Isn't the OP using Managed C++?

Allen: If you want to use .NET framework I would strongly advise
updating to VS2005 (or VS2007 hopefully out this later year), because
the syntax for managed code is completely different/much improved.
 
A

Allen Maki

Hi Luis,

I hope you knew that when I referred to language I was not referring to
English. I was referring to- the programming language- Visual C++ .NET
2003. The reason I said that, is because you might be using different
language such as Visual basic. If you were using the same programming
language, you may be so fluent that I could not catch up with you. I will
try to understand what you wrote and thank you very much for all of your
helps
 
A

Allen Maki

Hi David,

I am working, now, with Visual C++ .NET 2003. I have MS visual C++ 2005.
Thanks .

Allen.
 
G

Guest

Hi Allen,
The code I wrote was in Visual C++ 6.0. I don't use Visual C++ .NET because
I write Pro*C programs in order to connect to Oracle 8i databases, and there
is no Visual C++ .NET libraries for Oracle 8i Pro*C.
I thought that the only difference between .NET and 6.0 was the namespaces.
The C++ language is the same, and also you have a lot of advantages in the
Visual Studio 2003 .NET environment.
In response to David Wilkinson comments, I'll tell that of course Visual
Studio 2005 .NET is better than 2003, 2005 is the best because is the last
version and has still more advantages than 2003, but this is another theme.
Regards
--
Luis Antonio Rosello Garcia
Pulso Informatica, S.L.
mailto:[email protected]



Allen Maki said:
Hi David,

I am working, now, with Visual C++ .NET 2003. I have MS visual C++ 2005.
Thanks .

Allen.
 
B

Ben Voigt [C++ MVP]

Luis Antonio Rosello Garcia said:
Hi Allen,
The code I wrote was in Visual C++ 6.0. I don't use Visual C++ .NET
because
I write Pro*C programs in order to connect to Oracle 8i databases, and
there
is no Visual C++ .NET libraries for Oracle 8i Pro*C.
I thought that the only difference between .NET and 6.0 was the
namespaces.
The C++ language is the same, and also you have a lot of advantages in the
Visual Studio 2003 .NET environment.
In response to David Wilkinson comments, I'll tell that of course Visual
Studio 2005 .NET is better than 2003, 2005 is the best because is the last
version and has still more advantages than 2003, but this is another
theme.

If you haven't used .NET, you can't begin to imagine the ways in which
2005's C++/CLI language beats the abortive attempt that was 2003's Managed
Extensions for C++.

If you're talking only native code, then there are just a few new features
from 2002 -> 2003 -> 2005 (although all are much better than 6.0 as far as
support for ISO C++). But the .NET side took a huge leap forward with 2005.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top