Usually have no access to the MFC code, this is the project dictates, the project involves hands MFC, feeling a bit mean, so looking at the video to learn b station, had not started operating, just fly, a general understanding of this flow of the code, now offer video link station b: MFC advanced course in layman's language version of the
following is the course notes:
Why learn MFC?
MFC: emblem Soft Foundation Class Library (English:. Microsoft Foundation Classes referred to as MFC)
If you are doing on the windows GUI development platform, MFC is a good choice (Qt cross-platform), after all, huge windows accumulated subscriber base, market acceptance high degree.
However, not only to learn by learning MFC MFC, but also to learn MFC framework design.
If you will only use MFC, you may be looking for a job, once the work content to leave the MFC, you did not. Learn anything are the same, learning is a process, not just a technology itself, because the technology is certainly constantly updated, you learn now can be used on today, but no one can guarantee what will happen in the future, but always changing them, to understand the methods, learn what all the same.
MFC was born as a mature 20-year framework, its design is very worthy of our study. Of course, if and Qt, Andorid and ios kind of more "modern" compared framework, MFC does seem a bit out of place.
But if you read the ancestral slightly MFC source code will find powerful place of MFC. MFC can not imagine at that time even the C ++ STL (Standard Template Library, Standard Template Library) have not appeared, on the use of generic programming techniques to write a CList, CArray, CMap and other containers. MFC process is not just oriented API package is an object-oriented form, he was still behind to do a lot of things, including streamlining some processes, improve the stability of some (of course, it is for the Windows platform).
Many companies in some projects to do on a long time, often have their own libraries, their framework, we just need to continue to improve and expand on its basis. If you do not know the library, you are simply not start. This is why we want to learn the reason libraries, and frameworks design.
-------------------------------------------------
class schedule
The first day (Win message mechanism, the SDK programming basics):
1, Basic Concepts (SDK, API, a handle, a message queue, the WinMain function)
2, a windows interface program (WinAPI)
. 3, the message loop and window procedure function
4, the first MFC procedures (CWinApp, CFrameWnd)
5, message mapping
6, unicode character set Yu introduction
7. the wizard to create an MFC application
describes several important functions 8, MFC applications
9, add and delete events
on two days (graphics, text-based programming, menu):
1, simple drawing
2, using brush and the brush
3, using the caret
4, fonts operation
5, the operation menu related to
the third day (box, common control):
1, making dynamic icons (timer)
2, dialog box (modal and modeless)
3, dialog-based programming
3, based programming dialog
4, the common control using
the fourth day (and view documents, database programming) :
1, the document describes the view of the structure
2, use CArchive class
3, MFC odbc database operation
fifth day - the sixth day: drug inventory management system
-------------------------------------------------
First, the basic concept
SDK: Software Development Kit, Simple-Develop-Key, easy to develop key
JDK: Java Development Kit, Java Development Kit, Java language software development kit
IDE: VS qt
API: Application Programming Interface
windows platform: WINAPI system call, windows.h, call the system provides a special interface, system resources get
windows: the parent window and the child window, customers and non-customers district
handle: a structure variable flag of controls, window handle HWND, icon handle: HICO
message queue
message
window procedure function
main ()
the WinMain () // entry address WINAPI
Two, winAPI window procedure
1, defining the entry function the WinMain ()
2, creating a window of
a) the design window class the WNDCLASS (a member variable assignment)
B) register window class
c) create a window
d) display and update the window
3, the message cycle
4, the window procedure function
MSDN Library: winAPI, MFC // keywords to find the distinction: TextOut (Windows) / TextOut Method, (MFC)
MFC reference documentation (Chinese) // many times you create a class, you need to see its constructor, or need to be considered he passed parameter
Third, a program MFC (pure code) (# include <afxwin.h>)
1) application class the CWinApp
2) frame class the CFrameWnd
class the MyApp: public the CWinApp
{
public:
// MFC program entry address
Virtual BOOL the InitInstance ();
};
class of MyFrame: public the CFrameWnd
{
public:
of MyFrame ();
Private:
};
1) there is only one global application objects class
2) implement the functions in a program entry function InitInstance () // packaged inside the underlying function, see the main () and WinMain ()
a) is dynamically assigned to the frame-based objects MyFrame space (automatic calling its constructor)
a) MyFrame frame class object constructor function to create a window in the Create :: the CWnd
B) class object display window frame :: the ShowWindow the CWnd
C) to update the frame window class object :: the UpdateWindow the CWnd
D) save framework class object pointer CWinThread :: m_pMainWnd // not we use, but the back window mfc to use this pointer
Event Processing:
Message map
1, the operation class .h, the announcement message map macro
DECLARE_MESSAGE_MAP ()
2, the corresponding macro definitions .cpp
BEGIN_MESSAGE_MAP (MyFrame, CFrameWnd) // the name of the derived class, the base class name
ON_WM_LBUTTOND () // message map entry flag
END_MESSAGE_MAP ()
. 3, the corresponding class .h, the announcement message processing function
4, the corresponding message handling functions defined .cpp
steps of: selecting the desired category class inside view → → → → properties right-click message → WM_LBUTTONDOW → ADD
Fourth, create a project wizard
1, the structure of the document view
document class: it is a class, specifically to load store (write) data can be // own definition, background processing, no control
view class: it is a class, specifically to display and modify data
framework classes: a container, a view of the containers
2. A few of the more important functions
Application class the CWinApp:
the InitInstance (): entry address of the program
framework classes the CFrameWnd:
the PreCreateWindow (): call creating the window
OnCreate (): After a window is created trigger WM_CREATE, which is handler WM_CREATE message
view class CView:
the OnDraw () : drawing
WM_PAINT message handler OnPaint () → internal call the OnDraw ()
the OnPaint () and the OnDraw () exist, only the OnPaint () effective
the OnCreate (): after a window is created automatically call
Adding and deleting (message handler) 3. events
the difference between a) and frame views of
the steps of: selecting the desired category class inside view → → → → Properties right click → WM_LBUTTONDOW → ADD message
frame is equivalent to a container, the container release view
view corresponding to wallpaper
Fourth, character set
ANSI multi-byte, one-byte
char p [] = "abcdet" ; // a character byte
unicode byte wide, a 2-byte character
TCHAR * p = L "abc" ; // a character 2 byte
wcslen (P);
the MFC:
TCHAR: automatically adapt bytes (conditional compilation ANSI, unicode), equivalent to char, but the ratio of char intelligence.
TEXT ()
_T ()
Fifth, expand
afx_xxxx: global function, not part of a class-specific
xxxEx / xxxW, expanding functions, properties may be improved.
The TextOut, TextOutW
the MFC:
class name and function name: capitalized word
class MyClass {};
void SetName () {}
// parameter
isFlag
isPressTest
member variable
m_xxxx
m_hWnd
OnChar response to keyboarding
The first day of work
1. Please describe what kind of a drawing process when the message loop windows platform?
2, through WinAPI program to achieve the following
a) left-click on the window to get the coordinates clicked, a dialog box is displayed
Tip: a) how to obtain, view MSDN, see through the message, WM_XXX, window message (window information)
under b) windows, format string
TCHAR buf [1024] = {0};
wsprintf (buf, the TEXT ( "% D = X, Y = D%"), 10, 10);
B) key presses (up, down, left, Right), through dialogue displayed
macro (MSDN) keyboard values: VK_XXX, virtual key (virtual keys) initials, or ASCII value by comparing
3, WinApi and MFC What is the difference and contact?
Non-MFC wizard to create a program (pure code)
// visual stdio c ++ àwin32 project
#include<windows.h> // window procedure LRESULT CALLBACK DealMessage (the HWND the hWnd, // window handle The window message belongs UINT the uMsg, // Message flag WPARAM the wParam, // extensions LPARAM lParam) { switch(uMsg) { Case the WM_LBUTTONDOWN: // left mouse button pressed MessageBos (hWnd, TEXT ( " ABC " ), TEXT ( " the left mouse button pressed " ), MB_OK); BREAK ; Case WM_DESTROY: PostQuitMessage(2);//WM_QUIT,给主函数return msg.wParam break; case WM_PAINT: { PS the PAINTSTRUCT; // Drawing structure the HDC DC = the BeginPaint (the hWnd, & PS); TCHAR *p = L"aaaaaa"; TextOutW(dc, 30, 30, p, wcslen(p)); EndPaint(hWnd, &ps); break; } default: return DefWindowProc(hWnd, uMsg, wParam, lParam); } return 0; } // CALLBACK int WINAPI the WinMain (the HINSTANCE hInstance, // application instance the HINSTANCE hPrevInstance, // the application instance without LPSTR lpCmdLine, // command line parameters int nShowCmd // Style window display, maximize, minimize ) { /* 1. Define entry function WinMain () 2. Create a window a) Design of the WNDCLASS window class (bin value to the member variables) b) register window class c) Create a window class d) display and update the window 3. Message Loop 4. Process Window function */ // A) Design of the WNDCLASS window class (member variables to redeem the value of) the WNDCLASS WC; wc.cbClsExtra = 0 ; // class extensions wc.cbWndExtra = 0 ; // window extensions @ acquisition system default white brush wc.hbrfackxround = (HBRUSH) the GetStockObject (WHITE_BRUSH); // background color, must write // wc.hCursor = NULL; // use default WC = hCursor the LoadCursor (NULL, IDC_HELP);. // load system default cursor // wc.hlcon = NULL; wc.hIcon = the LoadIcon (NULL, IDI_WARNING); / / loading system recognize break icon wc.hInstance = hInstance; // application instance wc.lpfnWndProc = DealMessage; // window procedure name, message handler wc.lpszClassName = TEXT ( " abc " ); // name of the class wc.lpszMenuName = NULL; // menu name wc.style = nCmdShow; // display style // B) register a window class, the system tells the address entry window function process the RegisterClass (& WC); // c) class to create a window HWND hWnd = CreateWindow (TEXT ( " abc " ), TEXT ( " the Hello, world " ), WS_OVERLAPPEDWINDOW, CM_USEDEFAUT, CM_USEDEFAUT, CM_USEDEFAUT, CM_USEDEFAUT, NULL, NULL, hInstance, NULL); // D) and updates the display window ShowWindow (hWnd, SW_SHOWNORMAL); UpdateWindow(hWnd); // 3. The message loop the MSG MSG; // Upon receiving the WM_QUIT, returns 0, exit // if error, -1, not exit the while (the GetMessage (& MSG, NULL, 0 , 0 )) { // translation // virtual keys into standard characters WM_CHAR TranslateMessage (& msg); // to the operating system for distributing messages DispatchMlessage (& msg); } return msg.wParam; }