GIDForums  

Go Back   GIDForums > Computer Programming Forums > MS Visual C++ / MFC Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 03-Jun-2009, 08:34
littlehead littlehead is offline
New Member
 
Join Date: Jun 2009
Posts: 4
littlehead is on a distinguished road

How to use C code in MFC?


Hi,

I just started learning MFC. I want to make a graphical interface for my program instead of using command window. My program was coded in C. So how can I pass the input values from dialog box to my C program and how can I show the calculation results on dialog box?

Thanks,
Yuping
  #2  
Old 15-Jul-2009, 09:32
pixelereSet pixelereSet is offline
New Member
 
Join Date: Jul 2009
Posts: 4
pixelereSet is on a distinguished road

Re: How to use C code in MFC?


hello there! xD

Here is a little tutorial to learn the basic of mfc, create a proyect and draw a line declaring the two points of the line in the Doc...

creating a Single MFC document:

1-open the visual studio 2008
2-click file->New->Project
3- at "project types" click MFC
at "Templates" click MFC Application
4-Put a name and click Ok, put "example"
5- In the Welcome of the MFC Application Wizard:
click next

6- In the Application Type of the MFC Application Wizard:
click in the ratio button "Single document"
7- Click Finish.


Well your project in MFC had been created, now where

In the leftSide must be the "Solution Explorer" (if not, well click view->Solution Explorer) with your project and 3 folders (headers files, resources files and Source Files)

well in the Solution Explorer are two importants headers and sources named
exampleView.h exampleView.cpp and the exampleDoc.h exampleDoc.cpp

In the exampleDoc.cpp is where u will put your code referent to datas, and calculation.

In the exampleView.cpp u will put all referent to the drawwing of your application.

If want to deploy 2d figures, well in the doc u must have a arrary of figures, and in the view u acced to the Doc and draw the figures

How to draw a line, where that two points are in the exampleDoc.cpp:

1- add four int x0,y0,x1,y1 in the Attributes of the exampleDoc.h
2-in the constructor method CexampleDoc() in the exampleDoc.cpp,
add x0 =0; y0=0; x1 = 100; y1 = 100;
3-In the method OnDraw of the exampleView
at final of the method, where it says "//add draw code..."

impotant: uncoment the CDC* param of the OnDraw(CDC* /*pDC*/)

pDC->MoveTo(pDoc->x0, pDoc->y0);
pDC->LineTo(pDoc->x1, pDoc->y1);

compile, run, it will appear a line from point 0,0 to 100,100

see that to access to attributes in the exampleDoc u must use the pDoc variable...

i hope it could help
  #3  
Old 15-Jul-2009, 09:54
pixelereSet pixelereSet is offline
New Member
 
Join Date: Jul 2009
Posts: 4
pixelereSet is on a distinguished road

Re: How to use C code in MFC?


open a document using the openfolder icon button of the window:

in the class View ( View -> ClassView ), rightClick on the CexampleDoc and click properties,
click in Events, ( the Lightning icon ) in the Menu Commands click in ID_FILE_OPEN, and add it!

now u will have the method OnFileOpen( ) in this method u must add:

CPP / C++ / C Code:
void CexampleDoc::OnFileOpen( ) 
{

CFileDialog dialogo(1, 0, NULL, 0, 0, NULL, 0);

	if(dialogo.DoModal() == IDOK) {

		CString str = dialogo.GetFileName();
		const size_t StringSize = 100;
		char filename[StringSize];
		size_t CharactersConverted = 0;
		
		wcstombs_s(&CharactersConverted, filename, str.GetLength()+1, str,_TRUNCATE);

		//here u put what u will do when open your file
	}
}
 
 

Recent GIDBlogNot selected for officer school by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Trouble integrating console code into GUI Barman007 Java Forum 18 15-May-2008 13:05
How to sort random access file? wmmccoy0910 C Programming Language 12 04-Sep-2006 03:40
Here it is again! 35% - 40% off For Life! my-e-space Web Hosting Advertisements & Offers 0 20-Apr-2006 14:48
Guidelines for posting requests for help - UPDATED! WaltP C Programming Language 0 21-Apr-2005 02:44

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 21:35.


vBulletin, Copyright © 2000 - 2010, Jelsoft Enterprises Ltd.