SDK Program
SOURCE CODE:
#include<>
const char g_szClassName[]="myWindowClass";
LRESULT CALLBACK WndProc(HWND hwnd,UINT msg,WPARAM wparam,LPARAM lparam)
{
HDC hdc;
PAINTSTRUCT ps;
POINT parray[20]={10,70,50,70,50,10,90,10,90,50,30,50,30,90,70,90,70,30,10,30};
switch(msg)
{
case WM_PAINT:
hdc=BeginPaint(hwnd,&ps);
SelectObject(hdc,GetStockObject(GRAY_BRUSH));
SetPolyFillMode(hdc,ALTERNATE);
Polygon(hdc,parray,10);
CONST POINT;
EndPaint(hwnd,&ps);
return 0;
case WM_CLOSE:
DestroyWindow(hwnd);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd,msg,wparam,lparam);
}
return 0;
}
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpcCmdLine,int nCmdShow)
{
WNDCLASSEX wc;
HWND hwnd;
MSG msg;
wc.cbSize=sizeof(WNDCLASSEX);
wc.style=0;
wc.lpfnWndProc =WndProc;
wc.cbClsExtra =0;
wc.cbWndExtra =0;
wc.hInstance =hInstance;
wc.hIcon =LoadIcon(NULL,IDI_APPLICATION);
wc.hCursor =LoadCursor(NULL,IDC_ARROW);
wc.hbrBackground =(HBRUSH)(COLOR_WINDOW+1);
wc.lpszMenuName =NULL;
wc.lpszClassName =g_szClassName;
wc.hIconSm=LoadIcon(NULL,IDI_APPLICATION);
if(!RegisterClassEx(&wc))
{
MessageBox(NULL,"window registration failed!" ,"ERROR",
MB_ICONEXCLAMATIONMB_OK);
return 0;
}
hwnd=CreateWindowEx(WS_EX_CLIENTEDGE,g_szClassName,"filled area", WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,CW_USEDEFAULT,240,120,
NULL,NULL,hInstance,NULL);
if(hwnd==NULL)
{
MessageBox(NULL,"Window Creation failed!","Error",
MB_ICONEXCLAMATIONMB_OK);
return 0;
}
ShowWindow(hwnd,nCmdShow);
UpdateWindow(hwnd);
while(GetMessage(&msg,NULL,0,0)>0)
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
Creation of Simple windows
SOURCE CODE:
#include<>
LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,PSTR
szCmdLine,int iCmdShow)
{
static TCHAR szAppName[]=TEXT("hellowin");
HWND hwnd;
MSG msg;
WNDCLASS wndclass;
wndclass.style=CS_HREDRAWCS_VREDRAW;
wndclass.lpfnWndProc=WndProc;
wndclass.cbClsExtra =0;
wndclass.cbWndExtra =0;
wndclass.hInstance =hInstance;
wndclass.hIcon =LoadIcon(NULL,IDI_APPLICATION);
wndclass.hCursor =LoadCursor(NULL,IDC_ARROW);
wndclass.hbrBackground =(HBRUSH)GetStockObject(WHITE_BRUSH);
wndclass.lpszMenuName =NULL;
wndclass.lpszClassName =szAppName;
if(!RegisterClass(&wndclass))
{
MessageBox(NULL,TEXT("This Program Requires WindowsNT"),szAppName,MB_ICONERROR);
return 0;
}
hwnd=CreateWindow(szAppName,TEXT("The Hello Program"),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)
{
HDC hdc;
PAINTSTRUCT ps;
RECT rect;
switch(message)
{
case WM_CREATE:
//PlaySound(TEXT("hellowin.wav"),NULL,SND_FILENAMESND_ASYNC);
return 0;
case WM_PAINT:
hdc=BeginPaint(hwnd,&ps);
GetClientRect(hwnd,&rect);
DrawText(hdc,TEXT("Hello, Windows 98!"),-1, &rect,DT_SINGLELINEDT_CENTERDT_VCENTER);
EndPaint(hwnd,&ps);
return 0;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
}
return DefWindowProc(hwnd,message,wparam,lparam);
}
File System Control
Application using file system controls in VB
Screen Design
Private Sub Dir1_Change()
File1.FileName = Dir1.Path
File1.Pattern = "*.txt"
End Sub
Private Sub Drive1_Change()
Dir1.Path = Drive1.Drive
End Sub
Private Sub File1_Click()
x = File1.FileName
fileselected = File1.Path
If Right(fileselected, 1) = "/" Then
fileselected = File1.Path + x
Else
fileselected = File1.Path + "/" + x
End If
Me.RichTextBox1.LoadFile (fileselected)
End Sub
Private Sub Form_Load()
File1.Pattern = "*.txt"
End Sub
Output Screen
control arrays
Source Code
Dim opt As String
Dim a As Double
Dim b As Double
Dim c As Double
Dim i As Integer
Private Sub Command1_Click(Index As Integer)
Select Case Index
Case 0: Text1 = Text1 & "0"
Case 1: Text1 = Text1 & "1"
Case 2: Text1 = Text1 & "2"
Case 3: Text1 = Text1 & "3"
Case 4: Text1 = Text1 & "4"
Case 5: Text1 = Text1 & "5"
Case 6: Text1 = Text1 & "6"
Case 7: Text1 = Text1 & "7"
Case 8: Text1 = Text1 & "8"
Case 9: Text1 = Text1 & "9"
Case 10:
opt = "/"
a = Val(Text1)
Text1 = ""
Case 11:
opt = "*"
a = Val(Text1)
Text1 = ""
Case 12:
opt = "-"
a = Val(Text1)
Text1 = ""
Case 13:
opt = "+"
a = Val(Text1)
Text1 = ""
Case 14:
b = Val(Text1)
If opt = "/" Then
Text1 = a / b
ElseIf opt = "*" Then
Text1 = a * b
ElseIf opt = "-" Then
Text1 = a - b
ElseIf opt = "+" Then
Text1 = a + b
ElseIf opt = "%" Then
Text1 = a Mod b
End If
Case 15:
opt = IIf(InStr(Text1, ".") > 0, "", ".")
Text1 = Text1 & opt
If Left$(Text1, 1) = "0" Then
Text1 = Mid$(Text1, 2)
End If
Case 16:
opt = "%"
a = Val(Text1)
Text1 = ""
Case 17:
opt = "CE"
Text1 = ""
Case 18:
opt = "Backspace"
Text1 = Left(Text1, Len(Text1) - 1)
End Select
End Sub
Output
Employee Pay Roll
Activity Diagram
Sequence Diagram
Login Form
Private Sub Label1_Click(Index As Integer)
Form2.Show
Unload Me
End Sub
Private Sub Label2_Click()
DataReport1.Show
End Sub
Private Sub Label3_Click()
End
End Sub
Pay Slip Form
Source Code
Dim cn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim n As Integer
Private Sub AddNewButt_Click()
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
Text4.Text = ""
Text5.Text = ""
Text6.Text = ""
Text7.Text = ""
Text8.Text = ""
Text9.Text = ""
End Sub
Private Sub BackButt_Click()
Form1.Show
Unload Me
End Sub
Private Sub EditButt_Click()
a = InputBox("Enter the Employee ID")
rs.MoveFirst
Do While Not rs.EOF
If Val(a) = rs.Fields("id") Then
Text1.Text = rs.Fields("id")
Text2.Text = rs.Fields("name")
Text3.Text = rs.Fields("dept")
Text4.Text = rs.Fields("exp")
Text5.Text = rs.Fields("bpay")
Text6.Text = rs.Fields("hra")
Text7.Text = rs.Fields("pf")
Text8.Text = rs.Fields("cca")
Text9.Text = rs.Fields("gpay")
End If
rs.MoveNext
Loop
End Sub
Private Sub Form_Load()
cn.Open (" Provider=MSDASQL.1;Password=tiger;Persist Security Info=True;User ID=scott;Data Source=employee")
rs.Open "select * from emplak", cn, adOpenDynamic, adLockOptimistic
End Sub
Private Sub StoreButt_Click()
If cn.State = 1 Then cn.Close
cn.Open (" Provider=MSDASQL.1;Password=tiger;Persist Security Info=True;User ID=scott;Data Source=employee")
If Text1.Text <> "" And Text2.Text <> "" And Text3.Text <> "" And Text4.Text <> "" And Text5.Text <> "" And Text6.Text <> "" And Text7.Text <> "" And Text8.Text <> "" And Text8.Text <> "" And Text9.Text <> "" Then
cn.Execute ("insert into emplak values(" & Text1.Text & ",'" & Text2.Text & "','" & Text3.Text & "'," & Text4.Text & "," & Text5.Text & "," & Text6.Text & "," & Text7.Text & "," & Text8.Text & "," & Text9.Text & ")")
MsgBox ("UR Record has been Stored")
Else
MsgBox ("You have to Fill all the Fields")
End If
End Sub
Private Sub Text5_LostFocus()
Text6.Text = Val(Text5.Text) * 10 / 100
Text7.Text = Val(Text5.Text) * 12 / 100
Text8.Text = Val(Text5.Text) * 5 / 100
n = Val(Text5.Text) + Val(Text6.Text) + Val(Text8.Text)
Text9.Text = n - Val(Text7.Text)
End Sub
Private Sub UpdateButt_Click()
If cn.State = 1 Then cn.Close
cn.Open (" Provider=MSDASQL.1;Password=tiger;Persist Security Info=True;User ID=scott;Data Source=employee")
cn.Execute ("update emplak set name='" & Text2.Text & "',dept='" & Text3.Text & "',exp=" & Text4.Text & ",bpay=" & Text5.Text & ",hra=" & Text6.Text & ",pf=" & Text7.Text & ",cca=" & Text8.Text & ",gpay=" & Text9.Text & "where id=" & Text1.Text & "")
MsgBox "Updated"
End Sub
Output Screen PaySlip
Source Code Generation
Reverse Engineering
Use Case Diagram
Sequence Diagram for Student
Sequence Diagram for Teacher
Collboration Diagram for Student
Collboration Diagram for Teacher
Activity Diagram
Class Diagram
Component Diagram
#ifndef STUD_H_HEADER_INCLUDED_B603716B#define STUD_H_HEADER_INCLUDED_B603716B
//##ModelId=49FC98430376class STUD{ public: //##ModelId=49FC98710136 WRITE_TEST();
//##ModelId=49FC987803E6 GET_MARKS(); SPORTS();
private: //##ModelId=49FC98630183 NAME;
//##ModelId=49FC986902DB REG_NO;
};
#endif /* STUD_H_HEADER_INCLUDED_B603716B */
//##ModelId=49FC98710136STUD::WRITE_TEST(){}
//##ModelId=49FC987803E6STUD::GET_MARKS(){}
//##ModelId=49FC985103C5class TEACH{ public:
SET_QUESTIONS();
//##ModelId=49FC98B201F4 VALUATION();
//##ModelId=49FC98B9009C PRODUCE_RESULT();
private: //##ModelId=49FC988202EC NAME; EmpID
};
#endif /* TEACH_H_HEADER_INCLUDED_B6031566 */
//##ModelId=49FC98B201F4TEACH::VALUATION(){}
//##ModelId=49FC98B9009CTEACH::PRODUCE_RESULT(){}
Output
CONFIGURATION MANAGEMENT
Run AppWizard to generate toolbar application.
Use the resource editor to edit the application’s main menu.
- In resource view, double – click on IDR_MAINFRAME.
- create a new menu called draw with the following names & command ID’s
Menu Caption Command ID
Draw Circle ID_DRAW_CIRCLE
Draw Square ID_DRAW_SQUARE
Draw Pattern ID_DRAW_PATTERN
3. Use ClassWizard to add toolbarView class message handlers.
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 UPDATE_COMMAND_UI OnUpdateDrawPattern
ID_DRAW_SQUARE COMMAND OnDrawSquare
ID_DRAW_SQUARE UPDATE_COMMAND_UI OnUpdateDrawSquare
4. Add three data members to the toolbarView class.
- edit the file toolbarView.h
private:
CRect m_rect;
BOOL m_bCircle;
BOOL m_bPattern;
5. Edit the toolbarView.cpp file
CtoolbarView :: CtoolbarView() : m_rect (0,0,100,100)
{
m_bCircle = TRUE;
m_bPattern = FALSE;
}
Edit the OnDraw function.
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 -> SelectStockObject (WHITE_BRUSH);
}
Edit the OnDrawCircle, OnDrawSquare and OnDrawPattern function.
void CtoolbarView :: OnDrawCircle()
{
m_bCircle = TRUE;
m_rect += CPoint (25,25);
InvalidateRect (m_rect);
}
void CtoolbarView :: OnDrawSquare()
{
m_bCircle = FALSE;
m_rect += CPoint (25,25);
InvalidateRect (m_rect);
}
void CtoolbarView :: OnDrawPattern()
{
m_bPattern ^= 1;
}
Edit the OnUpdateDrawCircle, OnUpdateDrawSquare and OnUpdateDrawPattern function
void CtoolbarView :: OnUpdateDrawCircle (CCmdUI* pCmdUI)
{
pCmdUI -> Enable (!m-bCircle);
}
void CtoolbarView :: OnUpdateDrawSquare (CCmdUI* pCmdUI)
{
pCmdUI -> Enable (m_bCircle);
}
void CtoolbarView :: OnUpdateDrawPattern (CCmdUI* pCmdUI)
{
pCmdUI -> SetCheck (m_bPattern);
}
8. Build and Test the application.
RE-ENGINEERING
#include " conio.h "
void main()
{
int i,n,a[20],r,*a1,*a2;
clrscr();
printf("Enter No.of Elements: ");
scanf("%d",&n);
printf("Enter the elements:");
for(i=0;i < n;i++)
scanf("%d",&a[i]);
a1=&a[0];
a2=&r;
{
asm
{
asm mov si,a1
asm mov di,a2
asm mov cx,n
asm mov ax,00h
}
here: asm
{
asm mov bx, [si]
asm add ax,bx
asm add si,2
asm loop here
asm mov[di],ax
}
}
for (i=0;i < n;i++)
printf("%d\n0",a[i]);
printf("Sum=%d ",r);
getch();
}
OUTPUT
Enter No.of Elements: 10
Enter the elements: 2 4 6 8 10 12 14 15 16 18
Sum=105