Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I call member functions from header files?

Status
Not open for further replies.

TimeOut

Programmer
Nov 21, 2000
16
GB
I am a beginner to Visual C++ (so I hope my question makes sense).

I have a 'DOS' based application (cpp and header files). The headers and cpp files uses cin and cout commands.

I have created an MFC application and want to call member functions from the DOS header files when the user clicks the mouse on a button.

Any hints or tips will be really appreciated

Thanks in advance, Time Out
 
I'd like to re-phrase my question because I don't think it makes sense!

How do I display a window dialog/messagebox in a header file? What header file do I need to call? What do I do?

I've read displaying dialog/messagebox is something to do with the CDialog class. What header file can I find this class in? Help!!!!

Does my question make any sense?
 
Your question is a bit off but I know what your getting at. In a non-MFC application you need to include stdio.h, etc. to use functions such as prinf(), and others. In MFC you link to a library with all the MFC functions defined. Well not all but many. You can either link dynamically (default) or statically. This way you don't need to include forty header files.

There are two message boxes. AfxMessageBox(), or MessageBox(). Look at MSDN for info. If you want to use these in a non-MFC application you'll need to include windows.h at the top.

If you want to check out how to use a dialog box start a new application using the MFC wizard. Print out the code and start investigating. It's one of the best ways to learn. Too much to mention here.

Have fun,

Brother C
 
Thanks for your reply Brother C. Glad someone is willing to help me.

I know how display a messagebox in *Dlg.cpp (created a dialog based application using MFC wizard) via MFC classwizard.

I have have header files in plain 'non visual' C++ code. I would like to change the Cout commands in the header files to MessageBox commands. So when I call the member functions in in header via *Dlg.cpp (via a button), a MessageBox will be displayed on screen.

You said include windows.h in headers, which already had been included! I get errors stating 'MessageBoxA cannot take 1 parameters'. It doesen't matter how many parameter I put in it still gives me errors. I'am pretty sure I have the sytax right as I can create MessageBox in *Dlg.cpp very easily via the MFC Classwizard.

How can I fix this error?

Hope this question makes more sense than the last one...
Thanks
 
Here is what it should look like in it's simplest form: AfxMessageBox("This text displays on mess box.");

Add the header file to your poject, right click in the work space click on file view, right click on header files folder, add files to project, add the .h file. Take the text from cout << &quot;take this text&quot;, and put it in the AfxMessageBox(&quot;put text here&quot;). You can leave cout there it will not matter. Delete windows.h. Do a re-build all from the build pulldown menu. If you get errors add the following at the top of your .h #include &quot;stdafx.h&quot;. This include files has all the MFC header files in it. You can open it in your project and check it out if you like. Re-build and run your app.

If you still have problems let me know what the errors are. Sounds like you have all the code in your .h file. Usually you have a .h file and a .cpp file. The .h file is a footprint of the code in the .cpp file.

Brother C
 
Thanks for your reply Brother C. Your advice was really helpful and I am really grateful.

But now I have another problems! I don't really know how to open a file in Visual C++. Here is my code so far...

CFileDialog ofd(TRUE, NULL, NULL, NULL, &quot;Wave File (*.wav)
|*.wav|All File (*.*) | *.*||&quot;);
ofd.DoModal();

if (ofd.DoModal()== IDOK)
{
(further code to open a wave file)
}

I'am I on the right track? Hope there is someone out there who can help me....

Time Out, C++ Beginnner
 

To open a file with the default application (example, *.doc with MS Word). Use the following:

ShellExecute(NULL,
&quot;open&quot;,
&quot;c:\\temp\\DocName.doc&quot;,
NULL,
NULL,
SW_SHOWNORMAL);

You can change the path to an executable, bitmap, etc. It will use the default application as indicated under View, Folder Options, File Types, in explorer.

I'm not sure if this is what you're looking for but I hope so.

Enjoy,

Brother C
 
Hi Brother C

I found out how to open a wav. file for my application on my own. Though your reply did not help me much I still really appreciate you efforts friend.

On behalf of everyone else on this forum, Thanks

*TOPIC CLOSED*
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top