MFC Library:
It is a collection of
reusable classes that are used for the window program. This library is provided
by the dynamic link library (DLL). DLL consists of many executable functions.
The MFC program can be
created by two ways –
1. Using
Shared DLL.
2. Using
App and Class wizard.
·
Create MFC program using AppWizard
–
i.
Start visual studio, click on File
menu->New. Select MFC AppWizard(.exe). And give the name of project. And
click on ok button.
ii.
On new window select single
document radio button then click next.
iii.
On wizard step 3, select none radio
button and click next.
iv.
On wizard step 4, uncheck the
printing and print preview option and click next button.
v.
On wizard step 5, select radio
button MFC standard, as a shared DLL.
vi.
On wizard step 6, Indicate class name,
header file name and implementation name, then click on finish.
vii.
Now screen show that AppWizard
generate following code.
Event Handling:
MFC program allow the user
to handle various events such as key press and mouse click. These events can be
sent to the application in the form of message.
Some events in VC++
WM_KEYDOWN
WM_KEYUP
WM_LBUTTONDOWN
WM_RBUTTONDOWN
WM_LBUTTONUP
WM_RBUTTONUP
WM_LBUTTONDBLCLK
WM_RBUTTONDBLCLK
WM_MOUSEMOVE
WM_LBUTTONUP
WM_RBUTTONUP
WM_LBUTTONDBLCLK
WM_RBUTTONDBLCLK
WM_MOUSEMOVE
In order to handle these
messages there exist message map which convert these messages to the handler
function.
For Ex:
The handler function for the
message WM_LBUTTONUP will be.
Void
ProjView::OnLButtonUp(UINT nFlag, CPoint point)
{
//ToDo Add code here
CView :: OnLButtonUp(nFlag,point);
}
This skeleton code for the
message handler function will be get using class wizard. The above code gets
generated in ProjView.cpp file. The declaration of this function will be in ProjView.h file
Note: "Proj" is Project name here.
afx_msg void OnLButton(UINT
nFlags, CPoint point);
The afx_msg means that this
is a prototype declaration and there should some message map for this
declaration. This message map is a macro which will be as follows –
BEGIN_MESSAGE_MAP(ProjView,
Cview)
ON_WM_LBUTTONUP() //Entry specifically for OnLButtonUp
//Other message map entries
END_MESSAGE_MAP()
0 comments:
Post a Comment