|
I came across this over at the MSDN site:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/csref/html/vcwlkPlatformInvokeTutorial.asp[^]
It's written for C# programmers, but, you use the same attribute in C++.
Also, if you just want to set only the Font height, and leave all the other LOGFONT structure members in their default settings (except for the Face Name), you can just use the appropriate Font constructor from the .NET Framework class library (without calling the FromLogfont method). This is the simplest approach. You instantiate with the new operator, the same way you do for all Form controls.
It occurred to me that the GDI LOGFONT structure is unmanaged code, and the Interop Marshaler makes the data conversions from managed to unmanaged and back again (if necessary). The problem with the LOGFONT struct, is that the original definition takes the lfFaceName mamber as an array of type TCHAR. Since this could be either ANSI or Unicode, the size of the array is not known at compile time. I assume the Interop Marshaler does not convert these values correctly (and, you'd think they'd note that in the documentation for the FromLogfont method). And, so you must specify this explicitly with the MarshalAs pseudo-custom attribute.
There are lengthy explanations of the inner workings of Interop marshaling in Adam Nathan's book, ".NET and COM: The Complete Interoperability Guide".
|
|
|
|
|
I am fairly new at programming; I am using Viusal Studio.net 2003.
Here is the problem I am trying to solve:
I have an MDI parent form which has a control. I also have a child form that needs to tell the control on the parent to do something.
I seem to be able to pass the control by reference to the child form class, and if I try to manipulate the control while still in the class constructor, everything works fine. However, when I try to access it elsewhere in the child form, i get an "undeclared identifier" error. Does anyone know how to fix it? Here is some code to show what I am doing:
THIS CODE IS IN THE PARENT FORM:
private: System::Void button2_Click(System::Object * sender, System::EventArgs * e)
{
FormChild2 *formChild2 = new FormChild2(myControl);
formChild2->MdiParent = this;
formChild2->Show();
}
THIS CODE IS IN THE FORMCHILD2 FORM:
public __gc class FormChild2 : public System::Windows::Forms::Form
{
public:
FormChild2(AxInterop::TWSLib::AxTws *myControl)
{
InitializeComponent();
myControl->connect("",7496,1);
}
};
SO while still in the class constructor I can use the "connect" property of the control, which I just passed by reference.
However, I want to be able to use that control after a button_click event while in the FormChild2 form. But that is when I get the "undeclared identifier" error.
Any suggestions would appreciated.
Thanks,
Jody Blau
|
|
|
|
|
Hai Jody,
the myControl in your child form is only the function scope. ie u can only use it in the Constructor because you paased it as an arguement. If you want to use the myControl in ChildForm, please declare a variable of AxTws in ChildForm and link it with Parent from
//Parent Form
private: System::Void button2_Click(System::Object * sender, System::EventArgs * e)
{
FormChild2 *formChild2 = new FormChild2(myControl);
formChild2->MdiParent = this;
fromChild2->myControl=this->myControl;
formChild2->Show();
}
//Child Form
public __gc class FormChild2 : public System::Windows::Forms::Form
{
public:
AxInterop::TWSLib::AxTws *myControl
FormChild2()
{
InitializeComponent();
myControl->connect("",7496,1);
}
};
Now you can use the myControl from anywhere in the ChildFrom
|
|
|
|
|
That worked great!!
I had no idea I could do it like that. That opens up all sorts of possiblities for me
Thank you very much for taking the time to help me out!
Jody Blau
|
|
|
|
|
We are currently working on a multi platform game and require programers please email staff@kingszone.com
|
|
|
|
|
If you can't afford to run ads, then how can you afford to pay programmers?
Also, how are you running a 'multi platform' game in Managed C++ ? If you're too stupid to even find a forum that suits your post, once again, why would anyone want to work for you ?
Christian
I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
|
|
|
|
|
Ouch!
some men see things as they are and say why, i dream of things that never were and say why not. - Unknown
|
|
|
|
|
I'm a novice programmer. I am using Visual Studio.net 2003.
I am wondering if there is a way to create an event that isn't bound to a GUI control.
For example: Is it possible to create an event that fires when something is added to a hashtable; OR an event that fires when a Global variable is incremented.
Any info, suggestions and especically simple code examples would be greatly appreciated.
thanks,
Jody Blau
|
|
|
|
|
You can create an event where-ever you like, so long as the object defines the event, or you're writing or wrapping the object in order to cause it to fire. For example, if you write a class that encapsulates a hash table, you can define an event that your class will fire, but I don't believe that hash tables define such an event.
Christian
I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
|
|
|
|
|
<br />
private: System::Void menuOpenFile_Click(System::Object * sender, System::EventArgs * e)<br />
{<br />
StreamReader* InputStream;<br />
OpenFileDialog* openFileDialog1 = new OpenFileDialog();<br />
<br />
openFileDialog1->InitialDirectory = S"c:\\" ;<br />
openFileDialog1->Filter = S"txt files (*.txt)|*.txt|All files (*.*)|*.*" ;<br />
openFileDialog1->FilterIndex = 2 ;<br />
openFileDialog1->RestoreDirectory = true ;<br />
<br />
if(openFileDialog1->ShowDialog() == DialogResult::OK)<br />
{<br />
if((InputStream = openFileDialog1->OpenFile())!= 0)<br />
{<br />
txtBoxSource->Clear();<br />
<br />
<br />
<br />
String* lineOfText = InputStream->ReadLine();<br />
<br />
while(lineOfText != NULL)<br />
{<br />
txtBoxSource->Text = <br />
String::Concat(txtBoxSource->Text, lineOfText, S"\r\n");<br />
<br />
lineOfText = InputStream->ReadLine();<br />
<br />
}<br />
<br />
<br />
InputStream->Close();<br />
}<br />
}<br />
}<br />
<br />
This program invoke a open file dialog. Now when I select a file
in the open file dialog, how do I read it? I used StreadReader,
but I got an error saying that it can't convert from System::IO.Stream
to System::IO.StreamReader.
I want to read the file and put it to the text box named txtBoxSource.
Thanks
-----------------------------
C++ without virtual functions is not OO. Programming with classes but without dynamic binding is called "object based", but not "object oriented".
|
|
|
|
|
Hai Alex,
you can solve the problem with this help of FileStram class
FileStream* fs;
StreamReader* InputStream;
OpenFileDialog* openFileDialog1 = new OpenFileDialog();
if(openFileDialog1->ShowDialog() == DialogResult::OK)
{
fs=new FileStream(openFileDialog->FileName,FileMode::Open);
InputStream=new StreamReder(fs);
//Then done your reading using InputStream
}
NB: please include using namespace System::IO;
|
|
|
|
|
|
If you can't do these questions, then either your teacher is useless, you're really dumb, or you spent the classes trying to look up the skirt of the girl sitting next to you. To establish which of these is the problem, ask some of your fellow students, and if all are lost, talk to the school about it. Otherwise, try paying attention in class.
Also try paying attention online - this is the Managed C++ board, not the C++ board.
If you're still stuck, try having a go, and asking more specific questions than 'please do my homework because I can't be bothered'.
Christian
I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
|
|
|
|
|
hi,
i am pulry into c# for the last one and half years. Now i want to learn Managed C++. Which book is good enough to achive my intesion.
**************************
S r e e j i t h N a i r
**************************
|
|
|
|
|
hi,
if u know c++ and C# ( i mean CLR ,CTS ).It's Very easy to learn MC++.so u don't have to spend much time on it.u just go on coding in c++ and use classes which u used in c#.
There's lots articles submitted here.so go through it.
to start with select vc.net and then project type managed c++ application.so u are ready to code in c++.
i prefer wrox series for MC++.
by
baijumax;P
|
|
|
|
|
Hello,
I'm having trouble trying to use an access declaration. i.e I'm trying to manually change the access level of an inherited member (previously public) to protected. How do I do this in MC++?
void
|
|
|
|
|
During a design of my project there is no errors appear and then an unkown error apprear without any logical reasons or code error.
the following link has the picture of the message appear.
http://www.arabmoheet.com/Error.JPG[^]
thanks.
Waleed Eissa
|
|
|
|
|
hi...
can anyone help me wiritng c++ program that should compile and run on unix
the program does the following
1. Forks 3 child processes in parallel
2. child 1 prints : Hi, nice to see you!
child 2 prints : the weather is nice today!
child 3 prints : have fun !
3. waits on each child to finish
4. prints "see you later
thanks
aravind
|
|
|
|
|
Alright i have to write this code that is supposed to calculate the gardes of 10 students and output the highest average abd the student Identification number of the person with the highest average.I am stuck and so is my whole class so please help this is what i ahve so far.Please someone save my life
// This is the main project file for VC++ application project
// generated using an Application Wizard.
#include "stdafx.h"
#using <mscorlib.dll>
#include <tchar.h>
using namespace System;
char grade(int id, int t1, int t2);//function prototype
// This is the entry point for this application
int _tmain(void)
{
//declaration
char grade;
int t1,t2,tot,avg,max,high_avg_id,id,i;
max=0;
//Processing phase
for (i=1;i<=10;i++)
{
Console::WriteLine(S"Please enter your Student Id: ");
id = Int32::Parse(Console::Readline());
Console::WriteLine(S"Please enter Test one score: ");
t1 = Int32::Parse(Console::ReadLine());
Console::WriteLine(S"Please enter Test two score: ");
t2 = Int32::Parse(Console::ReadLine());
tot = t1 + t2;
avg = tot/2;
if (max < avg)
{
max = avg;
high_avg_id = id;
}
if (avg >= 90)
grade = 'A';
else
if (avg >= 80)
grade = 'B';
else
if (avg >= 70)
grade = 'C';
else
if (avg >= 60)
grade = 'D';
else
grade = 'F';
}
return 0
}
char grade
|
|
|
|
|
// Written By Baiju Max
//EMail:- Baijumax@gmail.com,baijumax@yahoo.com
hi man,
enjoy coding .see below solution for u r problem.
#include "stdafx.h"
#using <mscorlib.dll>
#include <tchar.h>
using namespace System;
int _tmain(void)
{
int nMark1(0),nMark2(0),nStudentID(0),nCurrentStudentID(0);
float flAvg(0),flMaxAvg(0);
String* strGrade = new String("No Grade");
//Read The Input From The User
for ( int iIndex = 0 ; iIndex < 2 ; iIndex ++ )
{
Console::Write(S"Pl's Enter The Student ID:");
nCurrentStudentID = Int32::Parse(Console::ReadLine());
Console::Write(S"Enter The Test One Score:") ;
nMark1 = Int32::Parse(Console::ReadLine());
Console::Write(S"Enter The Test One Score:") ;
nMark2 = Int32::Parse(Console::ReadLine());
//Now Caculate Avg
flAvg = (float) (nMark1 + nMark2 )/ 2 ;
if( flMaxAvg < flAvg )
{
flMaxAvg = flAvg;
nStudentID = nCurrentStudentID;
// Now Calculate The Grade
if ( flMaxAvg >= 50 && flMaxAvg < 60 ) //D- Grade 50-59
{ strGrade = "D" ;}
else if ( flMaxAvg >= 60 && flMaxAvg < 70 ) // C- Grade 60-69
{ strGrade = "C" ;}
else if ( flMaxAvg >= 70 && flMaxAvg < 80 ) // B- Grade 70-79
{ strGrade = "B" ;}
else if ( flMaxAvg >= 80 && flMaxAvg < 90 ) // A- Grade 80-89
{ strGrade = "A" ;}
else if ( flMaxAvg >= 90 && flMaxAvg <= 100 ) // S- Grade 90-100
{ strGrade = "A" ;}
else { strGrade = "F" ; }
}
}
Console::Write(S"Student ID Is:" );
Console::Write(nStudentID.ToString());
Console::Write(S"Highest Avg is:");
Console::Write( flMaxAvg.ToString());
Console::Write(S" Grade:");
Console::Write(strGrade);
Console::ReadLine();
return 0;
}
by
baijumax
|
|
|
|
|
your code gave me an error:LNK2019 unresolved external symbol_main refferenced in function_main CRT startup
fatal error LNK1120: 1 unresolved external
|
|
|
|
|
Hi,
I believe problem with your project file. do one thing
start vc.net then select managed c++ Application.
it will create main method;
cut and paste the code inside sample codes main.
by
baijumax;P
|
|
|
|
|
Hey thanks but i was able to resolve the issue.It was a very simple one at that and was totally my mistake.I for got to #include tchar.h
|
|
|
|
|
Don't do peoples homework for them, it doesn't help them in the long run. Also, u and r are letters, they are not words.
Christian
I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
|
|
|
|
|
hi,
Sorry About That.I accept your comment.
by
baijumax
|
|
|
|