3. READING KEYSTROKES FROM KEYBOARD
Step 2:-Select a project tab from new window and from that select MFC application wizard [exe] option and give a project name as keystrokes and click ok.
Step 3:-
Þ MFC Application Wizard Window is appeared.
Þ Select a single document default settings in step1, click next
Þ Select default settings from step2 to step6 and click finish
Þ New projects information on window will appear and click ok
Step 4:-Go to workspace window and select file view tab. Select Header files and click on KeystrokesDoc.h, declare a string of text to hold data in MFC CString object.
public:
virtual ~CKeystrokesDoc();
CString Strdata;
Step 5:-Double click on CKeyStrokes.Doc and in that select CKeyStrokes.Doc() Constructor and initialize the Strdata to an empty string as follows
CKeyStrokesDoc::CKeyStrokesDoc()
{
Strdata = “ “;
Step 6:-To read Key Storkes we have to add an event handler
Þ Goto View menu and from that select Class Wizard.
Þ Select CKeystrokesView under class name menu and select WM_CHAR from messages menu and double click it this adds OnChar() event handler.
Step 7:-To store the character the user typed into Strdata, add code to OnChar() method from CKeystrokesView in class view tab double click it.
void CKeystrokesView::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
{
CKeystrokesDoc* pDoc = Get Document();
ASSERT_VALID (pDoc);
pDoc->Strdata += nChar;
Invalidate();
CView::OnChar(nChar, nRepeat, nFlags);
}
Step 8:-Customize On Draw() method from CKeystrokes View as follows.
void CKeystrokesView::OnDraw(CDC *pDC)
{
CKeystrokes* pDoc = Get Document();
ASSERT_VALID(pDoc);
pDC-> TextOut(100, 100, pDoc-> Strdata);
}
Step 9:-Build………Compile……….Execute
No comments:
Post a Comment