Monday, April 1, 2013

visual c++,mfc program to handle key events..

    visual c++,mfc program to handle key events..          

#include<afxwin.h>
class myframe:public CFrameWnd
{
public:
    myframe()           
    {
        Create(0,"WELCOME");
    }
    OnKeyDown()
    {
        MessageBox("key down","haiii");
    }
    OnKeyUp()
    {
        MessageBox("key up","haiii");
    }
    OnSysKeyDown()
    {
        MessageBox("system key down","haiii");
    }
    OnSysKeyUp()
    {
        MessageBox("system key up","haiii");
    }
    OnChar()
    {
        MessageBox("character","haiii");
    }
DECLARE_MESSAGE_MAP()
};
BEGIN_MESSAGE_MAP(myframe,CFrameWnd)
ON_WM_KEYDOWN()
ON_WM_KEYUP()
ON_WM_CHAR()
ON_WM_SYSKEYDOWN()
ON_WM_SYSKEYUP()
END_MESSAGE_MAP()
class myapp:public CWinApp
{
public:
virtual BOOL InitInstance()
{
m_pMainWnd=new myframe();
m_pMainWnd->ShowWindow(1);
m_pMainWnd->UpdateWindow();
return TRUE;
}
};
myapp app; 
   
 Importance of events:

 This is the magic ingredient that makes the program 'interactive'. The form and buttons displayed on the computer screen is part of what is called a GUI, or Graphic User Interface. That simply means that the pictures on the screen interact with the mouse, keyboard, or maybe even something else. In the case of a touch screen, it might be your finger. Now, the program can do one thing when a user clicks button 'A' and something completely different when button 'B' is clicked. The 'event' is that one or the other button is clicked.

No comments:

Post a Comment