|
It was worth a try... I don't know what your parent window
is so I was just guessing, based on the fact there's a difference
between "parent" windows and "owner" windows.
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Well maybe that's part of my problem. I wasn't aware there is a difference. Could you explain that or provide a link that would elaborate on that more?
|
|
|
|
|
I would start in the Form class properties[^]
(Owner and Parent).
Also maybe search on ".net parent vs owner" or similar.
What are you using as a parent? A Win32 window (HWND) or another
Form/Control?
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
The main application is a .NET Form.
|
|
|
|
|
it looks to me the only way to do this without making
the form modal is manually...
MyForm^ f = gcnew MyForm();
f->StartPosition = FormStartPosition::Manual;
f->Location = System::Drawing::Point((this->Width - f->Width) / 2 + this->Location.X, (this->Height - f->Height) / 2 + this->Location.Y);
f->Show();
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
for ( y = 10 ; ; y++)
{
for (int x = 10; x <= ImageWidth/2 ; ++x)
{
colorref = Image->GetPixel(x,y);
R = GetRValue(colorref);
G = GetGValue(colorref);
B = GetBValue(colorref);
if ( R < 200 && G < 200 && B < 200)
{
miny_StudentName = y;
minx_StudentName = x;
goto exitfor;
//break;
}
}
exitfor:
}
Failure is Success If we learn from it!!
|
|
|
|
|
Does this mean anything? Do you have a question?
|
|
|
|
|
I'm attempting to write communication software to talk to a laser via RS232. If I setup a Managed C++ class that has a SerialPort variable how can I test the variable to see that it is present or has a valid value.
So in my code I have:
.h file
--------
SerialPort^ sp;
.cpp file
---------
if(sp) //Testing to see if 'sp' has already been assigned a value.
{
if(sp->IsOpen)
sp->Close();
}
sp = gcnew SerialPort("Com1");
Any idea how to check to see if an Object handle has been assigned?
Thanks,
George
|
|
|
|
|
...sp=nullptr;
if (sp==nullptr)
{
dosometing;
}
alse,you can do like this
..sp;
if (sp==nullptr)
{
dosometing;
}
in the c++/cli,the default object is equal to "nullptr".
|
|
|
|
|
Hello!
A week ago, I dealed with programming my first camera-control(live rendering). I never did something like that, so I read a lot. Because I`d like to handle with the .NET-platform without changing to C#, I started coding in C++/CLI. My problem is, dispite all that studing books, forums and so on, I still don`t know exactly how to react. There seems to be endless possibilities to get your camera-data on your screen. One option is to operate with the old-school device-contexts, like you know them from MFC-programming(but I want to code in the new syntax, so the old MFC-syntax is not my favourite). Another idea is to operate with streams. I think it`s obvious to work with streams, `cause what you receive is a flow of byte-values composing the single frames. Sounds easy, but I don`t really know how to realize it exactly. Acting Try-and-error didn`t help. So, next option is to create a Bitmap and to copy the byte-values of every frame with die interop::marshal::copy-method into the Bitmap. But doing that copy-method 15 times in a second doesn`t seem to be the right way. Searching for a advisable method, I found DirectShow. My problem is, that I´m quite a rookie in programming. I know some basics in C++, but my knowledge and experience are limited. So I avoid programming DirecX(DirectShow), cause after studing the msdn-help, it seems to me, that DirectShow is a section for itself.
So, what would you do? What would you advice me? I`m very grateful for every piece of advice or literatur and veryveryvery grateful for any code-snippet.
Thanks for your help!
|
|
|
|
|
|
I am building an application where I want to use some kinda autosave function.
I found a post about using threads but I cannot find a way to get it working...
Currently I have this:
LoadFiles() will get run at the beginning of the application. Here should the autosave thread be started...
public: Threading::Thread thd = new Thread(new ThreadStart(autoSave));
private: System::Void LoadFiles(void) {
Threading::Thread::Start();
}
private: System::Void autoSave(void) {
Threading::Thread.Sleep(5000);
}
And getting the following errors:
1>d:\app2\app2\Form1.h(424) : error C3845: 'App2::Form1::thd': only static data members can be initialized inside a ref class or value type
1>d:\app2\app2\Form1.h(58) : error C2512: 'System::Threading::Thread::Thread' : no appropriate default constructor available
1>d:\app2\app2\Form1.h(426) : error C2352: 'System::Threading::Thread::Start' : illegal call of non-static member function
1> c:\windows\microsoft.net\framework\v2.0.50727\mscorlib.dll : see declaration of 'System::Threading::Thread::Start'
1>d:\app2\app2\Form1.h(429) : error C2143: syntax error : missing ';' before '.'
1>d:\app2\app2\Form1.h(429) : error C2143: syntax error : missing ';' before '.'
1>Build log was saved at "file://d:\App2\App2\Release\BuildLog.htm"
Does anyone have any idea how to solve this OR how to make a better thingy? :p
Kind regards,
|
|
|
|
|
try as following
public: Threading::Thread ^thd = gcnew Thread(new ThreadStart(autoSave)); private: System::Void LoadFiles(void) {
thd->Start();
}
private: System::Void autoSave(void) { Threading::Thread.Sleep(5000);
}
|
|
|
|
|
1>d:\app2\app2\Form1.h(425) : error C3845: 'App2::Form1::thd': only static data members can be initialized inside a ref class or value type
1>d:\app2\app2\Form1.h(428) : error C2143: syntax error : missing ';' before '.'
1>d:\app2\app2\Form1.h(428) : error C2143: syntax error : missing ';' before '.'
But I corrected Threading::Thread.Sleep(5000); to Threading::Thread::Sleep(5000); which resolved those errors. Now Im still left with C3845.
|
|
|
|
|
The error message explains it.
You can't initialize "thd" like that unless you make
the variable static.
Either make the variable static, or move the initialization code
to a method, for example - the constructor:
public ref class MyClass
{
public:
System::Threading::Thread ^thd;
MyClass::MyClass()
{
thd = gcnew System::Threading::Thread(gcnew ThreadStart(this, &MyClass::autoSave));
}
private:
System::Void LoadFiles(void)
{
thd->Start();
}
System::Void autoSave()
{
Threading::Thread::Sleep(5000);
}
};
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Thanks for your reply.
I currently have this:
public ref class Form1 : public System::Windows::Forms::Form
{
public:
System::Threading::Thread ^thd;
Form1::MyClass() {
thd = gcnew System::Threading::Thread(gcnew ThreadStart(this, &Form1::autoSave));
}
private: System::Void autoSave(void) {
Threading::Thread::Sleep(5000);
warningBox("Test? 5000");
}
private: System::Void LoadFiles(void) {
thd->Start();
}
}
But it doesnt work due the following errors:
1>d:\app2\app2\Form1.h(61) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>d:\app2\app2\Form1.h(63) : warning C4183: 'MyClass': missing return type; assumed to be a member function returning 'int'
1>d:\app2\app2\Form1.h(62) : error C2061: syntax error : identifier 'ThreadStart'
1>d:\app2\app2\Form1.h(62) : error C2143: syntax error : missing ';' before ')'
1>d:\app2\app2\Form1.h(62) : error C2143: syntax error : missing ';' before ')'
|
|
|
|
|
iMikki wrote: But it doesnt work due the following errors:
MyClass was, well, my class name.....you need to adjust
the code to use your class name.
Are you a beginner in C++?
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Quite new yes. I had some CLI C++ at university but never worked with Managed stuff...
But I did change the first part to Form1 (referencing to public ref class Form1 : public System::Windows::Forms::Form )..
Any way you could help me? :p
Or do you might have another idea to realize this 'autosave' thing.
The code I currently have is 1400 lines long. :p
Kind regards,
|
|
|
|
|
Good - I found the solution after some trying and stuff :p (fail, retry, fail again, error, swear, trying, reading, failing again, fixing, waiting, evil laughing, posting the solution on CodeProject)
Here is the code I have now:
public ref class Form1 : public System::Windows::Forms::Form
{
public:
System::Threading::Thread ^thd;
private: System::Void autoSave(void) {
Threading::Thread::Sleep(5000);
warningBox("Test? 5000");
runSave();
}
private: System::Void runSave(void) {
thd = gcnew System::Threading::Thread(gcnew System::Threading::ThreadStart(this, &App2::Form1::autoSave));
thd->Start();
}
private: System::Void LoadFiles(void) {
runSave();
}
Works like a charm!
I started the app - and 5 second later I got this message! (warningBox(std::string msg) is a messageBox produced by the Windows::Apps thingy... :p
Thnx everyone!
Edit:
This code keeps restarting the thread.
modified on Thursday, December 3, 2009 7:49 AM
|
|
|
|
|
Good morning,
I am using Visual C++ 2005 and I import excel file in my program. If data are characters and numbers no problem, but when it is a date I have difficult. The system read date as a number. How can I do so I can read a date like a string or like a date exactly ?
Can you help me ?
|
|
|
|
|
Excel stored a date using a double internally. You can use Format(The_Date "mm/dd/yyyy") is you want to pass a string with that format. Otherwise, just use a conversion function...
|
|
|
|
|
I read Excel sheet range, I can not use this Format you say because I access the range values using GetValue(i,j). The way to do is to know how it convert this date to number so that I can write a function.
Who can help me to know the algorithm use by Excel to convert date to double.
Thanks
|
|
|
|
|
Again, use the System Convert functions. You do not need to know Excel's representation, but it is fairly easy to figure out with google or changing the format of dates in excel and looking at the numbers.
|
|
|
|
|
I my side I do not know what functions to use TO CHANGE DATE TO characters, the cell format do not change something in Excel. Can you show me how to do it please
|
|
|
|
|