You are on page 1of 75

Ex.

No:1 Coding:
#include<windows.h>

KEYBOARD AND MOUSE EVENTS

LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM); int WINAPI WinMain(HINSTANCE h,HINSTANCE hp,LPSTR lps,int in) { WNDCLASS wc; HWND hw; MSG ms; wc.style=CS_HREDRAW|CS_VREDRAW; wc.cbClsExtra=0; wc.cbWndExtra=0; wc.hbrBackground=(HBRUSH)GetStockObject(BLACK_BRUSH); wc.hCursor=LoadCursor(NULL,IDC_ARROW); wc.hIcon=LoadIcon(NULL,IDI_APPLICATION); wc.hInstance=h; wc.lpfnWndProc=WndProc; wc.lpszClassName="window"; wc.lpszMenuName=NULL; RegisterClass(&wc); hw=CreateWindow("window","MY FIRST WINDOW",WS_OVERLAPPEDWINDOW,0,0,300,300,NULL,NULL,h,NULL); ShowWindow(hw,in); UpdateWindow(hw); while(GetMessage(&ms,hw,0,0)) {

TranslateMessage(&ms); DispatchMessage(&ms); } return ms.wParam; } LRESULT CALLBACK WndProc(HWND hw,UINT ms,WPARAM w,LPARAM l) { HDC hdc; switch(ms) { acase WM_LBUTTONDOWN: hdc=GetDC(hw); TextOut(hdc,10,10,TEXT("LEFT BUTTON PRESSED"),25); ReleaseDC(hw,hdc); return 0; case WM_LBUTTONUP: hdc=GetDC(hw); TextOut(hdc,10,50,TEXT("LEFT BUTTON RELEASED"),25); case WM_RBUTTONDOWN: hdc=GetDC(hw); TextOut(hdc,10,70,TEXT("RIGHT BUTTON PRESSED"),25); ReleaseDC(hw,hdc); return 0; case WM_RBUTTONUP: hdc=GetDC(hw);

TextOut(hdc,10,100,TEXT("RIGHT BUTTON RELEASED"),25); ReleaseDC(hw,hdc); return 0; case WM_KEYDOWN: switch(w) { case VK_END: MessageBox(hw,"YOU PRESSED END KEY","ERROR",MB_OK); break; case VK_HOME: MessageBox(hw,"YOU PRESSED HOME KEY","ERROR",MB_OK); break; case VK_INSERT: MessageBox(hw,"YOU PRESSED INSERT KEY","ERROR",MB_OK); break; case VK_DELETE: MessageBox(hw,"YOU PRESSED DELETE KEY","ERROR",MB_OK); break; } return 0; case WM_DESTROY: PostQuitMessage(0); return 0; } return DefWindowProc(hw,ms,w,l);}

Output:

Ex.No:2 Coding:

DIALOG BASED APPLICATION

// dbDlg.cpp : implementation file// #include "stdafx.h" #include "db.h" #include "dbDlg.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CAboutDlg dialog used for App About class CAboutDlg : public CDialog { public: CAboutDlg(); // Dialog Data //{{AFX_DATA(CAboutDlg) enum { IDD = IDD_ABOUTBOX }; //}}AFX_DATA // ClassWizard generated virtual function overrides //{{AFX_VIRTUAL(CAboutDlg) protected: virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support

//}}AFX_VIRTUAL // Implementation protected: //{{AFX_MSG(CAboutDlg) //}}AFX_MSG DECLARE_MESSAGE_MAP() }; CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD) { //{{AFX_DATA_INIT(CAboutDlg) //}}AFX_DATA_INIT } void CAboutDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CAboutDlg) //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CAboutDlg, CDialog) //{{AFX_MSG_MAP(CAboutDlg) // No message handlers //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CDbDlg dialog

CDbDlg::CDbDlg(CWnd* pParent /*=NULL*/) : CDialog(CDbDlg::IDD, pParent) { //{{AFX_DATA_INIT(CDbDlg) m_nOperation = -1; m_dFirst = 0.0; m_dSecond = 0.0; m_dResult = 0.0; //}}AFX_DATA_INIT // Note that LoadIcon does not require a subsequent DestroyIcon in Win32 m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); } void CDbDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CDbDlg) DDX_Radio(pDX, IDC_OPERATION, m_nOperation); DDX_Text(pDX, IDC_FIRST, m_dFirst); DDX_Text(pDX, IDC_SECOND, m_dSecond); DDX_Text(pDX, IDC_RESULT, m_dResult); //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CDbDlg, CDialog) //{{AFX_MSG_MAP(CDbDlg) ON_WM_SYSCOMMAND()

ON_WM_PAINT() ON_WM_QUERYDRAGICON() ON_BN_CLICKED(IDC_COMPUTE, OnCompute) //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CDbDlg message handlers BOOL CDbDlg::OnInitDialog() { CDialog::OnInitDialog(); // Add "About..." menu item to system menu. // IDM_ABOUTBOX must be in the system command range. ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX); ASSERT(IDM_ABOUTBOX < 0xF000); CMenu* pSysMenu = GetSystemMenu(FALSE); if (pSysMenu != NULL) { CString strAboutMenu; strAboutMenu.LoadString(IDS_ABOUTBOX); if (!strAboutMenu.IsEmpty()) { pSysMenu->AppendMenu(MF_SEPARATOR); pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu); } }

// Set the icon for this dialog. The framework does this automatically // when the application's main window is not a dialog SetIcon(m_hIcon, TRUE); SetIcon(m_hIcon, FALSE); // Set big icon // Set small icon

// TODO: Add extra initialization here return TRUE; // return TRUE unless you set the focus to a control } void CDbDlg::OnSysCommand(UINT nID, LPARAM lParam) { if ((nID & 0xFFF0) == IDM_ABOUTBOX) { CAboutDlg dlgAbout; dlgAbout.DoModal(); } else { CDialog::OnSysCommand(nID, lParam); } } // If you add a minimize button to your dialog, you will need the code below // to draw the icon. For MFC applications using the document/view model, // this is automatically done for you by the framework. void CDbDlg::OnPaint() { if (IsIconic())

{ CPaintDC dc(this); // device context for painting SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0); // Center icon in client rectangle int cxIcon = GetSystemMetrics(SM_CXICON); int cyIcon = GetSystemMetrics(SM_CYICON); CRect rect; GetClientRect(&rect); int x = (rect.Width() - cxIcon + 1) / 2; int y = (rect.Height() - cyIcon + 1) / 2; // Draw the icon dc.DrawIcon(x, y, m_hIcon); } else { CDialog::OnPaint(); } } // The system calls this to obtain the cursor to display while the user drags // the minimized window. HCURSOR CDbDlg::OnQueryDragIcon() { return (HCURSOR) m_hIcon; } void CDbDlg::OnCompute()

{ UpdateData(TRUE); switch(m_nOperation) { case 0: //add m_dResult=m_dFirst + m_dSecond; break; case 1: //subtract m_dResult=m_dFirst - m_dSecond; break; case 2: //multiply m_dResult=m_dFirst * m_dSecond; break; case 3: //divide if(m_dSecond!=0.0) { m_dResult=m_dFirst / m_dSecond; } else { //For Error Message Box

AfxMessageBox("Divide by zero"); m_dResult=0.0; } break; default: TRACE("default;m_nOperation=%d\n",m_nOperation); } UpdateData(FALSE); }

Output:

Ex.No:3

MDI APPLICATION

Coding:
// ChildView.h : interface of the CChildView class// ///////////////////////////////////////////////////////////////////////////// #if!defined(AFX_CHILDVIEW_H__A95C210D_6A6D_4D8F_B877_C4038479ABCA__INCLUDED) #define AFX_CHILDVIEW_H__A95C210D_6A6D_4D8F_B877_C4038479ABCA__INCLUDED_ #if _MSC_VER > 1000 #pragma once #endif // _MSC_VER > 1000 ///////////////////////////////////////////////////////////////////////////// // CChildView window class CChildView : public CWnd { // Construction public: CChildView(); // Attributes public: // Operations public: // Overrides // ClassWizard generated virtual function overrides //{{AFX_VIRTUAL(CChildView) protected: virtual BOOL PreCreateWindow(CREATESTRUCT& cs); //}}AFX_VIRTUAL

// Implementation public: virtual ~CChildView(); // Generated message map functions protected: //{{AFX_MSG(CChildView) afx_msg void OnPaint(); //}}AFX_MSG DECLARE_MESSAGE_MAP() private: CRect m_rectEllipse; }; ///////////////////////////////////////////////////////////////////////////// //{{AFX_INSERT_LOCATION}} // Microsoft Visual C++ will insert additional declarations immediately before the previous line. #endif // !defined(AFX_CHILDVIEW_H__A95C210D_6A6D_4D8F_B877_C4038479ABCA__INCLUDED_)

// ChildView.cpp : implementation of the CChildView class// #include "stdafx.h" #include "MdiEx1.h" #include "ChildView.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif

///////////////////////////////////////////////////////////////////////////// // CChildView CChildView::CChildView():m_rectEllipse(200,200,15,30) { } CChildView::~CChildView() { } BEGIN_MESSAGE_MAP(CChildView,CWnd ) //{{AFX_MSG_MAP(CChildView) ON_WM_PAINT() //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CChildView message handlers BOOL CChildView::PreCreateWindow(CREATESTRUCT& cs) { if (!CWnd::PreCreateWindow(cs)) return FALSE; cs.dwExStyle |= WS_EX_CLIENTEDGE; cs.style &= ~WS_BORDER; cs.lpszClass = AfxRegisterWndClass(CS_HREDRAW|CS_VREDRAW|CS_DBLCLKS, ::LoadCursor(NULL, IDC_ARROW), HBRUSH(COLOR_WINDOW+1), NULL); return TRUE; } void CChildView::OnPaint()

{ CPaintDC dc(this); // device context for painting dc.TextOut(0,0,"Chendhuran"); dc.Rectangle(m_rectEllipse); } Output:

Ex.No:4 Coding:
#if

THREADS

!defined(AFX_COMPUTEDLG_H__92A3AEA5_1634_456F_B880_5BAC9C191821__INCLUDED_) #define AFX_COMPUTEDLG_H__92A3AEA5_1634_456F_B880_5BAC9C191821__INCLUDED_ #if _MSC_VER > 1000 #pragma once #endif // _MSC_VER > 1000 // ComputeDlg.h : header file// ///////////////////////////////////////////////////////////////////////////// // CComputeDlg dialog class CComputeDlg : public CDialog { // Construction public: CComputeDlg(CWnd* pParent = NULL); // standard constructor // Dialog Data //{{AFX_DATA(CComputeDlg) enum { IDD = IDD_DIALOG1 }; // NOTE: the ClassWizard will add data members here //}}AFX_DATA // Overrides // ClassWizard generated virtual function overrides //{{AFX_VIRTUAL(CComputeDlg) protected: virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support

//}}AFX_VIRTUAL private: int m_nTimer; int m_nCount; enum { nMaxCount = 10000 }; // Implementation protected: // Generated message map functions //{{AFX_MSG(CComputeDlg) afx_msg void OnTimer(UINT nIDEvent); afx_msg void OnStart(); virtual void OnCancel(); //}}AFX_MSG DECLARE_MESSAGE_MAP() }; //{{AFX_INSERT_LOCATION}} // Microsoft Visual C++ will insert additional declarations immediately before the previous line. #endif // !defined(AFX_COMPUTEDLG_H__92A3AEA5_1634_456F_B880_5BAC9C191821__INCLUDED_)

// ComputeDlg.cpp : implementation file #include "stdafx.h" #include "Thread.h" #include "ComputeDlg.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE

static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CComputeDlg dialog CComputeDlg::CComputeDlg(CWnd* pParent /*=NULL*/) : CDialog(CComputeDlg::IDD, pParent) { //{{AFX_DATA_INIT(CComputeDlg) // NOTE: the ClassWizard will add member initialization here //}}AFX_DATA_INIT m_nCount = 0; } void CComputeDlg::DoDataExchange(CDataExchange* pDX) {CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CComputeDlg) // NOTE: the ClassWizard will add DDX and DDV calls here //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CComputeDlg, CDialog) //{{AFX_MSG_MAP(CComputeDlg) ON_WM_TIMER() ON_BN_CLICKED(IDC_START, OnStart) //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CComputeDlg message handlers

void CComputeDlg::OnStart() { MSG message; m_nTimer = SetTimer(1, 100, NULL); ASSERT(m_nTimer != 0); GetDlgItem(IDC_START)->EnableWindow(FALSE); volatile int nTemp; for (m_nCount = 0; m_nCount < nMaxCount; m_nCount++) { for (nTemp = 0; nTemp < 100; nTemp++) { } if(::PeekMessage(&message, NULL, 0, 0, PM_REMOVE)) { ::TranslateMessage(&message); ::DispatchMessage(&message); } } CDialog::OnOK(); } void CComputeDlg::OnTimer(UINT nIDEvent) { CProgressCtrl* pBar = (CProgressCtrl*)GetDlgItem(IDC_PROGRESS1); pBar->SetPos(m_nCount * 10000 / nMaxCount); } void CComputeDlg::OnCancel() { TRACE("entering CComputeDlg::OnCancel\n"); if(m_nCount == 0)

{ CDialog::OnCancel(); } else { m_nCount = nMaxCount; } }

// ThreadView.cpp : implementation of the CThreadView class #include "stdafx.h" #include "Thread.h" #include "ThreadDoc.h" #include "ThreadView.h" #include "ComputeDlg.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CThreadView IMPLEMENT_DYNCREATE(CThreadView, CView) BEGIN_MESSAGE_MAP(CThreadView, CView) //{{AFX_MSG_MAP(CThreadView) ON_WM_LBUTTONDOWN()

//}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CThreadView construction/destruction CThreadView::CThreadView() { // TODO: add construction code here } CThreadView::~CThreadView() { } BOOL CThreadView::PreCreateWindow(CREATESTRUCT& cs) { // TODO: Modify the Window class or styles here by modifying // the CREATESTRUCT cs return CView::PreCreateWindow(cs); } ///////////////////////////////////////////////////////////////////////////// // CThreadView drawing void CThreadView::OnDraw(CDC* pDC) { pDC->TextOut(0,0,"Press the left mouse button here."); } ///////////////////////////////////////////////////////////////////////////// // CThreadView diagnostics #ifdef _DEBUG

void CThreadView::AssertValid() const { CView::AssertValid(); } void CThreadView::Dump(CDumpContext& dc) const { CView::Dump(dc); } CThreadDoc* CThreadView::GetDocument() // non-debug version is inline { ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CThreadDoc))); return (CThreadDoc*)m_pDocument; } #endif //_DEBUG ///////////////////////////////////////////////////////////////////////////// // CThreadView message handlers void CThreadView::OnLButtonDown(UINT nFlags, CPoint point) { CComputeDlg dlg; dlg.DoModal(); }

Output:

Ex.No:5

DOCUMENT VIEW ARCHITECTURE

Coding:
// dvaView.h : interface of the CDvaView class ///////////////////////////////////////////////////////////////////////////// #if !defined(AFX_DVAVIEW_H__A638B869_17F8_439B_AAC4_45EF008A67E9__INCLUDED_) #define AFX_DVAVIEW_H__A638B869_17F8_439B_AAC4_45EF008A67E9__INCLUDED_ #if _MSC_VER > 1000 #pragma once #endif // _MSC_VER > 1000 class CDvaView : public CView { protected: // create from serialization only CDvaView(); DECLARE_DYNCREATE(CDvaView) public: CPoint old; // Attributes public: CDvaDoc* GetDocument(); // Operations public: // Overrides // ClassWizard generated virtual function overrides //{{AFX_VIRTUAL(CDvaView) public:

virtual void OnDraw(CDC* pDC); // overridden to draw this view virtual BOOL PreCreateWindow(CREATESTRUCT& cs); protected: virtual BOOL OnPreparePrinting(CPrintInfo* pInfo); virtual void OnBeginPrinting(CDC* pDC, CPrintInfo* pInfo); virtual void OnEndPrinting(CDC* pDC, CPrintInfo* pInfo); //}}AFX_VIRTUAL // Implementation public: virtual ~CDvaView(); #ifdef _DEBUG virtual void AssertValid() const; virtual void Dump(CDumpContext& dc) const; #endif protected: // Generated message map functions protected: //{{AFX_MSG(CDvaView) afx_msg void OnMouseMove(UINT nFlags, CPoint point); //}}AFX_MSG DECLARE_MESSAGE_MAP() }; #ifndef _DEBUG // debug version in dvaView.cpp inline CDvaDoc* CDvaView::GetDocument() { return (CDvaDoc*)m_pDocument; } #endif

///////////////////////////////////////////////////////////////////////////// //{{AFX_INSERT_LOCATION}} // Microsoft Visual C++ will insert additional declarations immediately before the previous line. #endif // !defined(AFX_DVAVIEW_H__A638B869_17F8_439B_AAC4_45EF008A67E9__INCLUDED_) // dvaView.cpp : implementation of the CDvaView class #include "stdafx.h" #include "dva.h" #include "dvaDoc.h" #include "dvaView.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CDvaView IMPLEMENT_DYNCREATE(CDvaView, CView) BEGIN_MESSAGE_MAP(CDvaView, CView) //{{AFX_MSG_MAP(CDvaView) ON_WM_MOUSEMOVE() //}}AFX_MSG_MAP // Standard printing commands ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint) ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint) ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview) END_MESSAGE_MAP()

///////////////////////////////////////////////////////////////////////////// // CDvaView construction/destruction CDvaView::CDvaView() { // TODO: add construction code here } CDvaView::~CDvaView() { } BOOL CDvaView::PreCreateWindow(CREATESTRUCT& cs) { // TODO: Modify the Window class or styles here by modifying // the CREATESTRUCT cs return CView::PreCreateWindow(cs); } ///////////////////////////////////////////////////////////////////////////// // CDvaView drawing void CDvaView::OnDraw(CDC* pDC) { CDvaDoc* pDoc = GetDocument(); ASSERT_VALID(pDoc); // TODO: add draw code for native data here } ///////////////////////////////////////////////////////////////////////////// // CDvaView printing BOOL CDvaView::OnPreparePrinting(CPrintInfo* pInfo)

{ // default preparation return DoPreparePrinting(pInfo); } void CDvaView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/) { // TODO: add extra initialization before printing } void CDvaView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/) { // TODO: add cleanup after printing } ///////////////////////////////////////////////////////////////////////////// // CDvaView diagnostics #ifdef _DEBUG void CDvaView::AssertValid() const { CView::AssertValid(); } void CDvaView::Dump(CDumpContext& dc) const { CView::Dump(dc); } CDvaDoc* CDvaView::GetDocument() // non-debug version is inline { ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CDvaDoc)));

return (CDvaDoc*)m_pDocument; } #endif //_DEBUG ///////////////////////////////////////////////////////////////////////////// // CDvaView message handlers void CDvaView::OnMouseMove(UINT nFlags, CPoint point) { // TODO: Add your message handler code here and/or call default CView::OnMouseMove(nFlags, point); CClientDC dc(this); if(nFlags==MK_LBUTTON) { dc.MoveTo(old.x,old.y); dc.LineTo(point.x,point.y); old=point; } } Output:

Ex.No:6

DYNAMIC CONTROLS

Coding: STDMETHODIMP CTEST_ATL::add(long a, long b, long *c) { *c=a+b; return S_OK; } Private Sub Command1_Click() Dim a As MY_ATLLib.TEST_ATL Set a = New TEST_ATL Dim x As Long a.Add 20, 30, x MsgBox ("20 + 30 =" & x) End Sub

Ex.No:7A

MENUS AND KEYBOARD ACCELERATORS

Coding:
// menukeyDoc.h : interface of the CMenukeyDoc class // ///////////////////////////////////////////////////////////////////////////// #if !defined(AFX_MENUKEYDOC_H__FB11C03A_C46E_4BD7_87B6_1A8F1C1846B4__INCLUDED_) #define AFX_MENUKEYDOC_H__FB11C03A_C46E_4BD7_87B6_1A8F1C1846B4__INCLUDED_ #if _MSC_VER > 1000 #pragma once #endif // _MSC_VER > 1000 class CMenukeyDoc : public CDocument { public: CString m_strText; protected: // create from serialization only CMenukeyDoc(); DECLARE_DYNCREATE(CMenukeyDoc) // Attributes public: // Operations public: // Overrides // ClassWizard generated virtual function overrides //{{AFX_VIRTUAL(CMenukeyDoc) public: virtual BOOL OnNewDocument();

virtual void Serialize(CArchive& ar); //}}AFX_VIRTUAL // Implementation public: virtual ~CMenukeyDoc(); #ifdef _DEBUG virtual void AssertValid() const; virtual void Dump(CDumpContext& dc) const; #endif protected: // Generated message map functions protected: //{{AFX_MSG(CMenukeyDoc) afx_msg void OnEditClearAll(); afx_msg void OnUpdateEditClearAll(CCmdUI* pCmdUI); //}}AFX_MSG DECLARE_MESSAGE_MAP() }; ///////////////////////////////////////////////////////////////////////////// //{{AFX_INSERT_LOCATION}} // Microsoft Visual C++ will insert additional declarations immediately before the previous line. #endif // !defined(AFX_MENUKEYDOC_H__FB11C03A_C46E_4BD7_87B6_1A8F1C1846B4__INCLUDED_) // menukeyDoc.cpp : implementation of the CMenukeyDoc class // #include "stdafx.h" #include "menukey.h"

#include "menukeyDoc.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CMenukeyDoc IMPLEMENT_DYNCREATE(CMenukeyDoc, CDocument) BEGIN_MESSAGE_MAP(CMenukeyDoc, CDocument) //{{AFX_MSG_MAP(CMenukeyDoc) ON_COMMAND(ID_EDIT_CLEAR_ALL, OnEditClearAll) ON_UPDATE_COMMAND_UI(ID_EDIT_CLEAR_ALL, OnUpdateEditClearAll) //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CMenukeyDoc construction/destruction CMenukeyDoc::CMenukeyDoc() { // TODO: add one-time construction code here } CMenukeyDoc::~CMenukeyDoc() { } BOOL CMenukeyDoc::OnNewDocument() {

if (!CDocument::OnNewDocument()) return FALSE; m_strText = "Welcome Message from Document"; return TRUE; } ///////////////////////////////////////////////////////////////////////////// // CMenukeyDoc serialization void CMenukeyDoc::Serialize(CArchive& ar) { if (ar.IsStoring()) { // TODO: add storing code here } else { // TODO: add loading code here } } ///////////////////////////////////////////////////////////////////////////// // CMenukeyDoc diagnostics #ifdef _DEBUG void CMenukeyDoc::AssertValid() const { CDocument::AssertValid(); } void CMenukeyDoc::Dump(CDumpContext& dc) const

{ CDocument::Dump(dc); } #endif //_DEBUG ///////////////////////////////////////////////////////////////////////////// // CMenukeyDoc commands void CMenukeyDoc::OnEditClearAll() { m_strText.Empty(); } void CMenukeyDoc::OnUpdateEditClearAll(CCmdUI* pCmdUI) { pCmdUI->Enable(!m_strText.IsEmpty()); } // menukeyView.h : interface of the CMenukeyView class // ///////////////////////////////////////////////////////////////////////////// #if !defined(AFX_MENUKEYVIEW_H__40F159D9_4F49_4D42_BEC1_BB50659C14C2__INCLUDED_ ) #define AFX_MENUKEYVIEW_H__40F159D9_4F49_4D42_BEC1_BB50659C14C2__INCLUDED_ #if _MSC_VER > 1000 #pragma once #endif // _MSC_VER > 1000 class CMenukeyView : public CView { public:

CRichEditCtrl m_rich; protected: // create from serialization only CMenukeyView(); DECLARE_DYNCREATE(CMenukeyView) // Attributes public: CMenukeyDoc* GetDocument(); // Operations public: // Overrides // ClassWizard generated virtual function overrides //{{AFX_VIRTUAL(CMenukeyView) public: virtual void OnDraw(CDC* pDC); // overridden to draw this view virtual BOOL PreCreateWindow(CREATESTRUCT& cs); protected: //}}AFX_VIRTUAL // Implementation public: virtual ~CMenukeyView(); #ifdef _DEBUG virtual void AssertValid() const; virtual void Dump(CDumpContext& dc) const; #endif protected: // Generated message map functions

protected: //{{AFX_MSG(CMenukeyView) afx_msg void OnTransferGetdata(); afx_msg void OnTransferStoredata(); afx_msg void OnUpdateTransferStoredata(CCmdUI* pCmdUI); afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct); afx_msg void OnSize(UINT nType, int cx, int cy); //}}AFX_MSG DECLARE_MESSAGE_MAP() }; #ifndef _DEBUG // debug version in menukeyView.cpp inline CMenukeyDoc* CMenukeyView::GetDocument() { return (CMenukeyDoc*)m_pDocument; } #endif ///////////////////////////////////////////////////////////////////////////// //{{AFX_INSERT_LOCATION}} // Microsoft Visual C++ will insert additional declarations immediately before the previous line. #endif // !defined(AFX_MENUKEYVIEW_H__40F159D9_4F49_4D42_BEC1_BB50659C14C2__INCLUDED_ ) // menukeyView.cpp : implementation of the CMenukeyView class // #include "stdafx.h" #include "menukey.h" #include "menukeyDoc.h" #include "menukeyView.h" #ifdef _DEBUG

#define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CMenukeyView IMPLEMENT_DYNCREATE(CMenukeyView, CView) BEGIN_MESSAGE_MAP(CMenukeyView, CView) //{{AFX_MSG_MAP(CMenukeyView) ON_COMMAND(ID_TRANSFER_GETDATA, OnTransferGetdata) ON_COMMAND(ID_TRANSFER_STOREDATA, OnTransferStoredata) ON_UPDATE_COMMAND_UI(ID_TRANSFER_STOREDATA, OnUpdateTransferStoredata) ON_WM_CREATE() ON_WM_SIZE() //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CMenukeyView construction/destruction CMenukeyView::CMenukeyView() { // TODO: add construction code here } CMenukeyView::~CMenukeyView() { } BOOL CMenukeyView::PreCreateWindow(CREATESTRUCT& cs)

{ // TODO: Modify the Window class or styles here by modifying // the CREATESTRUCT cs return CView::PreCreateWindow(cs); } ///////////////////////////////////////////////////////////////////////////// // CMenukeyView drawing void CMenukeyView::OnDraw(CDC* pDC) { CMenukeyDoc* pDoc = GetDocument(); ASSERT_VALID(pDoc); // TODO: add draw code for native data here } ///////////////////////////////////////////////////////////////////////////// // CMenukeyView diagnostics #ifdef _DEBUG void CMenukeyView::AssertValid() const { CView::AssertValid(); } void CMenukeyView::Dump(CDumpContext& dc) const { CView::Dump(dc); }

CMenukeyDoc* CMenukeyView::GetDocument() // non-debug version is inline

{ ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMenukeyDoc))); return (CMenukeyDoc*)m_pDocument; } #endif //_DEBUG ///////////////////////////////////////////////////////////////////////////// // CMenukeyView message handlers void CMenukeyView::OnTransferGetdata() { CMenukeyDoc* pDoc = GetDocument(); m_rich.SetWindowText(pDoc->m_strText); m_rich.SetModify(FALSE); } void CMenukeyView::OnTransferStoredata() { CMenukeyDoc* pDoc = GetDocument(); m_rich.GetWindowText(pDoc->m_strText); m_rich.SetModify(FALSE); } void CMenukeyView::OnUpdateTransferStoredata(CCmdUI* pCmdUI) { pCmdUI->Enable(m_rich.GetModify()); } int CMenukeyView::OnCreate(LPCREATESTRUCT lpCreateStruct) { CRect rect(0, 0, 0, 0);

if (CView::OnCreate(lpCreateStruct) == -1) return -1; m_rich.Create(ES_AUTOVSCROLL | ES_MULTILINE | ES_WANTRETURN | WS_CHILD | WS_VISIBLE | WS_VSCROLL, rect, this, 1); return 0; } void CMenukeyView::OnSize(UINT nType, int cx, int cy) { CRect rect; CView::OnSize(nType, cx, cy); GetClientRect(rect); m_rich.SetWindowPos(&wndTop, 0, 0, rect.right - rect.left, rect.bottom - rect.top, SWP_SHOWWINDOW); } Output:

TOOLBAR AND TOOLTIP


Coding:
// toolbardemoView.h : interface of the CToolbardemoView class ///////////////////////////////////////////////////////////////////////////// #if !defined(AFX_TOOLBARDEMOVIEW_H__046F901A_C758_4ECA_AAAB_B028F391B7F7 __INCLUDED_) #define AFX_TOOLBARDEMOVIEW_H__046F901A_C758_4ECA_AAAB_B028F391B7F7__INCL UDED_ #if _MSC_VER > 1000 #pragma once #endif // _MSC_VER > 1000 class CToolbardemoView : public CView { private: CRect m_rect; BOOL m_bCircle; BOOL m_bPattern; protected: // create from serialization only CToolbardemoView(); DECLARE_DYNCREATE(CToolbardemoView) // Attributes public: CToolbardemoDoc* GetDocument(); // Operations

public: // Overrides // ClassWizard generated virtual function overrides //{{AFX_VIRTUAL(CToolbardemoView) public: virtual void OnDraw(CDC* pDC); // overridden to draw this view virtual BOOL PreCreateWindow(CREATESTRUCT& cs); protected: //}}AFX_VIRTUAL // Implementation public: virtual ~CToolbardemoView(); #ifdef _DEBUG virtual void AssertValid() const; virtual void Dump(CDumpContext& dc) const; #endif protected: // Generated message map functions protected: //{{AFX_MSG(CToolbardemoView) afx_msg void OnDrawSquare(); afx_msg void OnUpdateDrawSquare(CCmdUI* pCmdUI); afx_msg void OnDrawCircle(); afx_msg void OnUpdateDrawCircle(CCmdUI* pCmdUI); afx_msg void OnDrawPattern();

afx_msg void OnUpdateDrawPattern(CCmdUI* pCmdUI); //}}AFX_MSG DECLARE_MESSAGE_MAP() }; #ifndef _DEBUG // debug version in toolbardemoView.cpp inline CToolbardemoDoc* CToolbardemoView::GetDocument() { return (CToolbardemoDoc*)m_pDocument; } #endif ///////////////////////////////////////////////////////////////////////////// //{{AFX_INSERT_LOCATION}} // Microsoft Visual C++ will insert additional declarations immediately before the previous line. #endif // !defined(AFX_TOOLBARDEMOVIEW_H__046F901A_C758_4ECA_AAAB_B028F391B7F7 __INCLUDED_) // toolbardemoView.cpp : implementation of the CToolbardemoView class // #include "stdafx.h" #include "toolbardemo.h" #include "toolbardemoDoc.h" #include "toolbardemoView.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif /////////////////////////////////////////////////////////////////////////////

// CToolbardemoView IMPLEMENT_DYNCREATE(CToolbardemoView, CView) BEGIN_MESSAGE_MAP(CToolbardemoView, CView) //{{AFX_MSG_MAP(CToolbardemoView) ON_COMMAND(ID_DRAW_SQUARE, OnDrawSquare) ON_UPDATE_COMMAND_UI(ID_DRAW_SQUARE, OnUpdateDrawSquare) ON_COMMAND(ID_DRAW_CIRCLE, OnDrawCircle) ON_UPDATE_COMMAND_UI(ID_DRAW_CIRCLE, OnUpdateDrawCircle) ON_COMMAND(ID_DRAW_PATTERN, OnDrawPattern) ON_UPDATE_COMMAND_UI(ID_DRAW_PATTERN, OnUpdateDrawPattern) //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CToolbardemoView construction/destruction CToolbardemoView::CToolbardemoView():m_rect(0,0,100,100) { m_bCircle=TRUE; m_bPattern=FALSE; } CToolbardemoView::~CToolbardemoView() { } BOOL CToolbardemoView::PreCreateWindow(CREATESTRUCT& cs) { // TODO: Modify the Window class or styles here by modifying

// the CREATESTRUCT cs return CView::PreCreateWindow(cs); } ///////////////////////////////////////////////////////////////////////////// // CToolbardemoView drawing void CToolbardemoView::OnDraw(CDC* pDC) { CToolbardemoDoc* pDoc = GetDocument(); ASSERT_VALID(pDoc); CBrush brush(HS_VERTICAL,0L); if(m_bPattern) { pDC->SelectObject(&brush); } else { pDC->SelectStockObject(WHITE_BRUSH); } if(m_bCircle) { pDC->Ellipse(m_rect); } else { pDC->Rectangle(m_rect);

} pDC->SelectStockObject(WHITE_BRUSH); } ///////////////////////////////////////////////////////////////////////////// // CToolbardemoView diagnostics #ifdef _DEBUG void CToolbardemoView::AssertValid() const { CView::AssertValid(); } void CToolbardemoView::Dump(CDumpContext& dc) const { CView::Dump(dc); } CToolbardemoDoc* CToolbardemoView::GetDocument() // non-debug version is inline { ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CToolbardemoDoc))); return (CToolbardemoDoc*)m_pDocument; } #endif //_DEBUG ///////////////////////////////////////////////////////////////////////////// // CToolbardemoView message handlers void CToolbardemoView::OnDrawSquare() { m_bCircle=FALSE;

m_rect+=CPoint(25,25); InvalidateRect(m_rect); } void CToolbardemoView::OnUpdateDrawSquare(CCmdUI* pCmdUI) { pCmdUI->Enable(m_bCircle); } void CToolbardemoView::OnDrawCircle() { m_bCircle=TRUE; m_rect+=CPoint(25,25); InvalidateRect(m_rect); } void CToolbardemoView::OnUpdateDrawCircle(CCmdUI* pCmdUI) { pCmdUI->Enable(!m_bCircle); } void CToolbardemoView::OnDrawPattern() { m_bPattern^=1; } void CToolbardemoView::OnUpdateDrawPattern(CCmdUI* pCmdUI) { pCmdUI->SetCheck(m_bPattern); }

Output:

Ex.No:8 Coding:

ACTIVE X CONTROLS

activexDialog.h //{{AFX_INCLUDES() #include "calendar.h" //}}AFX_INCLUDES #if !defined(AFX_ACTIVEXDIALOG_H__92769575_3752_49C8_93BE_C0FA20506459__INCLUDED_) #define AFX_ACTIVEXDIALOG_H__92769575_3752_49C8_93BE_C0FA20506459__INCLUDED_ #if _MSC_VER > 1000 #pragma once #endif // _MSC_VER > 1000 // ActiveXDialog.h : header file // ///////////////////////////////////////////////////////////////////////////// // CActiveXDialog dialog class CActiveXDialog : public CDialog

{ // Construction public: CActiveXDialog(CWnd* pParent = NULL); // standard constructor // Dialog Data //{{AFX_DATA(CActiveXDialog) enum { IDD = IDD_ACTIVEXDIALOG } CCalendarm_calendar; shortm_sDay; shortm_sMonth; shortm_sYear; //}}AFX_DATA COleVariant m_varValue; unsigned long m_BackColor; // Overrides // ClassWizard generated virtual function overrides //{{AFX_VIRTUAL(CActiveXDialog) protected: virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support //}}AFX_VIRTUAL // Implementation protected: // Generated message map functions //{{AFX_MSG(CActiveXDialog) virtual BOOL OnInitDialog(); afx_msg void OnNewMonthCalendar1();

afx_msg void OnSelectdate(); afx_msg void OnNextweek(); virtual void OnOK(); DECLARE_EVENTSINK_MAP() //}}AFX_MSG DECLARE_MESSAGE_MAP() }; //{{AFX_INSERT_LOCATION}} // Microsoft Visual C++ will insert additional declarations immediately before the previous line. #endif // !defined(AFX_ACTIVEXDIALOG_H__92769575_3752_49C8_93BE_C0FA20506459__INCLUDED_)

// ActiveXDialog.cpp : implementation file // #include "stdafx.h" #include "active.h" #include "ActiveXDialog.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CActiveXDialog dialog CActiveXDialog::CActiveXDialog(CWnd* pParent /*=NULL*/) :CDialog(CActiveXDialog::IDD, pParent) {

//{{AFX_DATA_INIT(CActiveXDialog) m_sDay = 0; m_sMonth = 0; m_sYear = 0; //}}AFX_DATA_INIT m_BackColor = 0x8000000F; } void CActiveXDialog::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CActiveXDialog) DDX_Control(pDX, IDC_CALENDAR1, m_calendar); DDX_Text(pDX, IDC_DAY, m_sDay); DDX_Text(pDX, IDC_MONTH, m_sMonth); DDX_Text(pDX, IDC_YEAR, m_sYear); DDX_Control(pDX,IDC_CALENDAR1,m_calendar); DDX_OCColor(pDX,IDC_CALENDAR1,DISPID_BACKCOLOR,m_BackColor); //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CActiveXDialog, CDialog) //{{AFX_MSG_MAPCActiveXDialog) ON_BN_CLICKED(IDC_SELECTDATE, OnSelectdate) ON_BN_CLICKED(IDC_NEXTWEEK, OnNextweek) //}}AFX_MSG_MAP END_MESSAGE_MAP() /////////////////////////////////////////////////////////////////////////////

// CActiveXDialog message handlers BEGIN_EVENTSINK_MAP(CActiveXDialog, CDialog) //{{AFX_EVENTSINK_MAP(CActiveXDialog) ON_EVENT(CActiveXDialog, IDC_CALENDAR1, 3 /* NewMonth */, OnNewMonthCalendar1, VTS_NONE) //}}AFX_EVENTSINK_MAP END_EVENTSINK_MAP() BOOL CActiveXDialog::OnInitDialog() { CDialog::OnInitDialog(); m_calendar.SetValue(m_varValue); return TRUE; // return TRUE unless you set the focus to a control // EXCEPTION: OCX Property Pages should return FALSE } void CActiveXDialog::OnNewMonthCalendar1() { AfxMessageBox("EVENT:ActiveXDialog::OnNewMonthCalender1"); } void CActiveXDialog::OnSelectdate() { CDataExchange dx(this,TRUE); DDX_Text(&dx,IDC_DAY,m_sDay); DDX_Text(&dx,IDC_MONTH,m_sMonth); DDX_Text(&dx,IDC_YEAR,m_sYear); m_calendar.SetDay(m_sDay); m_calendar.SetMonth(m_sMonth); m_calendar.SetYear(m_sYear);

} void CActiveXDialog::OnNextweek() { m_calendar.NextWeek(); } void CActiveXDialog::OnOK() { CDialog::OnOK(); m_varValue = m_calendar.GetValue(); } // activeView.cpp : implementation of the CActiveView class // #include "stdafx.h" #include "active.h" #include "activeDoc.h" #include "activeView.h" #include "ActiveXDialog.h"" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CActiveView IMPLEMENT_DYNCREATE(CActiveView, CView) BEGIN_MESSAGE_MAP(CActiveView, CView)

//{{AFX_MSG_MAP(CActiveView) ON_WM_LBUTTONDOWN() //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CActiveView construction/destruction CActiveView::CActiveView() { // TODO: add construction code here } CActiveView::~CActiveView() {} BOOL CActiveView::PreCreateWindow(CREATESTRUCT& cs) { // TODO: Modify the Window class or styles here by modifying // the CREATESTRUCT cs return CView::PreCreateWindow(cs); } ///////////////////////////////////////////////////////////////////////////// // CActiveView drawing void CActiveView::OnDraw(CDC* pDC) { pDC->TextOut(0,0,"Press the left mouse button here"); } ///////////////////////////////////////////////////////////////////////////// // CActiveView diagnostics

#ifdef _DEBUG void CActiveView::AssertValid() const { CView::AssertValid(); } void CActiveView::Dump(CDumpContext& dc) const { CView::Dump(dc); } CActiveDoc* CActiveView::GetDocument() // non-debug version is inline { ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CActiveDoc))); return (CActiveDoc*)m_pDocument; } #endif //_DEBUG ///////////////////////////////////////////////////////////////////////////// // CActiveView message handlers void CActiveView::OnLButtonDown(UINT nFlags, CPoint point) { CActiveXDialog dlg; dlg.m_BackColor=RGB(255,251,240); COleDateTime today=COleDateTime::GetCurrentTime(); dlg.m_varValue=COleDateTime(today.GetYear(),today.GetMonth(),today.GetDay(),0,0,0); if(dlg.DoModal()==IDOK) { COleDateTime date(dlg.m_varValue);

AfxMessageBox(date.Format("%B %d,%Y")); } }

Output:

Ex.No:9

DATABASE ACCESS THROUGH ODBC

Coding:
// exno9View.cpp : implementation of the CExno9View class // #include "stdafx.h" #include "exno9.h" #include "exno9Set.h" #include "exno9Doc.h" #include "exno9View.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CExno9View IMPLEMENT_DYNCREATE(CExno9View, CRecordView)

BEGIN_MESSAGE_MAP(CExno9View, CRecordView) //{{AFX_MSG_MAP(CExno9View) ON_BN_CLICKED(IDC_BUTTON1, OnButton1) //}}AFX_MSG_MAP // Standard printing commands ON_COMMAND(ID_FILE_PRINT, CRecordView::OnFilePrint) ON_COMMAND(ID_FILE_PRINT_DIRECT, CRecordView::OnFilePrint) ON_COMMAND(ID_FILE_PRINT_PREVIEW, CRecordView::OnFilePrintPreview) END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CExno9View construction/destruction CExno9View::CExno9View() : CRecordView(CExno9View::IDD) { //{{AFX_DATA_INIT(CExno9View) m_pSet = NULL; m_text1 = _T(""); m_text2 = _T(""); //}}AFX_DATA_INIT // TODO: add construction code here } CExno9View::~CExno9View() { } void CExno9View::DoDataExchange(CDataExchange* pDX) {

CRecordView::DoDataExchange(pDX); //{{AFX_DATA_MAP(CExno9View) DDX_Text(pDX, IDC_EDIT1, m_text1); DDX_Text(pDX, IDC_EDIT2, m_text2); //}}AFX_DATA_MAP } BOOL CExno9View::PreCreateWindow(CREATESTRUCT& cs) { // TODO: Modify the Window class or styles here by modifying // the CREATESTRUCT cs return CRecordView::PreCreateWindow(cs); } void CExno9View::OnInitialUpdate() { m_pSet = &GetDocument()->m_exno9Set; CRecordView::OnInitialUpdate(); GetParentFrame()->RecalcLayout(); ResizeParentToFit(); } ///////////////////////////////////////////////////////////////////////////// // CExno9View printing BOOL CExno9View::OnPreparePrinting(CPrintInfo* pInfo) { // default preparation return DoPreparePrinting(pInfo); }

void CExno9View::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/) { // TODO: add extra initialization before printing } void CExno9View::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/) { // TODO: add cleanup after printing } ///////////////////////////////////////////////////////////////////////////// // CExno9View diagnostics #ifdef _DEBUG void CExno9View::AssertValid() const { CRecordView::AssertValid(); } void CExno9View::Dump(CDumpContext& dc) const { CRecordView::Dump(dc); } CExno9Doc* CExno9View::GetDocument() // non-debug version is inline { ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CExno9Doc))); return (CExno9Doc*)m_pDocument; } #endif //_DEBUG /////////////////////////////////////////////////////////////////////////////

// CExno9View database support CRecordset* CExno9View::OnGetRecordset() { return m_pSet; } ///////////////////////////////////////////////////////////////////////////// // CExno9View message handlers void CExno9View::OnButton1() { m_text1=m_pSet->m_Book_Name; UpdateData(false); m_text2=m_pSet->m_Each_Cost; UpdateData(false); } Output:

Ex.No:10

CREATING DLL

Coding:

// MyClass.cpp: implementation of the CMyClass class. // //////////////////////////////////////////////////////////////////////

#include "stdafx.h" #include "MyDll.h" #include "MyClass.h" #ifdef _DEBUG #undef THIS_FILE static char THIS_FILE[]=__FILE__; #define new DEBUG_NEW #endif ////////////////////////////////////////////////////////////////////// // Construction/Destruction ////////////////////////////////////////////////////////////////////// CMyClass::CMyClass() { } CMyClass::~CMyClass() { } CString CMyClass::SayHello(CString strName) { return "Hello"+ strName; } // MyClass.h: interface for the CMyClass class. // ////////////////////////////////////////////////////////////////////// #if !defined(AFX_MYCLASS_H__46E97A1F_2212_4182_885F_D489C6B0EEC4__INCLUDED_) #define AFX_MYCLASS_H__46E97A1F_2212_4182_885F_D489C6B0EEC4__INCLUDED_

#if _MSC_VER > 1000 #pragma once #endif // _MSC_VER > 1000 class CMyClass { public: _declspec(dllexport)CString SayHello(CString strName); _declspec(dllexport)CMyClass(); _declspec(dllexport)virtual ~CMyClass(); }; #endif // !defined(AFX_MYCLASS_H__46E97A1F_2212_4182_885F_D489C6B0EEC4__INCLUDED_)

// TestDllDlg.cpp : implementation file // #include "stdafx.h" #include "TestDll.h" #include "TestDllDlg.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CAboutDlg dialog used for App About class CAboutDlg : public CDialog {

public: CAboutDlg(); // Dialog Data //{{AFX_DATA(CAboutDlg) enum { IDD = IDD_ABOUTBOX }; //}}AFX_DATA // ClassWizard generated virtual function overrides //{{AFX_VIRTUAL(CAboutDlg) protected: virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support //}}AFX_VIRTUAL // Implementation protected: //{{AFX_MSG(CAboutDlg) //}}AFX_MSG DECLARE_MESSAGE_MAP() }; CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD) { //{{AFX_DATA_INIT(CAboutDlg) //}}AFX_DATA_INIT }

void CAboutDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX);

//{{AFX_DATA_MAP(CAboutDlg) //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CAboutDlg, CDialog) //{{AFX_MSG_MAP(CAboutDlg) // No message handlers //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CTestDllDlg dialog CTestDllDlg::CTestDllDlg(CWnd* pParent /*=NULL*/) : CDialog(CTestDllDlg::IDD, pParent) { //{{AFX_DATA_INIT(CTestDllDlg) m_edit = _T(""); //}}AFX_DATA_INIT // Note that LoadIcon does not require a subsequent DestroyIcon in Win32 m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); } void CTestDllDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CTestDllDlg) DDX_Text(pDX, IDC_NAME, m_edit); //}}AFX_DATA_MAP }

BEGIN_MESSAGE_MAP(CTestDllDlg, CDialog) //{{AFX_MSG_MAP(CTestDllDlg) ON_WM_SYSCOMMAND() ON_WM_PAINT() ON_WM_QUERYDRAGICON() //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CTestDllDlg message handlers BOOL CTestDllDlg::OnInitDialog() { CDialog::OnInitDialog(); // Add "About..." menu item to system menu. // IDM_ABOUTBOX must be in the system command range. ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX); ASSERT(IDM_ABOUTBOX < 0xF000); CMenu* pSysMenu = GetSystemMenu(FALSE); if (pSysMenu != NULL) { CString strAboutMenu; strAboutMenu.LoadString(IDS_ABOUTBOX); if (!strAboutMenu.IsEmpty()) { pSysMenu->AppendMenu(MF_SEPARATOR); pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu); }

} // Set the icon for this dialog. The framework does this automatically // when the application's main window is not a dialog SetIcon(m_hIcon, TRUE);// Set big icon SetIcon(m_hIcon, FALSE);// Set small icon // TODO: Add extra initialization here return TRUE; // return TRUE unless you set the focus to a control } void CTestDllDlg::OnSysCommand(UINT nID, LPARAM lParam) { if ((nID & 0xFFF0) == IDM_ABOUTBOX) { CAboutDlg dlgAbout; dlgAbout.DoModal(); } else { CDialog::OnSysCommand(nID, lParam); } }

// If you add a minimize button to your dialog, you will need the code below // to draw the icon. For MFC applications using the document/view model, // this is automatically done for you by the framework.

void CTestDllDlg::OnPaint()

{ if (IsIconic()) { CPaintDC dc(this); // device context for painting SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0); // Center icon in client rectangle int cxIcon = GetSystemMetrics(SM_CXICON); int cyIcon = GetSystemMetrics(SM_CYICON); CRect rect; GetClientRect(&rect); int x = (rect.Width() - cxIcon + 1) / 2; int y = (rect.Height() - cyIcon + 1) / 2; // Draw the icon dc.DrawIcon(x, y, m_hIcon); } else { CDialog::OnPaint(); } } // The system calls this to obtain the cursor to display while the user drags // the minimized window. HCURSOR CTestDllDlg::OnQueryDragIcon() { return (HCURSOR) m_hIcon; }

void CTestDllDlg::OnOK() { UpdateData(true); CString str=objMyClass.SayHello(m_edit); AfxMessageBox(str); } // TestDllDlg.h : header file // #include "z:\MyDll\MyClass.h" #if !defined(AFX_TESTDLLDLG_H__F91ED0AE_7208_4844_9E0B_A3FCB470A634__INCLUDED_) #define AFX_TESTDLLDLG_H__F91ED0AE_7208_4844_9E0B_A3FCB470A634__INCLUDED_ #if _MSC_VER > 1000 #pragma once #endif // _MSC_VER > 1000 ///////////////////////////////////////////////////////////////////////////// // CTestDllDlg dialog class CTestDllDlg : public CDialog { // Construction public: CMyClass objMyClass; CTestDllDlg(CWnd* pParent = NULL);// standard constructor

// Dialog Data //{{AFX_DATA(CTestDllDlg) enum { IDD = IDD_TESTDLL_DIALOG };

CStringm_edit; //}}AFX_DATA // ClassWizard generated virtual function overrides //{{AFX_VIRTUAL(CTestDllDlg) protected: virtual void DoDataExchange(CDataExchange* pDX);// DDX/DDV support //}}AFX_VIRTUAL // Implementation protected: HICON m_hIcon; // Generated message map functions //{{AFX_MSG(CTestDllDlg) virtual BOOL OnInitDialog(); afx_msg void OnSysCommand(UINT nID, LPARAM lParam); afx_msg void OnPaint(); afx_msg HCURSOR OnQueryDragIcon(); virtual void OnOK(); //}}AFX_MSG DECLARE_MESSAGE_MAP() }; //{{AFX_INSERT_LOCATION}} // Microsoft Visual C++ will insert additional declarations immediately before the previous line. #endif // !defined(AFX_TESTDLLDLG_H__F91ED0AE_7208_4844_9E0B_A3FCB470A634__INCLUDED_) Output:

You might also like