VP Lab 1-16 Programs
-
Upload
shanmugapriyan-murugesan -
Category
Documents
-
view
224 -
download
0
Transcript of VP Lab 1-16 Programs
-
8/3/2019 VP Lab 1-16 Programs
1/62
EX No: 1 STUDY OF VC++COMPONENTS
AIM
To study the components of visual C++.
COMPONENTS:
Project
A project is a collection of interrelated source files that are compiled and
linked to make up an executable windows based program or a DLL. Source files
for each project are generally stored in a separate subdirectory. A project depends
on many files outside the project subdirectory too, such as include files and library
files.
The Resource Editors
The main window hosts a resource editor appropriate for the resource type.The window can also host a wysiwyg editor for menus and a powerful graphical
editor for dialog boxes. Resources include project-specific items, such as bitmap
(BMP) and icon (ICO) files, and resources common to all visual C++ programs,
such as error message strings. Editing the RC file outside the resource editors is not
recommended.
The C/C++ Compiler
The Visual C++ compiler can process both C source code and C++ source
code. The compiler is complaint with all ANSI standards, including the latestrecommendations of a working group on C++ libraries. Templates, exceptions and
runtime type identification are fully supported in Visual C++ version 6.0,
The Source Code Editor
Visual C++ 6.0 includes a sophisticated source code editor that supports
many features such as dynamic syntax coloring, auto-tabbing, keyboard binding
for a variety of popular editors and pretty printing. In Visual C++ 6.0, an exiting
new feature named AutoComplete has been added. I.e the editor will provide with
list of possible completions to choose from.
The Resource Compiler
-
8/3/2019 VP Lab 1-16 Programs
2/62
The Visual C++ resource compiler reads an ASCII resource script (RC) file
the resource editors and writes a binary RES file for the linker.
The Linker
The linker reads the OBJ and RES files produced by the C/C++ compiler
and the resource compiler and it accesses LIB files for MFC code, runtime library
code and windows code. It then writes the projects EXE file.
The Debugger
The debugger works closely with Visual C++ to ensure that breakpoints are
saved on disk. If you position the cursor on a simple variable the debugger shows
you its value in a little window. To debug a program, you must build the program
with the compiler and linker options set to generate debugging information.
AppWizardAppWizard is a code generator that creates a working skeleton of a windows
application with features, class names, and resource code filenames that you
specify through dialog boxes. AppWizard code is minimalist code; the
functionality is inside the application framework base classes. AppWizard gets you
started quickly with a new application.
ClassWizard
ClassWizard is a program that is accessible from Visual C++ view menu.
ClassWizard takes the drudgery out of maintaining Visual C++ class code.
ClassWizard writes the prototypes, the function bodies and the code to link the
windows message to the function.
RESULT
Thus the Visual C++ components were studied.
Ex. No: 2 SIMPLE WINDOW CREATION
-
8/3/2019 VP Lab 1-16 Programs
3/62
OBJECTIVE:
To create a simple window using Win32 Application.
PROCEDURE:
Step 1: Choose FileNew Project tab.
Step 2: Select Win32 Application and enter Project name.
Step 3: Click OK and then choose an empty project from the dialog
box appears.
Step 4: Click finish button.
Step 5: Choose FileNew File tab.
Step 6: Select C++ source file and enter Source file name.
Step 7: Click OK
Step 8: Type the required coding and Save it.
Step 9: Build and Run the Application.
CODING:
#include
LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE
hPrevInstance,LPSTR
lpCmdLine,int nShowCmd)
{WNDCLASS wc;
HWND hwnd;
MSG Msg;
static TCHAR szAppName[]=TEXT("Simple Window Creation");
wc.style=CS_HREDRAW | CS_VREDRAW;
-
8/3/2019 VP Lab 1-16 Programs
4/62
wc.lpfnWndProc=WndProc;
wc.cbClsExtra=0;
wc.cbWndExtra=0;
wc.hInstance=hInstance;
wc.hIcon=LoadIcon(NULL,IDI_ASTERISK);
wc.hCursor=LoadCursor(NULL,IDC_WAIT);
wc.hbrBackground=(HBRUSH)GetStockObject(GRAY_BRUSH);
wc.lpszMenuName=NULL;
wc.lpszClassName=szAppName;
RegisterClass(&wc);
hwnd = CreateWindow (szAppName,"First window Program,
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,CW_USEDEFAULT,NULL,NULL,
hInstance,NULL);
ShowWindow(hwnd,nShowCmd);
UpdateWindow(hwnd);
while(GetMessage(&Msg,NULL,0,0))
{
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
return Msg.wParam;
}
LRESULT CALLBACK WndProc(HWND hwnd, UINT Message, WPARAM
wParam, LPARAM lParam)
{
switch(Message)
{
case WM_DESTROY:
PostQuitMessage(0);return 0;
}
return DefWindowProc(hwnd,Message,wParam,lParam);
}
-
8/3/2019 VP Lab 1-16 Programs
5/62
SAMPLE OUTPUT:
Viva Questions :
1. What are the parts of windows programming ?
2. List out the member of WNDCLASS structure ?
3. What are the parameters of CreateWindow function ?
4. What is the role of WM_DESTROY ?
5. Name any four APPWIZARD ?
-
8/3/2019 VP Lab 1-16 Programs
6/62
Ex No: 3 A SIMPLE WINDOW WITH DISPLAY MESSAGE
OBJECTIVE:
To create a simple window using Win32 Application.
PROCEDURE:
Step 1: Choose FileNew Project tab.
Step 2: Select Win32 Application and enter Project name.
Step 3: Click OK and then choose an empty project from the dialog box
appears.
Step 4: Click finish button.
Step 5: Choose FileNew File tab.
Step 6: Select C++ source file and enter Source file name.
Step 7: Click OK
Step 8: Type the required coding and Save it.
Step 9: Build and Run the Application.
CODING:
#include
LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);
int WINAPI WinMain(HINSTANCE hi,HINSTANCE hp,LPSTR lp,int n)
{
WNDCLASS wc;
MSG msg;
HWND hw;static TCHAR szApp[]=TEXT("Simple Application");
wc.style=CS_HREDRAW |CS_VREDRAW;
wc.lpfnWndProc =WndProc;
wc.cbClsExtra =0;
wc.cbWndExtra =0;
wc.hInstance =hi;
-
8/3/2019 VP Lab 1-16 Programs
7/62
wc.hCursor =LoadCursor(NULL,IDC_ARROW);
wc.hIcon =LoadIcon(NULL,IDI_APPLICATION);
wc.hbrBackground=(HBRUSH) GetStockObject(WHITE_BRUSH);
wc.lpszMenuName=NULL;
wc.lpszClassName="szApp";
RegisterClass(&wc);
hw=CreateWindow("szApp","CAPTION",WS_OVERLAPPEDWINDOW,CW_U
SEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,N
ULL,NULL,hi,NULL);
ShowWindow(hw,n);
UpdateWindow(hw);
while(GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);DispatchMessage(&msg);
}
return msg.wParam;
}
LRESULT CALLBACK WndProc(HWND hw, UINT msg, WPARAM w, LPARAM
l)
{
switch(msg)
{
case WM_KEYDOWN:
MessageBox(NULL,"Hello","Hai",1);
break;
case WM_KEYUP:
MessageBox(NULL,"Hello","Hai",1);
break;
case WM_LBUTTONDOWN:
MessageBox(NULL,"Hello","Hai",1);
break;
case WM_RBUTTONDOWN:MessageBox(NULL,"Hello","Hai",1);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
}
-
8/3/2019 VP Lab 1-16 Programs
8/62
return DefWindowProc(hw,msg,w,l);
}
SAMPLE OUTPUT:
Viva Questions:
1. What is message Loop?
2. What is window ?
3. Expand hIcon , hInstance ?
4. List out the functions of displaying a window ?
5. What are the parameters of WinMain() ?
-
8/3/2019 VP Lab 1-16 Programs
9/62
Ex. No: 4 A SIMPLE TEXTOUT
OBJECTIVE:
To write a VC++ program to display student details using TextOut
function.
PROCEDURE:
Step 1: Choose FileNew Project tab.
Step 2: Select Win32 Application and enter Project name.
Step 3: Click OK and then choose an empty project from the new dialog
box.
Step 4: Click finish button.
Step 5: Choose FileNew File tab.
Step 6: Select C++ source file and enter Source file name.
Step 7: Click OK
Step 8: Type the coding and Save it.
Step 9: Build and Run the Application.
CODING:
#include
LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);
int WINAPI WinMain(HINSTANCE hi,HINSTANCE hp,LPSTR lp,int n)
{
WNDCLASS wc;
MSG msg;HWND hw;
static TCHAR szApp[]=TEXT("Simple Application");
wc.style=CS_HREDRAW |CS_VREDRAW;
wc.lpfnWndProc =WndProc;
wc.cbClsExtra =0;
wc.cbWndExtra =0;
-
8/3/2019 VP Lab 1-16 Programs
10/62
wc.hInstance =hi;
wc.hCursor =LoadCursor(NULL,IDC_ARROW);
wc.hIcon =LoadIcon(NULL,IDI_APPLICATION);
wc.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);
wc.lpszMenuName=NULL;
wc.lpszClassName="szApp";
RegisterClass(&wc);
hw=CreateWindow("szApp","CAPTION",WS_OVERLAPPEDWINDOW,CW_U
SEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,N
ULL,NULL,hi,NULL);
ShowWindow(hw,n);
UpdateWindow(hw);
while(GetMessage(&msg,NULL,0,0))
{TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
LRESULT CALLBACK WndProc(HWND hw, UINT message, WPARAM wp,
LPARAM lp)
{
static int cxchar,cychar;
HDC hdc;
int i;
PAINTSTRUCT ps;
TEXTMETRIC tm;
static TCHAR szBuf[5]
[20]={"REGNUMBER","60904205031","60904205019","60904205024"};
static TCHAR szName[5][20]={"NAME","savitha","ramya","priya"};
static TCHAR dob[5][20]={"DOB","24-12-1986","21-5-1986","30-11-
1986"};
switch(message){
case WM_CREATE:
hdc=GetDC(hw);
GetTextMetrics(hdc,&tm);
cxchar=tm.tmAveCharWidth;
cychar=tm.tmHeight+tm.tmExternalLeading;
-
8/3/2019 VP Lab 1-16 Programs
11/62
ReleaseDC(hw,hdc);
case WM_PAINT:
hdc=BeginPaint(hw,&ps);
for(i=0;i
-
8/3/2019 VP Lab 1-16 Programs
12/62
SAMPLE OUTPUT:
Viva Questions :
1. State the function name for Loading the cursor and icon ?
2. Mention some window messages ?
3. State any two header files of Window ?
4. Give the syntax of Message Box ?
5. Define Handle ?
Ex. No: 5 SINE WAVE USING LINES AND POLYLINE
-
8/3/2019 VP Lab 1-16 Programs
13/62
OBJECTIVE:
To write a VC++ program to display sine wave using lines and
polyline function.
PROCEDURE:
Step 1: Choose FileNew Project tab.
Step 2: Select Win32 Application and enter Project name.
Step 3: Click OK and then choose an empty project from the new dialog
box.
Step 4: Click finish button.
Step 5: Choose FileNew File tab.
Step 6: Select C++ source file and enter Source file name.
Step 7: Click OK
Step 8: Type the coding and Save it.
Step 9: Build and Run the Application.
CODING:
#include
#include
#define NUM 1000
#define TWOPI (2*3.14159)
LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTRszCmdLine, int iCmdShow)
{
WNDCLASS wc;
MSG msg;
HWND hwnd;
static TCHAR szApp[]=TEXT("Sine Wave");
-
8/3/2019 VP Lab 1-16 Programs
14/62
wc.style=CS_HREDRAW |CS_VREDRAW;
wc.lpfnWndProc =WndProc;
wc.cbClsExtra =0;
wc.cbWndExtra =0;
wc.hInstance =hInstance;
wc.hCursor =LoadCursor(NULL,IDC_ARROW);
wc.hIcon =LoadIcon(NULL,IDI_APPLICATION);
wc.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);
wc.lpszMenuName=NULL;
wc.lpszClassName=szApp;
if(!RegisterClass(&wc))
{
MessageBox(NULL,TEXT("Program requires windows
NT!,szApp,MB_ICONERROR);
return 0;}
hwnd=CreateWindow(szApp, TEXT("SINE WAVE USING POLYLINE"),
WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT,
CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInstance, NULL);
ShowWindow(hwnd,iCmdShow);
UpdateWindow(hwnd);
while(GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM
wParam, LPARAM lParam)
{
static int cxclient,cyclient;
HDC hdc;
int i;PAINTSTRUCT ps;
POINT apt[NUM];
switch(message)
{
case WM_SIZE:
cxclient=LOWORD(lParam);
-
8/3/2019 VP Lab 1-16 Programs
15/62
cyclient=HIWORD(lParam);
return 0;
case WM_PAINT:
hdc=BeginPaint(hwnd,&ps);
MoveToEx(hdc,0,cyclient/2,NULL);
LineTo(hdc,cxclient,cyclient/2);
for(i=0;i
-
8/3/2019 VP Lab 1-16 Programs
16/62
SAMPLE OUTPUT:
Viva Questions :
1. Give the structure of message ?
2. Name the methods to get the device context.
3. What is the use of device handle ?
4. State the use of LineTo () and MoveToEx() ?
5. State the parameter of WndProc()
Ex. No: 6 GDI FUNCTION - LINE DEMO
-
8/3/2019 VP Lab 1-16 Programs
17/62
OBJECTIVE:
To draw the Grid lines in the client area using basic line drawing
function.
PROCEDURE:
Step 1: Choose FileNew Project tab.
Step 2: Select Win32 Application and enter Project name.
Step 3: Click OK and then choose an empty project from the new dialog
box.
Step 4: Click finish button.
Step 5: Choose FileNew File tab.
Step 6: Select C++ source file and enter Source file name.
Step 7: Click OK.
Step 8: Type the required coding and Save it.
Step 9: Build and Run the Application.
CODING:
#include
LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nShowCmd)
{
WNDCLASS wc;HWND hwnd;
MSG Msg;
static TCHAR szAppName[]=TEXT("SIMPLE WINDOW CREATION");
wc.style=CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc=WndProc;
wc.cbClsExtra=0;
-
8/3/2019 VP Lab 1-16 Programs
18/62
wc.cbWndExtra=0;
wc.hInstance=hInstance;
wc.hIcon=LoadIcon(NULL,IDI_ASTERISK);
wc.hCursor=LoadCursor(NULL,IDC_WAIT);
wc.hbrBackground=(HBRUSH)GetStockObject(GRAY_BRUSH);
wc.lpszMenuName=NULL;
wc.lpszClassName=szAppName;
RegisterClass(&wc);
hwnd = CreateWindow (szAppName,"Grid Lines",
WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT,
CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInstance, NULL);
ShowWindow(hwnd,nShowCmd);
UpdateWindow(hwnd);
while(GetMessage(&Msg,NULL,0,0))
{TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
return Msg.wParam;
}
LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM
wParam, LPARAM lParam)
{
PAINTSTRUCT ps ;
HDC hdc;
RECT rect ; int x,y ;
HPEN hpen;
switch(message)
{
case WM_PAINT:
hdc=BeginPaint(hwnd,&ps);
GetClientRect(hwnd,&rect);
hpen=CreatePen(PS_DASHDOTDOT,1,RGB(255,0,255));SelectObject(hdc,hpen);
for(x=0;x
-
8/3/2019 VP Lab 1-16 Programs
19/62
for(y=0;y
-
8/3/2019 VP Lab 1-16 Programs
20/62
Viva Questions :
1. List the different styles of pen ?2. Mention the types of brush ?
3. What are the members of RECT structure ?
4. State the function to create a Pen ?
5. What is the role of DefWndProc() ?
Ex. No: 7 SIMPLE KEYBOARD EVENTS
OBJECTIVE:
To write a VC++ program to demonstrate simple keyboard events.
PROCEDURE:
Step 1: Choose FileNew Project tab.
-
8/3/2019 VP Lab 1-16 Programs
21/62
Step 2: Select Win32 Application and enter Project name.
Step 3: Click OK and then choose an empty project from the new dialog
box.
Step 4: Click finish button.
Step 5: Choose FileNew File tab.
Step 6: Select C++ source file and enter Source file name.
Step 7: Click OK
Step 8: Type your coding and Save it.
Step 9: Build and Run the Application
CODINGS:
#include
#include
LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nShowCmd)
{
WNDCLASS wc;
HWND hwnd;
static TCHAR szAppName[] =TEXT("Simple Window");
MSG msg;
wc.style=CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc=WndProc;
wc.cbClsExtra=0;wc.cbWndExtra=0;
wc.hInstance=hInstance;
wc.hIcon=LoadIcon(NULL,IDI_APPLICATION);
wc.hCursor=LoadCursor(NULL,IDC_CROSS);
wc.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);
wc.lpszClassName=szAppName;
-
8/3/2019 VP Lab 1-16 Programs
22/62
wc.lpszMenuName=NULL;
RegisterClass(&wc);
hwnd=CreateWindow(szAppName, Key Events",
WS_OVERLAPPEDWINDOW, 10,10,400,300, HWND_DESKTOP,
NULL, hInstance, 0 );
ShowWindow(hwnd,nShowCmd);
UpdateWindow(hwnd);
while(GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAMwParam, LPARAM lParam)
{
switch(message)
{
case WM_KEYDOWN:
MessageBox(hwnd,"Key Down Event,
EVENTS",MB_OK);
return 0;
case WM_KEYUP:
MessageBox( hwnd,"Key Up Event","EVENTS",MB_OK);
return 0;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
}
return DefWindowProc(hwnd,message,wParam,lParam);
}
SAMPLE OUTPUT:
-
8/3/2019 VP Lab 1-16 Programs
23/62
Viva Questions :
1. Give some keyboard messages ?
2. Define Menu ?
3. State the various mapping modes ?
4. Mention some child window controls ?
5. Give any four VC++ components ?
Ex. No: 08 MOUSE EVENTS - PIXELS CONNECTING
PROGRAM
OBJECTIVE:
-
8/3/2019 VP Lab 1-16 Programs
24/62
To write a VC++ program to connect no. of pixels using basic mouse
events.
PROCEDURE:
Step 1: Choose FileNew Project tab.
Step 2: Select Win32 Application and enter Project name.
Step 3: Click OK and then choose an empty project from the new dialog
box.
Step 4: Click finish button.
Step 5: Choose FileNew File tab.
Step 6: Select C++ source file and enter Source file name.
Step 7: Click OK
Step 8: Type the required coding and Save it.
Step 9: Build and Run the Application.
CODING:
#include
LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM)
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
PSTR szCmdLine, int iCmdShow)
{
static TCHAR szAppName[] = TEXT ("SARAN") ;
HWND hwnd ;MSG msg ;
WNDCLASS wc ;
wc.style = CS_HREDRAW | CS_VREDRAW ;
wc.lpfnWndProc= WndProc ;
wc.cbClsExtra= 0 ;
wc.cbWndExtra = 0 ;
-
8/3/2019 VP Lab 1-16 Programs
25/62
wc.hInstance= hInstance ;
wc.hIcon = LoadIcon (NULL, IDI_APPLICATION) ;
wc.hCursor= LoadCursor (NULL, IDC_ARROW) ;
wc.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH) ;
wc.lpszMenuName = NULL ;
wc.lpszClassName = szAppName ;
RegisterClass (&wc);
hwnd=CreateWindow(szAppName,TEXT("MouseConnect"),
WS_OVERLAPPEDWINDOW,
100,100,500,300,NULL,NULL,hInstance,NULL) ;
ShowWindow (hwnd, iCmdShow) ;
UpdateWindow (hwnd) ;
while (GetMessage (&msg, NULL, 0, 0))
{
TranslateMessage (&msg);DispatchMessage (&msg);
}
return msg.wParam ;
}
LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM
wParam, LPARAM lParam)
{
static POINT pt[1000] ;
static int iCount ;
HDC hdc ;
int i, j ;
PAINTSTRUCT ps ;
HPEN hpen;
switch (message)
{
case WM_LBUTTONDOWN:
iCount = 0 ;
InvalidateRect (hwnd, NULL, TRUE);return 0 ;
case WM_MOUSEMOVE:
if (wParam & MK_LBUTTON && iCount < 1000)
{
pt[iCount ].x = LOWORD (lParam) ;
pt[iCount++].y = HIWORD (lParam) ;
-
8/3/2019 VP Lab 1-16 Programs
26/62
hdc = GetDC (hwnd) ;
SetPixel (hdc, LOWORD (lParam), HIWORD
(lParam),RGB(255,0,0)) ;
ReleaseDC (hwnd, hdc) ;
}
return 0 ;
case WM_LBUTTONUP:
InvalidateRect (hwnd, NULL, FALSE) ;
return 0 ;
case WM_PAINT:
hdc=GetDC(hwnd);
hdc = BeginPaint (hwnd, &ps) ;
hpen=CreatePen(PS_DOT,1,RGB(255,0,0));
SelectObject(hdc,hpen);
for (i = 0 ; i < iCount - 1 ; i++)for (j = i + 1 ; j < iCount ; j++)
{
MoveToEx (hdc, pt[i].x, pt[i].y, NULL) ;
LineTo (hdc, pt[j].x, pt[j].y) ;
}
DeleteObject(SelectObject(hdc,GetStockObject(BLACK_PEN)));
EndPaint (hwnd, &ps) ;
return 0 ;
case WM_DESTROY:
PostQuitMessage (0) ;
return 0 ;
}
return DefWindowProc (hwnd, message, wParam, lParam) ;
}
SAMPLE OUTPUT:
-
8/3/2019 VP Lab 1-16 Programs
27/62
Viva Questions:
1. Give any four GDI functions ?
2. List out different action done by mouse ?
3. Define GDI ?
4. What is Raster Font ?
5. Define Vector devices ?
-
8/3/2019 VP Lab 1-16 Programs
28/62
Ex. No: 09 MFC APPWIZARD - ELLIPSE DRAWING
OBJECTIVE:
. To Write a VC++ Program Using MFC to toggle the color of the ellipse
between Black & Gray.
PROCEDURE:
Step 1: Run the MFCAppwizard(exe).
Step 2: Select Single Document Application.
Step 3: Add the following Variables as private to the View Class.
int m_nColor.
CRect m_rectEllipse .
Step 4: Use Class Wizard to add Message Handle for
OnLButtondown to the
view Class .Edit The Code of OnLButtondown as
void CColor_EllipseView::OnLButtondown(UINT nFlags,CPoint point)
{
if (m_rectEllipse.ptInRect(point))
{
if(m_nColor ==GRAY_BRUSH)
{
m_nColor = BLACK_BRUSH;
}
else
{m_nColor = GRAY_BRUSH;
}
InvalidateRect(m_rectEllipse);
}
}
-
8/3/2019 VP Lab 1-16 Programs
29/62
Step 5: Edit the Constructor of the View Class to set the initial Value.
CColor_EllipseView::CColor_EllipseView():m_rectEllipse(0,0,200,200)
{
m_nColor = GRAY_BRUSH;
}
Step 6: Edit The OnDraw Member function Of the View Class.
VoidCColor_EllipseView::OnDraw(CDC *pDC)
{pDC->SelectStockObject(m_nColor);
pDC->Ellipse(m_rectEllipse);
}
Step 7: Build and Run the application.
-
8/3/2019 VP Lab 1-16 Programs
30/62
SAMPLE OUTPUT :
Viva Questions :
1. What is the use of Invalidate() function ?
2. Which is the base class for all windows operation ?
3. Explain OnPaint() ?
4. What is OnDraw() ?
5. Differentiate CWindowDC () and CClientDC() ?
Ex. No: 10 DIALOG BASED APPLICATIONS-SIMPLE
ARITHMETIC CALCULATOR
-
8/3/2019 VP Lab 1-16 Programs
31/62
OBJECTIVE:
To develop a dialog based application for performing simple arithmetic
operations.
PROCEDURE:
Step 1: Run the MFCAppwizard(exe).
Step 2: Select the Dialog based application in step1 and accepts the
default values for remaining steps(step 2 to step 6) .
Step 3: Add the following controls using to the dialog using control
palette.
Control Control ID Caption
Edit Box IDC_NUM1 -
Edit Box IDC_NUM2 -
Edit Box IDC_RES -
Static Text IDC_STATIC INPUT A
Static Text IDC_STATIC INPUT B
Static Text IDC_STATIC RESULT
Push Button IDC_CALC CalcPush Button IDC_CLEAR Clear
Radio
Button
IDC_ADD(Set the
Group Property)Addition
Radio
ButtonIDC_SUB Subtraction
Radio
ButtonIDC_MUL Multiplication
Radio
buttonIDC_DIV Division
Step 4: Use Class Wizard to add member variables to the following
Controls.
C Control IDVariable
NameType
-
8/3/2019 VP Lab 1-16 Programs
32/62
IDC_NUM1 m_numa Int
IDC_NUM2 m_numb Int
IDC_NUM3 m_res Int
Step 5: Use Class Wizard to add member functions to thefollowing controls
Control ID Message(Event) Function Name
IDC_RESULT BN_CLICKED OnResult( )
IDC_CLEAR BN_CLICKED OnClear( )
Step 6: Edit OnCalc() function to include the following
void CSimpleCalcDlg::OnCalc()
{
int choice;
m_numa=GetDlgItemInt(IDC_NUM1);
m_numb=GetDlgItemInt(IDC_NUM2);
choice=GetCheckedRadioButton(IDC_ADD,IDC_DIV);
switch(choice)
{
case IDC_ADD: m_res=m_numa+m_numb; break;case IDC_SUB: m_res=m_numa-m_numb; break;
case IDC_MUL: m_res=m_numa*m_numb; break;
case IDC_DIV:
if(m_numb==0)
MessageBox("Divide By Zero Error,
"ERROR",MB_OK+MB_ICONERROR);
else
m_res=m_numa/m_numb;
break;
}UpdateData(false);
}
Step 7: Edit the OnClear() member function to include the following
void CSimpleCalcDlg::OnClear()
-
8/3/2019 VP Lab 1-16 Programs
33/62
{
SetDlgItemInt(IDC_NUM1,0);
SetDlgItemInt(IDC_NUM2,0);
SetDlgItemInt(IDC_RES,0);
}
Step 8: Build and Run the Application.
SAMPLE OUTPUT:
-
8/3/2019 VP Lab 1-16 Programs
34/62
Viva Questions:
1. How does parent and child window communicates ?
2. List some common dialog controls ?
3. Define class wizard ?
4. Differentiate model and modal less dialog control ?
5. Give the syntax of switch case statement ?
-
8/3/2019 VP Lab 1-16 Programs
35/62
Ex No: 11 MFC APPWIZARD-TOOLBAR
OBJECTIVE:
. To Write a VC++ Program Using MFC to display the toolbar.
PROCEDURE:
Step 1: Run the MFCAppwizard(exe).
Step 2: Select Single Document Application.
Step 3: use the resource editor to edit the applications main menu
MENU CAPTION COMMAND ID
Draw Circle ID_DRAW_CIRCLEDraw Square ID_DRAW_SQUARE
Draw Pattern ID_DRAW_PATTERN
Step 4: use the resorce editor to update the applications toolbar.
Step 5: using class wizard view the message handlers:
OBJECT ID MESSAGEMEMBER
FUNCTIONSID_DRAW_CIRCLE COMMAND OnDrawCircle
ID_DRAW_CIRCLE UPDATE_COMMAND_UI OnUpdateDrawCircle
ID_DRAW_PATTERN COMMAND OnDrawPattern
ID_DRAW_PATTERN UPDATE_COMMAND_UI OnUpdateDrawPattern
ID_DRAW_SQUARE COMMAND OnDrawSquare
ID_DRAW_SQUARE UPDATE_COMMAND_UI OnUpdateDrawSquare
Step 6: Add the three data members to the CTool view class:
Private:
CRect m_rect;
BOOL m_bCircle
BOOL m_bPattern;
Step 7: Edit the Constructor of the View Class to set the initial Value.
-
8/3/2019 VP Lab 1-16 Programs
36/62
CToolbarView::CToolbarView():m_rect(0,0,100,100)
{
m_bCircle=TRUE;
m_bPattern=FALSE;
}
Step 8: Edit The OnDraw Member function Of the View Class.
void CToolbarView::OnDraw(CDC* pDC)
{
CBrush brush(HS_BDIAGONAL,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->1SelectStockObject(WHITE_BRUSH);
}
Step 9: Add the coding for the message handler functions
void CToolbarView::OnDrawCircle()
{
m_bCircle=TRUE;
m_rect += CPoint(25,25);
InvalidateRect(m_rect);
-
8/3/2019 VP Lab 1-16 Programs
37/62
}
void CToolbarView::OnUpdateDrawCircle(CCmdUI* pCmdUI)
{
pCmdUI->Enable(!m_bCircle);
}
void CToolbarView::OnDrawSquare()
{
m_bCircle=FALSE;
m_rect += CPoint(25,25);
InvalidateRect(m_rect);}
void CToolbarView::OnUpdateDrawSquare(CCmdUI* pCmdUI)
{
pCmdUI->Enable(m_bCircle);
}
void CToolbarView::OnDrawPattern()
{
m_bPattern ^=1;
}
void CToolbarView::OnUpdateDrawPattern(CCmdUI* pCmdUI)
{
pCmdUI->SetCheck (m_bPattern);
}
Step 10: Build and Run the Application.
-
8/3/2019 VP Lab 1-16 Programs
38/62
SAMPLE OUTPUT:
Viva Questions :
1. What is toolbar ?
2. List the various styles of toolbar state ?
3. How to load the toolbar manually ?
4. Mention the classes generated by AppWizard ?
5. What is the use of pCmdUI ?
-
8/3/2019 VP Lab 1-16 Programs
39/62
Ex No: 12 MFC APPWIZARD-STATUSBAR
OBJECTIVE:
. To Write a VC++ Program Using MFC to display the statusbar.
PROCEDURE:
Step 1: Run the MFCAppwizard(exe).
Step 2: Select Single Document Application.
Step 3: Use the string editor to edit the applications string table
resource.
String ID String Caption
ID_INDICATOR_LEFT LEFTID_INDICATOR_RIGHT RIGHT
Step 4: Use Visual c++ to edit the applications symbols.
Choose Resource symbols from the View menu.Add the new
status bar identifier,ID_MY_STATUSBAR,and
accept the default value.
Step 5: Use Classwizard to add view menu command handlers in the
class CMainFrame.Object ID Message Member Function
ID_VIEW_STATUS_BAR COMMAND OnViewStatusBar
ID_VIEW_STATUS_BAR UPDATE_COMMAND_UI OnUpdateViewStatusBar
Step 6: Add the following function prototypes to MainFrm.h.
afx_msg void OnUpdateLeft(CCmdUI * pCmdUI);
afx_msg void OnUpdateRight(CCmdUI * pCmdUI);
Step 7: Edit the MainFrm.cpp file
Static UINT indicator[]=
{
ID_SEPARATOR,
-
8/3/2019 VP Lab 1-16 Programs
40/62
-
8/3/2019 VP Lab 1-16 Programs
41/62
Step 10:Edit the following View menu functions that class wizard originally
generated in MainFrame.cpp.void CMainFrame::OnViewStatusBar(){
m_wndStatusBar.ShowWindow((m_wndStatusBar.GetStyle()&WS_VISIBLE)==0);
RecalcLayout();
}
void CMainFrame::OnUpdateViewStatusBar(CCmdUI* pCmdUI)
{
pCmdUI->SetCheck((m_wndStatusBar.GetStyle() & WS_VISIBLE) !=0);
}
Step 11: Edit the OnDraw function in Ex14bview.cpp.
void Ex14bview::OnDraw(CDC *pDC)
{
pDC->TextOut(0,0,Watch the status bar while you move and click
the mouse:);
}
Step 12:Build and Run the application.
-
8/3/2019 VP Lab 1-16 Programs
42/62
SAMPLE OUTPUT :
Viva Questions :
1. What is status bar ?
2. What is the use of ID_SEPARATOR ?
3. What is the base class for status bar ?
4. What are the types of text panes ?5. How to add new status bar ?
-
8/3/2019 VP Lab 1-16 Programs
43/62
Ex. No: 13 CREATION OF MENU, TOOLBAR BUTTONS,
ACCELERATORS & TOOLTIP
OBJECTIVE:
To write a VC++ program to illustrate the creation and working of
menu, tools, accelerator and tool tip
PROCEDURE:
Step1: Run the MFCAppWizard(exe) and select SDI application.
Step2: Add the menu items as per shown in below using the menu resource editor.
Main Menu: Graphics Line(Popup Menu)
Horizontal Line
Vertical Line
Ellipse
Circle
RoundRect
Rectangle
Main Menu: Color
Brush Color
Pen Color
Step3: Using Properties Dialog assign the ID for all the sub menu items as
Menu
Caption
Menu ID Prompt
Horizontal
Line
ID_GRAPH_HORZLINE Horizontal Line\n
HorzLine
Vertical
Line
ID_GRAPH_VERLINE
Draws Vertical lineEllipse ID_GRAPH_ELLIPSE Draws Ellipse\n Ellipse
Tool
Circle ID_GRAPH_CIRCLE This is circle menu
RoundRect ID_GRAPH_ROUNDRECT Displays Round
Rectangle
Rectangle ID_GRAPH_RECT This is rectangle
-
8/3/2019 VP Lab 1-16 Programs
44/62
Brush Color ID_COLOR_BRUSH Selects Brush Color
Pen Color ID_COLOR_PEN Selects Pen Color
NOTE: The Prompt strings are displayed at status bar whenever user points the
menu
item. The string after the \n(new line char) is shown as tool tip when the
user
points the corresponding tool.
Step 4: Declare the enumerated data type named as Graphics in the __view.cpp
file.
enum Graphics{LINE,VERLINE,HORILINE, CIRCLE,
RECTANGLE, ROUNDRECT,ELLIPSE};
Step 5: Add the member variable for enumerated data type Graphics named asshape in
View class.
enum Graphics shape;
Step 6: Add the following member variables for storing pen and brush color type
to the
View class.
private:
COLORREF PenColor;
COLORREF BrushColor;
Step 7: Using Class wizard add the COMMAND Event handlers to all the sub
menu
items.
void CMenucolorView::OnGraphEllipse()
{
shape=ELLIPSE;
Invalidate();
}
void CMenucolorView::OnGraphHorzline(){
shape=HORILINE;
Invalidate ();
}
void CMenucolorView::OnGraphRectangle()
{
-
8/3/2019 VP Lab 1-16 Programs
45/62
shape=RECTANGLE;
Invalidate();
}
void CMenucolorView::OnGraphRoundRect()
{
shape=ROUNDRECT;
Invalidate();
}
void CMenucolorView::OnGraphCircle()
{
shape=CIRCLE;
Invalidate();
}
void CMenucolorView::OnGraphVerline()
{shape=VERLINE;
Invalidate();
}
void CMenucolorView::OnColorBrush()
{
CColorDialog c;
if(c.DoModal()==1)
{
Brushcolor=c.GetColor();
Invalidate();
}
}
void CMenucolorView::OnColorPen()
{
CColorDialog c;
if(c.DoModal()==1)
m_ncolor=c.GetColor();Invalidate();
}
Step 9: Edit the OnDraw() function of the View Class to draw the various shapes.
void CMenucolorView::OnDraw(CDC* pDC)
{
-
8/3/2019 VP Lab 1-16 Programs
46/62
CPen pen;
pDC->SelectObject(new CBrush(m_ncolor1));
pen.CreatePen(PS_SOLID,2,m_ncolor);
pDC->SelectObject(&pen);
switch(shape)
{
case ELLIPSE:
pDC->Ellipse(10,10,200,150);
break;
case CIRCLE:
pDC->Ellipse(10,10,200,200);
break;
case RECTANGLE:
pDC->Rectangle(10,10,200,150);
break;case VERLINE:
pDC->MoveTo(10,10);
pDC->LineTo(10,100);
break;
case HORILINE:
pDC->MoveTo(10,10);
pDC->LineTo(100,10);
break;
case ROUNDRECT:
pDC->RoundRect(10,10,200,150,25,25);
break;
}
}
Step10: Creation of toolbar buttons for the menu items
Select Resource View Pane from the workspace window.
Select Toolbar folder & Double click IDR_MAINFRAME. It Opens tool
editor. Click the blank tool button and design the tool icon using the bitmap
shown.
Double Click the tool button to open the property box. In that select the
menu id to which you want to assign the tool.
-
8/3/2019 VP Lab 1-16 Programs
47/62
Step11: Creation of Accelerator keys for sub menu items
Select Resource View Pane from the workspace window.
Select Accelerator folder & Double click IDR_MAINFRAME. It shows
accelerator list. In which select blank entry and double click it add newone.
In the appeared Accel Properties do the following
o Select the Modifiers( ie Ctrl | Alt)
o Enter the char in the key text box.( ie if you want Ctrl+W as a
Accel, select Ctrl Modifier and type W in the key text box.
o Select the menu ID to which you want to assign a accelerator key
from the ID combo box.
Step12: Build and Run the application.
SAMPLE OUTPUT:
-
8/3/2019 VP Lab 1-16 Programs
48/62
Viva Questions :
1. Define Menu ?
2. What is popup menu ?
3. What is tooltip ?4. Define accelerator ?
5. What is the use of CDC ?
-
8/3/2019 VP Lab 1-16 Programs
49/62
Ex. No: 14 DLL CREATION FOR ADDITION AND
SUBTRACTION
OBJECTIVE:
To Write a VC++ Program to create the Regular DLL for addition and
subtraction of two numbers.
PROCEDURE:
DLL CREATION
Step 1: Choose File-> New->Project tab and select MFC AppWizard(Dll).
Step 2: Enter the DLL name and press the ok button.
Step 3: Select the option Regular DLL using Shared MFCDLL from the
MFCAppWizard(exe) dialog box appears.
Step 4: Click finish button.
Step 5: Write the export function declaration in the dll header file
__declspec(dllexport) int WINAPI Add(int a,int b);
__declspec(dllexport) int WINAPI Sub(int a,int b);
Step 6: Include the definition of export functions in the corresponding dll
Implementation(.cpp) file
__declspec (dllexport) int WINAPI Add (int a, int b)
{
return (a+b);}
__declspec (dllexport) int WINAPI Sub (int a, int b)
{
return (a-b);
}
-
8/3/2019 VP Lab 1-16 Programs
50/62
Step 7: Build the application to create the *.dll program.
CLIENT PROGRAM
Step 1: Run the MFC AppWizard (exe) and select the dialog based
application.
Step 2: Include the import function declaration in the dialog header file.
__declspec(dllimport)int WINAPI Add(int a,int b);
__declspec(dllimport)int WINAPI Sub(int a,int b);
Step 3: Add the dll header file in the dlg.cpp file with the full path name.
#include "D:\AddSub_Dll\AddSub_Dll.h"
Step 4: Add the required controls.
Control
Type
Control ID Caption Member
Variable
Event
Handler
Edit Box IDC_NUM1 m_NumA -
Edit Box IDC_NUM2 m_NumB -
Static IDC_STATIC1 Number
A
- -
Static IDC_STATIC2 Number B - -
Static IDC_STATIC3 A + B - -Static IDC_STATIC4 A - B - -
Edit Box IDC_ADDRES - m_addRes -
Edit Box IDC_SUBRES - m_subRes -
Push Button IDC_BUT_ADD Press Me - BN_CLICKED
-
8/3/2019 VP Lab 1-16 Programs
51/62
Step 5: Make the call to the import function in button control event handler
function.
void CAddSubClientDlg::OnButAdd()
{
UpdateData(true);
m_addRes=Add(m_NumA, m_NumB);
m_subRes=Sub(m_NumA, m_NumB);
UpdateData(false);
}
Step 6: Include the Dll library file using project setting option.
"D:\AddSub_Dll\AddSub_Dll\Debug\AddSub_Dll.lib"
Step 7: Copy the newly created *.dll (AddSub_Dll.dll) file in the window
system directory or debug folder of client program.
Step 8: Build and run the application program.
SAMPLE OUTPUT:
-
8/3/2019 VP Lab 1-16 Programs
52/62
Viva Questions :
1. What is DLL ?
2. What are the advantages of DLL ?
3. Mention drawbacks of DLL ?
4. What is the use of LoadLibrary () ?
Ex. No: 15 DLL CREATION FOR SQUAREROOT AND
FACTORIAL
OBJECTIVE:To Write a VC++ Program to compute the factorial and square root of a
given number using Regular DLL.
PROCEDURE:
DLL CREATION
Step 1: Choose File-> New->Project tab and select MFC AppWzard(Dll).
Step 2: Enter the DLL name and press the ok button.
Step 3: Select the option Regular DLL using Shared MFCDLL from the
MFCAppWizard (exe) dialog box appears.
Step 4: Click finish button.
Step 5: Write the export function declaration in the dll header file
__declspec (dllexport) double SquareRoot (double a);
__declspec (dllexport) long Factorial (int a);
Step 6: Include the definition of export functions in the corresponding dll
-
8/3/2019 VP Lab 1-16 Programs
53/62
implementation (.cpp) file
__declspec(dllexport)double SquareRoot(double a)
{
if(a
-
8/3/2019 VP Lab 1-16 Programs
54/62
CLIENT PROGRAM
Step 1: Run the MFC AppWizard (exe) and select the dialog based
application.
Step 2: Include the import function declaration in the dialog header file.
__declspec (dllimport) double SquareRoot (double a);
__declspec (dllimport) long Factorial (int a);
Step 3: Add the dll header file in the dlg.cpp file with the full path name.
"D:\FactSqrt_Dll\FactSqrt_Dll.h"
Step 4: Add the required controls.
Control
Type
Control ID Caption Member
Variable
Event
Handler
Edit Box IDC_INPUT - m_Input -
Edit Box IDC_FACT - m_FactOut -
Edit Box IDC_SQRT - m_SqrtOut -
Static IDC_STATIC1 Input - -Static IDC_STATIC2 Factorial - -
Static IDC_STATIC3 SquareRoot - -
Push Button IDC_CALC Calc - BN_CLICKED
Step 5: Make the call to the import function in Button control event handler
function.
void CFactSqrtClientDlg::OnClick()
{
UpdateData(true);
m_SqrtOut=SquareRoot((double)m_Input);
m_FactOut=Factorial(m_Input);
UpdateData(false);
-
8/3/2019 VP Lab 1-16 Programs
55/62
}
Step 6: Include the Dll lib file using project setting option.
D:\FactSqrt_Dll\Debug\FactSqrt_Dll.lib
Step 7: Save the newly created .dll (AddSub_Dll.dll) file in the window
system
directory or debug folder of client program.
Step 8: Build and run the application program.
SAMPLE OUTPUT:
Viva Questions :
1. What is the use of DllMain() ?
2. What is the finction used to export the dll ?
3. What do you mean by resource dll ?
4. Define regular mfc dll ?
-
8/3/2019 VP Lab 1-16 Programs
56/62
Ex. No: 16 ODBC CONNECTIVITY EMPLOYEE DETAILS
OBJECTIVE:
To write a VC++ program to demonstrate the working of ODBC
Connectivity for a DBMS.
PROCEDURE:
Step 1: Create the following table underMicrosot Access(stud1.mdb)
Field Name Data Type
regno Number
Name Text
Mark1 Number
Mark2 Number
total Number
Step 2: Create the new ODBC Connection.
Start->Settings->Control Panel->Admiistrative Tools -> Data
Sources[ODBC]
Choose User DSN Tab from the appeared ODBC Data Source
Administrator.
Click Add Button->Select Microsoft Access driver(*.mdb) from Create
New Data Source Dialog Box.
Enter the Data Source Name and Description in ODBCD Microsoft Access
Setup Dialog Box and assign the newly created database(EmpInfo.mdb) to
the ODBC using Select Button ->Click OK Button
Step 3: Creation of Front End of Application. In VC++ Environment
-
8/3/2019 VP Lab 1-16 Programs
57/62
Choose File Menu->New->MFCAppwizard(exe)->Enter Project Name.
In Step1 of MFC Appwizard Dialog ,select Single Document
In Step2 : Select the Database view without file support and Select thedatasource and table created under MS-Access using Datasource
Button.
Select Dynaset Option from the Record Set
Click Finish Button.
Step 4: Add the following controls to access the record field values.
Control
Type
Caption
Static Text regno
Static Text name
Static Text Mark1
Static Text
Static text
Mark2
total
Step 5: Using Class Wizard assign the record field names as member variable tofollowing controls.
Control ID Member Variable Data Type
IDC_regno ->m_regno long
IDC_NAME ->m_name CString
Control
Type
Control ID
Edit Box IDC_REGNO
Edit Box IDC_NAME
EditBox IDC_mark1
Edit Box IDC_mark2
Edit Box IDC_total
Control
Type
Control ID
Push Button IDC_ADDNEW
Push Button IDC_UPDATE
Push Button IDC_DELETE
Push Button IDC_CALC
Push Button IDC_EXIT
-
8/3/2019 VP Lab 1-16 Programs
58/62
IDC_MARK1 ->m_mark1 long
IDC_MARK2 ->m_mark2 Long
IDC_TOTAL ->m_total long
Step 6: Using Class Wizard add the Button Click (BN_CLICKED) Event Handler
member function to the following controls( to the View class).
void CStudView::OnAddnew()
{
SetDlgItemInt(IDC_REGNO,0);
SetDlgItemText(IDC_NAME,"");
SetDlgItemInt(IDC_MARK1,0);
SetDlgItemInt(IDC_MARK2,0);
SetDlgItemInt(IDC_TOTAL,0);
}
void CStudView::OnCalculate()
{
UpdateData(true);
m_pSet->m_total=m_pSet->m_mark1+m_pSet->m_mark2;
UpdateData(false);
}
void CStudView::OnDelete()
{
int f;
try
{
f=MessageBox("R U SURE","Delete",MB_OKCANCEL);
if(f=IDOK)
{
m_pSet->Delete();
MessageBox("Records Deleted");}
}
catch(CDBException *e)
{
MessageBox(e->m_strError);
e->Delete();
-
8/3/2019 VP Lab 1-16 Programs
59/62
}
m_pSet->MoveNext();
UpdateData(false);
}
void CStudView::OnEdit()
{
m_pSet->Edit();
UpdateData(true);
if(m_pSet->CanUpdate())
{
m_pSet->Update();
MessageBox("Records Added");
}}
void CStudView::OnUpdate()
{
m_pSet->AddNew();
UpdateData(true);
if(m_pSet->CanUpdate())
{
m_pSet->Update();
MessageBox("Record updated");
}
if(!m_pSet->IsEOF())
m_pSet->MoveLast();
UpdateData(false);
}
SAMPLE OUTPUT:
-
8/3/2019 VP Lab 1-16 Programs
60/62
-
8/3/2019 VP Lab 1-16 Programs
61/62
-
8/3/2019 VP Lab 1-16 Programs
62/62
Viva Questions :
1. Define ODBC ?
2. List the three main classes provided by MFC for database ?
3. What is the use of CRecordView class ?
4. Differentiate Snapshot and Dynaset ?
5. What should be done to refresh a record set ?