You are on page 1of 80

EX.

NO: DATE: SDK Type Program for Creating Simple Window

AIM:
To write a VC++ program for create a simple window using SDK.

PROCEDURE:
Step1: Start -> New -> Project -> win32 Application ->wndcreation -> Ok. Step2: Again, Goto ->New menu -> Files -> C++ Source File ->Filename as wnd.cpp. Step3: Then, code for create a window by using WindowProcedure function. Step4: And, save the C++ source file with the extension of .cpp Step5: Finally, Build and Run the application. Step6: Stop the execution after getting the necessary outcomes.

Coding:
#include <windows.h> LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM); char szClassName[ ] = "WindowsApp"; int WINAPI WinMain (HINSTANCE hThisInstance, HINSTANCE hPrevInstance,LPSTR pszArgument, int nFunsterStil) { HWND hwnd; MSG messages; WNDCLASSEX wincl; wincl.hInstance = hThisInstance; wincl.lpszClassName = szClassName; wincl.lpfnWndProc = WindowProcedure; wincl.style = CS_DBLCLKS; wincl.cbSize = sizeof (WNDCLASSEX); wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION); wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION); wincl.hCursor = LoadCursor (NULL, IDC_ARROW); wincl.lpszMenuName = NULL; wincl.cbClsExtra = 0; wincl.cbWndExtra = 0; wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND; if (!RegisterClassEx (&wincl))

return 0; hwnd = CreateWindowEx ( 0, szClassName, "Windows App", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 544, 375, HWND_DESKTOP, NULL, hThisInstance, NULL ); ShowWindow (hwnd, nFunsterStil); while (GetMessage (&messages, NULL, 0, 0)) { TranslateMessage(&messages); DispatchMessage(&messages); } return messages.wParam; } LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { switch (message) { case WM_DESTROY: PostQuitMessage (0); break; default: return DefWindowProc (hwnd, message, wParam, lParam); }

Output:

EX.NO: DATE: SDK Type Program for Handling Key Board & Mouse Events

AIM:
To write a VC++ program for handling Mouse and Key Board Events using SDK.

PROCEDURE:
Step1: Start -> New -> Project -> win32 Application -> mkevents -> Ok. Step2: Again, Go to -> New menu -> Files -> C++ Source File ->Filename as mkevents.cpp. Step3: Then, code for create a window by using Window Procedure Function. Step4: And, save the C++ source file with the extension of .cpp Step5: Finally, Build and Run the application. Step6: Stop the execution after getting the necessary outcomes.

Coding:
#include <windows.h> LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM); char szClassName[ ] = "WindowsApp"; int WINAPI WinMain (HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPSTR lpszArgument, int nFunsterStil) { HWND hwnd; MSG messages; WNDCLASSEX wincl; wincl.hInstance = hThisInstance; wincl.lpszClassName = szClassName; wincl.lpfnWndProc = WindowProcedure; wincl.style = CS_DBLCLKS; wincl.cbSize = sizeof (WNDCLASSEX); wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION); wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION); wincl.hCursor = LoadCursor (NULL, IDC_ARROW); wincl.lpszMenuName = NULL; wincl.cbClsExtra = 0; wincl.cbWndExtra = 0; wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND; if (!RegisterClassEx (&wincl))

return 0; hwnd = CreateWindowEx ( 0,szClassName, "Windows App", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT,544, 375, HWND_DESKTOP,NULL, hisInstance, NULL ); ShowWindow (hwnd, nFunsterStil); while (GetMessage (&messages, NULL, 0, 0)) { TranslateMessage(&messages); DispatchMessage(&messages); } return messages.wParam; } LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { switch (message) { case WM_DESTROY: PostQuitMessage (0); break; case WM_LBUTTONDOWN: MessageBox(0,"left button clicked"," mouse event handling",0); case WM_RBUTTONDOWN: MessageBox(0,"right button clicked"," mouse event handling",0); case WM_KEYDOWN:

MessageBox(0,"keyboard key pressed"," keyboard event handling",0); case WM_KEYUP: MessageBox(0,"keyboard key released"," keyboard event handling",0); default: return DefWindowProc (hwnd, message, wParam, lParam); } return 0; }

Output:

EX.NO: DATE: SDK Type Program for using GDI objects (Font)

AIM:
To write a VC++ program for using GDI objects (font).

PROCEDURE:
Step1: Start -> New -> Project -> win32 Application ->gdifont -> Ok. Step2: Again, Goto ->New menu -> Files -> C++ Source File ->Filename as gdifont.cpp. Step3: Then, code for create a window by using WindowProcedure function. Step4: And, save the C++ source file with the extension of .cpp Step5: Finally, Build and Run the application. Step6: Stop the execution after getting the necessary outcomes.

EX.NO: DATE: SDK Type Program for using GDI objects (Brush)

AIM:
To write a VC++ program for using GDI objects(Brush)

PROCEDURE:
Step1: Start -> New -> Project -> win32 Application ->gdifont -> Ok. Step2: Again, Goto ->New menu -> Files -> C++ Source File ->Filename as gdifont.cpp. Step3: Then, code for create a window by using WindowProcedure function. Step4: And, save the C++ source file with the extension of .cpp Step5: Finally, Build and Run the application. Step6: Stop the execution after getting the necessary outcomes

CODING:
#include <windows.h> LRESULT CALLBACK WindProcedure(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam); INT WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { WNDCLASSEX WndCls; static char szAppName[] = "ExoBrush"; MSG Msg; WndCls.cbSize = sizeof(WndCls); WndCls.style = CS_OWNDC | CS_VREDRAW | CS_HREDRAW; WndCls.lpfnWndProc = WindProcedure; WndCls.cbClsExtra = 0; WndCls.cbWndExtra = 0; WndCls.hInstance = hInstance; WndCls.hIcon = LoadIcon(NULL, IDI_APPLICATION); WndCls.hCursor = LoadCursor(NULL, IDC_ARROW); WndCls.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH); WndCls.lpszMenuName = NULL; WndCls.lpszClassName = szAppName; WndCls.hIconSm = LoadIcon(hInstance, IDI_APPLICATION); RegisterClassEx(&WndCls); CreateWindowEx(WS_EX_OVERLAPPEDWINDOW, szAppName, "GDI Brushes Fundamentals", WS_OVERLAPPEDWINDOW | WS_VISIBLE, CW_USEDEFAULT, CW_USEDEFAULT, 420, 220, NULL, NULL, hInstance, NULL); while( GetMessage(&Msg, NULL, 0, 0) ) { TranslateMessage(&Msg); DispatchMessage(&Msg); } return static_cast<int>(Msg.wParam); } LRESULT CALLBACK WindProcedure(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)

{ HDC hDC; PAINTSTRUCT Ps; HBRUSH NewBrush; switch(Msg) { case WM_PAINT: hDC = BeginPaint(hWnd, &Ps); NewBrush = CreateSolidBrush(RGB(250, 25, 5)); SelectObject(hDC, NewBrush); Rectangle(hDC, 20, 20, 250, 125); DeleteObject(NewBrush); EndPaint(hWnd, &Ps); break; case WM_DESTROY: PostQuitMessage(WM_QUIT); break; default: return DefWindowProc(hWnd, Msg, wParam, lParam); } return 0; }

OUTPUT:

EX.NO: DATE:

Dialog Based application using Interest Computation

AIM:
To write a VC++ program for calculating the simple interest by using Dialog based application.

PROCEDURE:
Step1: Start the program and open VC++ application. Step2: Select ->MFC AppWizard(exe) ->Projectname as Interest -> Dialog based application . Step3: Design the dialog by using the controls. Step4: create four Static textboxes, four editboxes and one button for control the calculations. Step5: Assign the member variables for those edit boxes as follows:

Control IDs IDC_EDIT1 IDC_EDIT2 IDC_EDIT3 IDC_EDIT4

Type double double double double

Member m_P m_N m_I m_A

Step6: After that, the button control can be edited as member function as OnButton1() . Step7: Then, code for that button control. Step8: Finally, build the application (F7) and run (ctrl+F5) the application .

CODING:
void CInterestDlg::OnButton1() { UpdateData(TRUE); m_A=m_P*m_N*m_I/100; UpdateData(FALSE); }

OUTPUT:

EX.NO: DATE: AIM:


To write a VC++ program for modal dialog using SDI application.

Creating SDI based Modal Dialog Application

PROCEDURE:
Step1: Start -> VC++ ->New ->MFC(exe) -> project -> modalsdi -> Single Document. Step2:Then, deselect -> Print and Preview option in step4 of 6 -> Finish. Step3: Goto -> ResourceView -> Dialog -> design the dialog using controls. Step4: Then, add one list box, three command buttons for ADD, CLICK ME and CLOSE. Step5: Goto ->Class Wizard(Ctrl+W) ->Create new class as modal -> Ok. Step6: Then, Goto -> FileView -> Header files -> ModalsdiView.h -> add header file. Step 7: Again, Goto -> Class Wizard -> add the member functions for those button controls from the modal class. Step8: Then, invoke the member functions as WM_LBUTTONDOWN and WM_MOUSEMOVE from the ModalsdiView class. Step9: Finally, Build and Run the application.

CODING:

//Goto -> FileView -> Header files -> ModalsdiView.h -> add header file #include "modal.h"

//Class Wizard -> Modal ->Button1() for ADD void modal::OnButton1() { CListBox* pLB=(CListBox*)GetDlgItem(IDC_LIST1); pLB->InsertString(-1," 1 MCA"); pLB->InsertString(-1," 2 MCA"); pLB->InsertString(-1," 3 MCA"); }

//Class Wizard -> Modal ->Button2() for CLICK ME void modal::OnButton2() { MessageBox("hello","mca vp lab",0); }

//Class Wizard -> Modal ->Button3() for CLOSE void modal::OnButton3() { OnCancel();

//FileView -> Source files ->CModalsdiView ->OnLButtonDown() void CModalsdiView::OnLButtonDown(UINT nFlags, CPoint point) { modal obj; int ret =obj.DoModal(); CView::OnLButtonDown(nFlags, point); }

//FileView -> Source files ->CModalsdiView ->OnMouseMove() void CModalsdiView::OnMouseMove(UINT nFlags, CPoint point) { // TODO: Add your message handler code here and/or call default CView::OnMouseMove(nFlags, point); }

OUTPUT:

EX.NO: DATE: Creating MDI based Modal Dialog Application

AIM:
To write a VC++ program for modal dialog using MDI application.

PROCEDURE:
Step1: Start -> VC++ ->New ->MFC(exe) -> project modalmdi -> Multiple Document. Step2:Then, deselect -> Print and Preview option in step4 of 6 -> Finish. Step3: Goto -> ResourceView -> Dialog -> design the dialog using controls. Step4: Then, add one list box, three command buttons for ADD, CLICK ME and CLOSE. Step5: Goto ->Class Wizard(Ctrl+W) ->Create new class as modal -> Ok. Step6: Then, Goto -> FileView -> Header files -> ModalmdiView.h -> add header file. Step 7: Again, Goto -> Class Wizard -> add the member functions for those button controls from the modal class. Step8: Then, invoke the member functions as WM_KEYDOWN and WM_KEYUP from the ModalmdiView class. Step9: Finally, Build and Run the application.

CODING:

//Goto -> FileView -> Header files -> ModalmdiView.h -> add header file #include "modal.h" //Class Wizard -> Modal ->Button1() for ADD void modal::OnButton1() { CListBox* pLB=(CListBox*)GetDlgItem(IDC_LIST1); pLB->InsertString(-1," 1 MCA"); pLB->InsertString(-1," 2 MCA"); pLB->InsertString(-1," 3 MCA"); } //Class Wizard -> Modal ->Button2() for CLICK ME void modal::OnButton2() { MessageBox("hello","mca vp lab",0); } /Class Wizard -> Modal ->Button3() for CLOSE void modal::OnButton3() { OnCancel(); } //FileView -> Source files ->CModalmdiView ->OnKeyDown() void CModalmdiView::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)

{ modal obj; int ret=obj.DoModal(); CView::OnKeyDown(nChar, nRepCnt, nFlags); } //FileView -> Source files ->CModalmdiView ->OnKeyUp() void CModalmdiView::OnKeyUp(UINT nChar, UINT nRepCnt, UINT nFlags) { modal obj; int ret=obj.DoModal(); CView::OnKeyUp(nChar, nRepCnt, nFlags); }

OUTPUT:

EX.NO: DATE: Creating SDI based Modaless Dialog Application

AIM:
To write a VC++ program for modaless dialog using SDI application.

PROCEDURE:
Step1: Start -> VC++ ->New ->MFC(exe) -> project -> mymfc9 -> Single Document. Step2:Then, deselect -> Print and Preview and ActiveX controls -> Finish. Step3: Goto -> ResourceView -> Dialog -> Change the properties for dialog as below: ID -> IDD_DIALOG1 Caption -> Modeless Dialog More Styles -> Visible Step4: Design the dialog using the controls. Static Text control : ID -> IDC_STATIC Caption -> Edit1 Edit Box control : ID -> IDC_EDIT1 Step5: Goto -> ClassWizard -> Create new class with the info as, Name : CMymfc9Dialog File name : CMymfc9Dialog.cpp Base class : CDialog Dialog ID : IDD_DIALOG1

Step6: Then, add the member function for the Ok and Cancel buttons. Step7:Then, add the member variable for the edit text as follows:

Control ID IDC_EDIT1

Type CString

Member m_strEdit1

Step8: Goto -> FileView -> Headerfiles -> Mymfc9Dialog.h -> Add new access specifier as public and private and add member variables for it. Step9: Goto -> FileView -> Headerfiles -> Mymfc9Dialog.h ->define the WM_GOODBYE Message ID. Step10: Goto ->View menu -> Resource symbols -> select -> IDC_EDIT1 -> Ok. Step11: Goto -> FileView -> Sourcefiles -> Mymfc9Dialog.cpp -> code for modeless constructor. Step12: Again,Goto -> FileView -> Sourcefiles -> Mymfc9Dialog.cpp -> code for Create function. Step13: In that also, code for Cancel and Ok buttons. Step14: After that, Goto -> FileView -> Headerfiles -> Mymfc9View.h ->declare private specifier and also add the forward declaration at the top of the page. Step15: Goto -> FileView ->Sourcefiles ->Mymfc9View.cpp -> allocate and deallocate the data member for that class ( Constructor & Destructor functions ). Step16: Then, Goto -> ClassView -> CMymfc9View -> Ondraw() -> code here for display. Step17: Goto -> ClassWizard -> Get the message handler functions as WM_LBUTTONDOWN and WM_RBUTTONDOWN and code for it in mymfc9View.cpp class.

(i.e.,)Goto -> FileView ->Sourcefiles -> mymfc9View.cpp -> code for above messages. Step18: Add the header file in mymfc9View.cpp, which is placed in Sourcefiles as follows: #include "mymfc9Dialog.h" Step19: Add the following line after the BEGIN_MESSAGE_MAP statement but outside the AFX_MSG_MAP brackets in mymfc9View.cpp as follows: ON_MESSAGE(WM_GOODBYE, OnGoodbye) Step20: Also, add the message handler function for OnGoodBye in mymfc9View.cpp class. (i.e.,)Goto -> FileView -> Sourcefile -> mymfc9View.cpp -> Code for it. Step21: Again, Goto -> FileView -> Headerfiles -> mymfc9View.h -> add this line statement, but outside the AFX_ MSG brackets: afx_msg LRESULT OnGoodbye(WPARAM wParam, LPARAM lParam); Step22: Finally, Build (F7 key) and Run (Ctrl+F5 key) the application.

CODING:
//FileView -> Headerfiles -> Mymfc9Dialog.h private: CView* m_pView; public: CMymfc9Dialog(CView* pView); BOOL Create(); // FileView -> Headerfiles -> Mymfc9Dialog.h -> Define message ID #endif // _MSC_VER > 1000 #define WM_GOODBYE WM_USER + 5 // FileView -> Sourcefiles -> Mymfc9Dialog.cpp ->Constructor fn CMymfc9Dialog::CMymfc9Dialog(CWnd* pParent /*=NULL*/) : CDialog(CMymfc9Dialog::IDD, pParent) { //{{AFX_DATA_INIT(CMymfc9Dialog) m_strEdit1 = _T(""); //}}AFX_DATA_INIT m_pView = NULL; } // modeless constructor CMymfc9Dialog::CMymfc9Dialog(CView* pView) { m_pView = pView; }

// FileView -> Sourcefiles -> Mymfc9Dialog.cpp ->Create( ) function BOOL CMymfc9Dialog::Create() { return CDialog::Create(CMymfc9Dialog::IDD); } BOOL CMymfc9Dialog::Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID, CCreateContext* pContext) { //return CDialog::Create(IDD, pParentWnd); return CDialog::Create(CMymfc9Dialog::IDD); } //FileView -> Sourcefiles -> Mymfc9Dialog.cpp ->Code for Cancel and Ok buttons. void CMymfc9Dialog::OnCancel() { if (m_pView != NULL) { // modeless case - do not call base class OnCancel

m_pView->PostMessage(WM_GOODBYE, IDCANCEL); } else { CDialog::OnCancel(); } } void CMymfc9Dialog::OnOK() {

if (m_pView != NULL) { // modeless case -- do not call base class OnOK UpdateData(TRUE); m_pView->PostMessage(WM_GOODBYE, IDOK); } else { CDialog::OnOK(); } } // Goto -> FileView -> Headerfiles -> Mymfc9View.h -> Private specifier private: CMymfc9Dialog* m_pDlg; // Goto -> FileView -> Headerfiles -> Mymfc9View.h -> Forward declaration class CMymfc9Dialog; // FileView ->Sourcefiles ->Mymfc9View.cpp -> Constructor and destructor function CMymfc9View::CMymfc9View() { } CMymfc9View::~CMymfc9View() { delete m_pDlg; } m_pDlg = new CMymfc9Dialog(this);

// ClassView -> CMymfc9View -> Ondraw ( ) void CMymfc9View::OnDraw(CDC* pDC) { CMymfc9Doc* pDoc = GetDocument(); ASSERT_VALID(pDoc); pDC->TextOut(30, 30, "Press the left mouse button here."); } // FileView ->Sourcefiles ->Mymfc9View.cpp ->Code for message handlers void CMymfc9View::OnLButtonDown(UINT nFlags, CPoint point) { // creates the dialog if not created already if (m_pDlg->GetSafeHwnd() == 0) { m_pDlg->Create(); // displays the dialog window } } void CMymfc9View::OnRButtonDown(UINT nFlags, CPoint point) { m_pDlg->DestroyWindow(); // no problem if window was already destroyed }

// FileView -> Sourcefile -> mymfc9View.cpp -> Code for OnGoodBye() LRESULT CMymfc9View::OnGoodbye(WPARAM wParam, LPARAM lParam) { TRACE("CMymfc9View::OnGoodbye %x, %lx\n", wParam, lParam); TRACE("Dialog edit1 contents = %s\n", (const char*) m_pDlg->m_strEdit1); m_pDlg->DestroyWindow(); return 0L; }

OUTPUT:

EX.NO: DATE: Reading and Writing Documents

AIM:
To write a VC++ program for read and write the documents.

PROCEDURE:
Step1: Start the program and open VC++ application. Step2: Select ->MFC AppWizard(exe) ->Project rdwr -> Single Document Application. Step3: Then, Goto -> FileView -> HeaderFiles ->RdwrDoc.h -> Then declare the variable in public mode. Step4: Again, Goto -> FileView -> SourceFiles ->RdwrDoc.cpp ->Serialize() -> add the condition for it. Step5: Goto, ClassView -> CRdwrView ->OnDraw() and code the data for it. Step6: Again, goto -> ClassView ->CRdwrView ->add the message handler ->OnChar() . Step7: Finally, Build (F7) the application, and Run(ctrl + F5) the application. Step8: Stop the program execution.

CODING:

//FileView -> HeaderFiles ->RdwrDoc.h class CRdwrDoc : public CDocument { protected: // create from serialization only CRdwrDoc(); DECLARE_DYNCREATE(CRdwrDoc) // Attributes public: CString strData; }; // FileView -> SourceFiles ->RdwrDoc.cpp void CRdwrDoc::Serialize(CArchive& ar) { if (ar.IsStoring()) { ar<<strData;// TODO: add storing code here } else { ar>>strData; // TODO: add loading code here } }

//ClassView -> CRdwrView ->OnDraw() void CRdwrView::OnDraw(CDC* pDC) { CRdwrDoc* pDoc = GetDocument(); ASSERT_VALID(pDoc); pDC->TextOut(0,0,pDoc->strData);

//ClassView -> CRdwrView ->OnChar() void CRdwrView::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags) { CRdwrDoc* pDoc = GetDocument(); ASSERT_VALID(pDoc); pDoc->strData+=nChar; Invalidate(); pDoc->SetModifiedFlag(); CView::OnChar(nChar, nRepCnt, nFlags); }

OUTPUT:

EX.NO: DATE: Dynamic Controls for Progress,Slider,Tree Control

AIM:
To write a VC++ program for inheriting the CTreeView control.

PROCEDURE:
Step1: Start -> VC++ ->New ->MFC(exe) -> project tree -> Dialog based application. Step2: Goto -> ResourceView -> Dialog -> design the dialog using controls. Step3: Then, pick the controls as slider, progress, tree control from that control box and place it in our dialog box. Step4: Goto -> Class Wizard (Ctrl+W) -> add member variable as follows: Control IDs IDC_SLIDER IDC_EDIT1 IDC_TREE1 IDC_EDIT2 IDC_EDIT3 IDC_EDIT4 IDC_PROGESS1 IDC_PROGRESS2 IDC_PROGRESS3 Type CSliderCtrl CString CTreeCtrl CString CString CString CProgressCtrl CProgressCtrl CProgressCtrl Member m_Slider m_SliderValue m_tree m_ValueHours m_ValueMinutes m_ValueSeconds m_ProgressHours m_ProgressMinutes m_ProgressSeconds

Step5: Again, Goto -> Class Wizard -> Doubleclick ->OnInitDialog() member function.

Step6: And also, add the member function for WM_HSCROLL and WM_TIMER. Step7: Finally, Build(F7 key) and Run(ctrl+F5 key) the application. Step8: Stop the program execution.

CODING:
//Goto -> CTreeDlg ->OnInitDialog() BOOL CTreeDlg::OnInitDialog() { CDialog::OnInitDialog(); HTREEITEM h1=m_tree.InsertItem("PRINCIPAL",TVI_ROOT); HTREEITEM h2=m_tree.InsertItem("HOD",h1,TVI_LAST); HTREEITEM h3=m_tree.InsertItem("AO",h1,TVI_LAST); HTREEITEM h4=m_tree.InsertItem("DEAN",h1,TVI_LAST); HTREEITEM h5=m_tree.InsertItem("STAFF",h2,TVI_LAST); HTREEITEM h6=m_tree.InsertItem("STUDENTS",h5,TVI_LAST); m_Slider.SetRangeMin(1, false); m_Slider.SetRangeMax(100, false); m_SliderValue = "1"; UpdateData(FALSE); m_ProgressHours.SetRange(0, 23); m_ProgressHours.SetStep(1); m_ProgressMinutes.SetRange(0, 59); m_ProgressMinutes.SetStep(1); m_ProgressSeconds.SetRange(0, 59); m_ProgressSeconds.SetStep(1); SetTimer(1, 40, NULL); return TRUE;

// Goto -> CTreeDlg ->OnHScroll() void CTreeDlg::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar) { if(nSBCode == SB_THUMBPOSITION) { m_SliderValue.Format("%ld", nPos); UpdateData(false); } else { CDialog::OnHScroll(nSBCode, nPos, pScrollBar); } CDialog::OnHScroll(nSBCode, nPos, pScrollBar); } // Goto -> CTreeDlg ->WM_TIMER() void CTreeDlg::OnTimer(UINT nIDEvent) { // Get the current time of the computer CTime CurTime = CTime::GetCurrentTime(); // Find the hour, the minute, and the second values of the time int ValHours = CurTime.GetHour(); int ValMinutes = CurTime.GetMinute();

int ValSeconds = CurTime.GetSecond(); // Change each progress bar accordingly m_ProgressHours.SetPos(ValHours); m_ProgressMinutes.SetPos(ValMinutes); m_ProgressSeconds.SetPos(ValSeconds); // Display the position of the progress in the right label m_ValueHours.Format("%d", m_ProgressHours.GetPos()); m_ValueMinutes.Format("%d", m_ProgressMinutes.GetPos()); m_ValueSeconds.Format("%d", m_ProgressSeconds.GetPos()); UpdateData(FALSE); CDialog::OnTimer(nIDEvent); }

OUTPUT:

EX.NO: DATE: Windows common control(CricheditView)

AIM:
To write a VC++ program for CRichEditView controls.

ALGORITHM:
Step1: Start ->open VC++ application ->AppWizard(exe) ->Projectname as RichEdit. Step2: Accept all defaults in MFC AppWizard and goto Step 6 of 6, change the name of your view class as follows: Class name: CExoView Base class: CRichEditView Header file: CExoView.h Implementation file: CExoView.cpp

Step3: Finally, it araises one warning, after reading that click Finish -> Ok Step4: Goto ->Build -> Set Active Configuration.... Double-click RichText - Win32 Release Step5: Goto -> FileView -> Sourcefiles ->ExoView.cpp -. Code for OnInitialUpdate() Step6: Then, Goto -> Resource view->toll bar-> select IDR_MAINFRAME Step7: Then create four controls as Bold, Italic, Underline and Strikeout. For that, Select the Text from the control -> type the font. Goto -> View menu ->Properties(Alt+Enter) -> change the ID &visible. Font B I ID ID_CHARBOLD ID_CHARITALIC

U S

ID_CHARUNDERLINE ID_CHARSTRIKE

Step8: Goto, FileView->Header files-> Exoview.h-> Declare the variables in protected mode. Step9: Again, Goto ->File view->Source files->Exoview.cpp, Initialize the constructor function. Step10: Then, Goto -> Classwizard -> get the member functions for those controls as COMMAND and UPDATE functions. Step11: Then edit the functions and code for it in view class. Step12: Build(F7 key) and Run(Ctrl+F5 key) the application.

CODING:
//FileView -> Sourcefiles ->ExoView.cpp ->OnInitialUpdate() void CExoView::OnInitialUpdate() { CRichEditView::OnInitialUpdate(); CRichEditCtrl& rCtrl = GetRichEditCtrl(); CHARFORMAT cfm;

cfm.cbSize = sizeof(cfm); cfm.dwMask = CFM_SIZE | CFM_ITALIC | CFM_BOLD | CFM_UNDERLINE | CFM_STRIKEOUT | CFM_PROTECTED | CFM_FACE; cfm.dwEffects = 0; cfm.yHeight = 240; strcpy (cfm.szFaceName, "Times New Roman"); rCtrl.SetDefaultCharFormat(cfm); // Set the printing margins (720 twips = 1/2 inch). SetMargins(CRect(720, 720, 720, 720)); }

// Goto, FileView->Header files-> Exoview.h class CExoView : public CRichEditView { protected: // create from serialization only CExoView(); DECLARE_DYNCREATE(CExoView)

BOOL bBold; BOOL bItalic; BOOL bUnderline; BOOL bStrikeout; };

// File view->Source files->Exoview.cpp ->CExoView() CExoView::CExoView() { bBold bItalic = FALSE; = FALSE;

bUnderline = FALSE; bStrikeout } // Totally 8 functions and write coding for each function void CExoView::OnCharbold() { bBold = !bBold; OnCharEffect(CFM_BOLD, CFE_BOLD); } void CExoView::OnUpdateCharbold(CCmdUI* pCmdUI) { pCmdUI->SetCheck(bBold); } void CExoView::OnCharitalic() { = FALSE;

bItalic = !bItalic; OnCharEffect(CFM_ITALIC, CFM_ITALIC); } void CExoView::OnUpdateCharitalic(CCmdUI* pCmdUI) { pCmdUI->SetCheck(bItalic); } void CExoView::OnCharstrike() { bStrikeout = !bStrikeout; OnCharEffect(CFM_STRIKEOUT, CFE_STRIKEOUT); } void CExoView::OnUpdateCharstrike(CCmdUI* pCmdUI) { pCmdUI->SetCheck(bStrikeout); } void CExoView::OnCharunderline() { bUnderline = !bUnderline; OnCharEffect(CFM_UNDERLINE, CFE_UNDERLINE); } void CExoView::OnUpdateCharunderline(CCmdUI* pCmdUI) { pCmdUI->SetCheck(bUnderline); }

OUTPUT:

EX.NO: DATE: Creating Static Splitter Windows using SDI

AIM:
To write a VC++ program for create a static splitter on our created window.

PROCEDURE:
Step 1: Start -> VC++ -> New ->MFC(exe) ->splitsdi -> Single Document Application. Step 2: Then, Goto -> Step4 in MFC Apppwizard -> deselect -> print and preview. Step 3: Again, selct the Advanced option in step4 -> select Window styles ->mark -> Use split window ->Finish . Step 4: Then, Goto -> ClassView -> CSplitsdiView ->OnDraw() Step 5: Finally Build the application(F7 key) and run the application(ctrl+F5 key). Step 6: Stop the process after getting the necessary outcomes.

CODING:
//ClassView -> CSplitsdiView ->OnDraw() void CSplitsdiView::OnDraw(CDC* pDC) { CSplitsdiDoc* pDoc = GetDocument(); pDC->TextOut(100,100,"Splitter Window"); ASSERT_VALID(pDoc); // TODO: add draw code for native data here }

OUTPUT:

EX.NO: DATE: Creating Dynamic Splitter Windows using MDI

AIM:
To write a VC++ program for create a dynamic splitter on our created window.

PROCEDURE:
Step 1: Start -> VC++ -> New ->MFC(exe) ->splitmdi -> Multiple Document Application. Step 2: Then, Goto -> Step4 in MFC Apppwizard -> deselect -> print and preview. Step 3: Again, selct Advanced option in step4 -> select Window styles ->mark the checkbox -> Use split window -> Finish . Step 4: Then, Goto -> ClassView -> CSplitsdiView ->OnDraw() Step 5: Finally Build the application(F7 key) and run the application(ctrl+F5 key). Step 6: Stop the process after getting necessary outcomes.

CODING:
//ClassView -> CSplitsdiView ->OnDraw() void CSplitmdiView::OnDraw(CDC* pDC) { CSplitmdiDoc* pDoc = GetDocument(); pDC->TextOut(100,100,"Splitter Window"); ASSERT_VALID(pDoc); // TODO: add draw code for native data here }

OUTPUT:

EX.NO: DATE: Dynamic Linking Library

AIM:
To write a VC++ program for dynamic linking library for execute the operations by hiding them.

PROCEDURE ( dll ) :
Step1: Open VC++ -> New ->MFC(dll) ->projectname -> dll ->Finish. Step2: Goto -> FileView -> SourceFiles -> dll.cpp -> code at last for export the dll to dllexe. Step3: Then, save and build the application.

PROCEDURE ( dllexe ) :
Step1: Open VC++ -> New ->MFC(exe) ->projectname -> dllexe ->DialogBased. Step2: Goto -> FileView -> SourceFiles -> dllexeDlg.cpp->code at last for import the dll into dllexe. Step3: Goto -> ResourceView -> Dialog -> create a new dialog with the controls. Control ID IDC_EDIT1 IDC_EDIT2 Type double double Member m_v1 m_v2

Step4: Also, Create one button control for add the values, and the button was named as ADD and edit the control in CDllexeDlg class. Step5: Finally, Build (F7) the application, and Run(ctrl + F5) the application. Step6: Stop the program execution.

CODING:
// In dll, Goto -> FileView -> SourceFiles -> dll.h #include resource.h #includemath.h extern "C"__declspec(dllexport)double mysqrt(double d) { return sqrt(d); }

// In dllexe, Goto -> FileView -> SourceFiles -> dllexeDlg.h #includeresource.h #includemath.h extern"C"__declspec(dllimport)double mysqrt(double d);

// In dllexe, Goto -> FileView -> SourceFiles -> dllexeDlg.cpp ->OnButton1()

void CDllexeDlg::OnButton1() { UpdateData(true); m_v2=sqrt(m_v1); UpdateData(false); }

OUTPUT:

EX.NO: DATE: AIM:


To write a VC++ program for developing and controls the Internet Explorer controls. PROCEDURE: Step1: Start -> VC++ ->MFC(exe) ->Project name as ie -> Dialog based application -> Finish. Step2: Design the dialog using the controls and add member variables for those controls. Step3: Goto, ClassWizard -> add member variables as follows:

INTERNET EXPLORER COMMON CONTROLS

Control ID IDC_DATETIMEPICKER1 IDC_DATETIMEPICKER2 IDC_DATETIMEPICKER3 IDC_DATETIMEPICKER4 IDC_IPADDRESS1 IDC_MONTHCALENDAR1 IDC_EDIT1 IDC_EDIT2 IDC_EDIT3 IDC_EDIT4 IDC_EDI IDC_EDIT6 IDC_EDIT7 T5

Data Member m_MonthCal1 m_MonthCal2 m_MonthCal3 m_MonthCal4 m_ptrIPCtrl m_MonthCal5 m_strDate1 m_strDate2 m_strDate3 m_strDate4 m_strDate5 m_strIPValue m_strComboEx1

Type CDateTimeCtrl CDateTimeCtrl CDateTimeCtrl CDateTimeCtrl CIPAddressCtrl CMonthCalCtrl CString CString CString CString CString CString CString

Step4: Then, Goto -> FileView -> SourceFiles -> ieDlg.cpp ->OnInitDialog() for set the IP address. Step5: Again, Goto -> ClassWizard -> Select those controls and edit that follows: Object IDs IDC_DATETIMEPICKER1 IDC_DATETIMEPICKER2 IDC_DATETIMEPICKER3 IDC_DATETIMEPICKER4 IDC_IPADDRESS1 IDC_MONTHCALENDAR1 IDC_COMBOBOXEX1 Messages DTN_DATETIMECHANGE DTN_DATETIMECHANGE DTN_DATETIMECHANGE DTN_DATETIMECHANGE IPN_FIELDCHANGED MCN_SELCHANGE CBN_SELCHANGE

Step6: After that, edit those functions and code for it. Step7: Finally, Build(F7 key) and Run(Ctrl+F5 key) the application.

CODING:
//FileView -> SourceFiles -> ieDlg.cpp ->OnInitDialog() m_ptrIPCtrl.SetAddress(0L); // FileView -> SourceFiles -> ieDlg.cpp -> Code for those controls. void CIeDlg::OnDatetimechangeDatetimepicker1(NMHDR* pNMHDR, LRESULT* pResult) { CTime ct; m_MonthCal1.GetTime(ct); m_strDate1.Format(_T("%02d/%02d/%2d"), ct.GetMonth(),ct.GetDay(),ct.GetYear()); UpdateData(FALSE); *pResult = 0; } void CIeDlg::OnDatetimechangeDatetimepicker2(NMHDR* pNMHDR, LRESULT* pResult) { CTime ct; m_MonthCal2.GetTime(ct); m_strDate2.Format(_T("%02d/%02d/%2d"), ct.GetMonth(),ct.GetDay(),ct.GetYear()); UpdateData(FALSE); *pResult = 0; } void CIeDlg::OnDatetimechangeDatetimepicker3(NMHDR* pNMHDR, LRESULT* pResult) {

CTime ct; int nRetVal = m_MonthCal3.GetTime(ct); if (nRetVal) { m_strDate3 = "NO DATE SPECIFIED!!"; } else { m_strDate3.Format(_T("%02d/%02d/%2d"),ct.GetMonth(), ct.GetDay(),ct.GetYear()); } UpdateData(FALSE); *pResult = 0; } void CIeDlg::OnDatetimechangeDatetimepicker4(NMHDR* pNMHDR, LRESULT* pResult) { CTime ct; m_MonthCal4.GetTime(ct); m_strDate4.Format(_T("%02d:%02d:%2d"), ct.GetHour(), ct.GetMinute(), ct.GetSecond()); UpdateData(FALSE); *pResult = 0; } void CIeDlg::OnSelchangeMonthcalendar1(NMHDR* pNMHDR, LRESULT* pResult) {

CTime ct; m_MonthCal5.GetCurSel(ct); m_strDate5.Format(_T("%02d/%02d/%2d"), ct.GetMonth(),ct.GetDay(),ct.GetYear()); UpdateData(FALSE); *pResult = 0; }

void CIeDlg::OnFieldchangedIpaddress1(NMHDR* pNMHDR, LRESULT* pResult) { DWORD dwIPAddress; m_ptrIPCtrl.GetAddress(dwIPAddress); m_strIPValue.Format("%d.%d.%d.%d %x.%x.%x.%x", HIBYTE(HIWORD(dwIPAddress)), LOBYTE(HIWORD(dwIPAddress)), HIBYTE(LOWORD(dwIPAddress)), LOBYTE(LOWORD(dwIPAddress)), HIBYTE(HIWORD(dwIPAddress)), LOBYTE(HIWORD(dwIPAddress)), HIBYTE(LOWORD(dwIPAddress)), LOBYTE(LOWORD(dwIPAddress))); UpdateData(FALSE); *pResult = 0; } void CIeDlg::OnSelchangeComboboxex1()

{ COMBOBOXEXITEM cbi; CString str ("dummy_string"); CComboBoxEx * pCombo = (CComboBoxEx *)GetDlgItem(IDC_COMBOBOXEX1); int nSel = pCombo->GetCurSel(); cbi.iItem = nSel; cbi.pszText = (LPTSTR)(LPCTSTR)str; cbi.mask = CBEIF_TEXT; cbi.cchTextMax = str.GetLength(); pCombo->GetItem(&cbi); SetDlgItemText(IDC_EDIT7,str); return; }

OUTPUT:

EX.NO: DATE: Data Access through ODBC

AIM:
To develop an application for access the database connectivity through ODBC

PROCEDURE :
Step 1: Start->program->Visual studio->Microsoft Visual C++. Step 2: Select the application with new project name Student Database in MFC Appwizard(exe)and click OK. Step 3: Select the type of the application as Single Document & Document/View Archiecture in step 1. Step 4: Select Database with file support for database support. Step 5: Click the Data source button and select the database name on ODBC from Data source. Step 6: Select Dynaset from Record set type and click OK button. Step 7: Select the table name and click OK. Step 8: Click Finish button and click OK. Step 9: Design the form with necessary fields using Static text, Edit box and Button.

Controls Static Text Static Text Static Text

IDCs IDC_STATIC IDC_STATIC IDC_STATIC Name RollNo Mark1

Caption

Static Text Static Text Static Text Edit Text Edit Text Edit Text Edit Text Edit Text Edit Text Command Button Command Button Command Button Command Button Command Button Command Button Command Button Command Button Command Button

IDC_STATIC IDC_STATIC IDC_STATIC IDC_NAME IDC_ROLLNO IDC_MARK1 IDC_MARK2 IDC_TOTAL IDC_AVG IDC_CALCULATE IDC_ADD IDC_UPDATE IDC_DELETE IDC_EXIT IDC_FIRST IDC_PREVIOUS IDC_LAST IDC_NEXT

Mark2 Total Avg

Calculate Add Update Delete Exit First Previous Last Next

Step 10: Go to the properties and specify the control IDs and caption for the controls.

IDS IDC_SNAME IDC_ROLLNO IDC_MARK1 IDC_MARK2 IDC_TOTAL IDC_AVG

Member Variable Name m_Sname m_rSollno m_Smark1 m_Smark2 m_Stotal M_Savg

Type CString int int int int float

Step 11: Select Class Wizard from view menu, in message maps tab and select the required control IDs and add the required variables by clicking the ADD Variable And click OK Step 12: After that, edit those functions and code for it. Step13 : Finally, Build(F7 key) and Run(Ctrl+F5 key) the application.

Coding:
//FileView -> SourceFiles ->StudentDatabase.cpp void CDataaccessView::OnAdd() { m_pSet->AddNew(); } void CDataaccessView::OnCalculate() { UpdateData(true); m_Stotal=m_Smark1+Smark2; m_Savg=m_Stotal; UpdateData(false); } void CDataaccessView::OnDelete() { m_pSet->Delete(); clear(); m_pSet->MoveFirst(); formtransfer(); } void CDataaccessView::OnExit() { exit(0); } void CDataaccessView::OnFirst() { m_pSet->MoveFirst(); formtransfer(); } void CDataaccessView::OnLast() { m_pSet->MoveLast(); formtransfer();

void CDataaccessView::OnNext() { if(m_pSet->IsEOF()) m_pSet->MoveFirst(); else m_pSet->MoveNext(); formtransfer(); } void CDataaccessView::OnPrevious() { if(m_pSet->IsBOF()) m_pSet->MoveLast(); else m_pSet->MovePrev(); formtransfer(); } void CDataaccessView::clear() { m_Sname=""; m_Srollno=0; m_Smark1=0; m_Smark2=0; m_Stotal=0; m_Savg=0; UpdateData(false); } void CDataaccessView::transfer() { UpdateData(true); m_pSet->m_Sname=m_Sname; m_pSet->m_Srollno=m_Srollno; m_pSet->m_Smark1=m_Smark1;

m_pSet->m_Smark2=m_Smark2; m_pSet->m_Stotal=m_Stotal; m_pSet->m_Savg=m_Savg; } void CDataaccessView::formtransfer() { m_Sname=m_pSet->m_Sname; m_Srollno=m_pSet->m_Srollno; m_Smark1=m_pSet->m_Smark1; m_Smark2=m_pSet->m_Smark2; m_Stotal=m_pSet->m_Stotal; m_Savg=m_pSet->m_Savg; UpdateData(false); } void CDataaccessView::OnUpdate() { transfer(); m_pSet->Update(); m_pSet->MoveLast(); formtransfer(); clear(); }

DATA ACCESS THROUGH ODBC OUTPUT

EX.NO: DATE: ActiveX control Dialog

AIM:
To write a VC++ program for create a calendar using ActiveX controls.

PROCEDURE :
Step 1: Start->Program->Microsoft visual studio->select visual C++. Step 2: Select project type MFC Application Wizard(exe) and project Name: Calender Step 3: Select next option, choose single document. Step 4: Finally press finish button now an empty single document is created. Step 5: Now an empty dialog based application is created and we want to design dialog box for the following ways. Step 6: Click right button of mouse, in side of dialog box and choose insert ActiveXControls. Step 7: Now place the controls and code here. CONTROLS Command Button Command Button Command Button Command Button Command Button Command Button IDS ID_NEXT DAY ID_NEXT WEEK ID_NEXT MONTH ID_NEXT YEAR ID_PREV DAY ID_PREV WEEK CAPTION Next Day Next Week Next Month Next Year Previous Day Previous Week

Command Button Command Button

ID_PREV MONTH ID_NEXT YEAR

Previous Month Previous Year

Step 8: Goto->Classwizard->membervariable->Activexcalender->m_cal Step 8: Finally, Build and Run the application. Step9: Stop the execution after getting the necessary outcomes.

Coding:
//Fileview->SourceFile->Calender.cpp void CActiveView::OnNextday() { UpdateData(true); m_cal.NextDay(); UpdateData(false); } void CActiveView::OnNextweek() { UpdateData(true); m_cal.NextWeek(); UpdateData(false); } void CActiveView::OnNextmonth() { UpdateData(true); m_cal.NextMonth(); UpdateData(false); } void CActiveView::OnNextyear() { UpdateData(true); m_cal.NextYear();

UpdateData(false); } void CActiveView::OnPrevday() { UpdateData(true); m_cal.PreviousDay(); UpdateData(false); } void CActiveView::OnPrevweek() { UpdateData(true); m_cal.PreviousWeek(); UpdateData(false); } void CActiveView::OnPrevmonth() { UpdateData(true); m_cal.PreviousMonth(); UpdateData(false); }

OUTPUT:

You might also like