Hi, I´m writing on an application that is "small" but with several classes with their own header file... To avoid having to much files around I have written all the code in the header files...i.e. class declarations, function declarations and definitions etc. (I have read several places that it doesn´t really matter) This is probably bad code-writing, but is there any drawback to this? Do the compiler treat code in the .h file differenly? Is there code that cannot be written in the header file? (sorry if this is a stupid question, but still I feel like a beginner in this) doneirik
doneirik
Posts
-
basic question to .h and .cpp files -
namespace does not existHello, Could anyone tell me how to cope with this error message. the start of my code goes like
#pragma once using namespace std;
... I get the errormessage that the namespace does not exist, and msdn provide little information about this error message.error C2871: ´std´:a namespace with this name does not exist
Sorry if I provide to little code or further descriptions... But maybe somebody has a tips best regards doneirik -
closing a form/dialogHi, I asked this question before in the VC++ forum, but I think my question was misunderstood. I´ll try it again with more explanation... I´m making an Windows Form appl. using VC++ .Net 2003. As I start an "Form" is automatically created for me. Then I want to make my own "MessageBox"-like class (due to interference with the "windows.h" header I cannot use the included MessageBox" properly.) I go to Project->Add new Item->Windows Form (.NET) and a new "Form" is created, that I want to use as a dialog box, and I add a Label and an OK-button rto it. In the Forms properties I set: FormBorterStyle = FixedDialog MaximizeBox = False MinimizeBox = False However, I don´t know which property I must set, or which method to call for making the Form close when I push the OK-button. Does anybody have a suggestion? (I display it by calling the ShowDialog() method.) Apart from that it works as a dialogbox (I know there are probably better ways to solve the problem, but I´m quite new to VC/C++, and this seemed like the easiest way around it) regards doneirik
-
dispose formHi I´m creating my own "MessageBox" -like class, derived from ::Form. I want the messagebox to close when I press the "OK" button , i.e. to work as if the "x" (close)-button was pressed. I don´t know where to find the code for this. Can anyone help? sincerely doneirik
-
windows.h / MessageBoxhi ...posted a question yesterday concerning a problem with "MessageBox" Now I know where the problem is, but I don´t know how to solve it. Making a Windows Form App with VC++ .Net 2003, I add my own header file to the project. Trying to use MessageBox::Show("String") gives me an errormessage but only as long as the header file windows.h is included in the project. Is this windows.h header file incompatible with VC++ or is there any tricks I have to know? doneirik
-
problem with MessageBoxI´m callin MessageBox : MessageBox::Show("string"); I´m doing it in the self generated code simply because double-clicking e.g. an Button in the design mode, the method that handles this is placed in the Form1.h file automatically. Don´t really need to have it there. Just trying to learn the basics now... doneirik
-
problem with MessageBoxHola! I´m making a small Windows Forms App. using VC++.net 2003. Adding a "MessageBox" in the self generated code (the Form1.h - file) works fine, until I add my own header file to the project and include this new header file at the top of the "Form1.h" -file. I get the error message:
error C2653:"MessageBoxA" is not a class or a namespace name.
Why this "MessageBoxA"? What could be wrong? thanks doneirik -
doubts about .net / managed C++Hi, I have a small question: Working with Visual C++ .Net 2003, if I choose to create a .NET project, does this mean that I must work with managed C++ ? Is MFC and Managed code mutually exclusive, or what is the relation between the two? thanks regards doneirik
-
problem with Picturebox / windows.hthanks Didn´t have time to try your suggestion yet, however, tried the examples on the msdn site: http://support.microsoft.com/default.aspx?scid=kb;en-us;888267[^] This works, but after adding this code, I cannot get back to design modus... donE
-
cannot go back to design modusHi After making some changes in my code I cannot get back to "Design" modus in my VC++ project. (because of problems with the GetObject function I have to un- define and then -re define it during some other fuction calls) I get an error message saying:
"An error occurred while loading the document.Fix the error, and then try loading the document again. The error message follows: MCppCodeDomParser Error Line 98, Column 4---unexpected token for a `term´
I can compile and run the application, but I cannot make any changes in the GUI using the visual interface. Is there a way to "fix the error" as the errormessage suggests? regards doneirik -
problem with Picturebox / windows.hHi I made an application that operates on the serialport. Using "CreateFile" I must include windows.h Now I have re-written my app and wanted to include an image in the GUI, so I used "Picturebox". However, with the picturebox and the picture, it looks like I cannot include the headerfile windows.h. When I include it , I get the message:
error C2039: "GetObjectA" is not a member of "System::Resources::ResourceManager"
This errormessage is pointing to the line in my code dealing with the image. Does anybody know what I have done wrong? regards donE -
maintaining layout of windowhi What do I have to do to maintain the layout of a Form when I maximize the window? Is it possible to desig the GUI working in a window that is 50% smaller than the final GUI and configure the window to maximize when executing such that all the containers in the form maintain its position in relation to the borders AND resizes. (i.e. if I maximize the window from 50% to 100& I want all the containers to double in size as well) doneirik
-
how to close a thread?I have a second thread in my application, created like this:
Thread* secondThread; ThreadStart* second = new ThreadStart(this,my_method); secondThread = new Thread(second); secondThread->Start();
This thread does not close when I close down the application. I tried with "Abort". I guess I need some try-catch, but sot sure how to use it... tried with this in the generated dispose method...try{ secondThread->Abort(); } catch(char* szException){} components->Dispose;
...this didn´t work. Any suggestions as to how to close the thread. (doesn´t need to be "proffesional" as I´m just building a test app with really dirty coding...) Also...is the creation of the thread the "best" way to create a thread (I have seen a couple of different solution, though this was the one that I found easier imediately. regards, doneirik -
arrays as parameters to functionsmorning I´d like to know how I can pass arrays as parameters to functions in VC++. (I´m a beginner to VC++, and have all the methods inside one class) When I try, I get an error message saying that the array must specify __gc or __nogc. However, trying to declare the funtion like this:
bool function(__gc char array[]){return true;}
I get a msg saying that __gc can only be applied to an array !! How should I declare the array in the firs place, and how should it be declared in the parameter list? doneirik -
how to display integersHello
char array[5] = {'H','E','L','L','O'}; this->textBox1->Text = array;
(This works, even without appending '\0' at the end) Is there a way to display integers directly, without first convert them to strings.(So far I used the sprintf function) t. -
char to intTHANKS
-
char to int..morning... How do I convert a
char
to anint
int VC++? doneirik -
Another question to threadsI have created a separate thread to continuously monitor the serial port (i.e. to wait for something to arrive and then read it out) Is it possible to write to the serial port at the same time (in the main thread), or does the read thread block. I have tried...it didn´t work, but the problem might be somewhere else... If I cannot send while monitoring the port, what would be the proper solution? Do I have to temporarily Suspend, Sleep or Abort the thread while performing the write operation? doneirik
-
problem with threadsHi again, I just started programming with threads and I´m not sure how everything works yet... Problem: So far I have a 2-threaded Windows Forms Application. When I abort the program by clicking the x-button I cannot recompile the program without restarting my computer. I get an error message saying:
fatal error LNK1104:Cannot open file C:.....program.exe
I guess I have some process running that I didn´t terminate properly. Though, in the automatically generated "void Dispose" method I placed some code:myThread.suspend();
Isn´t this enough for terminating the thread, or is the problem perhaps somewhere else? doneirik -
how to convert BYTE to StringThanks, it worked.