Вы находитесь на странице: 1из 10

VISUAL PROGRAMMING

PROGRAMS

1)MFC Program for window creation


#include<afxwin.h>
class CMainWin:public CFrameWnd
{
public:CMainWin()

{
Create(NULL,"Hello mfc");
}
};
class CApp:public CWinApp
{
public:BOOL InitInstance()
{
m_pMainWnd=new CMainWin;
m_pMainWnd->ShowWindow(2);
m_pMainWnd->UpdateWindow();
return TRUE;
}
};
CApp app;
OUTPUT:

2)Program for reading the keypress


#include<afxwin.h>
#include<string.h>
char str[80];
class CMainWin:public CFrameWnd

{
public:CMainWin()
{
Create(NULL,"MFC Window");
}
afx_msg void OnChar(UINT ch,UINT count,UINT flag);
DECLARE_MESSAGE_MAP()
};
class CApp:public CWinApp
{
public:BOOL InitInstance()
{
m_pMainWnd=new CMainWin;
m_pMainWnd->ShowWindow(2);
m_pMainWnd->UpdateWindow();
return TRUE;
}
};
BEGIN_MESSAGE_MAP(CMainWin,CFrameWnd)
ON_WM_CHAR()
END_MESSAGE_MAP()
afx_msg void CMainWin::OnChar(UINT ch,UINT count,UINT flag)
{
CClientDC dc(this);
dc.TextOut(1,1," ",3);
wsprintf(str,"%c",ch);
dc.TextOut(1,1,str,strlen(str));
}
CApp app;
OUTPUT:

3)Program for message box


#include<afxwin.h>
class CMainWin:public CFrameWnd

{
public:
CMainWin()
{
Create(NULL,"MFC window");
}
void OnLButtonDown(UINT a,CPoint p);
void OnRButtonDown(UINT a,CPoint p);
DECLARE_MESSAGE_MAP()
};
void CMainWin::OnLButtonDown(UINT a,CPoint p)
{
MessageBox("Left button clicked","Messagebox",MB_YESNOCANCEL);
}
void CMainWin::OnRButtonDown(UINT a,CPoint p)
{
MessageBox("Right button clicked","Messagebox",MB_YESNO);
}
BEGIN_MESSAGE_MAP(CMainWin,CFrameWnd)
ON_WM_LBUTTONDOWN()
ON_WM_RBUTTONDOWN()
END_MESSAGE_MAP()
class CApp:public CWinApp
{
public:BOOL InitInstance()
{
m_pMainWnd=new CMainWin;
m_pMainWnd->ShowWindow(2);
m_pMainWnd->UpdateWindow();
return TRUE;
}
};
CApp app;

OUTPUT:

4)Program for Menuhandler

#include<afxwin.h>
#include "resource.h"
class CMainWin:public CFrameWnd
{
public:
CMainWin()
{
Create(NULL,"Menu
habndler",WS_OVERLAPPEDWINDOW,rectDefault,0,MAKEINTRESOURCE(101));
}
void menuhand()
{
MessageBox("You have selected menu item NEW","Messagebox");
}
DECLARE_MESSAGE_MAP()
};
BEGIN_MESSAGE_MAP(CMainWin,CFrameWnd)
ON_COMMAND(40001,menuhand)
END_MESSAGE_MAP()
class CApp:public CWinApp
{
public:BOOL InitInstance()
{
m_pMainWnd=new CMainWin;
m_pMainWnd->ShowWindow(2);
m_pMainWnd->UpdateWindow();
return TRUE;
}
};
CApp app;

OUTPUT:

5)Program for dialog box

#include<afxwin.h>
#include "resource.h"
class mydialog:public CDialog
{
public:
mydialog(int n):CDialog(n)
{
}
};
class CMainWin:public CFrameWnd
{
public:
CMainWin()
{
Create(NULL,"Dialog",WS_OVERLAPPEDWINDOW,rectDefault,0,MAKEINTRESOURCE(10
2));
}
void newfile()
{
mydialog d(101);
d.DoModal();
}
DECLARE_MESSAGE_MAP()
};
BEGIN_MESSAGE_MAP(CMainWin,CFrameWnd)
ON_COMMAND(40001,newfile)
END_MESSAGE_MAP()
class CApp:public CWinApp
{
public:BOOL InitInstance()
{
m_pMainWnd=new CMainWin;
m_pMainWnd->ShowWindow(2);
m_pMainWnd->UpdateWindow();
return TRUE;
}
};
CApp app;

OUTPUT:

6)Program for dialog box


7)Program for editbox and push buttons

8)Program for staus bar


9)Program display bitmap
10)Program for cursor
11)Program for Spin control
12)Program for slider control
13)Program for Toolbar
14)Program for
15)

Вам также может понравиться