Windows application Framework and examples

Source: Internet
Author: User

Application framework:
The structure of the same type of application is roughly the same and has many of the same source code,
So you can use an application framework AFX (application frameworks)
Write generic source code for the same type of application.

Main wizard:
Datebase Project: Creating a Database project

MFC ActiveX Control Wizard: Creating MFC-based ActiveX controls

MFC Appwizard[dll]: Creating an MFC-based dynamic link library

MFC Appwizard[exe]: Creating MFC-based applications (most commonly used)

New database Wizard: Create a SQL Server database on SQL Servers

WIN32 application: Create a WIN32 application that can be programmed with SDK methods without using MFC

WIN32 Console Application: Create a WIN32 console application under DOS,
Programming with C + + or C language

Win32 Dynamic-link Library: Creating Win32 dynamic Link libraries, using the SDK approach

Win32 Static Library: Create a Win32 static link library, using the SDK approach


The purpose of introducing the application Wizard: to avoid programmers repeating code.

Different from DOS programs, even if a simple Windows program:
It must also show a program run window that requires writing complex program code.
The same type of application's frame window style is the same, such as the same menu bar, toolbar,
status bar and user area.
The functions of the Basic menu commands are the same, such as the same file manipulation and editing commands.

To write an MFC application that implements specific functionality:

★ According to the application features in the MFC Appwizard[exe] Application Wizard Each step of the dialog box to choose,
Create a framework for an application.

★ Use the Resource Editor to edit or add resources to the program, such as Edit menu, add dialog box, etc.

★ Use the ClassWizard Class Wizard or manually add declarations for classes, member variables, and member functions.

★ Write the specific function code as needed.

★ Compile and link programs. If the program has syntax errors, you need to modify the source program. Until there is no compile, link error,
To get an executable program.

★ Test the application functions, if the program does not implement the functions required by the programming, start the Debug debugger
Debug, find and modify the logic errors in the program design.

We can make an image summary of Visual C + + MFC Programming:

The ◇MFC application framework makes our program design work like filling questions.

The integration tools in ◇developer Studio make our program design work like a choice question,
Programmers are like skilled workers in software-integrated assembly shops.

Common file types in Visual C + +
Suffix type description
DSW Workspace files combine the details of a project into a workspace
DSP project file stores the details of the project and replaces the MAK file
Hc++ the definition code for the header file storage class
Cppc++ implementation code for member functions of the source file storage class
RC Resource script file stores resources such as menus, toolbars, and dialog boxes
RC2 resource files are used to include resources in the project
ICO icon File Store application icon
BMP bitmap File storage bitmap
CLW Class Wizard files store class information used by the ClassWizard Class Wizard

Resource identifier prefixes in MFC
Identifier prefix description
IDR_ main Menu, toolbar, application diagram
Key and accelerator tables
Idd_ dialog box
IDC_ Controls and cursors
Ids_ string
Idp_ the string for the Hint message dialog box
Id_ menu command Items
Application Examples:
Example 1: Create an application framework.
The purpose of this example is to illustrate the methods and procedures for creating a Windows application

1 //contains the definition of the data type and structure required by the application2#include <windows.h>3 4LRESULT CALLBACK WndProc (Hwnd,uint,wparam,lparam);//window Function Description5 6 //----------------------The following initialization window class-------------------------7 intWINAPI WinMain8 (9 hinstance hinstance,Ten hinstance Hprevinst, One LPSTR lpszCmdLine, A intnCmdShow - ) - { the HWND HW - nd; - msg msg; - wndclass wndclass; + CharLpszclassname[] ="window";//window class name - CharLpsztitle[] ="my_windows";//Window Title name +  A //------------------the definition of a window class--------------------------- atwndclass.style=0;//window type is the default type -Wndclass.lpfnwndproc=wndproc;//defining window processing functions -Wndclass.cbclsextra=0;//window class no extension -Wndclass.cbwndextra=0;//window instance has no extension -Wndclass.hinstance=hinstance;//Current instance handle -wndclass.hicon=LoadIcon (null,idi_application); in //the minimized icon for the window is the default icon -Wndclass.hcursor=loadcursor (null,idc_arrow); to //window with arrow cursor +Wndclass.hbrbackground=Getstockobject (white_brush); - //window background is white theWndclass.lpszmenuname=null;//no menu in Window *Wndclass.lpszclassname=lpszclassname;//window class is named "Window" $ Panax Notoginseng //------------------The following to register the window class------------ - if(! RegisterClass (&wndclass))//warn if registration fails the { +Messgaebeep (0); A returnFALSE; the } + //--------------------Create a window------------------------- -hwnd =CreateWindow $ ( $lpszClassName,//window class name -Lpsztitle,//the title name of the window instance -Ws_overlappedwindow,//the style of the window the Cw_usedefault, -Cw_usedefault,//the upper-left corner of the window coordinates the default valueWuyi Cw_usedefault, theCw_usedefault,//the height and width of the window are the default values -Null//This window has no parent window WuNull//This window has no main menu -HINSTANCE,//The current handle of the application that created this window AboutNull//do not use this value $  - ); - //------------------------Display window----------------------- - ShowWindow (hwnd,ncmdshow); A  + //------------------------Draw the user area--------------------- the UpdateWindow (HWND);  - //------------------------message loop----------------------- $  while(GetMessage (&msg,null,0,0)) the { theTranslateMessage (&MSG); theDispatchMessage (&MSG); the } -  in //Message loop ends when the program terminates and returns the message to the operating system the returnMsg.wparam; the } About  the //---------------------------------window Functions-------------------- the LRESULT CALLBACK WndProc the (HWND hwnd, + UINT message, - WPARAM WPARAM, the LPARAM LPARAMBayi ) the  the {  - Switch(message) - {  the  CaseWm_destroy: thePostQuitMessage (0);//call PostQuitMessage to emit a vm_quit message the default://System Message Default handler function is used by default the returnDefWindowProc (hwnd,message,wparam,lparam); - } the return(0); the}

Windows application Framework and examples

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.