How to write small window gui application using MFC

No.of Views593
Bookmarked0 times
Downloads 
Votes0
By  shine   On  22 Feb 2011 11:02:04
Tag : Visual C++ , Dialog & Windows
Creating the pure MFC hand held code on how to create a simple window
emailbookmarkadd commentsprint

Images in this article missing? We recently lost them in a site migration. We're working to restore these as you read this. Should you need an image in an emergency, please contact us at info@codegain.com

 

Introduction

Creating a Simple window or dialog application using VC++ 6.00 or 7.00 applications Wizard is quiet easy job. But if you Examine the code you find that a lot of Stuff inside that you not familiar and for a beginner he will not get any idea how the basic stuff will work.
Here i am going to explain how you can create a simple window without the help of Wizard. For simplicity I am using VC++ 6.00 Editor . Your machine must have installed the VC++ 6.0Start The VC++ Editor From your Programs And

The following window will pop up

Give ‘Simple Window’ in the project name box. And click ‘win32 Application’ from the project List and click OK. You can see the next dialog as shown below


now select ‘An empty project’ and click finishNow you have created the workspace named ’simple window’ sucessfully.Next you have to add the Cpp files to the workspace. For adding the files to the workspace goto File->New and select the ‘files’ tab from the pop up dialog. select ‘C++ Source file from the tab’ and give ‘Windowsource’ in the as shown in the following figure and click OK button

 

Now you have created all the necessaries to create a simple window.
Now we can move to the coding section open the Windowsource.cpp and decalre the following header

#include “afxwin.h


The above decalration will afxwin.h contain all the decalarations and reference for accessing the MFC classes including the CFrameWnd and CWinApp
Write down the following code to the Windowsource.cpp

#include “afxwin.h

class mywindow : public CFrameWnd
{
 public :
     mywindow()
       {
         Create(0,”Simple Window”);
      } 
};

class myapplication : public CWinApp
{
       public: int InitInstance()
{
     mywindow *p = new mywindow;
     p->ShowWindow(1);
     m_pMainWnd = p;
    return 1;
}
};
myapplication a;

Before compiling you go to project->settings or click ALT + F7 .Now your code redy to compile.

 

Now Run the project by selecting Build->Execute Simple Window.exe or use Ctrl + F5
ow you can see the window on your desktop.

You can download the sample that is provided on the Top.

Try Your self see it working. 

shine joseph .

 
Sign Up to vote for this article
 
About Author
 
shine
Occupation-Not Provided
Company-Not Provided
Member Type-Fresh
Location-India
Joined date-22 Feb 2011
Home Page-Not Provided
Blog Page-Not Provided
 
 
Other popularSectionarticles
    This article discusses how you can display the page in print preview as grayscale if the printer is black-and-white. It discusses first how you can convert colors to grayscale. After that is discusses how to detect whether you are in print preview or not and whether the current printer is color or black-and-white printer. Let's go!
    Published Date : 02/Sep/2010
    MFC allows you to override CWinApp::OnIdle function to perform idle-time processing.This function is called whenever there are no messages are waiting for processing in the message queue.
    Published Date : 02/Sep/2010
Comments
There is no comments for this articles.
Leave a Reply
Title:
Display Name:
Email:
(not display in page for the security purphase)
Website:
Message:
Please refresh your screen using Ctrl+F5
If you can't read this number refresh your screen
Please input the anti-spam code that you can read in the image.
^ Scroll to Top