Click here to Skip to main content
Licence CPOL
First Posted 2 Mar 2008
Views 47,766
Downloads 663
Bookmarked 83 times

My First GUI program

By | 2 Mar 2008 | Article
simple dealing with buttons and edit control

Introduction

For beginners working with VC++ for the first time, they always find a very silly example called “Hello World” when I first studied C I had it, then I found it again in C++ and now when I read VC++ also.

It’s quite confusing when you start with a very small example while you are not familiar with the surrounding environment _at least this what happened with me_ so I thought about a small example to practice some real things and it do something useful, and here when I had the idea of making the temperature conversion application.

Background

The Idea is simple, create simple dialog box with 2 buttons and 2 Edit controls. Assign one button and one edit box for “Celsius” and the other for “Fahrenheit”. All what you have to do is to write the temperature in the edit box that is assigned for it and press the button to convert and display on the other edit box the equivalent temperature.

Using the code

After you add you controls, its time to play. Make sure that the (Number) is set to true in the edit control properties since we will not deal with other kind of input but numbers.

Add member variables for the edit controls by right clicking on the edit control and select

“Add variable”. Add float member variable to both of them, I added m_nC and m_nF for “Celsius” and “Fahrenheit” respectively.

Then right click on the button of converting from “Celsius” to “Fahrenheit”, select “Add Event Handler…” make sure that in the message type you selected BN_CLICKED. This allows you to make the application react when this button will be clicked. After that click on “Add and Edit” the time for adding conversion equation had come.

Formula should be something similar like this:

Blocks of code should be set as style "Formatted" like this:

//“Celsius” to “Fahrenheit” C2F
 void CF2CandC2FDlg::OnBnClickedButtonC2f()
{
      // TODO: Add your control notification handler code here
      UpdateData(TRUE);
      m_nF=(m_nC*1.8)+32;
      UpdateData(FALSE);
}
//"Fahrenheit" to "Celsius" F2C
void CF2CandC2FDlg::OnBnClickedButtonF2c()
{
      // TODO: Add your control notification handler code here
      UpdateData(TRUE);
      m_nC=(m_nF-32)/1.8;
      UpdateData(FALSE);
}
     


Note: I had used VC++8.0 that’s why there is now class wizzard

Points of Interest

I practiced the environment in a very simple application and I learned how to read and write data from and to edit controls using buttons which is very familiar in almost every application these days.

Note: I welcome all the feedbacks and don’t forget that I’m a beginner.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Kusay J. Mohammed

Software Developer

Iraq Iraq

Member

I had MSC in computer Engineering From IRAQ and i worked with telecommunication field with ZTE and ALCATEL but i look forward to practice programming alot. i had studied C, C++, and VC++. I hope that i will continue my studies to the PhD and to write a book about Computer Engineering in general.

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralMy vote of 1 PinmemberNaren Neelamegam21:34 25 Jan '10  
GeneralMore Hard! PinmemberAric Green19:50 24 Dec '09  
GeneralMy vote of 1 PinmemberAmir Mehrabi J.20:27 29 Nov '09  
GeneralMy vote of 1 Pinmemberkreuzer3:11 30 Jan '09  
GeneralMy vote of 1 Pinmemberkreuzer3:09 30 Jan '09  
GeneralMy vote of 1 Pinmemberkreuzer3:08 30 Jan '09  
GeneralError: Missing File "F2CandC2FDlg.h" PinmemberFremont Knight12:31 13 May '08  
Questionedit controls Pinmemberkubonsey5:38 5 Apr '08  
GeneralRe: edit controls PinmemberKusay J. Mohammed9:30 5 Apr '08  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Mobile
Web02 | 2.5.120517.1 | Last Updated 3 Mar 2008
Article Copyright 2008 by Kusay J. Mohammed
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid