Bible Verses

Wednesday, November 25, 2009

VISUAL PROGRAMMING LAB MANUAL

Ex. No: 1 DISPLAY SIMPLE SDK WINDOW

AIM:
To write a program to display a simple SDK window.

ALGORITHM:

1. Open Microsoft VC++.
2. Select new from the file menu and click the project tab.
3. Select win32 application.
4. In the project name field type the name of the project.
5. Create a new workspace and select win32 and click empty project and then
Press finish button.
6. Select new from file menu, again click c++ source file
7. Type the program.

PROGRAM:

#include
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(WHITE_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","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)
{
return DefWindowProc(hw,ms,w,l);
}





Ex. No: 2 KEYBOARD AND MOUSE EVENTS

AIM:
To write a program to display keyboard and mouse events.

ALGORITHM:

1. Open Microsoft VC++.
2. Select new from the file menu and click the project tab.
3. Select win32 application.
4. In the project name field type the name of the project.
5. Create a new workspace and select win32 and click empty project and then
Press finish button.
6. Select new from file menu, again click c++ source file
7. Type the program.

PROGRAM:

#include
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)
{
case 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,40,TEXT("LEFT BUTTON RELEASED"),25);
ReleaseDC(hw,hdc);
return 0;
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);
}



Ex. No:3 BASIC DRAWING FUNCTIONS

AIM:
To write a program to display keyboard and mouse events.

ALGORITHM:

1. Open Microsoft VC++.
2. Select new from the file menu and click the project tab.
3. Select win32 application.
4. In the project name field type the name of the project.
5. Create a new workspace and select win32 and click empty project and then
Press finish button.
6. Select new from file menu, again click c++ source file
7. Type the program.

PROGRAM:

#include
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(WHITE_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","FIRST WINDOW", WS_OVERLAPPEDWINDOW, 0, 0, 300, 300,NULL,NULL,h,NULL);
ShowWindow(hw,in);
UpdateWindow(hw);
while(GetMessage(&ms,NULL,0,0))
{
TranslateMessage(&ms);
DispatchMessage(&ms);
}
return ms.wParam;
}
LRESULT CALLBACK WndProc(HWND hw,UINT ms,WPARAM w,LPARAM l)
{
PAINTSTRUCT Ps;
HDC hdc;
static int x1,x2,y1,y2;
switch(ms)
{
case WM_SIZE:
x1=LOWORD(l);
x2=HIWORD(l);
return 0;
case WM_PAINT:
hdc=BeginPaint(hw,&Ps);
Rectangle(hdc,7*x1/8,7*x2/8,7*x1/8,7*x2/8);
MoveToEx(hdc,0,0,NULL);
LineTo(hdc,x1,x2);
MoveToEx(hdc,0,x2,NULL);
LineTo(hdc,x1,0);
Ellipse(hdc,x1/8,x2/8,7*x1/8,7*x2/8);
RoundRect(hdc,x1/4,x2/4,3*x1/4,3*x2/4,x1/4,x2/4);
EndPaint(hw,&Ps);
return 0;
case WM_LBUTTONDOWN:
x1=LOWORD(l);
x2=HIWORD(l);
hdc=GetDC(hw);
TextOut(hdc,x1,x2,"KCG College of Technology",25);
ReleaseDC(hw,hdc);
break;
}
return DefWindowProc(hw,ms,w,l);
}



Ex. No:4 DIALOG BASED APPLICATION USING SDK

AIM:
To write a program for a dialog base application using SDK.

ALGORITHM:

1. Open Microsoft VC++.
2. Select new from the file menu and click the project tab.
3. Select win32 application.
4. In the project name field type the name of the project.
5. Create a new workspace and type the program.
6. After typing, select resource from insert menu and select dialog box.
7. Construct the required box.
8. Choose the approximate class for application program.
9. Execute the program.

PROGRAM:

#include
#include"resource.h"
LRESULT CALLBACK DlgProc(HWND hw,UINT ms,WPARAM w,LPARAM
l);
INT APIENTRY WinMain(HINSTANCE h,HINSTANCE hp,LPSTR lps,int in)
{
DialogBox(h,MAKEINTRESOURCE(IDD_DIALOG1),NULL,(DLGPROC)DlgProc);
return 0;
}
LRESULT CALLBACK DlgProc(HWND hw,UINT ms,WPARAM w,LPARAM l)
{
static int inc;
static BOOL B;
switch(ms)
{
case WM_CREATE:
inc=0;
break;
case WM_CLOSE:
EndDialog(hw,0);
break;
case WM_INITDIALOG:
SetDlgItemInt(hw,IDC_EDIT1,0,TRUE);
SendMessage(GetDlgItem(hw,IDC_RONE),BM_SETCHECK,TRUE,0);
inc=1;
break;
case WM_COMMAND:
switch(LOWORD(w))
{
case IDOK:
EndDialog(hw,TRUE);
break;
case IDCANCEL:
EndDialog(hw,FALSE);
break;
case IDC_ADD:
ms=GetDlgItemInt(hw,IDC_EDIT1,&B,TRUE);
ms+=inc;
SetDlgItemInt(hw,IDC_EDIT1,ms,TRUE);
break;

case IDC_SUB:
ms=GetDlgItemInt(hw,IDC_EDIT1,&B,TRUE);
ms-=inc;
SetDlgItemInt(hw,IDC_EDIT1,ms,TRUE);
break;

case IDC_RONE:
inc=1;
break;
case IDC_RTWO:
inc=2;
break;
case IDC_RFOUR:
inc=4;
break;
case IDC_REIGHT:
inc=8;
break;
}
break;
}
return 0;
}



Ex. No:5 DIALOG BASED APPLICATION USING VC++

AIM:
To write a vc++ program to create a dialog based application.

ALGORITHM:

1. Select MFC AppWizard(exe).
2. Select dialog based application.
3. Accept all default settings.
4. Design the calculator.
5. Use dialog editor assign as

CONTROL ID

EDIT1 IDC_FIRST
EDIT2 IDC_SECOND
EDIT3 IDC_RESULT
RADIO BUTTON IDC_OPERATION
COMMAND BUTTON IDC_COMPUTE


6. Open dialog box properties.

CLICKS-STYLE TAB
SELECT-SYSTEM MENU
-MINIMIZE BOX
7. Use class wizard to add member variables and command handler (in view).
8. Add data member as follows:

CONTROL ID MEMBERVARIABLE TYPE
IDC_LEFT m_dfirst double
IDC_RIGHT m_dsecond double
IDC_RESULT m_dresult double
IDC_OPERATION m_noperator int


9. Use class wizard to add the message handler for IDC_COMPUTE
msg;accept Default function name oncomputer().
10. Write the following code for oncompute() function.

PROGRAM:

Write the following code for OnCompute function in the DialogBased MenuDlg.cpp file

void MENUDlg::OnCompute()
{
UpdateData(TRUE);
switch(m_nOperation)
{
case 0:
m_dResult=m_dFirst+m_dSecond;
break;
case 1:
m_dResult=m_dFirst-m_dSecond;
break;
case 2:
m_dResult=m_dFirst*m_dSecond;
break;
case 3:
if(m_dSecond!=0.0)
{
m_dResult=m_dFirst/m_dSecond;
}
{
MessageBox("Divide by zero");
m_dResult=0.0;
}
break;
}
UpdateData(FALSE);
}



Ex. No:6 SDI AND MDI APPLICATION

AIM:
To develop a SDI and MDI application using application wizard.

ALGORITHM:

SDI APPLICATION:

1. Chose new from VC++ file menu.
2. Select the MFC Appwizard(exe) and give project name.
3. Select single document and deselect the document view architecture.
4. Accept all the default settings and press finish.
5. Now the application wizard creates a new SDI project.
6.Add the code in view.cpp file.
7. Edit the onpain() function in childview.cpp and the code is given.
8. Build and run the application.

PROGRAM:
Single Document Interface

Open the file childView.cpp and edit the OnPaint() function

void CChildView::OnPaint()
{
CPaintDC dc(this);
dc.SelectStockObject(2);
dc.Rectangle(10,10,100,100);
dc.SelectStockObject(3);
dc.Ellipse(100,100,200,200);
dc.TextOut(250,250,"welcome to SDI application");
}


MDI APPLICATION:

1. Chose new from VC++ file menu.
2. Select the MFC Appwizard(exe) and give project name.
3. Select Multiple document and deselect the document view architecture.
4. Accept all the default settings.
5. Go to header file and click childview and add the given codes.
6. Edit childview.cpp in source file and add the given codes.
8. Build and run the application.

PROGRAM:
Multiple Document Interface

Add the private variables in CMDIView.h

private:
CRect m_rectEllipse;

Add the initialization code in MDIView.cpp file constructor.

Open the file ChildView.cpp and do the following changes in OnPaint()



Ex. No:7 MENUS AND KEYBOARD ACCELERATOR

AIM:
To develop menu and keyboard accelerator using application wizard.

ALGORITHM:

Step1- Run vc++ application wizard(exe) to create an SDI application and select the document view architecture and deselect the printing and print preview by accepting all the default settings and click finish to design the project.

Step 2 - Use the resource editor to edit the applications main menu

Step 3 - Click on the resource view tab in the workspace window and edit the IDR_MAINFRAME menu resource to add a separator and a clear document item to edit menu.

Step 4 - Fill the following command ids for the new menu items

Menu Caption Command id

Transfer &GetData From Document \t F2 ID_TRANSFER_GETDATA

Step 5 - Use the resource editor to add keyboard accelerator.

Step 6 - Open the IDR_MAINFRAME accelerator table and then use the insert key to add the items.
Accelerator ID Key
ID_TRANSFER_GETDATA VK_F2

Step 7 - Using class wizard select the CMenuViewClass in Class Name and then add the following member functions as shown below

Object ID Message Member function
ID_TRANSFER_GETDATA Command OnTransferGetData

Step 8 - Using class wizard select the Cmenudoc class and the following member functions
Object id Message Member fucntion
ID_EDIT_CLEAR COMMAND OnEditClear
ID_EDIT_CLEAR UPDATE_COMMAND_UI OnUpdateEditClear

Step 9 - Add a CString data member to the CMenuDoc class and edit the file MenuDoc.h

Step 10 - Edit the document class member functions in MenuDoc.cpp

Step 11 - Add a CRichEditCtrl datamember to the CMenuView class and edit the file MenuView.h

Step 12 - Select the classwizard from menu view to map the WM_CREATE and WM_SIZE messages in the CMenuView class.

Step13 - Edit OnCreate( ) Message handler

Step 14 - Edit OnSize( ) Message handler

Step 15 - Edit OnTransferGetdata( ) Message handler

Step 16 - Build and test the program.

PROGRAM:

Add a CString data member to the Cmenudoc class and edit the file MenuDoc.h

Public:
CString m_strWindowText;

Edit the document class member functions in MenuDoc.cpp

BOOL CMenuDoc::OnNewDocument()
{
m_strWindowText = "Copy Successful";
if (!CDocument::OnNewDocument())
return FALSE;
return TRUE;
}

Add a CrichEditCtrl datamember to the cmenuviewclass and edit the file MenuView.h

public:
CRichEditCtrl m_richEdit;

Edit OnCreate( ) Message handler


int CMenuView::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
CRect rect(0,0,0,0);
m_richEdit.Create(ES_AUTOVSCROLL|ES_MULTILINE|ES_WANTRETURN|WS_CHILD|WS_VISIBLE|WS_VSCROLL,rect,this,1);
if (CView::OnCreate(lpCreateStruct) == -1)
return -1;
return 0;
}

Edit OnSize( ) Message handler

void CMenuView::OnSize(UINT nType, int cx, int cy)
{
CView::OnSize(nType, cx, cy);
CRect rect;
GetClientRect(rect);
m_richEdit.SetWindowPos(&wndTop,0,0,rect.right - rect.left,rect.bottom - rect.top,SWP_SHOWWINDOW);
}

Edit OnTransferGetdata( ) Message handler

void CMenuView::OnTransferGetdata()
{
CMenushriDoc* pDoc=GetDocument();
m_richEdit.SetWindowText(pDoc->m_strWindowText);
m_richEdit.SetModify(FALSE);
}


Ex. No:8 TOOLBAR

AIM:
To prepare a tool bar to perform drawing functions.

ALGORITHM:

1. Run vc++ application wizard(exe) to create an SDI application and select the
Document view architecture and deselect the printing and print preview by
Accepting all the default settings and click finish to design the project.

2. Use the resource editor to edit the applications main menu.
3. In resource view,double click on IDR_MAINFRAME under MENU and EDIT
The ID_MAINFRAME menu resource to create a menu.

MENU CAPTION COMMAND ID

Draw Circle ID_DRAW_CIRCLE
Draw Pattern ID_DRAW_PATTERN




4. Use the resource editor to update the application’s toolbar.
5. Edit the IDR_MAINFRAME toolbar resource to create a bitmap.
6. Assign the IDs as ID_DRAW_CIRCLE and ID_DRAW_PATTERN to the two
new buttons.
7. Use class wizard to add CToolBarsStatusView.h view class message handlers
for the following command and update command UI messages.

OBJECT ID MESSAGE MEMBER FUNCTION
ID_DRAW_CIRCLE COMMAND OnDrawCircle
ID_DRAW_CIRCLE UPDATE_COMMAND_UI OnUpdateDrawCircle
ID_DRAW_PATTERN COMMAND OnDrawPattern
ID_DRAW_PATTERN UPDATED_COMMAND_UI OnUpdateDrawPattern

8. Add three data members to the CToolBarStatusView Class and edit the file ToolBarStatusView.cpp.
9. Build and test the application.

PROGRAM:

Edit the ToolBarView.h file and
add the following three data members
private:
Crect m_rect;
BOOL m_bCircle;
BOOL m_Pattern;


Edit the ToolBarView.cpp file as follows.

CToolView::CToolView():m_rect(0,0,150,150)
{
m_bCircle=TRUE;
m_bPattern=FALSE;
}

Edit OnDraw() Function in ToolBarView.cpp file

CToolDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
CBrush brush(HS_BDIAGONAL,5L);
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);

Edit OnDrawCircle() Function in ToolBarView.cpp file

void CToolView::OnDrawCircle()
{
// TODO: Add your command handler code here
m_bCircle=TRUE;
m_rect+=CPoint(25,25);
InvalidateRect(m_rect);
}

Edit OnUpdateDrawCircle() Function in ToolBarView.cpp file

void CToolView::OnUpdateDrawCircle(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->Enable(!m_bCircle);
}

Edit OnDrawPattern() Function in ToolBarView.cpp file

void CToolView::OnDrawPattern()
{
// TODO: Add your command handler code here
m_bPattern ^=1;
}

Edit OnUpdateDrawPattern() Function in ToolBarView.cpp file

void CToolView::OnUpdateDrawPattern(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->SetCheck(m_bPattern);

}

Edit OnDrawSquare() Function in ToolBarView.cpp file

void CToolView::OnDrawSquare()
{
// TODO: Add your command handler code here
m_bCircle=FALSE;
m_rect+=CPoint(25,25);
InvalidateRect(m_rect);
}

Edit OnUpdateDrawSquare() Function in ToolBarView.cpp file

void CToolView::OnUpdateDrawSquare(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->Enable(m_bCircle);
}




Ex. No:9 DYNAMIC LINKING LIBRARY

AIM:
To create a server DLL with a function to display the string and to invoke that function from the client DLL.

ALGORITHM:

1. Run VC++ to create an MFC AppWizard(DLL) and type the project name.
2. Select regular DLL using shared MFC DLL and click finish.
3. Goto class view and right click the MyDLL class and choose new class.
4. Select class type to be generic class and type the class name as CMyclass then
click ok.
5. Then add member function to the CMyClass by right clicking the CMyClass and type the function type as double and function name as calc(double a,double b) and acces type as public.
6. Add the function definition in MyClass.cpp.
7. To call the dll function from external application we have to prefix the function with the signature in myclass.h-declspec(dllexport).
8.complete the code without executing.

DLL CLIENT(testdll.dsw):

1. Run vc++ application wizard(exe) to develop a dialog based application and click finish to develop the project.
2. The resource editor will be enabled on finishing the project and add now design the dialog box.
3. Add the Id for the edit control IDC_NAME and add the add the member variable as m_edit and type as CString by using the class wizard.
4. Use the class wizard to map the message OnOk function for IDOk in the testDlldlg.cpp.
5. Now edit the code no TestDlldlg.cpp.
6. Now add the entire path of MyDll server reader file in TeatDlldlg.
7. Create an object for CMyclass of Mydll in TestDlldlg.cpp as CMyclass.objmyclass.
8. click the project menu and select the settings and click on the link tab type the entire path of Mydll lib file in the object/library modules text box as C:\MyDll\debug\MyDll.lib.
9. Now copy the MyDll.dll in the MyDll debug folder in to the TestDll folder.
10. Now build the project and execute by giving your name on the editbox.press ok.so that the message box will be displayed.

PROGRAM:

Open the file MyClass.cpp and do the following changes in the function SayHello()

CString CMyClass::SayHello(CString StrName)
{
return "Hello"+StrName;
}


________________________________________________________________________

Open the file MyClass.h and do the following changes

public:

_declspec(dllexport)CString SayHello(CString StrName);
_declspec(dllexport)CMyClass();
_declspec(dllexport)virtual ~CMyClass();

_______________________________________________________________________

Open the file testdlldlg.cpp and do the following changes in OnOk() function.

void CTestDLLDlg::OnOK()
{
// TODO: Add extra validation here
UpdateData(TRUE);
CMyClass ObjMyClass;
CString Str = ObjMyClass.SayHello(m_edit);
AfxMessageBox(Str);
CDialog::OnOK();
}


Open the file testDlldlg.h file and include the following statement.

#include "c:\MyDLL\MyDLL\MyClass.h"


Click the project menu and select the settings option and click the link tab and type the path as

"C:\MyDLL\MyDLL\debug\MyDLL.lib" in the object library text box.


Now copy the mydll.dll in the MyDLL debug folder into the testdll folder.



Ex. No:10 ACTIVEX CONTROLS

AIM:
To install ActiveX controls in our program and to perform some operation.

ALGORITHM:

1. Run vc++ application wizard(exe) to create an SDI application and select the document view architecture and deselect the printing and print preview by accepting all the default settings.
2. Select the ActiveX controls in the AppWizard step3 dialog make sure ActiveX controls option is selected.
3. Choose add to project from VC++ project menu,then chosse the components and conrrols.
4. Choose registered ActiveX controls and choose calendar control 8.0.
5. Use the dialog editor to Create a new dialog resource .choose resource from insert menu and then choose dialog and create the dialog.
6. Change the ID of newly created dialog as IDD_ACTIVEXDIALOG Accept default then click ok and CANCEL with ID’s IDOK and IDCANCEL.Select new from file menu, again click c++ source file.
7. Modify the ID of all the controls in the dialog box.Add the ID of the controls in the dialog.

CONTROL ID
Calendar Control IDC_CALENDAR
Select date Button IDC_SELECTDATE
Edit Control IDC_DAY
Edit control IDC_MONTH
Edit Control IDC_YEAR
Next Week Button IDC_NEXTWEEK

8.Use class wizard to create the CActiveXDialog class for newly created Dialog box.Select the class wizard from view menu.
9. Click on the class wizard message maps tab an dthen add the following message handler functions.

OBJECT ID MESSAGE MEMBER FUNCTION
CActiveXDialog WM_INIDIALOG OnInitDialog(virtual function)
IDC_CALENDAR NextMonth(event) OnNewmonthCalendar
IDC_SELECTDATE BN_CLICKED OnSelectDate
IDC_NEXTWEEK BN_CLICKED Onnextweek
IDOK BN_CLICKED OnOk(virtual function)

10.Use class wizard to add datamembers to CActiveXDialog class.Add the data member in the CActiveDialog class by using class wizard.
11.Edit the ActiveXDialog .h and add the m_varvalue and m_back data members.
12.Initialize the m_BackColor value in Active in ActiveDialog.h.
13.Edit the message handling functions OnInitDialog,OnNewMonthCalendar,OnSelectDate,OnNextWeek and OnOk in ActiveDialog.cpp.
14.Add the message handler for the view class for displaying the dialog box on the view window when the user presses the left mouse button.Use class wizard to map the WM_LBUTTONDOWN message and then edit the handler function.
15.Edit the virtual function OnDraw function and include the header file #include”ActiveXDialog.h” in the file
AcitveXcontorlsView.cpp.
16.Build and run the project.

PROGRAM:

Edit the ActiveXDialog.h file and add the data members

// Dialog Data
//{{AFX_DATA(CactiveXDialog)
enum { IDD = IDD_ACTIVEXDIALOG };
Ccalendar m_calendar;
short m_sDay;
short m_sMonth;
short m_sYear;
//}}AFX_DATA
COleVariant m_varValue;
Unsigned long m_BackColor;


Initialize the m_BackColor value in ActiveXDialog.cpp file as,
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;
}

Open the file CActiveXDialog.cpp file and do the following changes on OnInitDialog, OnNewMonthCalendar1, OnSelectDate, OnNextWeek, and OnOk as follows,

BOOL CActiveXDialog::OnInitDialog()
{
CDialog::OnInitDialog();
m_calendar.SetValue(m_varValue);
return TRUE;
}
void CActiveXDialog::OnNewMonthCalendar1()
{
AfxMessageBox(“EVENT:ActiveXDialog::OnNewMonthCalendar1”);
}
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();
}

Use class wizard to map WM_LBUTTONDOWN message and then edit the handler function OnLButtonDown which is as follows.
void CActiveXControlsView::OnLButtonDown(UINT nFlags, CPoint point)
{
CActiveXDialog dlg;
dlg.m_BackColor = RGB(255, 251, 240);
COleDateTime today = COleDateTime::GetCurrentTime();
dlg.m_varValue =OleDateTime(today.GetYear(),today.GetMonth(), today.GetDay(), 0, 0, 0);
if(dlg.DoModal() == IDOk)
{
COleDateTime date(dlg.m_varValue);
AfxMessageBox(date.Format(“%B %d, %Y”);
}
}

Open the ActiveXDialog.cpp file to include the following statements.
#include “ActiveXDialog.h”


Open ActiveXControlView.cpp and do thye following changes in OnDraw function.
void CActiveXControls View::OnDraw(CDC* pDC)
{
pDC->TextOut(0,0,”Press the left mouse here”);
}



Ex. No:11 DATABASE ACCESS THROUGH ODBC

AIM:
To create a database using MS Access the database from VC++ through ODBC database connectivity.

ALGORITHM:

1. Create the database namely purchase with the fields namely book name and cost using MS Access.
2. Run VC++ application wizard to create an SDI application.Accept all the default settings and select MFC AppWizard(exe) and type the project name and select the document view architecture.
3. In step of MFC Appwizard.Select database view with support and click the database button.
4. Then select ODBC and select MS Access database and click ok.
5. Then select the database from the directory where we have created the database and click ok.select the table.
6. Now click OK and then accept all the default settings of the project and click finish and the files developed.Select new from file menu, again click c++ source file
7. Once you click finish a dialog box will appear and design the dialog box as shown.
8.Then create member variables for two variables name and cost.


CONTROL ID TYPE MEMBER
IDC_EDIT1 CString m_text1
IDC_EDIT CString M_text2

9. Then create message handler function for the button and edit the code.
10. Build and run the program.

PROGRAM:

void CDatabaseView::OnButton1()
{
m_text1=m_pSet->m_StudentName;
UpdateData(false);
m_text2=m_pSet->m_RollNo;
UpdateData(false);
m_text4=m_pSet->m_Fee;
UpdateData(false);
}

Ex. No:12 IMPLEMENTATION OF COM

AIM:

To implement COM and to check its functionality using visual basic.

ALGORITHM:

1. Start VC++.
2. Select new from file menu and select Allcom AppWizard.accept all the default
Settings.Clicking Dll and then finish button.
3. Click class file, right click and then select new ATL object.
4. Then click simple object in ATL object wizard and click next.
5. Fill the ATL object wizard attributes and click ok.
6. Right click the project class workspace to add a method.
7. Fill the method name ‘add’ and attributes as [in]long a,[in]long
b,[out]long c and click ok.
8. Right click and write the following code for the function.
9. Save the project, compile the code without executing and the com is
new Created successfully.
10. Now test COM using Visual Basic and open VB6.0 and create a new standard
exe project.
11. Then create a new form and design a button.
12. Select references on the project menu. Browse and select COM project.
13. Open the COM project and select library file and activate COM type
library.
14. Write the following code for the command button.
15. Run the project.


PROGRAM:

STDMETHODIMP CTEST_ATL::add(long a, long b, long *c)
{
*c=a+b;
return S_OK;
}
private sub Command1_Click()
Dim a As KCG_ATL1Lib.TEST_ATL
Set a = New TEST_ATL
Dim x As Long
a.Add 20, 30, x
MsgBox (“20+30”= &x)
End Sub

0 comments:

  © Blogger templates Psi by Ourblogtemplates.com 2008

Back to TOP